This will be useful for Indeo Audio decoder which is almost the same but supports stereo.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -49,9 +49,7 @@ · 48 unmodified lines | |||
| 49 | #define BANDS 32 | 49 | #define BANDS 32 |
| 50 | #define COEFFS 256 | 50 | #define COEFFS 256 |
| 51 | 51 | ||
| 52 | typedef struct { | 52 | typedef struct IMCChannel { |
| 53 | AVFrame frame; | ||
| 54 | |||
| 55 | float old_floor[BANDS]; | 53 | float old_floor[BANDS]; |
| 56 | float flcoeffs1[BANDS]; | 54 | float flcoeffs1[BANDS]; |
| 57 | float flcoeffs2[BANDS]; | 55 | float flcoeffs2[BANDS]; |
| @@ -61,16 +59,6 @@ typedef struct { · 3 unmodified lines | |||
| 61 | float flcoeffs6[BANDS]; | 59 | float flcoeffs6[BANDS]; |
| 62 | float CWdecoded[COEFFS]; | 60 | float CWdecoded[COEFFS]; |
| 63 | 61 | ||
| 64 | /** MDCT tables */ | ||
| 65 | //@{ | ||
| 66 | float mdct_sine_window[COEFFS]; | ||
| 67 | float post_cos[COEFFS]; | ||
| 68 | float post_sin[COEFFS]; | ||
| 69 | float pre_coef1[COEFFS]; | ||
| 70 | float pre_coef2[COEFFS]; | ||
| 71 | float last_fft_im[COEFFS]; | ||
| 72 | //@} | ||
| 73 | |||
| 74 | int bandWidthT[BANDS]; ///< codewords per band | 62 | int bandWidthT[BANDS]; ///< codewords per band |
| 75 | int bitsBandT[BANDS]; ///< how many bits per codeword in band | 63 | int bitsBandT[BANDS]; ///< how many bits per codeword in band |
| 76 | int CWlengthT[COEFFS]; ///< how many bits in each codeword | 64 | int CWlengthT[COEFFS]; ///< how many bits in each codeword |
| @@ -82,9 +70,28 @@ typedef struct { · 5 unmodified lines | |||
| 82 | int skipFlagCount[BANDS]; ///< skipped coeffients per band | 70 | int skipFlagCount[BANDS]; ///< skipped coeffients per band |
| 83 | int skipFlags[COEFFS]; ///< skip coefficient decoding or not | 71 | int skipFlags[COEFFS]; ///< skip coefficient decoding or not |
| 84 | int codewords[COEFFS]; ///< raw codewords read from bitstream | 72 | int codewords[COEFFS]; ///< raw codewords read from bitstream |
| 73 | |||
| 74 | float last_fft_im[COEFFS]; | ||
| 75 | |||
| 76 | int decoder_reset; | ||
| 77 | } IMCChannel; | ||
| 78 | |||
| 79 | typedef struct { | ||
| 80 | AVFrame frame; | ||
| 81 | |||
| 82 | IMCChannel chctx[1]; | ||
| 83 | |||
| 84 | /** MDCT tables */ | ||
| 85 | //@{ | ||
| 86 | float mdct_sine_window[COEFFS]; | ||
| 87 | float post_cos[COEFFS]; | ||
| 88 | float post_sin[COEFFS]; | ||
| 89 | float pre_coef1[COEFFS]; | ||
| 90 | float pre_coef2[COEFFS]; | ||
| 91 | //@} | ||
| 92 | |||
| 85 | float sqrt_tab[30]; | 93 | float sqrt_tab[30]; |
| 86 | GetBitContext gb; | 94 | GetBitContext gb; |
| 87 | int decoder_reset; | ||
| 88 | float one_div_log2; | 95 | float one_div_log2; |
| 89 | 96 | ||
| 90 | DSPContext dsp; | 97 | DSPContext dsp; |
| @@ -115,10 +122,15 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 24 unmodified lines | |||
| 115 | return AVERROR_PATCHWELCOME; | 122 | return AVERROR_PATCHWELCOME; |
| 116 | } | 123 | } |
| 117 | 124 | ||
| 118 | q->decoder_reset = 1; | 125 | for (j = 0; j < avctx->channels; j++) { |
| 126 | q->chctx[j].decoder_reset = 1; | ||
| 119 | 127 | ||
| 120 | for (i = 0; i < BANDS; i++) | 128 | for (i = 0; i < BANDS; i++) |
| 121 | q->old_floor[i] = 1.0; | 129 | q->chctx[j].old_floor[i] = 1.0; |
| 130 | |||
| 131 | for (i = 0; i < COEFFS / 2; i++) | ||
| 132 | q->chctx[j].last_fft_im[i] = 0; | ||
| 133 | } | ||
| 122 | 134 | ||
| 123 | /* Build mdct window, a simple sine window normalized with sqrt(2) */ | 135 | /* Build mdct window, a simple sine window normalized with sqrt(2) */ |
| 124 | ff_sine_window_init(q->mdct_sine_window, COEFFS); | 136 | ff_sine_window_init(q->mdct_sine_window, COEFFS); |
| @@ -138,8 +150,6 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 13 unmodified lines | |||
| 138 | q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0); | 150 | q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0); |
| 139 | q->pre_coef2[i] = (r1 - r2) * sqrt(2.0); | 151 | q->pre_coef2[i] = (r1 - r2) * sqrt(2.0); |
| 140 | } | 152 | } |
| 141 | |||
| 142 | q->last_fft_im[i] = 0; | ||
| 143 | } | 153 | } |
| 144 | 154 | ||
| 145 | /* Generate a square root table */ | 155 | /* Generate a square root table */ |
| @@ -164,8 +174,9 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 18 unmodified lines | |||
| 164 | return ret; | 174 | return ret; |
| 165 | } | 175 | } |
| 166 | ff_dsputil_init(&q->dsp, avctx); | 176 | ff_dsputil_init(&q->dsp, avctx); |
| 167 | avctx->sample_fmt = AV_SAMPLE_FMT_FLT; | 177 | avctx->sample_fmt = AV_SAMPLE_FMT_FLT; |
| 168 | avctx->channel_layout = AV_CH_LAYOUT_MONO; | 178 | avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO |
| 179 | : AV_CH_LAYOUT_STEREO; | ||
| 169 | 180 | ||
| 170 | avcodec_get_frame_defaults(&q->frame); | 181 | avcodec_get_frame_defaults(&q->frame); |
| 171 | avctx->coded_frame = &q->frame; | 182 | avctx->coded_frame = &q->frame; |
| @@ -313,8 +324,8 @@ static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, · 141 unmodified lines | |||
| 313 | /** | 324 | /** |
| 314 | * Perform bit allocation depending on bits available | 325 | * Perform bit allocation depending on bits available |
| 315 | */ | 326 | */ |
| 316 | static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, | 327 | static int bit_allocation(IMCContext *q, IMCChannel *chctx, |
| 317 | int flag) | 328 | int stream_format_code, int freebits, int flag) |
| 318 | { | 329 | { |
| 319 | int i, j; | 330 | int i, j; |
| 320 | const float limit = -1.e20; | 331 | const float limit = -1.e20; |
| @@ -333,43 +344,43 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 12 unmodified lines | |||
| 333 | int found_indx = 0; | 344 | int found_indx = 0; |
| 334 | 345 | ||
| 335 | for (i = 0; i < BANDS; i++) | 346 | for (i = 0; i < BANDS; i++) |
| 336 | highest = FFMAX(highest, q->flcoeffs1[i]); | 347 | highest = FFMAX(highest, chctx->flcoeffs1[i]); |
| 337 | 348 | ||
| 338 | for (i = 0; i < BANDS - 1; i++) | 349 | for (i = 0; i < BANDS - 1; i++) |
| 339 | q->flcoeffs4[i] = q->flcoeffs3[i] - log(q->flcoeffs5[i]) / log(2); | 350 | chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log(chctx->flcoeffs5[i]) / log(2); |
| 340 | q->flcoeffs4[BANDS - 1] = limit; | 351 | chctx->flcoeffs4[BANDS - 1] = limit; |
| 341 | 352 | ||
| 342 | highest = highest * 0.25; | 353 | highest = highest * 0.25; |
| 343 | 354 | ||
| 344 | for (i = 0; i < BANDS; i++) { | 355 | for (i = 0; i < BANDS; i++) { |
| 345 | indx = -1; | 356 | indx = -1; |
| 346 | if ((band_tab[i + 1] - band_tab[i]) == q->bandWidthT[i]) | 357 | if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i]) |
| 347 | indx = 0; | 358 | indx = 0; |
| 348 | 359 | ||
| 349 | if ((band_tab[i + 1] - band_tab[i]) > q->bandWidthT[i]) | 360 | if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i]) |
| 350 | indx = 1; | 361 | indx = 1; |
| 351 | 362 | ||
| 352 | if (((band_tab[i + 1] - band_tab[i]) / 2) >= q->bandWidthT[i]) | 363 | if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i]) |
| 353 | indx = 2; | 364 | indx = 2; |
| 354 | 365 | ||
| 355 | if (indx == -1) | 366 | if (indx == -1) |
| 356 | return AVERROR_INVALIDDATA; | 367 | return AVERROR_INVALIDDATA; |
| 357 | 368 | ||
| 358 | q->flcoeffs4[i] += xTab[(indx * 2 + (q->flcoeffs1[i] < highest)) * 2 + flag]; | 369 | chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag]; |
| 359 | } | 370 | } |
| 360 | 371 | ||
| 361 | if (stream_format_code & 0x2) { | 372 | if (stream_format_code & 0x2) { |
| 362 | q->flcoeffs4[0] = limit; | 373 | chctx->flcoeffs4[0] = limit; |
| 363 | q->flcoeffs4[1] = limit; | 374 | chctx->flcoeffs4[1] = limit; |
| 364 | q->flcoeffs4[2] = limit; | 375 | chctx->flcoeffs4[2] = limit; |
| 365 | q->flcoeffs4[3] = limit; | 376 | chctx->flcoeffs4[3] = limit; |
| 366 | } | 377 | } |
| 367 | 378 | ||
| 368 | for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) { | 379 | for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) { |
| 369 | iacc += q->bandWidthT[i]; | 380 | iacc += chctx->bandWidthT[i]; |
| 370 | summa += q->bandWidthT[i] * q->flcoeffs4[i]; | 381 | summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i]; |
| 371 | } | 382 | } |
| 372 | q->bandWidthT[BANDS - 1] = 0; | 383 | chctx->bandWidthT[BANDS - 1] = 0; |
| 373 | summa = (summa * 0.5 - freebits) / iacc; | 384 | summa = (summa * 0.5 - freebits) / iacc; |
| 374 | 385 | ||
| 375 | 386 | ||
| @@ -382,13 +393,13 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 6 unmodified lines | |||
| 382 | iacc = 0; | 393 | iacc = 0; |
| 383 | 394 | ||
| 384 | for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) { | 395 | for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) { |
| 385 | cwlen = av_clipf(((q->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); | 396 | cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); |
| 386 | 397 | ||
| 387 | q->bitsBandT[j] = cwlen; | 398 | chctx->bitsBandT[j] = cwlen; |
| 388 | summer += q->bandWidthT[j] * cwlen; | 399 | summer += chctx->bandWidthT[j] * cwlen; |
| 389 | 400 | ||
| 390 | if (cwlen > 0) | 401 | if (cwlen > 0) |
| 391 | iacc += q->bandWidthT[j]; | 402 | iacc += chctx->bandWidthT[j]; |
| 392 | } | 403 | } |
| 393 | 404 | ||
| 394 | flg = t2; | 405 | flg = t2; |
| @@ -405,13 +416,13 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 10 unmodified lines | |||
| 405 | 416 | ||
| 406 | for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) { | 417 | for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) { |
| 407 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) | 418 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) |
| 408 | q->CWlengthT[j] = q->bitsBandT[i]; | 419 | chctx->CWlengthT[j] = chctx->bitsBandT[i]; |
| 409 | } | 420 | } |
| 410 | 421 | ||
| 411 | if (freebits > summer) { | 422 | if (freebits > summer) { |
| 412 | for (i = 0; i < BANDS; i++) { | 423 | for (i = 0; i < BANDS; i++) { |
| 413 | workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 | 424 | workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20 |
| 414 | : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415); | 425 | : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415); |
| 415 | } | 426 | } |
| 416 | 427 | ||
| 417 | highest = 0.0; | 428 | highest = 0.0; |
| @@ -432,11 +443,11 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 14 unmodified lines | |||
| 432 | 443 | ||
| 433 | if (highest > -1.e20) { | 444 | if (highest > -1.e20) { |
| 434 | workT[found_indx] -= 2.0; | 445 | workT[found_indx] -= 2.0; |
| 435 | if (++q->bitsBandT[found_indx] == 6) | 446 | if (++chctx->bitsBandT[found_indx] == 6) |
| 436 | workT[found_indx] = -1.e20; | 447 | workT[found_indx] = -1.e20; |
| 437 | 448 | ||
| 438 | for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) { | 449 | for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) { |
| 439 | q->CWlengthT[j]++; | 450 | chctx->CWlengthT[j]++; |
| 440 | summer++; | 451 | summer++; |
| 441 | } | 452 | } |
| 442 | } | 453 | } |
| @@ -444,7 +455,7 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 1 unmodified line | |||
| 444 | } | 455 | } |
| 445 | if (freebits < summer) { | 456 | if (freebits < summer) { |
| 446 | for (i = 0; i < BANDS; i++) { | 457 | for (i = 0; i < BANDS; i++) { |
| 447 | workT[i] = q->bitsBandT[i] ? (q->bitsBandT[i] * -2 + q->flcoeffs4[i] + 1.585) | 458 | workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585) |
| 448 | : 1.e20; | 459 | : 1.e20; |
| 449 | } | 460 | } |
| 450 | if (stream_format_code & 0x2) { | 461 | if (stream_format_code & 0x2) { |
| @@ -466,12 +477,12 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 15 unmodified lines | |||
| 466 | // break; | 477 | // break; |
| 467 | workT[low_indx] = lowest + 2.0; | 478 | workT[low_indx] = lowest + 2.0; |
| 468 | 479 | ||
| 469 | if (!--q->bitsBandT[low_indx]) | 480 | if (!--chctx->bitsBandT[low_indx]) |
| 470 | workT[low_indx] = 1.e20; | 481 | workT[low_indx] = 1.e20; |
| 471 | 482 | ||
| 472 | for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) { | 483 | for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) { |
| 473 | if (q->CWlengthT[j] > 0) { | 484 | if (chctx->CWlengthT[j] > 0) { |
| 474 | q->CWlengthT[j]--; | 485 | chctx->CWlengthT[j]--; |
| 475 | summer--; | 486 | summer--; |
| 476 | } | 487 | } |
| 477 | } | 488 | } |
| @@ -480,54 +491,54 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 2 unmodified lines | |||
| 480 | return 0; | 491 | return 0; |
| 481 | } | 492 | } |
| 482 | 493 | ||
| 483 | static void imc_get_skip_coeff(IMCContext *q) | 494 | static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx) |
| 484 | { | 495 | { |
| 485 | int i, j; | 496 | int i, j; |
| 486 | 497 | ||
| 487 | memset(q->skipFlagBits, 0, sizeof(q->skipFlagBits)); | 498 | memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits)); |
| 488 | memset(q->skipFlagCount, 0, sizeof(q->skipFlagCount)); | 499 | memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount)); |
| 489 | for (i = 0; i < BANDS; i++) { | 500 | for (i = 0; i < BANDS; i++) { |
| 490 | if (!q->bandFlagsBuf[i] || !q->bandWidthT[i]) | 501 | if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i]) |
| 491 | continue; | 502 | continue; |
| 492 | 503 | ||
| 493 | if (!q->skipFlagRaw[i]) { | 504 | if (!chctx->skipFlagRaw[i]) { |
| 494 | q->skipFlagBits[i] = band_tab[i + 1] - band_tab[i]; | 505 | chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i]; |
| 495 | 506 | ||
| 496 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { | 507 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { |
| 497 | q->skipFlags[j] = get_bits1(&q->gb); | 508 | chctx->skipFlags[j] = get_bits1(&q->gb); |
| 498 | if (q->skipFlags[j]) | 509 | if (chctx->skipFlags[j]) |
| 499 | q->skipFlagCount[i]++; | 510 | chctx->skipFlagCount[i]++; |
| 500 | } | 511 | } |
| 501 | } else { | 512 | } else { |
| 502 | for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) { | 513 | for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) { |
| 503 | if (!get_bits1(&q->gb)) { // 0 | 514 | if (!get_bits1(&q->gb)) { // 0 |
| 504 | q->skipFlagBits[i]++; | 515 | chctx->skipFlagBits[i]++; |
| 505 | q->skipFlags[j] = 1; | 516 | chctx->skipFlags[j] = 1; |
| 506 | q->skipFlags[j + 1] = 1; | 517 | chctx->skipFlags[j + 1] = 1; |
| 507 | q->skipFlagCount[i] += 2; | 518 | chctx->skipFlagCount[i] += 2; |
| 508 | } else { | 519 | } else { |
| 509 | if (get_bits1(&q->gb)) { // 11 | 520 | if (get_bits1(&q->gb)) { // 11 |
| 510 | q->skipFlagBits[i] += 2; | 521 | chctx->skipFlagBits[i] += 2; |
| 511 | q->skipFlags[j] = 0; | 522 | chctx->skipFlags[j] = 0; |
| 512 | q->skipFlags[j + 1] = 1; | 523 | chctx->skipFlags[j + 1] = 1; |
| 513 | q->skipFlagCount[i]++; | 524 | chctx->skipFlagCount[i]++; |
| 514 | } else { | 525 | } else { |
| 515 | q->skipFlagBits[i] += 3; | 526 | chctx->skipFlagBits[i] += 3; |
| 516 | q->skipFlags[j + 1] = 0; | 527 | chctx->skipFlags[j + 1] = 0; |
| 517 | if (!get_bits1(&q->gb)) { // 100 | 528 | if (!get_bits1(&q->gb)) { // 100 |
| 518 | q->skipFlags[j] = 1; | 529 | chctx->skipFlags[j] = 1; |
| 519 | q->skipFlagCount[i]++; | 530 | chctx->skipFlagCount[i]++; |
| 520 | } else { // 101 | 531 | } else { // 101 |
| 521 | q->skipFlags[j] = 0; | 532 | chctx->skipFlags[j] = 0; |
| 522 | } | 533 | } |
| 523 | } | 534 | } |
| 524 | } | 535 | } |
| 525 | } | 536 | } |
| 526 | 537 | ||
| 527 | if (j < band_tab[i + 1]) { | 538 | if (j < band_tab[i + 1]) { |
| 528 | q->skipFlagBits[i]++; | 539 | chctx->skipFlagBits[i]++; |
| 529 | if ((q->skipFlags[j] = get_bits1(&q->gb))) | 540 | if ((chctx->skipFlags[j] = get_bits1(&q->gb))) |
| 530 | q->skipFlagCount[i]++; | 541 | chctx->skipFlagCount[i]++; |
| 531 | } | 542 | } |
| 532 | } | 543 | } |
| 533 | } | 544 | } |
| @@ -536,7 +547,8 @@ static void imc_get_skip_coeff(IMCContext *q) · 2 unmodified lines | |||
| 536 | /** | 547 | /** |
| 537 | * Increase highest' band coefficient sizes as some bits won't be used | 548 | * Increase highest' band coefficient sizes as some bits won't be used |
| 538 | */ | 549 | */ |
| 539 | static void imc_adjust_bit_allocation(IMCContext *q, int summer) | 550 | static void imc_adjust_bit_allocation(IMCContext *q, IMCChannel *chctx, |
| 551 | int summer) | ||
| 540 | { | 552 | { |
| 541 | float workT[32]; | 553 | float workT[32]; |
| 542 | int corrected = 0; | 554 | int corrected = 0; |
| @@ -545,8 +557,8 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 2 unmodified lines | |||
| 545 | int found_indx = 0; | 557 | int found_indx = 0; |
| 546 | 558 | ||
| 547 | for (i = 0; i < BANDS; i++) { | 559 | for (i = 0; i < BANDS; i++) { |
| 548 | workT[i] = (q->bitsBandT[i] == 6) ? -1.e20 | 560 | workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20 |
| 549 | : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415); | 561 | : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415); |
| 550 | } | 562 | } |
| 551 | 563 | ||
| 552 | while (corrected < summer) { | 564 | while (corrected < summer) { |
| @@ -564,12 +576,12 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 11 unmodified lines | |||
| 564 | 576 | ||
| 565 | if (highest > -1.e20) { | 577 | if (highest > -1.e20) { |
| 566 | workT[found_indx] -= 2.0; | 578 | workT[found_indx] -= 2.0; |
| 567 | if (++(q->bitsBandT[found_indx]) == 6) | 579 | if (++(chctx->bitsBandT[found_indx]) == 6) |
| 568 | workT[found_indx] = -1.e20; | 580 | workT[found_indx] = -1.e20; |
| 569 | 581 | ||
| 570 | for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) { | 582 | for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) { |
| 571 | if (!q->skipFlags[j] && (q->CWlengthT[j] < 6)) { | 583 | if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) { |
| 572 | q->CWlengthT[j]++; | 584 | chctx->CWlengthT[j]++; |
| 573 | corrected++; | 585 | corrected++; |
| 574 | } | 586 | } |
| 575 | } | 587 | } |
| @@ -577,17 +589,17 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 1 unmodified line | |||
| 577 | } | 589 | } |
| 578 | } | 590 | } |
| 579 | 591 | ||
| 580 | static void imc_imdct256(IMCContext *q) | 592 | static void imc_imdct256(IMCContext *q, IMCChannel *chctx) |
| 581 | { | 593 | { |
| 582 | int i; | 594 | int i; |
| 583 | float re, im; | 595 | float re, im; |
| 584 | 596 | ||
| 585 | /* prerotation */ | 597 | /* prerotation */ |
| 586 | for (i = 0; i < COEFFS / 2; i++) { | 598 | for (i = 0; i < COEFFS / 2; i++) { |
| 587 | q->samples[i].re = -(q->pre_coef1[i] * q->CWdecoded[COEFFS - 1 - i * 2]) - | 599 | q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) - |
| 588 | (q->pre_coef2[i] * q->CWdecoded[i * 2]); | 600 | (q->pre_coef2[i] * chctx->CWdecoded[i * 2]); |
| 589 | q->samples[i].im = (q->pre_coef2[i] * q->CWdecoded[COEFFS - 1 - i * 2]) - | 601 | q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) - |
| 590 | (q->pre_coef1[i] * q->CWdecoded[i * 2]); | 602 | (q->pre_coef1[i] * chctx->CWdecoded[i * 2]); |
| 591 | } | 603 | } |
| 592 | 604 | ||
| 593 | /* FFT */ | 605 | /* FFT */ |
| @@ -598,15 +610,16 @@ static void imc_imdct256(IMCContext *q) · 4 unmodified lines | |||
| 598 | for (i = 0; i < COEFFS / 2; i++) { | 610 | for (i = 0; i < COEFFS / 2; i++) { |
| 599 | re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]); | 611 | re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]); |
| 600 | im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]); | 612 | im = (-q->samples[i].im * q->post_cos[i]) - ( q->samples[i].re * q->post_sin[i]); |
| 601 | q->out_samples[i * 2] = (q->mdct_sine_window[COEFFS - 1 - i * 2] * q->last_fft_im[i]) | 613 | q->out_samples[i * 2] = (q->mdct_sine_window[COEFFS - 1 - i * 2] * chctx->last_fft_im[i]) |
| 602 | + (q->mdct_sine_window[i * 2] * re); | 614 | + (q->mdct_sine_window[i * 2] * re); |
| 603 | q->out_samples[COEFFS - 1 - i * 2] = (q->mdct_sine_window[i * 2] * q->last_fft_im[i]) | 615 | q->out_samples[COEFFS - 1 - i * 2] = (q->mdct_sine_window[i * 2] * chctx->last_fft_im[i]) |
| 604 | - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re); | 616 | - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re); |
| 605 | q->last_fft_im[i] = im; | 617 | chctx->last_fft_im[i] = im; |
| 606 | } | 618 | } |
| 607 | } | 619 | } |
| 608 | 620 | ||
| 609 | static int inverse_quant_coeff(IMCContext *q, int stream_format_code) | 621 | static int inverse_quant_coeff(IMCContext *q, IMCChannel *chctx, |
| 622 | int stream_format_code) | ||
| 610 | { | 623 | { |
| 611 | int i, j; | 624 | int i, j; |
| 612 | int middle_value, cw_len, max_size; | 625 | int middle_value, cw_len, max_size; |
| @@ -614,30 +627,30 @@ static int inverse_quant_coeff(IMCContext *q, int stream_format_code) · 1 unmodified line | |||
| 614 | 627 | ||
| 615 | for (i = 0; i < BANDS; i++) { | 628 | for (i = 0; i < BANDS; i++) { |
| 616 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { | 629 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { |
| 617 | q->CWdecoded[j] = 0; | 630 | chctx->CWdecoded[j] = 0; |
| 618 | cw_len = q->CWlengthT[j]; | 631 | cw_len = chctx->CWlengthT[j]; |
| 619 | 632 | ||
| 620 | if (cw_len <= 0 || q->skipFlags[j]) | 633 | if (cw_len <= 0 || chctx->skipFlags[j]) |
| 621 | continue; | 634 | continue; |
| 622 | 635 | ||
| 623 | max_size = 1 << cw_len; | 636 | max_size = 1 << cw_len; |
| 624 | middle_value = max_size >> 1; | 637 | middle_value = max_size >> 1; |
| 625 | 638 | ||
| 626 | if (q->codewords[j] >= max_size || q->codewords[j] < 0) | 639 | if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0) |
| 627 | return AVERROR_INVALIDDATA; | 640 | return AVERROR_INVALIDDATA; |
| 628 | 641 | ||
| 629 | if (cw_len >= 4) { | 642 | if (cw_len >= 4) { |
| 630 | quantizer = imc_quantizer2[(stream_format_code & 2) >> 1]; | 643 | quantizer = imc_quantizer2[(stream_format_code & 2) >> 1]; |
| 631 | if (q->codewords[j] >= middle_value) | 644 | if (chctx->codewords[j] >= middle_value) |
| 632 | q->CWdecoded[j] = quantizer[q->codewords[j] - 8] * q->flcoeffs6[i]; | 645 | chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i]; |
| 633 | else | 646 | else |
| 634 | q->CWdecoded[j] = -quantizer[max_size - q->codewords[j] - 8 - 1] * q->flcoeffs6[i]; | 647 | chctx->CWdecoded[j] = -quantizer[max_size - chctx->codewords[j] - 8 - 1] * chctx->flcoeffs6[i]; |
| 635 | }else{ | 648 | }else{ |
| 636 | quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (q->bandFlagsBuf[i] << 1)]; | 649 | quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)]; |
| 637 | if (q->codewords[j] >= middle_value) | 650 | if (chctx->codewords[j] >= middle_value) |
| 638 | q->CWdecoded[j] = quantizer[q->codewords[j] - 1] * q->flcoeffs6[i]; | 651 | chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i]; |
| 639 | else | 652 | else |
| 640 | q->CWdecoded[j] = -quantizer[max_size - 2 - q->codewords[j]] * q->flcoeffs6[i]; | 653 | chctx->CWdecoded[j] = -quantizer[max_size - 2 - chctx->codewords[j]] * chctx->flcoeffs6[i]; |
| 641 | } | 654 | } |
| 642 | } | 655 | } |
| 643 | } | 656 | } |
| @@ -645,16 +658,16 @@ static int inverse_quant_coeff(IMCContext *q, int stream_format_code) · 1 unmodified line | |||
| 645 | } | 658 | } |
| 646 | 659 | ||
| 647 | 660 | ||
| 648 | static int imc_get_coeffs(IMCContext *q) | 661 | static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx) |
| 649 | { | 662 | { |
| 650 | int i, j, cw_len, cw; | 663 | int i, j, cw_len, cw; |
| 651 | 664 | ||
| 652 | for (i = 0; i < BANDS; i++) { | 665 | for (i = 0; i < BANDS; i++) { |
| 653 | if (!q->sumLenArr[i]) | 666 | if (!chctx->sumLenArr[i]) |
| 654 | continue; | 667 | continue; |
| 655 | if (q->bandFlagsBuf[i] || q->bandWidthT[i]) { | 668 | if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) { |
| 656 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { | 669 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { |
| 657 | cw_len = q->CWlengthT[j]; | 670 | cw_len = chctx->CWlengthT[j]; |
| 658 | cw = 0; | 671 | cw = 0; |
| 659 | 672 | ||
| 660 | if (get_bits_count(&q->gb) + cw_len > 512) { | 673 | if (get_bits_count(&q->gb) + cw_len > 512) { |
| @@ -662,47 +675,25 @@ static int imc_get_coeffs(IMCContext *q) · 1 unmodified line | |||
| 662 | return AVERROR_INVALIDDATA; | 675 | return AVERROR_INVALIDDATA; |
| 663 | } | 676 | } |
| 664 | 677 | ||
| 665 | if (cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j])) | 678 | if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j])) |
| 666 | cw = get_bits(&q->gb, cw_len); | 679 | cw = get_bits(&q->gb, cw_len); |
| 667 | 680 | ||
| 668 | q->codewords[j] = cw; | 681 | chctx->codewords[j] = cw; |
| 669 | } | 682 | } |
| 670 | } | 683 | } |
| 671 | } | 684 | } |
| 672 | return 0; | 685 | return 0; |
| 673 | } | 686 | } |
| 674 | 687 | ||
| 675 | static int imc_decode_frame(AVCodecContext *avctx, void *data, | 688 | static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch) |
| 676 | int *got_frame_ptr, AVPacket *avpkt) | ||
| 677 | { | 689 | { |
| 678 | const uint8_t *buf = avpkt->data; | ||
| 679 | int buf_size = avpkt->size; | ||
| 680 | |||
| 681 | IMCContext *q = avctx->priv_data; | ||
| 682 | |||
| 683 | int stream_format_code; | 690 | int stream_format_code; |
| 684 | int imc_hdr, i, j, ret; | 691 | int imc_hdr, i, j, ret; |
| 685 | int flag; | 692 | int flag; |
| 686 | int bits, summer; | 693 | int bits, summer; |
| 687 | int counter, bitscount; | 694 | int counter, bitscount; |
| 688 | LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]); | 695 | IMCChannel *chctx = q->chctx + ch; |
| 689 | 696 | ||
| 690 | if (buf_size < IMC_BLOCK_SIZE) { | ||
| 691 | av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); | ||
| 692 | return AVERROR_INVALIDDATA; | ||
| 693 | } | ||
| 694 | |||
| 695 | /* get output buffer */ | ||
| 696 | q->frame.nb_samples = COEFFS; | ||
| 697 | if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) { | ||
| 698 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | ||
| 699 | return ret; | ||
| 700 | } | ||
| 701 | q->out_samples = (float*)q->frame.data[0]; | ||
| 702 | |||
| 703 | q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2); | ||
| 704 | |||
| 705 | init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); | ||
| 706 | 697 | ||
| 707 | /* Check the frame header */ | 698 | /* Check the frame header */ |
| 708 | imc_hdr = get_bits(&q->gb, 9); | 699 | imc_hdr = get_bits(&q->gb, 9); |
| @@ -721,90 +712,90 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, · 12 unmodified lines | |||
| 721 | // av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code); | 712 | // av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code); |
| 722 | 713 | ||
| 723 | if (stream_format_code & 0x04) | 714 | if (stream_format_code & 0x04) |
| 724 | q->decoder_reset = 1; | 715 | chctx->decoder_reset = 1; |
| 725 | 716 | ||
| 726 | if (q->decoder_reset) { | 717 | if (chctx->decoder_reset) { |
| 727 | memset(q->out_samples, 0, sizeof(q->out_samples)); | 718 | memset(q->out_samples, 0, sizeof(q->out_samples)); |
| 728 | for (i = 0; i < BANDS; i++) | 719 | for (i = 0; i < BANDS; i++) |
| 729 | q->old_floor[i] = 1.0; | 720 | chctx->old_floor[i] = 1.0; |
| 730 | for (i = 0; i < COEFFS; i++) | 721 | for (i = 0; i < COEFFS; i++) |
| 731 | q->CWdecoded[i] = 0; | 722 | chctx->CWdecoded[i] = 0; |
| 732 | q->decoder_reset = 0; | 723 | chctx->decoder_reset = 0; |
| 733 | } | 724 | } |
| 734 | 725 | ||
| 735 | flag = get_bits1(&q->gb); | 726 | flag = get_bits1(&q->gb); |
| 736 | imc_read_level_coeffs(q, stream_format_code, q->levlCoeffBuf); | 727 | imc_read_level_coeffs(q, stream_format_code, chctx->levlCoeffBuf); |
| 737 | 728 | ||
| 738 | if (stream_format_code & 0x4) | 729 | if (stream_format_code & 0x4) |
| 739 | imc_decode_level_coefficients(q, q->levlCoeffBuf, | 730 | imc_decode_level_coefficients(q, chctx->levlCoeffBuf, |
| 740 | q->flcoeffs1, q->flcoeffs2); | 731 | chctx->flcoeffs1, chctx->flcoeffs2); |
| 741 | else | 732 | else |
| 742 | imc_decode_level_coefficients2(q, q->levlCoeffBuf, q->old_floor, | 733 | imc_decode_level_coefficients2(q, chctx->levlCoeffBuf, chctx->old_floor, |
| 743 | q->flcoeffs1, q->flcoeffs2); | 734 | chctx->flcoeffs1, chctx->flcoeffs2); |
| 744 | 735 | ||
| 745 | memcpy(q->old_floor, q->flcoeffs1, 32 * sizeof(float)); | 736 | memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float)); |
| 746 | 737 | ||
| 747 | counter = 0; | 738 | counter = 0; |
| 748 | for (i = 0; i < BANDS; i++) { | 739 | for (i = 0; i < BANDS; i++) { |
| 749 | if (q->levlCoeffBuf[i] == 16) { | 740 | if (chctx->levlCoeffBuf[i] == 16) { |
| 750 | q->bandWidthT[i] = 0; | 741 | chctx->bandWidthT[i] = 0; |
| 751 | counter++; | 742 | counter++; |
| 752 | } else | 743 | } else |
| 753 | q->bandWidthT[i] = band_tab[i + 1] - band_tab[i]; | 744 | chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i]; |
| 754 | } | 745 | } |
| 755 | memset(q->bandFlagsBuf, 0, BANDS * sizeof(int)); | 746 | memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int)); |
| 756 | for (i = 0; i < BANDS - 1; i++) { | 747 | for (i = 0; i < BANDS - 1; i++) { |
| 757 | if (q->bandWidthT[i]) | 748 | if (chctx->bandWidthT[i]) |
| 758 | q->bandFlagsBuf[i] = get_bits1(&q->gb); | 749 | chctx->bandFlagsBuf[i] = get_bits1(&q->gb); |
| 759 | } | 750 | } |
| 760 | 751 | ||
| 761 | imc_calculate_coeffs(q, q->flcoeffs1, q->flcoeffs2, q->bandWidthT, q->flcoeffs3, q->flcoeffs5); | 752 | imc_calculate_coeffs(q, chctx->flcoeffs1, chctx->flcoeffs2, chctx->bandWidthT, chctx->flcoeffs3, chctx->flcoeffs5); |
| 762 | 753 | ||
| 763 | bitscount = 0; | 754 | bitscount = 0; |
| 764 | /* first 4 bands will be assigned 5 bits per coefficient */ | 755 | /* first 4 bands will be assigned 5 bits per coefficient */ |
| 765 | if (stream_format_code & 0x2) { | 756 | if (stream_format_code & 0x2) { |
| 766 | bitscount += 15; | 757 | bitscount += 15; |
| 767 | 758 | ||
| 768 | q->bitsBandT[0] = 5; | 759 | chctx->bitsBandT[0] = 5; |
| 769 | q->CWlengthT[0] = 5; | 760 | chctx->CWlengthT[0] = 5; |
| 770 | q->CWlengthT[1] = 5; | 761 | chctx->CWlengthT[1] = 5; |
| 771 | q->CWlengthT[2] = 5; | 762 | chctx->CWlengthT[2] = 5; |
| 772 | for (i = 1; i < 4; i++) { | 763 | for (i = 1; i < 4; i++) { |
| 773 | bits = (q->levlCoeffBuf[i] == 16) ? 0 : 5; | 764 | bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5; |
| 774 | q->bitsBandT[i] = bits; | 765 | chctx->bitsBandT[i] = bits; |
| 775 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { | 766 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { |
| 776 | q->CWlengthT[j] = bits; | 767 | chctx->CWlengthT[j] = bits; |
| 777 | bitscount += bits; | 768 | bitscount += bits; |
| 778 | } | 769 | } |
| 779 | } | 770 | } |
| 780 | } | 771 | } |
| 781 | 772 | ||
| 782 | if ((ret = bit_allocation(q, stream_format_code, | 773 | if ((ret = bit_allocation(q, chctx, stream_format_code, |
| 783 | 512 - bitscount - get_bits_count(&q->gb), | 774 | 512 - bitscount - get_bits_count(&q->gb), |
| 784 | flag)) < 0) { | 775 | flag)) < 0) { |
| 785 | av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n"); | 776 | av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n"); |
| 786 | q->decoder_reset = 1; | 777 | chctx->decoder_reset = 1; |
| 787 | return ret; | 778 | return ret; |
| 788 | } | 779 | } |
| 789 | 780 | ||
| 790 | for (i = 0; i < BANDS; i++) { | 781 | for (i = 0; i < BANDS; i++) { |
| 791 | q->sumLenArr[i] = 0; | 782 | chctx->sumLenArr[i] = 0; |
| 792 | q->skipFlagRaw[i] = 0; | 783 | chctx->skipFlagRaw[i] = 0; |
| 793 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) | 784 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) |
| 794 | q->sumLenArr[i] += q->CWlengthT[j]; | 785 | chctx->sumLenArr[i] += chctx->CWlengthT[j]; |
| 795 | if (q->bandFlagsBuf[i]) | 786 | if (chctx->bandFlagsBuf[i]) |
| 796 | if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > q->sumLenArr[i]) && (q->sumLenArr[i] > 0)) | 787 | if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0)) |
| 797 | q->skipFlagRaw[i] = 1; | 788 | chctx->skipFlagRaw[i] = 1; |
| 798 | } | 789 | } |
| 799 | 790 | ||
| 800 | imc_get_skip_coeff(q); | 791 | imc_get_skip_coeff(q, chctx); |
| 801 | 792 | ||
| 802 | for (i = 0; i < BANDS; i++) { | 793 | for (i = 0; i < BANDS; i++) { |
| 803 | q->flcoeffs6[i] = q->flcoeffs1[i]; | 794 | chctx->flcoeffs6[i] = chctx->flcoeffs1[i]; |
| 804 | /* band has flag set and at least one coded coefficient */ | 795 | /* band has flag set and at least one coded coefficient */ |
| 805 | if (q->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != q->skipFlagCount[i]) { | 796 | if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) { |
| 806 | q->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] / | 797 | chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] / |
| 807 | q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - q->skipFlagCount[i])]; | 798 | q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])]; |
| 808 | } | 799 | } |
| 809 | } | 800 | } |
| 810 | 801 | ||
| @@ -812,49 +803,88 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, · 1 unmodified line | |||
| 812 | bits = summer = 0; | 803 | bits = summer = 0; |
| 813 | 804 | ||
| 814 | for (i = 0; i < BANDS; i++) { | 805 | for (i = 0; i < BANDS; i++) { |
| 815 | if (q->bandFlagsBuf[i]) { | 806 | if (chctx->bandFlagsBuf[i]) { |
| 816 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { | 807 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) { |
| 817 | if (q->skipFlags[j]) { | 808 | if (chctx->skipFlags[j]) { |
| 818 | summer += q->CWlengthT[j]; | 809 | summer += chctx->CWlengthT[j]; |
| 819 | q->CWlengthT[j] = 0; | 810 | chctx->CWlengthT[j] = 0; |
| 820 | } | 811 | } |
| 821 | } | 812 | } |
| 822 | bits += q->skipFlagBits[i]; | 813 | bits += chctx->skipFlagBits[i]; |
| 823 | summer -= q->skipFlagBits[i]; | 814 | summer -= chctx->skipFlagBits[i]; |
| 824 | } | 815 | } |
| 825 | } | 816 | } |
| 826 | imc_adjust_bit_allocation(q, summer); | 817 | imc_adjust_bit_allocation(q, chctx, summer); |
| 827 | 818 | ||
| 828 | for (i = 0; i < BANDS; i++) { | 819 | for (i = 0; i < BANDS; i++) { |
| 829 | q->sumLenArr[i] = 0; | 820 | chctx->sumLenArr[i] = 0; |
| 830 | 821 | ||
| 831 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) | 822 | for (j = band_tab[i]; j < band_tab[i + 1]; j++) |
| 832 | if (!q->skipFlags[j]) | 823 | if (!chctx->skipFlags[j]) |
| 833 | q->sumLenArr[i] += q->CWlengthT[j]; | 824 | chctx->sumLenArr[i] += chctx->CWlengthT[j]; |
| 834 | } | 825 | } |
| 835 | 826 | ||
| 836 | memset(q->codewords, 0, sizeof(q->codewords)); | 827 | memset(chctx->codewords, 0, sizeof(chctx->codewords)); |
| 837 | 828 | ||
| 838 | if (imc_get_coeffs(q) < 0) { | 829 | if (imc_get_coeffs(q, chctx) < 0) { |
| 839 | av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n"); | 830 | av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n"); |
| 840 | q->decoder_reset = 1; | 831 | chctx->decoder_reset = 1; |
| 841 | return AVERROR_INVALIDDATA; | 832 | return AVERROR_INVALIDDATA; |
| 842 | } | 833 | } |
| 843 | 834 | ||
| 844 | if (inverse_quant_coeff(q, stream_format_code) < 0) { | 835 | if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) { |
| 845 | av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n"); | 836 | av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n"); |
| 846 | q->decoder_reset = 1; | 837 | chctx->decoder_reset = 1; |
| 838 | return AVERROR_INVALIDDATA; | ||
| 839 | } | ||
| 840 | |||
| 841 | memset(chctx->skipFlags, 0, sizeof(chctx->skipFlags)); | ||
| 842 | |||
| 843 | imc_imdct256(q, chctx); | ||
| 844 | |||
| 845 | return 0; | ||
| 846 | } | ||
| 847 | |||
| 848 | static int imc_decode_frame(AVCodecContext *avctx, void *data, | ||
| 849 | int *got_frame_ptr, AVPacket *avpkt) | ||
| 850 | { | ||
| 851 | const uint8_t *buf = avpkt->data; | ||
| 852 | int buf_size = avpkt->size; | ||
| 853 | int ret, i; | ||
| 854 | |||
| 855 | IMCContext *q = avctx->priv_data; | ||
| 856 | |||
| 857 | LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]); | ||
| 858 | |||
| 859 | if (buf_size < IMC_BLOCK_SIZE) { | ||
| 860 | av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); | ||
| 847 | return AVERROR_INVALIDDATA; | 861 | return AVERROR_INVALIDDATA; |
| 848 | } | 862 | } |
| 849 | 863 | ||
| 850 | memset(q->skipFlags, 0, sizeof(q->skipFlags)); | 864 | /* get output buffer */ |
| 865 | q->frame.nb_samples = COEFFS; | ||
| 866 | if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) { | ||
| 867 | av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); | ||
| 868 | return ret; | ||
| 869 | } | ||
| 851 | 870 | ||
| 852 | imc_imdct256(q); | 871 | for (i = 0; i < avctx->channels; i++) { |
| 872 | q->out_samples = (float*)q->frame.data[0] + i; | ||
| 873 | |||
| 874 | q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2); | ||
| 875 | |||
| 876 | init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); | ||
| 877 | |||
| 878 | buf += IMC_BLOCK_SIZE; | ||
| 879 | |||
| 880 | if ((ret = imc_decode_block(avctx, q, i)) < 0) | ||
| 881 | return ret; | ||
| 882 | } | ||
| 853 | 883 | ||
| 854 | *got_frame_ptr = 1; | 884 | *got_frame_ptr = 1; |
| 855 | *(AVFrame *)data = q->frame; | 885 | *(AVFrame *)data = q->frame; |
| 856 | 886 | ||
| 857 | return IMC_BLOCK_SIZE; | 887 | return IMC_BLOCK_SIZE * avctx->channels; |
| 858 | } | 888 | } |
| 859 | 889 | ||
| 860 | 890 | ||