comparison flacdec.c @ 9115:1b68b8e9b4c9 libavcodec

flacdec: Avoid parsing the STREAMINFO multiple times.
author jbr
date Tue, 03 Mar 2009 23:49:36 +0000
parents 8053722e1c7f
children cd1e39c1fa42
comparison
equal deleted inserted replaced
9114:3bf99f635933 9115:1b68b8e9b4c9
64 int blocksize; ///< number of samples in the current frame 64 int blocksize; ///< number of samples in the current frame
65 int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits 65 int curr_bps; ///< bps for current subframe, adjusted for channel correlation and wasted bits
66 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit 66 int sample_shift; ///< shift required to make output samples 16-bit or 32-bit
67 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit 67 int is32; ///< flag to indicate if output should be 32-bit instead of 16-bit
68 enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame 68 enum decorrelation_type decorrelation; ///< channel decorrelation type in the current frame
69 int got_streaminfo; ///< indicates if the STREAMINFO has been read
69 70
70 int32_t *decoded[MAX_CHANNELS]; ///< decoded samples 71 int32_t *decoded[MAX_CHANNELS]; ///< decoded samples
71 uint8_t *bitstream; 72 uint8_t *bitstream;
72 unsigned int bitstream_size; 73 unsigned int bitstream_size;
73 unsigned int bitstream_index; 74 unsigned int bitstream_index;
142 return -1; 143 return -1;
143 144
144 /* initialize based on the demuxer-supplied streamdata header */ 145 /* initialize based on the demuxer-supplied streamdata header */
145 ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); 146 ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo);
146 allocate_buffers(s); 147 allocate_buffers(s);
148 s->got_streaminfo = 1;
147 149
148 return 0; 150 return 0;
149 } 151 }
150 152
151 static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s) 153 static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
224 * parse metadata 226 * parse metadata
225 * @return 1 if some metadata was read, 0 if no fLaC marker was found 227 * @return 1 if some metadata was read, 0 if no fLaC marker was found
226 */ 228 */
227 static int metadata_parse(FLACContext *s) 229 static int metadata_parse(FLACContext *s)
228 { 230 {
229 int i, metadata_last, metadata_type, metadata_size, streaminfo_updated=0; 231 int i, metadata_last, metadata_type, metadata_size;
230 int initial_pos= get_bits_count(&s->gb); 232 int initial_pos= get_bits_count(&s->gb);
231 233
232 if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) { 234 if (show_bits_long(&s->gb, 32) == MKBETAG('f','L','a','C')) {
233 skip_bits_long(&s->gb, 32); 235 skip_bits_long(&s->gb, 32);
234 236
243 } 245 }
244 246
245 if (metadata_size) { 247 if (metadata_size) {
246 switch (metadata_type) { 248 switch (metadata_type) {
247 case FLAC_METADATA_TYPE_STREAMINFO: 249 case FLAC_METADATA_TYPE_STREAMINFO:
250 if (!s->got_streaminfo) {
248 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, 251 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s,
249 s->gb.buffer+get_bits_count(&s->gb)/8); 252 s->gb.buffer+get_bits_count(&s->gb)/8);
250 streaminfo_updated = 1; 253 s->got_streaminfo = 1;
251 254 }
252 default: 255 default:
253 for (i = 0; i < metadata_size; i++) 256 for (i = 0; i < metadata_size; i++)
254 skip_bits(&s->gb, 8); 257 skip_bits(&s->gb, 8);
255 } 258 }
256 } 259 }
257 } while (!metadata_last); 260 } while (!metadata_last);
258 261
259 if (streaminfo_updated) 262 if (s->got_streaminfo)
260 allocate_buffers(s); 263 allocate_buffers(s);
261 return 1; 264 return 1;
262 } 265 }
263 return 0; 266 return 0;
264 } 267 }