diff options
author | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2015-05-12 13:00:29 +0200 |
---|---|---|
committer | Carl Eugen Hoyos <cehoyos@ag.or.at> | 2015-05-17 02:08:58 +0200 |
commit | e609cfd697f8eed7325591f767585041719807d1 (patch) | |
tree | de8a4644b6f5192633100b191d58a10bdcba1327 /libavcodec/flacenc.c | |
parent | 38f5a266eed1160e87da8e832a0a07818d7673cb (diff) | |
download | ffmpeg-e609cfd697f8eed7325591f767585041719807d1.tar.gz |
lavc/flac: Fix encoding and decoding with high lpc.
Based on an analysis by trac user lvqcl.
Fixes ticket #4421, reported by Chase Walker.
Diffstat (limited to 'libavcodec/flacenc.c')
-rw-r--r-- | libavcodec/flacenc.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index bc6d00af7f..b6dc4d5c07 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -838,8 +838,13 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) order = av_clip(order, min_order - 1, max_order - 1); if (order == last_order) continue; - s->flac_dsp.lpc_encode(res, smp, n, order+1, coefs[order], - shift[order]); + if (s->bps_code * 4 + s->options.lpc_coeff_precision + av_log2(order) <= 32) { + s->flac_dsp.lpc16_encode(res, smp, n, order+1, coefs[order], + shift[order]); + } else { + s->flac_dsp.lpc32_encode(res, smp, n, order+1, coefs[order], + shift[order]); + } bits[i] = find_subframe_rice_params(s, sub, order+1); if (bits[i] < bits[opt_index]) { opt_index = i; @@ -853,7 +858,11 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) opt_order = 0; bits[0] = UINT32_MAX; for (i = min_order-1; i < max_order; i++) { - s->flac_dsp.lpc_encode(res, smp, n, i+1, coefs[i], shift[i]); + if (s->bps_code * 4 + s->options.lpc_coeff_precision + av_log2(i) <= 32) { + s->flac_dsp.lpc16_encode(res, smp, n, i+1, coefs[i], shift[i]); + } else { + s->flac_dsp.lpc32_encode(res, smp, n, i+1, coefs[i], shift[i]); + } bits[i] = find_subframe_rice_params(s, sub, i+1); if (bits[i] < bits[opt_order]) opt_order = i; @@ -871,7 +880,11 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) for (i = last-step; i <= last+step; i += step) { if (i < min_order-1 || i >= max_order || bits[i] < UINT32_MAX) continue; - s->flac_dsp.lpc_encode(res, smp, n, i+1, coefs[i], shift[i]); + if (s->bps_code * 4 + s->options.lpc_coeff_precision + av_log2(i) <= 32) { + s->flac_dsp.lpc32_encode(res, smp, n, i+1, coefs[i], shift[i]); + } else { + s->flac_dsp.lpc16_encode(res, smp, n, i+1, coefs[i], shift[i]); + } bits[i] = find_subframe_rice_params(s, sub, i+1); if (bits[i] < bits[opt_order]) opt_order = i; @@ -886,7 +899,11 @@ static int encode_residual_ch(FlacEncodeContext *s, int ch) for (i = 0; i < sub->order; i++) sub->coefs[i] = coefs[sub->order-1][i]; - s->flac_dsp.lpc_encode(res, smp, n, sub->order, sub->coefs, sub->shift); + if (s->bps_code * 4 + s->options.lpc_coeff_precision + av_log2(opt_order) <= 32) { + s->flac_dsp.lpc16_encode(res, smp, n, sub->order, sub->coefs, sub->shift); + } else { + s->flac_dsp.lpc32_encode(res, smp, n, sub->order, sub->coefs, sub->shift); + } find_subframe_rice_params(s, sub, sub->order); |