[FFmpeg-devel] [PATCH] Parse DEFINESOUND tags in swf (fix ticket 1638)

Michael Niedermayer michaelni at gmx.at
Tue Oct 9 21:57:40 CEST 2012


On Tue, Oct 09, 2012 at 10:34:34AM -0600, Michael Bradshaw wrote:
> Hi,
> 
> Attached patch fixes ticket 1638 for me. Please review and make sure it's
> sane.
> 
> Thanks,
> 
> Michael

>  swf.h    |    1 +
>  swfdec.c |   37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+)
> 6d9b13586d93dc72c634a1d9f1227475a3dadd49  0003-Parse-DEFINESOUND-tags-in-swf-fix-ticket-1638.patch
> From 7bfcc4c09a2eb230abdbe0efb6c780ecaa9a2775 Mon Sep 17 00:00:00 2001
> From: Michael Bradshaw <mbradshaw at sorensonmedia.com>
> Date: Tue, 9 Oct 2012 10:29:16 -0600
> Subject: [PATCH 3/3] Parse DEFINESOUND tags in swf (fix ticket 1638)
> 
> Signed-off-by: Michael Bradshaw <mbradshaw at sorensonmedia.com>
> ---
>  libavformat/swf.h    |    1 +
>  libavformat/swfdec.c |   37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 38 insertions(+), 0 deletions(-)
> 
> diff --git a/libavformat/swf.h b/libavformat/swf.h
> index 5f0d486..4e8f877 100644
> --- a/libavformat/swf.h
> +++ b/libavformat/swf.h
> @@ -44,6 +44,7 @@
>  #define TAG_FREECHARACTER 3
>  #define TAG_PLACEOBJECT   4
>  #define TAG_REMOVEOBJECT  5
> +#define TAG_DEFINESOUND   14
>  #define TAG_STREAMHEAD    18
>  #define TAG_STREAMBLOCK   19
>  #define TAG_JPEG2         21
> diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
> index 3967d82..b8c7c7c 100644
> --- a/libavformat/swfdec.c
> +++ b/libavformat/swfdec.c
> @@ -200,6 +200,43 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
>              ast->codec->sample_rate = 44100 >> (3 - sample_rate_code);
>              avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
>              len -= 4;
> +        } else if (tag == TAG_DEFINESOUND) {
> +            /* audio stream */
> +            int sample_rate_code;
> +            int ch_id = avio_rl16(pb);
> +
> +            for (i=0; i<s->nb_streams; i++) {
> +                st = s->streams[i];
> +                if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == ch_id)
> +                    goto skip;
> +            }
> +
> +            // Note: 8-bit uncompressed PCM audio will be interpreted as 16-bit
> +            v = avio_r8(pb);
> +            ast = avformat_new_stream(s, NULL);
> +            if (!ast)
> +                return -1;
> +            ast->id = ch_id;
> +            ast->codec->channels = 1 + (v&1);
> +            ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +            ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15);
> +            ast->need_parsing = AVSTREAM_PARSE_FULL;
> +            sample_rate_code= (v>>2) & 3;
> +            ast->codec->sample_rate = 44100 >> (3 - sample_rate_code);

> +            avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate);

> +            ast->time_base.num = 1;
> +            ast->time_base.den = ast->codec->sample_rate;

these 2 should be redundant


> +            ast->duration = avio_rl32(pb); // number of samples
> +            if (((v>>4) & 15) == 2) { // MP3 sound data record
> +                ast->skip_samples = avio_rl16(pb);
> +                len -= 2;
> +            }
> +            len -= 7;

> +            if ((res = av_get_packet(pb, pkt, len)) < 0)
> +                return res;

can this chunk be big ? i mean 100mb or so ?
if this happens in realworld files its probably better to split in
some fixed size packets to reduce memory need and latency until its
fully loaded


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121009/52878010/attachment.asc>


More information about the ffmpeg-devel mailing list