Revision 9072c29e libavcodec/aaccoder.c

View differences:

libavcodec/aaccoder.c
468 468
                                       const float lambda)
469 469
{
470 470
    int q, w, w2, g, start = 0;
471
    int i;
471
    int i, j;
472 472
    int idx;
473
    TrellisPath paths[256*121];
473
    TrellisPath paths[121][256];
474 474
    int bandaddr[121];
475 475
    int minq;
476 476
    float mincost;
477 477

  
478 478
    for (i = 0; i < 256; i++) {
479
        paths[i].cost    = 0.0f;
480
        paths[i].prev    = -1;
481
        paths[i].min_val = i;
482
        paths[i].max_val = i;
479
        paths[0][i].cost    = 0.0f;
480
        paths[0][i].prev    = -1;
481
        paths[0][i].min_val = i;
482
        paths[0][i].max_val = i;
483 483
    }
484
    for (i = 256; i < 256*121; i++) {
485
        paths[i].cost    = INFINITY;
486
        paths[i].prev    = -2;
487
        paths[i].min_val = INT_MAX;
488
        paths[i].max_val = 0;
484
    for (j = 1; j < 121; j++) {
485
        for (i = 0; i < 256; i++) {
486
            paths[j][i].cost    = INFINITY;
487
            paths[j][i].prev    = -2;
488
            paths[j][i].min_val = INT_MAX;
489
            paths[j][i].max_val = 0;
490
        }
489 491
    }
490
    idx = 256;
492
    idx = 1;
491 493
    abs_pow34_v(s->scoefs, sce->coeffs, 1024);
492 494
    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
493 495
        start = w*128;
......
496 498
            float qmin, qmax;
497 499
            int nz = 0;
498 500

  
499
            bandaddr[idx >> 8] = w * 16 + g;
501
            bandaddr[idx] = w * 16 + g;
500 502
            qmin = INT_MAX;
501 503
            qmax = 0.0f;
502 504
            for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
......
539 541
                    for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) {
540 542
                        float cost;
541 543
                        int minv, maxv;
542
                        if (isinf(paths[idx - 256 + i].cost))
544
                        if (isinf(paths[idx - 1][i].cost))
543 545
                            continue;
544
                        cost = paths[idx - 256 + i].cost + dist
546
                        cost = paths[idx - 1][i].cost + dist
545 547
                               + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
546
                        minv = FFMIN(paths[idx - 256 + i].min_val, q);
547
                        maxv = FFMAX(paths[idx - 256 + i].max_val, q);
548
                        if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) {
549
                            paths[idx + q].cost    = cost;
550
                            paths[idx + q].prev    = idx - 256 + i;
551
                            paths[idx + q].min_val = minv;
552
                            paths[idx + q].max_val = maxv;
548
                        minv = FFMIN(paths[idx - 1][i].min_val, q);
549
                        maxv = FFMAX(paths[idx - 1][i].max_val, q);
550
                        if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) {
551
                            paths[idx][q].cost    = cost;
552
                            paths[idx][q].prev    = i;
553
                            paths[idx][q].min_val = minv;
554
                            paths[idx][q].max_val = maxv;
553 555
                        }
554 556
                    }
555 557
                }
556 558
            } else {
557 559
                for (q = 0; q < 256; q++) {
558
                    if (!isinf(paths[idx - 256 + q].cost)) {
559
                        paths[idx + q].cost = paths[idx - 256 + q].cost + 1;
560
                        paths[idx + q].prev = idx - 256 + q;
561
                        paths[idx + q].min_val = FFMIN(paths[idx - 256 + q].min_val, q);
562
                        paths[idx + q].max_val = FFMAX(paths[idx - 256 + q].max_val, q);
560
                    if (!isinf(paths[idx - 1][q].cost)) {
561
                        paths[idx][q].cost = paths[idx - 1][q].cost + 1;
562
                        paths[idx][q].prev = q;
563
                        paths[idx][q].min_val = FFMIN(paths[idx - 1][q].min_val, q);
564
                        paths[idx][q].max_val = FFMAX(paths[idx - 1][q].max_val, q);
563 565
                        continue;
564 566
                    }
565 567
                    for (i = FFMAX(q - SCALE_MAX_DIFF, 0); i < FFMIN(q + SCALE_MAX_DIFF, 256); i++) {
566 568
                        float cost;
567 569
                        int minv, maxv;
568
                        if (isinf(paths[idx - 256 + i].cost))
570
                        if (isinf(paths[idx - 1][i].cost))
569 571
                            continue;
570
                        cost = paths[idx - 256 + i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
571
                        minv = FFMIN(paths[idx - 256 + i].min_val, q);
572
                        maxv = FFMAX(paths[idx - 256 + i].max_val, q);
573
                        if (cost < paths[idx + q].cost && maxv-minv < SCALE_MAX_DIFF) {
574
                            paths[idx + q].cost    = cost;
575
                            paths[idx + q].prev    = idx - 256 + i;
576
                            paths[idx + q].min_val = minv;
577
                            paths[idx + q].max_val = maxv;
572
                        cost = paths[idx - 1][i].cost + ff_aac_scalefactor_bits[q - i + SCALE_DIFF_ZERO];
573
                        minv = FFMIN(paths[idx - 1][i].min_val, q);
574
                        maxv = FFMAX(paths[idx - 1][i].max_val, q);
575
                        if (cost < paths[idx][q].cost && maxv-minv < SCALE_MAX_DIFF) {
576
                            paths[idx][q].cost    = cost;
577
                            paths[idx][q].prev    = i;
578
                            paths[idx][q].min_val = minv;
579
                            paths[idx][q].max_val = maxv;
578 580
                        }
579 581
                    }
580 582
                }
581 583
            }
582 584
            sce->zeroes[w*16+g] = !nz;
583 585
            start += sce->ics.swb_sizes[g];
584
            idx   += 256;
586
            idx++;
585 587
        }
586 588
    }
587
    idx -= 256;
588
    mincost = paths[idx].cost;
589
    minq    = idx;
589
    idx--;
590
    mincost = paths[idx][0].cost;
591
    minq    = 0;
590 592
    for (i = 1; i < 256; i++) {
591
        if (paths[idx + i].cost < mincost) {
592
            mincost = paths[idx + i].cost;
593
            minq = idx + i;
593
        if (paths[idx][i].cost < mincost) {
594
            mincost = paths[idx][i].cost;
595
            minq = i;
594 596
        }
595 597
    }
596
    while (minq >= 256) {
597
        sce->sf_idx[bandaddr[minq>>8]] = minq & 0xFF;
598
        minq = paths[minq].prev;
598
    while (idx) {
599
        sce->sf_idx[bandaddr[idx]] = minq;
600
        minq = paths[idx][minq].prev;
601
        idx--;
599 602
    }
600 603
    //set the same quantizers inside window groups
601 604
    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w])

Also available in: Unified diff