diff options
author | Claudio Freire <klaussfreire@gmail.com> | 2015-12-04 22:56:34 -0300 |
---|---|---|
committer | Claudio Freire <klaussfreire@gmail.com> | 2015-12-04 22:56:34 -0300 |
commit | 293c170f59414647b9bba9cb4602eb92989fd4ba (patch) | |
tree | c05447deae4df2f74749f6caa68d92d02eccb7be /libavcodec/aaccoder.c | |
parent | 7a4652dd5da0502ff21c183b5ca7d76b1cfd6c51 (diff) | |
download | ffmpeg-293c170f59414647b9bba9cb4602eb92989fd4ba.tar.gz |
AAC encoder: ANMR, avoid empty search ranges
Avoid generating broken paths when some bands have an
empty search space.
Diffstat (limited to 'libavcodec/aaccoder.c')
-rw-r--r-- | libavcodec/aaccoder.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index e8a61cef6c..14862ec3c1 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -261,9 +261,9 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, } //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped - q0 = coef2minsf(q0f); + q0 = av_clip(coef2minsf(q0f), 0, SCALE_MAX_POS-1); //maximum scalefactor index is when maximum coefficient after quantizing is still not zero - q1 = coef2maxsf(q1f); + q1 = av_clip(coef2maxsf(q1f), 1, SCALE_MAX_POS); if (q1 - q0 > 60) { int q0low = q0; int q1high = q1; @@ -279,6 +279,12 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, q1 = q1high; } } + // q0 == q1 isn't really a legal situation + if (q0 == q1) { + // the following is indirect but guarantees q1 != q0 && q1 near q0 + q1 = av_clip(q0+1, 1, SCALE_MAX_POS); + q0 = av_clip(q1-1, 0, SCALE_MAX_POS - 1); + } for (i = 0; i < TRELLIS_STATES; i++) { paths[0][i].cost = 0.0f; @@ -327,6 +333,10 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, maxscale = coef2maxsf(qmax); minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1); maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES); + if (minscale == maxscale) { + maxscale = av_clip(minscale+1, 1, TRELLIS_STATES); + minscale = av_clip(maxscale-1, 0, TRELLIS_STATES - 1); + } maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start); for (q = minscale; q < maxscale; q++) { float dist = 0; |