comparison flac.c @ 6729:071888974d8a libavcodec

share streaminfo parsing function
author jbr
date Fri, 02 May 2008 21:34:34 +0000
parents 56c5bbd0996f
children 362abbd862f1
comparison
equal deleted inserted replaced
6728:56c5bbd0996f 6729:071888974d8a
92 int64_t val; 92 int64_t val;
93 GET_UTF8(val, get_bits(gb, 8), return -1;) 93 GET_UTF8(val, get_bits(gb, 8), return -1;)
94 return val; 94 return val;
95 } 95 }
96 96
97 static void metadata_streaminfo(AVCodecContext *avctx, FLACContext *s, const uint8_t *buffer);
98 static void allocate_buffers(FLACContext *s); 97 static void allocate_buffers(FLACContext *s);
99 static int metadata_parse(FLACContext *s); 98 static int metadata_parse(FLACContext *s);
100 99
101 static av_cold int flac_decode_init(AVCodecContext * avctx) 100 static av_cold int flac_decode_init(AVCodecContext * avctx)
102 { 101 {
105 104
106 if (avctx->extradata_size > 4) { 105 if (avctx->extradata_size > 4) {
107 /* initialize based on the demuxer-supplied streamdata header */ 106 /* initialize based on the demuxer-supplied streamdata header */
108 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); 107 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
109 if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) { 108 if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
110 metadata_streaminfo(avctx, s, avctx->extradata); 109 ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, avctx->extradata);
111 allocate_buffers(s); 110 allocate_buffers(s);
112 } else { 111 } else {
113 metadata_parse(s); 112 metadata_parse(s);
114 } 113 }
115 } 114 }
116 115
117 return 0; 116 return 0;
118 } 117 }
119 118
120 static void dump_headers(AVCodecContext *avctx, FLACContext *s) 119 static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
121 { 120 {
122 av_log(avctx, AV_LOG_DEBUG, " Blocksize: %d .. %d (%d)\n", s->min_blocksize, s->max_blocksize, s->blocksize); 121 av_log(avctx, AV_LOG_DEBUG, " Blocksize: %d .. %d\n", s->min_blocksize, s->max_blocksize);
123 av_log(avctx, AV_LOG_DEBUG, " Max Framesize: %d\n", s->max_framesize); 122 av_log(avctx, AV_LOG_DEBUG, " Max Framesize: %d\n", s->max_framesize);
124 av_log(avctx, AV_LOG_DEBUG, " Samplerate: %d\n", s->samplerate); 123 av_log(avctx, AV_LOG_DEBUG, " Samplerate: %d\n", s->samplerate);
125 av_log(avctx, AV_LOG_DEBUG, " Channels: %d\n", s->channels); 124 av_log(avctx, AV_LOG_DEBUG, " Channels: %d\n", s->channels);
126 av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps); 125 av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps);
127 } 126 }
141 } 140 }
142 141
143 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); 142 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize);
144 } 143 }
145 144
146 static void metadata_streaminfo(AVCodecContext *avctx, FLACContext *s, 145 void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
147 const uint8_t *buffer) 146 const uint8_t *buffer)
148 { 147 {
149 GetBitContext gb; 148 GetBitContext gb;
150 init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8); 149 init_get_bits(&gb, buffer, FLAC_STREAMINFO_SIZE*8);
151 150
152 /* mandatory streaminfo */ 151 /* mandatory streaminfo */
195 " metadata block: flag = %d, type = %d, size = %d\n", 194 " metadata block: flag = %d, type = %d, size = %d\n",
196 metadata_last, metadata_type, metadata_size); 195 metadata_last, metadata_type, metadata_size);
197 if (metadata_size) { 196 if (metadata_size) {
198 switch (metadata_type) { 197 switch (metadata_type) {
199 case METADATA_TYPE_STREAMINFO: 198 case METADATA_TYPE_STREAMINFO:
200 metadata_streaminfo(s->avctx, s, s->gb.buffer+get_bits_count(&s->gb)/8); 199 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, s->gb.buffer+get_bits_count(&s->gb)/8);
201 streaminfo_updated = 1; 200 streaminfo_updated = 1;
202 201
203 default: 202 default:
204 for (i=0; i<metadata_size; i++) 203 for (i=0; i<metadata_size; i++)
205 skip_bits(&s->gb, 8); 204 skip_bits(&s->gb, 8);
571 s->blocksize = blocksize; 570 s->blocksize = blocksize;
572 s->samplerate = samplerate; 571 s->samplerate = samplerate;
573 s->bps = bps; 572 s->bps = bps;
574 s->decorrelation= decorrelation; 573 s->decorrelation= decorrelation;
575 574
576 // dump_headers(s->avctx, s); 575 // dump_headers(s->avctx, (FLACStreaminfo *)s);
577 576
578 /* subframes */ 577 /* subframes */
579 for (i = 0; i < s->channels; i++) 578 for (i = 0; i < s->channels; i++)
580 { 579 {
581 // av_log(s->avctx, AV_LOG_DEBUG, "decoded: %x residual: %x\n", s->decoded[i], s->residual[i]); 580 // av_log(s->avctx, AV_LOG_DEBUG, "decoded: %x residual: %x\n", s->decoded[i], s->residual[i]);