# HG changeset patch # User jbr # Date 1236124176 0 # Node ID 1b68b8e9b4c9a7a27cae02a0a5b4210ab7263551 # Parent 3bf99f6359338177d37dc995c6408464c6505ee7 flacdec: Avoid parsing the STREAMINFO multiple times. diff -r 3bf99f635933 -r 1b68b8e9b4c9 flacdec.c --- a/flacdec.c Tue Mar 03 22:51:30 2009 +0000 +++ b/flacdec.c Tue Mar 03 23:49:36 2009 +0000 @@ -66,6 +66,7 @@ int sample_shift; ///< shift required to make output samples 16-bit or 32-bit int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame + int got_streaminfo; ///< indicates if the STREAMINFO has been read int32_t *decoded[MAX_CHANNELS]; ///< decoded samples uint8_t *bitstream; @@ -144,6 +145,7 @@ /* initialize based on the demuxer-supplied streamdata header */ ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); allocate_buffers(s); + s->got_streaminfo = 1; return 0; } @@ -226,7 +228,7 @@ */ static int metadata_parse(FLACContext *s) { - int i, metadata_last, metadata_type, metadata_size, streaminfo_updated=0; + int i, metadata_last, metadata_type, metadata_size; int initial_pos= get_bits_count(&s->gb); if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) { @@ -245,10 +247,11 @@ if (metadata_size) { switch (metadata_type) { case FLAC_METADATA_TYPE_STREAMINFO: + if (!s->got_streaminfo) { ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, s->gb.buffer+get_bits_count(&s->gb)/8); - streaminfo_updated = 1; - + s->got_streaminfo = 1; + } default: for (i = 0; i < metadata_size; i++) skip_bits(&s->gb, 8); @@ -256,7 +259,7 @@ } } while (!metadata_last); - if (streaminfo_updated) + if (s->got_streaminfo) allocate_buffers(s); return 1; }