Mercurial > libavcodec.hg
comparison flacdec.c @ 9135:05c6e8598143 libavcodec
flacdec: Simplify frame sync by not using the bitstream reader.
author | jbr |
---|---|
date | Thu, 05 Mar 2009 01:15:38 +0000 |
parents | e82d5e006de5 |
children | ebad2cb9e015 |
comparison
equal
deleted
inserted
replaced
9134:e82d5e006de5 | 9135:05c6e8598143 |
---|---|
608 static int flac_decode_frame(AVCodecContext *avctx, | 608 static int flac_decode_frame(AVCodecContext *avctx, |
609 void *data, int *data_size, | 609 void *data, int *data_size, |
610 const uint8_t *buf, int buf_size) | 610 const uint8_t *buf, int buf_size) |
611 { | 611 { |
612 FLACContext *s = avctx->priv_data; | 612 FLACContext *s = avctx->priv_data; |
613 int tmp = 0, i, j = 0, input_buf_size = 0, bytes_read = 0; | 613 int i, j = 0, input_buf_size = 0, bytes_read = 0; |
614 int16_t *samples_16 = data; | 614 int16_t *samples_16 = data; |
615 int32_t *samples_32 = data; | 615 int32_t *samples_32 = data; |
616 int alloc_data_size= *data_size; | 616 int alloc_data_size= *data_size; |
617 | 617 |
618 *data_size=0; | 618 *data_size=0; |
662 } | 662 } |
663 bytes_read = get_metadata_size(buf, buf_size); | 663 bytes_read = get_metadata_size(buf, buf_size); |
664 goto end; | 664 goto end; |
665 } | 665 } |
666 | 666 |
667 /* check for frame sync code and resync stream if necessary */ | |
668 if ((AV_RB16(buf) & 0xFFFE) != 0xFFF8) { | |
669 const uint8_t *buf_end = buf + buf_size; | |
670 av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); | |
671 while (buf+2 < buf_end && (AV_RB16(buf) & 0xFFFE) != 0xFFF8) | |
672 buf++; | |
673 bytes_read = buf_size - (buf_end - buf); | |
674 goto end; // we may not have enough bits left to decode a frame, so try next time | |
675 } | |
676 | |
677 /* decode frame */ | |
667 init_get_bits(&s->gb, buf, buf_size*8); | 678 init_get_bits(&s->gb, buf, buf_size*8); |
668 | |
669 tmp = show_bits(&s->gb, 16); | |
670 if ((tmp & 0xFFFE) != 0xFFF8) { | |
671 av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); | |
672 while (get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8) | |
673 skip_bits(&s->gb, 8); | |
674 goto hdr_end; // we may not have enough bits left to decode a frame, so try next time | |
675 } | |
676 skip_bits(&s->gb, 16); | 679 skip_bits(&s->gb, 16); |
677 if (decode_frame(s, alloc_data_size) < 0) { | 680 if (decode_frame(s, alloc_data_size) < 0) { |
678 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); | 681 av_log(s->avctx, AV_LOG_ERROR, "decode_frame() failed\n"); |
679 s->bitstream_size=0; | 682 s->bitstream_size=0; |
680 s->bitstream_index=0; | 683 s->bitstream_index=0; |
715 DECORRELATE( (a-=b>>1) + b, a) | 718 DECORRELATE( (a-=b>>1) + b, a) |
716 } | 719 } |
717 | 720 |
718 *data_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); | 721 *data_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); |
719 | 722 |
720 hdr_end: | |
721 bytes_read = (get_bits_count(&s->gb)+7)/8; | 723 bytes_read = (get_bits_count(&s->gb)+7)/8; |
722 end: | 724 end: |
723 if (bytes_read > buf_size) { | 725 if (bytes_read > buf_size) { |
724 av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size); | 726 av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", bytes_read - buf_size); |
725 s->bitstream_size=0; | 727 s->bitstream_size=0; |