37 #ifndef AVCODEC_AACCODER_TRELLIS_H 38 #define AVCODEC_AACCODER_TRELLIS_H 60 int win,
int group_len,
const float lambda)
63 int w, swb, cb, start, size;
65 const int max_sfb = sce->ics.
max_sfb;
66 const int run_bits = sce->ics.num_windows == 1 ? 5 : 3;
67 const int run_esc = (1 << run_bits) - 1;
69 int stackrun[120], stackcb[120], stack_len;
70 float next_minbits = INFINITY;
73 s->abs_pow34(s->scoefs, sce->coeffs, 1024);
76 path[0][cb].
cost = run_bits+4;
80 for (swb = 0; swb < max_sfb; swb++) {
82 if (sce->
zeroes[win*16 + swb]) {
83 float cost_stay_here = path[swb][0].
cost;
84 float cost_get_here = next_minbits + run_bits + 4;
85 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run]
86 != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1])
87 cost_stay_here += run_bits;
88 if (cost_get_here < cost_stay_here) {
89 path[swb+1][0].
prev_idx = next_mincb;
90 path[swb+1][0].
cost = cost_get_here;
91 path[swb+1][0].run = 1;
94 path[swb+1][0].
cost = cost_stay_here;
95 path[swb+1][0].run = path[swb][0].run + 1;
97 next_minbits = path[swb+1][0].
cost;
100 path[swb+1][cb].
cost = 61450;
102 path[swb+1][cb].run = 0;
105 float minbits = next_minbits;
106 int mincb = next_mincb;
107 int startcb = sce->
band_type[win*16+swb];
108 startcb = aac_cb_in_map[startcb];
109 next_minbits = INFINITY;
111 for (cb = 0; cb < startcb; cb++) {
112 path[swb+1][cb].
cost = 61450;
114 path[swb+1][cb].run = 0;
117 float cost_stay_here, cost_get_here;
119 if (cb >= 12 && sce->
band_type[win*16+swb] != aac_cb_out_map[cb]) {
120 path[swb+1][cb].
cost = 61450;
122 path[swb+1][cb].run = 0;
125 for (w = 0; w < group_len; w++) {
126 bits += quantize_band_cost_bits(s, &sce->coeffs[start + w*128],
127 &s->scoefs[start + w*128], size,
130 0, INFINITY, NULL, NULL, 0);
132 cost_stay_here = path[swb][cb].
cost + bits;
133 cost_get_here = minbits + bits + run_bits + 4;
134 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run]
135 != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1])
136 cost_stay_here += run_bits;
137 if (cost_get_here < cost_stay_here) {
139 path[swb+1][cb].
cost = cost_get_here;
140 path[swb+1][cb].run = 1;
143 path[swb+1][cb].
cost = cost_stay_here;
144 path[swb+1][cb].run = path[swb][cb].run + 1;
146 if (path[swb+1][cb].
cost < next_minbits) {
147 next_minbits = path[swb+1][cb].
cost;
159 if (path[max_sfb][cb].
cost < path[max_sfb][idx].
cost)
165 stackrun[stack_len] = path[ppos][cb].run;
166 stackcb [stack_len] = cb;
167 idx = path[ppos-path[ppos][cb].run+1][cb].
prev_idx;
168 ppos -= path[ppos][cb].run;
173 for (i = stack_len - 1; i >= 0; i--) {
174 cb = aac_cb_out_map[stackcb[i]];
175 put_bits(&s->pb, 4, cb);
177 memset(sce->
zeroes + win*16 + start, !cb, count);
179 for (j = 0; j < count; j++) {
183 while (count >= run_esc) {
184 put_bits(&s->pb, run_bits, run_esc);
187 put_bits(&s->pb, run_bits, count);
int prev_idx
pointer to the previous path point
Definition: aaccoder_trellis.h:53
AAC encoder context.
Definition: aacenc.h:376
uint8_t max_sfb
number of scalefactor bands per group
Definition: aac.h:175
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
Libavcodec external API header.
float cost
path cost
Definition: aaccoder_trellis.h:54
This file contains a template for the codebook_trellis_rate selector function.
Definition: aaccoder_trellis.h:52
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
Definition: aac.h:182
struct TrellisBandCodingPath TrellisBandCodingPath
This file contains a template for the codebook_trellis_rate selector function.
#define CB_TOT_ALL
Total number of codebooks, including special ones.
Definition: aacenctab.h:37
uint8_t zeroes[128]
band is not coded (used by encoder)
Definition: aac.h:257
int sf_idx[128]
scalefactor indices (used by encoder)
Definition: aac.h:256
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:248
enum BandType band_type[128]
band types
Definition: aac.h:252