changeset 9115:1b68b8e9b4c9 libavcodec

flacdec: Avoid parsing the STREAMINFO multiple times.
author jbr
date Tue, 03 Mar 2009 23:49:36 +0000
parents 3bf99f635933
children cd1e39c1fa42
files flacdec.c
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }