History

AAC encoder: ANMR, avoid empty search ranges

Avoid generating broken paths when some bands have an empty search space.

Claudio Freire committed 10 years ago

Commit 293c1701 parent 7a4652d1 file · +12 −2Browse files

Showing the changes to libavcodec/aaccoder.c (1 of 1 file). Show all

Unified · Split

libavcodec/aaccoder.c+12−2
@@ -261,9 +261,9 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 260 unmodified lines
261261 }
262262
263263 //minimum scalefactor index is when minimum nonzero coefficient after quantizing is not clipped
264− q0 = coef2minsf(q0f);
264+ q0 = av_clip(coef2minsf(q0f), 0, SCALE_MAX_POS-1);
265265 //maximum scalefactor index is when maximum coefficient after quantizing is still not zero
266− q1 = coef2maxsf(q1f);
266+ q1 = av_clip(coef2maxsf(q1f), 1, SCALE_MAX_POS);
267267 if (q1 - q0 > 60) {
268268 int q0low = q0;
269269 int q1high = q1;
@@ -279,6 +279,12 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 9 unmodified lines
279279 q1 = q1high;
280280 }
281281 }
282+ // q0 == q1 isn't really a legal situation
283+ if (q0 == q1) {
284+ // the following is indirect but guarantees q1 != q0 && q1 near q0
285+ q1 = av_clip(q0+1, 1, SCALE_MAX_POS);
286+ q0 = av_clip(q1-1, 0, SCALE_MAX_POS - 1);
287+ }
282288
283289 for (i = 0; i < TRELLIS_STATES; i++) {
284290 paths[0][i].cost = 0.0f;
@@ -327,6 +333,10 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, · 42 unmodified lines
327333 maxscale = coef2maxsf(qmax);
328334 minscale = av_clip(minscale - q0, 0, TRELLIS_STATES - 1);
329335 maxscale = av_clip(maxscale - q0, 0, TRELLIS_STATES);
336+ if (minscale == maxscale) {
337+ maxscale = av_clip(minscale+1, 1, TRELLIS_STATES);
338+ minscale = av_clip(maxscale-1, 0, TRELLIS_STATES - 1);
339+ }
330340 maxval = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], s->scoefs+start);
331341 for (q = minscale; q < maxscale; q++) {
332342 float dist = 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t