AAC encoder: ANMR, avoid empty search ranges
Avoid generating broken paths when some bands have an empty search space.
This commit is contained in:
parent
7a4652dd5d
commit
293c170f59
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user