[FFmpeg-devel] [PATCH] flac demuxer

Michael Niedermayer michaelni
Thu May 1 11:17:35 CEST 2008


On Wed, Apr 30, 2008 at 10:15:35PM -0400, Justin Ruggles wrote:
> Hi,
> 
> I wrote:
> > I'll make the appropriate changes and submit new patch(es).
> 
> Here are 6 new patches which do the same as the last patch.
> 
> -Justin
> 
> 
> 

> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index b849e7f..bb92bb0 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -94,7 +94,7 @@ static int64_t get_utf8(GetBitContext *gb){
>      return val;
>  }
>  
> -static void metadata_streaminfo(FLACContext *s);
> +static void metadata_streaminfo(AVCodecContext *avctx, FLACContext *s, const uint8_t *buffer);
>  static void allocate_buffers(FLACContext *s);
>  static int metadata_parse(FLACContext *s);
>  
> @@ -107,7 +107,7 @@ static av_cold int flac_decode_init(AVCodecContext * avctx)
>          /* initialize based on the demuxer-supplied streamdata header */
>          init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
>          if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
> -            metadata_streaminfo(s);
> +            metadata_streaminfo(avctx, s, avctx->extradata);
>              allocate_buffers(s);
>          } else {
>              metadata_parse(s);
> @@ -143,26 +143,30 @@ static void allocate_buffers(FLACContext *s){
>      s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
>  }
>  
> -static void metadata_streaminfo(FLACContext *s)
> +static void metadata_streaminfo(AVCodecContext *avctx, FLACContext *s,
> +                                const uint8_t *buffer)
>  {
> +    GetBitContext gb;
> +    init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8);
> +
>      /* mandatory streaminfo */
> -    s->min_blocksize = get_bits(&s->gb, 16);
> -    s->max_blocksize = get_bits(&s->gb, 16);
> +    s->min_blocksize = get_bits(&gb, 16);
> +    s->max_blocksize = get_bits(&gb, 16);
>  
> -    skip_bits(&s->gb, 24); /* skip min frame size */
> -    s->max_framesize = get_bits_long(&s->gb, 24);
> +    skip_bits(&gb, 24); /* skip min frame size */
> +    s->max_framesize = get_bits_long(&gb, 24);
>  
> -    s->samplerate = get_bits_long(&s->gb, 20);
> -    s->channels = get_bits(&s->gb, 3) + 1;
> -    s->bps = get_bits(&s->gb, 5) + 1;
> +    s->samplerate = get_bits_long(&gb, 20);
> +    s->channels = get_bits(&gb, 3) + 1;
> +    s->bps = get_bits(&gb, 5) + 1;
>  
> -    s->avctx->channels = s->channels;
> -    s->avctx->sample_rate = s->samplerate;
> +    avctx->channels = s->channels;
> +    avctx->sample_rate = s->samplerate;
>  
> -    skip_bits(&s->gb, 36); /* total num of samples */
> +    skip_bits(&gb, 36); /* total num of samples */
>  
> -    skip_bits(&s->gb, 64); /* md5 sum */
> -    skip_bits(&s->gb, 64); /* md5 sum */
> +    skip_bits(&gb, 64); /* md5 sum */
> +    skip_bits(&gb, 64); /* md5 sum */
>  
>      dump_headers(s);
>  }
> @@ -193,9 +197,8 @@ static int metadata_parse(FLACContext *s)
>              if (metadata_size) {
>                  switch (metadata_type) {
>                  case METADATA_TYPE_STREAMINFO:
> -                    metadata_streaminfo(s);
> +                    metadata_streaminfo(s->avctx, s, s->gb.buffer+get_bits_count(&s->gb)/8);
>                      streaminfo_updated = 1;
> -                    break;
>  
>                  default:
>                      for (i=0; i<metadata_size; i++)

ok



> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index bb92bb0..28e25e7 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -117,13 +117,13 @@ static av_cold int flac_decode_init(AVCodecContext * avctx)
>      return 0;
>  }
>  
> -static void dump_headers(FLACContext *s)
> +static void dump_headers(AVCodecContext *avctx, FLACContext *s)
>  {
> -    av_log(s->avctx, AV_LOG_DEBUG, "  Blocksize: %d .. %d (%d)\n", s->min_blocksize, s->max_blocksize, s->blocksize);
> -    av_log(s->avctx, AV_LOG_DEBUG, "  Max Framesize: %d\n", s->max_framesize);
> -    av_log(s->avctx, AV_LOG_DEBUG, "  Samplerate: %d\n", s->samplerate);
> -    av_log(s->avctx, AV_LOG_DEBUG, "  Channels: %d\n", s->channels);
> -    av_log(s->avctx, AV_LOG_DEBUG, "  Bits: %d\n", s->bps);
> +    av_log(avctx, AV_LOG_DEBUG, "  Blocksize: %d .. %d (%d)\n", s->min_blocksize, s->max_blocksize, s->blocksize);
> +    av_log(avctx, AV_LOG_DEBUG, "  Max Framesize: %d\n", s->max_framesize);
> +    av_log(avctx, AV_LOG_DEBUG, "  Samplerate: %d\n", s->samplerate);
> +    av_log(avctx, AV_LOG_DEBUG, "  Channels: %d\n", s->channels);
> +    av_log(avctx, AV_LOG_DEBUG, "  Bits: %d\n", s->bps);
>  }
>  
>  static void allocate_buffers(FLACContext *s){
> @@ -168,7 +168,7 @@ static void metadata_streaminfo(AVCodecContext *avctx, FLACContext *s,
>      skip_bits(&gb, 64); /* md5 sum */
>      skip_bits(&gb, 64); /* md5 sum */
>  
> -    dump_headers(s);
> +    dump_headers(avctx, s);
>  }
>  
>  /**
> @@ -573,7 +573,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
>      s->bps          = bps;
>      s->decorrelation= decorrelation;
>  
> -//    dump_headers(s);
> +//    dump_headers(s->avctx, s);
>  
>      /* subframes */
>      for (i = 0; i < s->channels; i++)

ok


> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index 28e25e7..fb1ac49 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -119,7 +119,7 @@ static av_cold int flac_decode_init(AVCodecContext * avctx)
>  
>  static void dump_headers(AVCodecContext *avctx, FLACContext *s)
>  {
> -    av_log(avctx, AV_LOG_DEBUG, "  Blocksize: %d .. %d (%d)\n", s->min_blocksize, s->max_blocksize, s->blocksize);
> +    av_log(avctx, AV_LOG_DEBUG, "  Blocksize: %d .. %d\n", s->min_blocksize, s->max_blocksize);
>      av_log(avctx, AV_LOG_DEBUG, "  Max Framesize: %d\n", s->max_framesize);
>      av_log(avctx, AV_LOG_DEBUG, "  Samplerate: %d\n", s->samplerate);
>      av_log(avctx, AV_LOG_DEBUG, "  Channels: %d\n", s->channels);

why?


[...]
> +#ifndef FFMPEG_FLAC_H
> +#define FFMPEG_FLAC_H
> +
> +#include "avcodec.h"
> +
> +/**
> + * Data needed from the Streaminfo header for use by the raw FLAC demuxer
> + * and/or the FLAC decoder.
> + */
> +#define FLACSTREAMINFO \
> +    int min_blocksize;      /**< minimum block size, in samples          */\
> +    int max_blocksize;      /**< maximum block size, in samples          */\
> +    int max_framesize;      /**< maximum frame size, in bytes            */\
> +    int samplerate;         /**< sample rate                             */\
> +    int channels;           /**< number of channels                      */\
> +    int bps;                /**< bits-per-sample                         */\
> +
> +#endif /* FFMPEG_FLAC_H */

This file does NOT need avcodec.h


[...]
> diff --git a/libavcodec/flac.c b/libavcodec/flac.c
> index 60cd2aa..729f61a 100644
> --- a/libavcodec/flac.c
> +++ b/libavcodec/flac.c
> @@ -104,11 +104,11 @@ static av_cold int flac_decode_init(AVCodecContext * avctx)
>  
>      if (avctx->extradata_size > 4) {
>          /* initialize based on the demuxer-supplied streamdata header */
> -        init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
>          if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
>              ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, avctx->extradata);
>              allocate_buffers(s);
>          } else {
> +            init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
>              metadata_parse(s);
>          }
>      }

ok


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

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080501/fe7f1087/attachment.pgp>



More information about the ffmpeg-devel mailing list