comparison flacdec.c @ 9232:2c3b2ce51b04 libavcodec

flacdec: comments and white space. move skipping of frame header to decode_frame()
author jbr
date Sun, 22 Mar 2009 19:12:02 +0000
parents 35370ebfbeeb
children 8aa63f696237
comparison
equal deleted inserted replaced
9231:e150ca8d7f91 9232:2c3b2ce51b04
484 { 484 {
485 int bs_code, sr_code, bps_code, i; 485 int bs_code, sr_code, bps_code, i;
486 int ch_mode, bps, blocksize, samplerate; 486 int ch_mode, bps, blocksize, samplerate;
487 GetBitContext *gb = &s->gb; 487 GetBitContext *gb = &s->gb;
488 488
489 /* frame sync code */
490 skip_bits(&s->gb, 16);
491
492 /* block size and sample rate codes */
489 bs_code = get_bits(gb, 4); 493 bs_code = get_bits(gb, 4);
490
491 sr_code = get_bits(gb, 4); 494 sr_code = get_bits(gb, 4);
492 495
493 ch_mode = get_bits(gb, 4); /* channel assignment */ 496 /* channels and decorrelation */
497 ch_mode = get_bits(gb, 4);
494 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) { 498 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) {
495 ch_mode = FLAC_CHMODE_INDEPENDENT; 499 ch_mode = FLAC_CHMODE_INDEPENDENT;
496 } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) { 500 } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) {
497 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", 501 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",
498 ch_mode, s->channels); 502 ch_mode, s->channels);
499 return -1; 503 return -1;
500 } 504 }
501 505
506 /* bits per sample */
502 bps_code = get_bits(gb, 3); 507 bps_code = get_bits(gb, 3);
503 if (bps_code == 0) 508 if (bps_code == 0)
504 bps= s->bps; 509 bps= s->bps;
505 else if ((bps_code != 3) && (bps_code != 7)) 510 else if ((bps_code != 3) && (bps_code != 7))
506 bps = sample_size_table[bps_code]; 511 bps = sample_size_table[bps_code];
518 s->sample_shift = 16 - bps; 523 s->sample_shift = 16 - bps;
519 s->is32 = 0; 524 s->is32 = 0;
520 } 525 }
521 s->bps = s->avctx->bits_per_raw_sample = bps; 526 s->bps = s->avctx->bits_per_raw_sample = bps;
522 527
528 /* reserved bit */
523 if (get_bits1(gb)) { 529 if (get_bits1(gb)) {
524 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); 530 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");
525 return -1; 531 return -1;
526 } 532 }
527 533
534 /* sample or frame count */
528 if (get_utf8(gb) < 0) { 535 if (get_utf8(gb) < 0) {
529 av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n"); 536 av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n");
530 return -1; 537 return -1;
531 } 538 }
532 539
540 /* blocksize */
533 if (bs_code == 0) { 541 if (bs_code == 0) {
534 av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n"); 542 av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n");
535 return -1; 543 return -1;
536 } else if (bs_code == 6) 544 } else if (bs_code == 6)
537 blocksize = get_bits(gb, 8)+1; 545 blocksize = get_bits(gb, 8)+1;
547 } 555 }
548 556
549 if (blocksize * s->channels * (s->is32 ? 4 : 2) > alloc_data_size) 557 if (blocksize * s->channels * (s->is32 ? 4 : 2) > alloc_data_size)
550 return -1; 558 return -1;
551 559
560 /* sample rate */
552 if (sr_code == 0) 561 if (sr_code == 0)
553 samplerate= s->samplerate; 562 samplerate= s->samplerate;
554 else if (sr_code < 12) 563 else if (sr_code < 12)
555 samplerate = ff_flac_sample_rate_table[sr_code]; 564 samplerate = ff_flac_sample_rate_table[sr_code];
556 else if (sr_code == 12) 565 else if (sr_code == 12)
563 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", 572 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",
564 sr_code); 573 sr_code);
565 return -1; 574 return -1;
566 } 575 }
567 576
577 /* header CRC-8 check */
568 skip_bits(gb, 8); 578 skip_bits(gb, 8);
569 if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer, 579 if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,
570 get_bits_count(gb)/8)) { 580 get_bits_count(gb)/8)) {
571 av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch\n"); 581 av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch\n");
572 return -1; 582 return -1;
663 goto end; // we may not have enough bits left to decode a frame, so try next time 673 goto end; // we may not have enough bits left to decode a frame, so try next time
664 } 674 }
665 675
666 /* decode frame */ 676 /* decode frame */
667 init_get_bits(&s->gb, buf, buf_size*8); 677 init_get_bits(&s->gb, buf, buf_size*8);
668 skip_bits(&s->gb, 16);
669 if (decode_frame(s, alloc_data_size) < 0) { 678 if (decode_frame(s, alloc_data_size) < 0) {
670 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); 679 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n");
671 s->bitstream_size=0; 680 s->bitstream_size=0;
672 s->bitstream_index=0; 681 s->bitstream_index=0;
673 return -1; 682 return -1;