Mercurial > libavcodec.hg
comparison aaccoder.c @ 11732:c40cc26cd23f libavcodec
aacenc: Add a rate only trellis for codebook selection for the TLS.
| author | alexc |
|---|---|
| date | Fri, 14 May 2010 16:49:51 +0000 |
| parents | 73f923159384 |
| children | 0c1f5ab77b36 |
comparison
equal
deleted
inserted
replaced
| 11731:73f923159384 | 11732:c40cc26cd23f |
|---|---|
| 302 for (cb = 1; cb < 12; cb++) | 302 for (cb = 1; cb < 12; cb++) |
| 303 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost) | 303 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost) |
| 304 idx = cb; | 304 idx = cb; |
| 305 ppos = max_sfb; | 305 ppos = max_sfb; |
| 306 while (ppos > 0) { | 306 while (ppos > 0) { |
| 307 cb = idx; | |
| 308 stackrun[stack_len] = path[ppos][cb].run; | |
| 309 stackcb [stack_len] = cb; | |
| 310 idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx; | |
| 311 ppos -= path[ppos][cb].run; | |
| 312 stack_len++; | |
| 313 } | |
| 314 //perform actual band info encoding | |
| 315 start = 0; | |
| 316 for (i = stack_len - 1; i >= 0; i--) { | |
| 317 put_bits(&s->pb, 4, stackcb[i]); | |
| 318 count = stackrun[i]; | |
| 319 memset(sce->zeroes + win*16 + start, !stackcb[i], count); | |
| 320 //XXX: memset when band_type is also uint8_t | |
| 321 for (j = 0; j < count; j++) { | |
| 322 sce->band_type[win*16 + start] = stackcb[i]; | |
| 323 start++; | |
| 324 } | |
| 325 while (count >= run_esc) { | |
| 326 put_bits(&s->pb, run_bits, run_esc); | |
| 327 count -= run_esc; | |
| 328 } | |
| 329 put_bits(&s->pb, run_bits, count); | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, | |
| 334 int win, int group_len, const float lambda) | |
| 335 { | |
| 336 BandCodingPath path[120][12]; | |
| 337 int w, swb, cb, start, start2, size; | |
| 338 int i, j; | |
| 339 const int max_sfb = sce->ics.max_sfb; | |
| 340 const int run_bits = sce->ics.num_windows == 1 ? 5 : 3; | |
| 341 const int run_esc = (1 << run_bits) - 1; | |
| 342 int idx, ppos, count; | |
| 343 int stackrun[120], stackcb[120], stack_len; | |
| 344 float next_minrd = INFINITY; | |
| 345 int next_mincb = 0; | |
| 346 | |
| 347 abs_pow34_v(s->scoefs, sce->coeffs, 1024); | |
| 348 start = win*128; | |
| 349 for (cb = 0; cb < 12; cb++) { | |
| 350 path[0][cb].cost = run_bits+4; | |
| 351 path[0][cb].prev_idx = -1; | |
| 352 path[0][cb].run = 0; | |
| 353 } | |
| 354 for (swb = 0; swb < max_sfb; swb++) { | |
| 355 start2 = start; | |
| 356 size = sce->ics.swb_sizes[swb]; | |
| 357 if (sce->zeroes[win*16 + swb]) { | |
| 358 for (cb = 0; cb < 12; cb++) { | |
| 359 path[swb+1][cb].prev_idx = cb; | |
| 360 path[swb+1][cb].cost = path[swb][cb].cost; | |
| 361 path[swb+1][cb].run = path[swb][cb].run + 1; | |
| 362 } | |
| 363 } else { | |
| 364 float minrd = next_minrd; | |
| 365 int mincb = next_mincb; | |
| 366 int startcb = sce->band_type[win*16+swb]; | |
| 367 next_minrd = INFINITY; | |
| 368 next_mincb = 0; | |
| 369 for (cb = 0; cb < startcb; cb++) { | |
| 370 path[swb+1][cb].cost = 61450; | |
| 371 path[swb+1][cb].prev_idx = -1; | |
| 372 path[swb+1][cb].run = 0; | |
| 373 } | |
| 374 for (cb = startcb; cb < 12; cb++) { | |
| 375 float cost_stay_here, cost_get_here; | |
| 376 float rd = 0.0f; | |
| 377 for (w = 0; w < group_len; w++) { | |
| 378 rd += quantize_band_cost(s, sce->coeffs + start + w*128, | |
| 379 s->scoefs + start + w*128, size, | |
| 380 sce->sf_idx[(win+w)*16+swb], cb, | |
| 381 0, INFINITY, NULL); | |
| 382 } | |
| 383 cost_stay_here = path[swb][cb].cost + rd; | |
| 384 cost_get_here = minrd + rd + run_bits + 4; | |
| 385 if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run] | |
| 386 != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1]) | |
| 387 cost_stay_here += run_bits; | |
| 388 if (cost_get_here < cost_stay_here) { | |
| 389 path[swb+1][cb].prev_idx = mincb; | |
| 390 path[swb+1][cb].cost = cost_get_here; | |
| 391 path[swb+1][cb].run = 1; | |
| 392 } else { | |
| 393 path[swb+1][cb].prev_idx = cb; | |
| 394 path[swb+1][cb].cost = cost_stay_here; | |
| 395 path[swb+1][cb].run = path[swb][cb].run + 1; | |
| 396 } | |
| 397 if (path[swb+1][cb].cost < next_minrd) { | |
| 398 next_minrd = path[swb+1][cb].cost; | |
| 399 next_mincb = cb; | |
| 400 } | |
| 401 } | |
| 402 } | |
| 403 start += sce->ics.swb_sizes[swb]; | |
| 404 } | |
| 405 | |
| 406 //convert resulting path from backward-linked list | |
| 407 stack_len = 0; | |
| 408 idx = 0; | |
| 409 for (cb = 1; cb < 12; cb++) | |
| 410 if (path[max_sfb][cb].cost < path[max_sfb][idx].cost) | |
| 411 idx = cb; | |
| 412 ppos = max_sfb; | |
| 413 while (ppos > 0) { | |
| 414 if (idx < 0) abort(); | |
| 307 cb = idx; | 415 cb = idx; |
| 308 stackrun[stack_len] = path[ppos][cb].run; | 416 stackrun[stack_len] = path[ppos][cb].run; |
| 309 stackcb [stack_len] = cb; | 417 stackcb [stack_len] = cb; |
| 310 idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx; | 418 idx = path[ppos-path[ppos][cb].run+1][cb].prev_idx; |
| 311 ppos -= path[ppos][cb].run; | 419 ppos -= path[ppos][cb].run; |
| 580 else if (qmaxval == 2) cb = 3; | 688 else if (qmaxval == 2) cb = 3; |
| 581 else if (qmaxval <= 4) cb = 5; | 689 else if (qmaxval <= 4) cb = 5; |
| 582 else if (qmaxval <= 7) cb = 7; | 690 else if (qmaxval <= 7) cb = 7; |
| 583 else if (qmaxval <= 12) cb = 9; | 691 else if (qmaxval <= 12) cb = 9; |
| 584 else cb = 11; | 692 else cb = 11; |
| 693 sce->band_type[w*16+g] = cb; | |
| 585 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { | 694 for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { |
| 586 int b; | 695 int b; |
| 587 dist += quantize_band_cost(s, coefs + w2*128, | 696 dist += quantize_band_cost(s, coefs + w2*128, |
| 588 scaled + w2*128, | 697 scaled + w2*128, |
| 589 sce->ics.swb_sizes[g], | 698 sce->ics.swb_sizes[g], |
| 918 quantize_and_encode_band, | 1027 quantize_and_encode_band, |
| 919 search_for_ms, | 1028 search_for_ms, |
| 920 }, | 1029 }, |
| 921 { | 1030 { |
| 922 search_for_quantizers_twoloop, | 1031 search_for_quantizers_twoloop, |
| 923 encode_window_bands_info, | 1032 codebook_trellis_rate, |
| 924 quantize_and_encode_band, | 1033 quantize_and_encode_band, |
| 925 search_for_ms, | 1034 search_for_ms, |
| 926 }, | 1035 }, |
| 927 { | 1036 { |
| 928 search_for_quantizers_fast, | 1037 search_for_quantizers_fast, |
