ffmpeg | branch: master | James Almer <[email protected]> | Tue Nov 7 19:08:46 2017 -0300| [ec703910af668b8deb8432d2953222385b821b2c] | committer: James Almer
Merge commit '0f5ad12ba2b538cb329c507ecc914e06bfa70194' * commit '0f5ad12ba2b538cb329c507ecc914e06bfa70194': flac: Use a local cache for decode_residual() Merged-by: James Almer <[email protected]> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ec703910af668b8deb8432d2953222385b821b2c --- libavcodec/flacdec.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 567f6f88a7..6c8ba15777 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -220,12 +220,13 @@ static int get_metadata_size(const uint8_t *buf, int buf_size) static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order) { + GetBitContext gb = s->gb; int i, tmp, partition, method_type, rice_order; int rice_bits, rice_esc; int samples; - method_type = get_bits(&s->gb, 2); - rice_order = get_bits(&s->gb, 4); + method_type = get_bits(&gb, 2); + rice_order = get_bits(&gb, 4); samples = s->blocksize >> rice_order; rice_bits = 4 + method_type; @@ -253,15 +254,15 @@ static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order) } for (partition = 0; partition < (1 << rice_order); partition++) { - tmp = get_bits(&s->gb, rice_bits); + tmp = get_bits(&gb, rice_bits); if (tmp == rice_esc) { - tmp = get_bits(&s->gb, 5); + tmp = get_bits(&gb, 5); for (; i < samples; i++) - *decoded++ = get_sbits_long(&s->gb, tmp); + *decoded++ = get_sbits_long(&gb, tmp); } else { int real_limit = tmp ? (INT_MAX >> tmp) + 2 : INT_MAX; for (; i < samples; i++) { - int v = get_sr_golomb_flac(&s->gb, tmp, real_limit, 0); + int v = get_sr_golomb_flac(&gb, tmp, real_limit, 0); if (v == 0x80000000){ av_log(s->avctx, AV_LOG_ERROR, "invalid residual\n"); return AVERROR_INVALIDDATA; @@ -273,6 +274,8 @@ static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order) i= 0; } + s->gb = gb; + return 0; } ====================================================================== diff --cc libavcodec/flacdec.c index 567f6f88a7,87ab2e5bfb..6c8ba15777 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@@ -220,12 -199,13 +220,13 @@@ static int get_metadata_size(const uint static int decode_residuals(FLACContext *s, int32_t *decoded, int pred_order) { - BitstreamContext bc = s->bc; ++ GetBitContext gb = s->gb; int i, tmp, partition, method_type, rice_order; int rice_bits, rice_esc; int samples; - method_type = get_bits(&s->gb, 2); - rice_order = get_bits(&s->gb, 4); - method_type = bitstream_read(&bc, 2); - rice_order = bitstream_read(&bc, 4); ++ method_type = get_bits(&gb, 2); ++ rice_order = get_bits(&gb, 4); samples = s->blocksize >> rice_order; rice_bits = 4 + method_type; @@@ -253,26 -227,21 +254,28 @@@ } for (partition = 0; partition < (1 << rice_order); partition++) { - tmp = get_bits(&s->gb, rice_bits); - tmp = bitstream_read(&bc, rice_bits); ++ tmp = get_bits(&gb, rice_bits); if (tmp == rice_esc) { - tmp = get_bits(&s->gb, 5); - tmp = bitstream_read(&bc, 5); ++ tmp = get_bits(&gb, 5); for (; i < samples; i++) - *decoded++ = get_sbits_long(&s->gb, tmp); - *decoded++ = bitstream_read_signed(&bc, tmp); ++ *decoded++ = get_sbits_long(&gb, tmp); } else { + int real_limit = tmp ? (INT_MAX >> tmp) + 2 : INT_MAX; for (; i < samples; i++) { - int v = get_sr_golomb_flac(&s->gb, tmp, real_limit, 0); - *decoded++ = get_sr_golomb_flac(&bc, tmp, INT_MAX, 0); ++ int v = get_sr_golomb_flac(&gb, tmp, real_limit, 0); + if (v == 0x80000000){ + av_log(s->avctx, AV_LOG_ERROR, "invalid residual\n"); + return AVERROR_INVALIDDATA; + } + + *decoded++ = v; } } i= 0; } - s->bc = bc; ++ s->gb = gb; + return 0; } _______________________________________________ ffmpeg-cvslog mailing list [email protected] http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog
