comparison flacdec.c @ 9228:2b7bc08cf831 libavcodec

flacdec: use a local variable for GetBitContext in decode_frame()
author jbr
date Sun, 22 Mar 2009 18:52:15 +0000
parents 64246d9e583a
children aec6d4ca45a3
comparison
equal deleted inserted replaced
9227:98f102ead3c6 9228:2b7bc08cf831
482 482
483 static int decode_frame(FLACContext *s, int alloc_data_size) 483 static int decode_frame(FLACContext *s, int alloc_data_size)
484 { 484 {
485 int blocksize_code, sample_rate_code, sample_size_code, i, crc8; 485 int blocksize_code, sample_rate_code, sample_size_code, i, crc8;
486 int ch_mode, bps, blocksize, samplerate; 486 int ch_mode, bps, blocksize, samplerate;
487 487 GetBitContext *gb = &s->gb;
488 blocksize_code = get_bits(&s->gb, 4); 488
489 489 blocksize_code = get_bits(gb, 4);
490 sample_rate_code = get_bits(&s->gb, 4); 490
491 491 sample_rate_code = get_bits(gb, 4);
492 ch_mode = get_bits(&s->gb, 4); /* channel assignment */ 492
493 ch_mode = get_bits(gb, 4); /* channel assignment */
493 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) { 494 if (ch_mode < FLAC_MAX_CHANNELS && s->channels == ch_mode+1) {
494 ch_mode = FLAC_CHMODE_INDEPENDENT; 495 ch_mode = FLAC_CHMODE_INDEPENDENT;
495 } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) { 496 } else if (ch_mode > FLAC_CHMODE_MID_SIDE || s->channels != 2) {
496 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", 497 av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n",
497 ch_mode, s->channels); 498 ch_mode, s->channels);
498 return -1; 499 return -1;
499 } 500 }
500 501
501 sample_size_code = get_bits(&s->gb, 3); 502 sample_size_code = get_bits(gb, 3);
502 if (sample_size_code == 0) 503 if (sample_size_code == 0)
503 bps= s->bps; 504 bps= s->bps;
504 else if ((sample_size_code != 3) && (sample_size_code != 7)) 505 else if ((sample_size_code != 3) && (sample_size_code != 7))
505 bps = sample_size_table[sample_size_code]; 506 bps = sample_size_table[sample_size_code];
506 else { 507 else {
517 s->sample_shift = 16 - bps; 518 s->sample_shift = 16 - bps;
518 s->is32 = 0; 519 s->is32 = 0;
519 } 520 }
520 s->bps = s->avctx->bits_per_raw_sample = bps; 521 s->bps = s->avctx->bits_per_raw_sample = bps;
521 522
522 if (get_bits1(&s->gb)) { 523 if (get_bits1(gb)) {
523 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); 524 av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");
524 return -1; 525 return -1;
525 } 526 }
526 527
527 if (get_utf8(&s->gb) < 0) { 528 if (get_utf8(gb) < 0) {
528 av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n"); 529 av_log(s->avctx, AV_LOG_ERROR, "utf8 fscked\n");
529 return -1; 530 return -1;
530 } 531 }
531 532
532 if (blocksize_code == 0) { 533 if (blocksize_code == 0) {
533 av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n"); 534 av_log(s->avctx, AV_LOG_ERROR, "reserved blocksize code: 0\n");
534 return -1; 535 return -1;
535 } else if (blocksize_code == 6) 536 } else if (blocksize_code == 6)
536 blocksize = get_bits(&s->gb, 8)+1; 537 blocksize = get_bits(gb, 8)+1;
537 else if (blocksize_code == 7) 538 else if (blocksize_code == 7)
538 blocksize = get_bits(&s->gb, 16)+1; 539 blocksize = get_bits(gb, 16)+1;
539 else 540 else
540 blocksize = ff_flac_blocksize_table[blocksize_code]; 541 blocksize = ff_flac_blocksize_table[blocksize_code];
541 542
542 if (blocksize > s->max_blocksize) { 543 if (blocksize > s->max_blocksize) {
543 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize, 544 av_log(s->avctx, AV_LOG_ERROR, "blocksize %d > %d\n", blocksize,
551 if (sample_rate_code == 0) 552 if (sample_rate_code == 0)
552 samplerate= s->samplerate; 553 samplerate= s->samplerate;
553 else if (sample_rate_code < 12) 554 else if (sample_rate_code < 12)
554 samplerate = ff_flac_sample_rate_table[sample_rate_code]; 555 samplerate = ff_flac_sample_rate_table[sample_rate_code];
555 else if (sample_rate_code == 12) 556 else if (sample_rate_code == 12)
556 samplerate = get_bits(&s->gb, 8) * 1000; 557 samplerate = get_bits(gb, 8) * 1000;
557 else if (sample_rate_code == 13) 558 else if (sample_rate_code == 13)
558 samplerate = get_bits(&s->gb, 16); 559 samplerate = get_bits(gb, 16);
559 else if (sample_rate_code == 14) 560 else if (sample_rate_code == 14)
560 samplerate = get_bits(&s->gb, 16) * 10; 561 samplerate = get_bits(gb, 16) * 10;
561 else { 562 else {
562 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n", 563 av_log(s->avctx, AV_LOG_ERROR, "illegal sample rate code %d\n",
563 sample_rate_code); 564 sample_rate_code);
564 return -1; 565 return -1;
565 } 566 }
566 567
567 skip_bits(&s->gb, 8); 568 skip_bits(gb, 8);
568 crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, 569 crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0,
569 s->gb.buffer, get_bits_count(&s->gb)/8); 570 gb->buffer, get_bits_count(gb)/8);
570 if (crc8) { 571 if (crc8) {
571 av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch crc=%2X\n", crc8); 572 av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch crc=%2X\n", crc8);
572 return -1; 573 return -1;
573 } 574 }
574 575
583 for (i = 0; i < s->channels; i++) { 584 for (i = 0; i < s->channels; i++) {
584 if (decode_subframe(s, i) < 0) 585 if (decode_subframe(s, i) < 0)
585 return -1; 586 return -1;
586 } 587 }
587 588
588 align_get_bits(&s->gb); 589 align_get_bits(gb);
589 590
590 /* frame footer */ 591 /* frame footer */
591 skip_bits(&s->gb, 16); /* data crc */ 592 skip_bits(gb, 16); /* data crc */
592 593
593 return 0; 594 return 0;
594 } 595 }
595 596
596 static int flac_decode_frame(AVCodecContext *avctx, 597 static int flac_decode_frame(AVCodecContext *avctx,