comparison flacdec.c @ 8658:dc8fd7c55928 libavcodec

flacdec: cosmetics: some line wrapping at 80 chars
author jbr
date Sat, 24 Jan 2009 19:05:52 +0000
parents 62c52fff9ac0
children 61ae841cd13e
comparison
equal deleted inserted replaced
8657:62c52fff9ac0 8658:dc8fd7c55928
105 s->avctx = avctx; 105 s->avctx = avctx;
106 106
107 if (avctx->extradata_size > 4) { 107 if (avctx->extradata_size > 4) {
108 /* initialize based on the demuxer-supplied streamdata header */ 108 /* initialize based on the demuxer-supplied streamdata header */
109 if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) { 109 if (avctx->extradata_size == FLAC_STREAMINFO_SIZE) {
110 ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, avctx->extradata); 110 ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s,
111 avctx->extradata);
111 allocate_buffers(s); 112 allocate_buffers(s);
112 } else { 113 } else {
113 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); 114 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
114 metadata_parse(s); 115 metadata_parse(s);
115 } 116 }
119 return 0; 120 return 0;
120 } 121 }
121 122
122 static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s) 123 static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
123 { 124 {
124 av_log(avctx, AV_LOG_DEBUG, " Blocksize: %d .. %d\n", s->min_blocksize, s->max_blocksize); 125 av_log(avctx, AV_LOG_DEBUG, " Blocksize: %d .. %d\n", s->min_blocksize,
126 s->max_blocksize);
125 av_log(avctx, AV_LOG_DEBUG, " Max Framesize: %d\n", s->max_framesize); 127 av_log(avctx, AV_LOG_DEBUG, " Max Framesize: %d\n", s->max_framesize);
126 av_log(avctx, AV_LOG_DEBUG, " Samplerate: %d\n", s->samplerate); 128 av_log(avctx, AV_LOG_DEBUG, " Samplerate: %d\n", s->samplerate);
127 av_log(avctx, AV_LOG_DEBUG, " Channels: %d\n", s->channels); 129 av_log(avctx, AV_LOG_DEBUG, " Channels: %d\n", s->channels);
128 av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps); 130 av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps);
129 } 131 }
133 int i; 135 int i;
134 136
135 assert(s->max_blocksize); 137 assert(s->max_blocksize);
136 138
137 if (s->max_framesize == 0 && s->max_blocksize) { 139 if (s->max_framesize == 0 && s->max_blocksize) {
138 s->max_framesize= (s->channels * s->bps * s->max_blocksize + 7)/ 8; //FIXME header overhead 140 // FIXME header overhead
141 s->max_framesize= (s->channels * s->bps * s->max_blocksize + 7)/ 8;
139 } 142 }
140 143
141 for (i = 0; i < s->channels; i++) { 144 for (i = 0; i < s->channels; i++) {
142 s->decoded[i] = av_realloc(s->decoded[i], sizeof(int32_t)*s->max_blocksize); 145 s->decoded[i] = av_realloc(s->decoded[i],
146 sizeof(int32_t)*s->max_blocksize);
143 } 147 }
144 148
145 if (s->allocated_bitstream_size < s->max_framesize) 149 if (s->allocated_bitstream_size < s->max_framesize)
146 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); 150 s->bitstream= av_fast_realloc(s->bitstream,
151 &s->allocated_bitstream_size,
152 s->max_framesize);
147 } 153 }
148 154
149 void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, 155 void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
150 const uint8_t *buffer) 156 const uint8_t *buffer)
151 { 157 {
200 } 206 }
201 207
202 if (metadata_size) { 208 if (metadata_size) {
203 switch (metadata_type) { 209 switch (metadata_type) {
204 case METADATA_TYPE_STREAMINFO: 210 case METADATA_TYPE_STREAMINFO:
205 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, s->gb.buffer+get_bits_count(&s->gb)/8); 211 ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s,
212 s->gb.buffer+get_bits_count(&s->gb)/8);
206 streaminfo_updated = 1; 213 streaminfo_updated = 1;
207 214
208 default: 215 default:
209 for (i = 0; i < metadata_size; i++) 216 for (i = 0; i < metadata_size; i++)
210 skip_bits(&s->gb, 8); 217 skip_bits(&s->gb, 8);
224 int i, tmp, partition, method_type, rice_order; 231 int i, tmp, partition, method_type, rice_order;
225 int sample = 0, samples; 232 int sample = 0, samples;
226 233
227 method_type = get_bits(&s->gb, 2); 234 method_type = get_bits(&s->gb, 2);
228 if (method_type > 1) { 235 if (method_type > 1) {
229 av_log(s->avctx, AV_LOG_ERROR, "illegal residual coding method %d\n", method_type); 236 av_log(s->avctx, AV_LOG_ERROR, "illegal residual coding method %d\n",
237 method_type);
230 return -1; 238 return -1;
231 } 239 }
232 240
233 rice_order = get_bits(&s->gb, 4); 241 rice_order = get_bits(&s->gb, 4);
234 242
235 samples= s->blocksize >> rice_order; 243 samples= s->blocksize >> rice_order;
236 if (pred_order > samples) { 244 if (pred_order > samples) {
237 av_log(s->avctx, AV_LOG_ERROR, "invalid predictor order: %i > %i\n", pred_order, samples); 245 av_log(s->avctx, AV_LOG_ERROR, "invalid predictor order: %i > %i\n",
246 pred_order, samples);
238 return -1; 247 return -1;
239 } 248 }
240 249
241 sample= 250 sample=
242 i= pred_order; 251 i= pred_order;
324 av_log(s->avctx, AV_LOG_ERROR, "invalid coeff precision\n"); 333 av_log(s->avctx, AV_LOG_ERROR, "invalid coeff precision\n");
325 return -1; 334 return -1;
326 } 335 }
327 qlevel = get_sbits(&s->gb, 5); 336 qlevel = get_sbits(&s->gb, 5);
328 if (qlevel < 0) { 337 if (qlevel < 0) {
329 av_log(s->avctx, AV_LOG_ERROR, "qlevel %d not supported, maybe buggy stream\n", qlevel); 338 av_log(s->avctx, AV_LOG_ERROR, "qlevel %d not supported, maybe buggy stream\n",
339 qlevel);
330 return -1; 340 return -1;
331 } 341 }
332 342
333 for (i = 0; i < pred_order; i++) { 343 for (i = 0; i < pred_order; i++) {
334 coeffs[i] = get_sbits(&s->gb, coeff_prec); 344 coeffs[i] = get_sbits(&s->gb, coeff_prec);
441 if (assignment < 8 && s->channels == assignment+1) 451 if (assignment < 8 && s->channels == assignment+1)
442 decorrelation = INDEPENDENT; 452 decorrelation = INDEPENDENT;
443 else if (assignment >=8 && assignment < 11 && s->channels == 2) 453 else if (assignment >=8 && assignment < 11 && s->channels == 2)
444 decorrelation = LEFT_SIDE + assignment - 8; 454 decorrelation = LEFT_SIDE + assignment - 8;
445 else { 455 else {
446 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", assignment, s->channels); 456 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",
457 assignment, s->channels);
447 return -1; 458 return -1;
448 } 459 }
449 460
450 sample_size_code = get_bits(&s->gb, 3); 461 sample_size_code = get_bits(&s->gb, 3);
451 if (sample_size_code == 0) 462 if (sample_size_code == 0)
452 bps= s->bps; 463 bps= s->bps;
453 else if ((sample_size_code != 3) && (sample_size_code != 7)) 464 else if ((sample_size_code != 3) && (sample_size_code != 7))
454 bps = sample_size_table[sample_size_code]; 465 bps = sample_size_table[sample_size_code];
455 else { 466 else {
456 av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", sample_size_code); 467 av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n",
468 sample_size_code);
457 return -1; 469 return -1;
458 } 470 }
459 471
460 if (get_bits1(&s->gb)) { 472 if (get_bits1(&s->gb)) {
461 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); 473 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");
475 blocksize = get_bits(&s->gb, 16)+1; 487 blocksize = get_bits(&s->gb, 16)+1;
476 else 488 else
477 blocksize = blocksize_table[blocksize_code]; 489 blocksize = blocksize_table[blocksize_code];
478 490
479 if (blocksize > s->max_blocksize) { 491 if (blocksize > s->max_blocksize) {
480 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, s->max_blocksize); 492 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize,
493 s->max_blocksize);
481 return -1; 494 return -1;
482 } 495 }
483 496
484 if (blocksize * s->channels * sizeof(int16_t) > alloc_data_size) 497 if (blocksize * s->channels * sizeof(int16_t) > alloc_data_size)
485 return -1; 498 return -1;
493 else if (sample_rate_code == 13) 506 else if (sample_rate_code == 13)
494 samplerate = get_bits(&s->gb, 16); 507 samplerate = get_bits(&s->gb, 16);
495 else if (sample_rate_code == 14) 508 else if (sample_rate_code == 14)
496 samplerate = get_bits(&s->gb, 16) * 10; 509 samplerate = get_bits(&s->gb, 16) * 10;
497 else { 510 else {
498 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", sample_rate_code); 511 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",
512 sample_rate_code);
499 return -1; 513 return -1;
500 } 514 }
501 515
502 skip_bits(&s->gb, 8); 516 skip_bits(&s->gb, 8);
503 crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, 517 crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
554 568
555 if (s->allocated_bitstream_size < s->bitstream_size + buf_size) 569 if (s->allocated_bitstream_size < s->bitstream_size + buf_size)
556 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size); 570 s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->bitstream_size + buf_size);
557 571
558 if (s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size) { 572 if (s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size) {
559 memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); 573 memmove(s->bitstream, &s->bitstream[s->bitstream_index],
574 s->bitstream_size);
560 s->bitstream_index=0; 575 s->bitstream_index=0;
561 } 576 }
562 memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); 577 memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size],
578 buf, buf_size);
563 buf= &s->bitstream[s->bitstream_index]; 579 buf= &s->bitstream[s->bitstream_index];
564 buf_size += s->bitstream_size; 580 buf_size += s->bitstream_size;
565 s->bitstream_size= buf_size; 581 s->bitstream_size= buf_size;
566 582
567 if (buf_size < s->max_framesize && input_buf_size) { 583 if (buf_size < s->max_framesize && input_buf_size) {