History

imc: move channel-specific data into separate context

This will be useful for Indeo Audio decoder which is almost the same but supports stereo.

Kostya Shishkov committed 14 years ago

Commit c45e2da1 parent 803391f1 file · +217 −187Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/imc.c+217−187
@@ -49,9 +49,7 @@ · 48 unmodified lines
4949 #define BANDS 32
5050 #define COEFFS 256
5151
52−typedef struct {
53− AVFrame frame;
54−
52+typedef struct IMCChannel {
5553 float old_floor[BANDS];
5654 float flcoeffs1[BANDS];
5755 float flcoeffs2[BANDS];
@@ -61,16 +59,6 @@ typedef struct { · 3 unmodified lines
6159 float flcoeffs6[BANDS];
6260 float CWdecoded[COEFFS];
6361
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−
7462 int bandWidthT[BANDS]; ///< codewords per band
7563 int bitsBandT[BANDS]; ///< how many bits per codeword in band
7664 int CWlengthT[COEFFS]; ///< how many bits in each codeword
@@ -82,9 +70,28 @@ typedef struct { · 5 unmodified lines
8270 int skipFlagCount[BANDS]; ///< skipped coeffients per band
8371 int skipFlags[COEFFS]; ///< skip coefficient decoding or not
8472 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+
8593 float sqrt_tab[30];
8694 GetBitContext gb;
87− int decoder_reset;
8895 float one_div_log2;
8996
9097 DSPContext dsp;
@@ -115,10 +122,15 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 24 unmodified lines
115122 return AVERROR_PATCHWELCOME;
116123 }
117124
118− q->decoder_reset = 1;
125+ for (j = 0; j < avctx->channels; j++) {
126+ q->chctx[j].decoder_reset = 1;
119127
120− for (i = 0; i < BANDS; i++)
121− q->old_floor[i] = 1.0;
128+ for (i = 0; i < BANDS; i++)
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+ }
122134
123135 /* Build mdct window, a simple sine window normalized with sqrt(2) */
124136 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
138150 q->pre_coef1[i] = -(r1 + r2) * sqrt(2.0);
139151 q->pre_coef2[i] = (r1 - r2) * sqrt(2.0);
140152 }
141−
142− q->last_fft_im[i] = 0;
143153 }
144154
145155 /* Generate a square root table */
@@ -164,8 +174,9 @@ static av_cold int imc_decode_init(AVCodecContext *avctx) · 18 unmodified lines
164174 return ret;
165175 }
166176 ff_dsputil_init(&q->dsp, avctx);
167− avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
168− avctx->channel_layout = AV_CH_LAYOUT_MONO;
177+ avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
178+ avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
179+ : AV_CH_LAYOUT_STEREO;
169180
170181 avcodec_get_frame_defaults(&q->frame);
171182 avctx->coded_frame = &q->frame;
@@ -313,8 +324,8 @@ static void imc_decode_level_coefficients2(IMCContext *q, int *levlCoeffBuf, · 141 unmodified lines
313324 /**
314325 * Perform bit allocation depending on bits available
315326 */
316−static int bit_allocation(IMCContext *q, int stream_format_code, int freebits,
317− int flag)
327+static int bit_allocation(IMCContext *q, IMCChannel *chctx,
328+ int stream_format_code, int freebits, int flag)
318329 {
319330 int i, j;
320331 const float limit = -1.e20;
@@ -333,43 +344,43 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 12 unmodified lines
333344 int found_indx = 0;
334345
335346 for (i = 0; i < BANDS; i++)
336− highest = FFMAX(highest, q->flcoeffs1[i]);
347+ highest = FFMAX(highest, chctx->flcoeffs1[i]);
337348
338349 for (i = 0; i < BANDS - 1; i++)
339− q->flcoeffs4[i] = q->flcoeffs3[i] - log(q->flcoeffs5[i]) / log(2);
340− q->flcoeffs4[BANDS - 1] = limit;
350+ chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log(chctx->flcoeffs5[i]) / log(2);
351+ chctx->flcoeffs4[BANDS - 1] = limit;
341352
342353 highest = highest * 0.25;
343354
344355 for (i = 0; i < BANDS; i++) {
345356 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])
347358 indx = 0;
348359
349− if ((band_tab[i + 1] - band_tab[i]) > q->bandWidthT[i])
360+ if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i])
350361 indx = 1;
351362
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])
353364 indx = 2;
354365
355366 if (indx == -1)
356367 return AVERROR_INVALIDDATA;
357368
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];
359370 }
360371
361372 if (stream_format_code & 0x2) {
362− q->flcoeffs4[0] = limit;
363− q->flcoeffs4[1] = limit;
364− q->flcoeffs4[2] = limit;
365− q->flcoeffs4[3] = limit;
373+ chctx->flcoeffs4[0] = limit;
374+ chctx->flcoeffs4[1] = limit;
375+ chctx->flcoeffs4[2] = limit;
376+ chctx->flcoeffs4[3] = limit;
366377 }
367378
368379 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) {
369− iacc += q->bandWidthT[i];
370− summa += q->bandWidthT[i] * q->flcoeffs4[i];
380+ iacc += chctx->bandWidthT[i];
381+ summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i];
371382 }
372− q->bandWidthT[BANDS - 1] = 0;
383+ chctx->bandWidthT[BANDS - 1] = 0;
373384 summa = (summa * 0.5 - freebits) / iacc;
374385
375386
@@ -382,13 +393,13 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 6 unmodified lines
382393 iacc = 0;
383394
384395 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);
386397
387− q->bitsBandT[j] = cwlen;
388− summer += q->bandWidthT[j] * cwlen;
398+ chctx->bitsBandT[j] = cwlen;
399+ summer += chctx->bandWidthT[j] * cwlen;
389400
390401 if (cwlen > 0)
391− iacc += q->bandWidthT[j];
402+ iacc += chctx->bandWidthT[j];
392403 }
393404
394405 flg = t2;
@@ -405,13 +416,13 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 10 unmodified lines
405416
406417 for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) {
407418 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];
409420 }
410421
411422 if (freebits > summer) {
412423 for (i = 0; i < BANDS; i++) {
413− workT[i] = (q->bitsBandT[i] == 6) ? -1.e20
414− : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415);
424+ workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
425+ : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
415426 }
416427
417428 highest = 0.0;
@@ -432,11 +443,11 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 14 unmodified lines
432443
433444 if (highest > -1.e20) {
434445 workT[found_indx] -= 2.0;
435− if (++q->bitsBandT[found_indx] == 6)
446+ if (++chctx->bitsBandT[found_indx] == 6)
436447 workT[found_indx] = -1.e20;
437448
438449 for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) {
439− q->CWlengthT[j]++;
450+ chctx->CWlengthT[j]++;
440451 summer++;
441452 }
442453 }
@@ -444,7 +455,7 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 1 unmodified line
444455 }
445456 if (freebits < summer) {
446457 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)
448459 : 1.e20;
449460 }
450461 if (stream_format_code & 0x2) {
@@ -466,12 +477,12 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 15 unmodified lines
466477 // break;
467478 workT[low_indx] = lowest + 2.0;
468479
469− if (!--q->bitsBandT[low_indx])
480+ if (!--chctx->bitsBandT[low_indx])
470481 workT[low_indx] = 1.e20;
471482
472483 for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) {
473− if (q->CWlengthT[j] > 0) {
474− q->CWlengthT[j]--;
484+ if (chctx->CWlengthT[j] > 0) {
485+ chctx->CWlengthT[j]--;
475486 summer--;
476487 }
477488 }
@@ -480,54 +491,54 @@ static int bit_allocation(IMCContext *q, int stream_format_code, int freebits, · 2 unmodified lines
480491 return 0;
481492 }
482493
483−static void imc_get_skip_coeff(IMCContext *q)
494+static void imc_get_skip_coeff(IMCContext *q, IMCChannel *chctx)
484495 {
485496 int i, j;
486497
487− memset(q->skipFlagBits, 0, sizeof(q->skipFlagBits));
488− memset(q->skipFlagCount, 0, sizeof(q->skipFlagCount));
498+ memset(chctx->skipFlagBits, 0, sizeof(chctx->skipFlagBits));
499+ memset(chctx->skipFlagCount, 0, sizeof(chctx->skipFlagCount));
489500 for (i = 0; i < BANDS; i++) {
490− if (!q->bandFlagsBuf[i] || !q->bandWidthT[i])
501+ if (!chctx->bandFlagsBuf[i] || !chctx->bandWidthT[i])
491502 continue;
492503
493− if (!q->skipFlagRaw[i]) {
494− q->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
504+ if (!chctx->skipFlagRaw[i]) {
505+ chctx->skipFlagBits[i] = band_tab[i + 1] - band_tab[i];
495506
496507 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
497− q->skipFlags[j] = get_bits1(&q->gb);
498− if (q->skipFlags[j])
499− q->skipFlagCount[i]++;
508+ chctx->skipFlags[j] = get_bits1(&q->gb);
509+ if (chctx->skipFlags[j])
510+ chctx->skipFlagCount[i]++;
500511 }
501512 } else {
502513 for (j = band_tab[i]; j < band_tab[i + 1] - 1; j += 2) {
503514 if (!get_bits1(&q->gb)) { // 0
504− q->skipFlagBits[i]++;
505− q->skipFlags[j] = 1;
506− q->skipFlags[j + 1] = 1;
507− q->skipFlagCount[i] += 2;
515+ chctx->skipFlagBits[i]++;
516+ chctx->skipFlags[j] = 1;
517+ chctx->skipFlags[j + 1] = 1;
518+ chctx->skipFlagCount[i] += 2;
508519 } else {
509520 if (get_bits1(&q->gb)) { // 11
510− q->skipFlagBits[i] += 2;
511− q->skipFlags[j] = 0;
512− q->skipFlags[j + 1] = 1;
513− q->skipFlagCount[i]++;
521+ chctx->skipFlagBits[i] += 2;
522+ chctx->skipFlags[j] = 0;
523+ chctx->skipFlags[j + 1] = 1;
524+ chctx->skipFlagCount[i]++;
514525 } else {
515− q->skipFlagBits[i] += 3;
516− q->skipFlags[j + 1] = 0;
526+ chctx->skipFlagBits[i] += 3;
527+ chctx->skipFlags[j + 1] = 0;
517528 if (!get_bits1(&q->gb)) { // 100
518− q->skipFlags[j] = 1;
519− q->skipFlagCount[i]++;
529+ chctx->skipFlags[j] = 1;
530+ chctx->skipFlagCount[i]++;
520531 } else { // 101
521− q->skipFlags[j] = 0;
532+ chctx->skipFlags[j] = 0;
522533 }
523534 }
524535 }
525536 }
526537
527538 if (j < band_tab[i + 1]) {
528− q->skipFlagBits[i]++;
529− if ((q->skipFlags[j] = get_bits1(&q->gb)))
530− q->skipFlagCount[i]++;
539+ chctx->skipFlagBits[i]++;
540+ if ((chctx->skipFlags[j] = get_bits1(&q->gb)))
541+ chctx->skipFlagCount[i]++;
531542 }
532543 }
533544 }
@@ -536,7 +547,8 @@ static void imc_get_skip_coeff(IMCContext *q) · 2 unmodified lines
536547 /**
537548 * Increase highest' band coefficient sizes as some bits won't be used
538549 */
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)
540552 {
541553 float workT[32];
542554 int corrected = 0;
@@ -545,8 +557,8 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 2 unmodified lines
545557 int found_indx = 0;
546558
547559 for (i = 0; i < BANDS; i++) {
548− workT[i] = (q->bitsBandT[i] == 6) ? -1.e20
549− : (q->bitsBandT[i] * -2 + q->flcoeffs4[i] - 0.415);
560+ workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20
561+ : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415);
550562 }
551563
552564 while (corrected < summer) {
@@ -564,12 +576,12 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 11 unmodified lines
564576
565577 if (highest > -1.e20) {
566578 workT[found_indx] -= 2.0;
567− if (++(q->bitsBandT[found_indx]) == 6)
579+ if (++(chctx->bitsBandT[found_indx]) == 6)
568580 workT[found_indx] = -1.e20;
569581
570582 for (j = band_tab[found_indx]; j < band_tab[found_indx+1] && (corrected < summer); j++) {
571− if (!q->skipFlags[j] && (q->CWlengthT[j] < 6)) {
572− q->CWlengthT[j]++;
583+ if (!chctx->skipFlags[j] && (chctx->CWlengthT[j] < 6)) {
584+ chctx->CWlengthT[j]++;
573585 corrected++;
574586 }
575587 }
@@ -577,17 +589,17 @@ static void imc_adjust_bit_allocation(IMCContext *q, int summer) · 1 unmodified line
577589 }
578590 }
579591
580−static void imc_imdct256(IMCContext *q)
592+static void imc_imdct256(IMCContext *q, IMCChannel *chctx)
581593 {
582594 int i;
583595 float re, im;
584596
585597 /* prerotation */
586598 for (i = 0; i < COEFFS / 2; i++) {
587− q->samples[i].re = -(q->pre_coef1[i] * q->CWdecoded[COEFFS - 1 - i * 2]) -
588− (q->pre_coef2[i] * q->CWdecoded[i * 2]);
589− q->samples[i].im = (q->pre_coef2[i] * q->CWdecoded[COEFFS - 1 - i * 2]) -
590− (q->pre_coef1[i] * q->CWdecoded[i * 2]);
599+ q->samples[i].re = -(q->pre_coef1[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
600+ (q->pre_coef2[i] * chctx->CWdecoded[i * 2]);
601+ q->samples[i].im = (q->pre_coef2[i] * chctx->CWdecoded[COEFFS - 1 - i * 2]) -
602+ (q->pre_coef1[i] * chctx->CWdecoded[i * 2]);
591603 }
592604
593605 /* FFT */
@@ -598,15 +610,16 @@ static void imc_imdct256(IMCContext *q) · 4 unmodified lines
598610 for (i = 0; i < COEFFS / 2; i++) {
599611 re = ( q->samples[i].re * q->post_cos[i]) + (-q->samples[i].im * q->post_sin[i]);
600612 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])
602614 + (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])
604616 - (q->mdct_sine_window[COEFFS - 1 - i * 2] * re);
605− q->last_fft_im[i] = im;
617+ chctx->last_fft_im[i] = im;
606618 }
607619 }
608620
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)
610623 {
611624 int i, j;
612625 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
614627
615628 for (i = 0; i < BANDS; i++) {
616629 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
617− q->CWdecoded[j] = 0;
618− cw_len = q->CWlengthT[j];
630+ chctx->CWdecoded[j] = 0;
631+ cw_len = chctx->CWlengthT[j];
619632
620− if (cw_len <= 0 || q->skipFlags[j])
633+ if (cw_len <= 0 || chctx->skipFlags[j])
621634 continue;
622635
623636 max_size = 1 << cw_len;
624637 middle_value = max_size >> 1;
625638
626− if (q->codewords[j] >= max_size || q->codewords[j] < 0)
639+ if (chctx->codewords[j] >= max_size || chctx->codewords[j] < 0)
627640 return AVERROR_INVALIDDATA;
628641
629642 if (cw_len >= 4) {
630643 quantizer = imc_quantizer2[(stream_format_code & 2) >> 1];
631− if (q->codewords[j] >= middle_value)
632− q->CWdecoded[j] = quantizer[q->codewords[j] - 8] * q->flcoeffs6[i];
644+ if (chctx->codewords[j] >= middle_value)
645+ chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 8] * chctx->flcoeffs6[i];
633646 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];
635648 }else{
636− quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (q->bandFlagsBuf[i] << 1)];
637− if (q->codewords[j] >= middle_value)
638− q->CWdecoded[j] = quantizer[q->codewords[j] - 1] * q->flcoeffs6[i];
649+ quantizer = imc_quantizer1[((stream_format_code & 2) >> 1) | (chctx->bandFlagsBuf[i] << 1)];
650+ if (chctx->codewords[j] >= middle_value)
651+ chctx->CWdecoded[j] = quantizer[chctx->codewords[j] - 1] * chctx->flcoeffs6[i];
639652 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];
641654 }
642655 }
643656 }
@@ -645,16 +658,16 @@ static int inverse_quant_coeff(IMCContext *q, int stream_format_code) · 1 unmodified line
645658 }
646659
647660
648−static int imc_get_coeffs(IMCContext *q)
661+static int imc_get_coeffs(IMCContext *q, IMCChannel *chctx)
649662 {
650663 int i, j, cw_len, cw;
651664
652665 for (i = 0; i < BANDS; i++) {
653− if (!q->sumLenArr[i])
666+ if (!chctx->sumLenArr[i])
654667 continue;
655− if (q->bandFlagsBuf[i] || q->bandWidthT[i]) {
668+ if (chctx->bandFlagsBuf[i] || chctx->bandWidthT[i]) {
656669 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
657− cw_len = q->CWlengthT[j];
670+ cw_len = chctx->CWlengthT[j];
658671 cw = 0;
659672
660673 if (get_bits_count(&q->gb) + cw_len > 512) {
@@ -662,47 +675,25 @@ static int imc_get_coeffs(IMCContext *q) · 1 unmodified line
662675 return AVERROR_INVALIDDATA;
663676 }
664677
665− if (cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j]))
678+ if (cw_len && (!chctx->bandFlagsBuf[i] || !chctx->skipFlags[j]))
666679 cw = get_bits(&q->gb, cw_len);
667680
668− q->codewords[j] = cw;
681+ chctx->codewords[j] = cw;
669682 }
670683 }
671684 }
672685 return 0;
673686 }
674687
675−static int imc_decode_frame(AVCodecContext *avctx, void *data,
676− int *got_frame_ptr, AVPacket *avpkt)
688+static int imc_decode_block(AVCodecContext *avctx, IMCContext *q, int ch)
677689 {
678− const uint8_t *buf = avpkt->data;
679− int buf_size = avpkt->size;
680−
681− IMCContext *q = avctx->priv_data;
682−
683690 int stream_format_code;
684691 int imc_hdr, i, j, ret;
685692 int flag;
686693 int bits, summer;
687694 int counter, bitscount;
688− LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]);
695+ IMCChannel *chctx = q->chctx + ch;
689696
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);
706697
707698 /* Check the frame header */
708699 imc_hdr = get_bits(&q->gb, 9);
@@ -721,90 +712,90 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, · 12 unmodified lines
721712 // av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code);
722713
723714 if (stream_format_code & 0x04)
724− q->decoder_reset = 1;
715+ chctx->decoder_reset = 1;
725716
726− if (q->decoder_reset) {
717+ if (chctx->decoder_reset) {
727718 memset(q->out_samples, 0, sizeof(q->out_samples));
728719 for (i = 0; i < BANDS; i++)
729− q->old_floor[i] = 1.0;
720+ chctx->old_floor[i] = 1.0;
730721 for (i = 0; i < COEFFS; i++)
731− q->CWdecoded[i] = 0;
732− q->decoder_reset = 0;
722+ chctx->CWdecoded[i] = 0;
723+ chctx->decoder_reset = 0;
733724 }
734725
735726 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);
737728
738729 if (stream_format_code & 0x4)
739− imc_decode_level_coefficients(q, q->levlCoeffBuf,
740− q->flcoeffs1, q->flcoeffs2);
730+ imc_decode_level_coefficients(q, chctx->levlCoeffBuf,
731+ chctx->flcoeffs1, chctx->flcoeffs2);
741732 else
742− imc_decode_level_coefficients2(q, q->levlCoeffBuf, q->old_floor,
743− q->flcoeffs1, q->flcoeffs2);
733+ imc_decode_level_coefficients2(q, chctx->levlCoeffBuf, chctx->old_floor,
734+ chctx->flcoeffs1, chctx->flcoeffs2);
744735
745− memcpy(q->old_floor, q->flcoeffs1, 32 * sizeof(float));
736+ memcpy(chctx->old_floor, chctx->flcoeffs1, 32 * sizeof(float));
746737
747738 counter = 0;
748739 for (i = 0; i < BANDS; i++) {
749− if (q->levlCoeffBuf[i] == 16) {
750− q->bandWidthT[i] = 0;
740+ if (chctx->levlCoeffBuf[i] == 16) {
741+ chctx->bandWidthT[i] = 0;
751742 counter++;
752743 } else
753− q->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
744+ chctx->bandWidthT[i] = band_tab[i + 1] - band_tab[i];
754745 }
755− memset(q->bandFlagsBuf, 0, BANDS * sizeof(int));
746+ memset(chctx->bandFlagsBuf, 0, BANDS * sizeof(int));
756747 for (i = 0; i < BANDS - 1; i++) {
757− if (q->bandWidthT[i])
758− q->bandFlagsBuf[i] = get_bits1(&q->gb);
748+ if (chctx->bandWidthT[i])
749+ chctx->bandFlagsBuf[i] = get_bits1(&q->gb);
759750 }
760751
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);
762753
763754 bitscount = 0;
764755 /* first 4 bands will be assigned 5 bits per coefficient */
765756 if (stream_format_code & 0x2) {
766757 bitscount += 15;
767758
768− q->bitsBandT[0] = 5;
769− q->CWlengthT[0] = 5;
770− q->CWlengthT[1] = 5;
771− q->CWlengthT[2] = 5;
759+ chctx->bitsBandT[0] = 5;
760+ chctx->CWlengthT[0] = 5;
761+ chctx->CWlengthT[1] = 5;
762+ chctx->CWlengthT[2] = 5;
772763 for (i = 1; i < 4; i++) {
773− bits = (q->levlCoeffBuf[i] == 16) ? 0 : 5;
774− q->bitsBandT[i] = bits;
764+ bits = (chctx->levlCoeffBuf[i] == 16) ? 0 : 5;
765+ chctx->bitsBandT[i] = bits;
775766 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
776− q->CWlengthT[j] = bits;
767+ chctx->CWlengthT[j] = bits;
777768 bitscount += bits;
778769 }
779770 }
780771 }
781772
782− if ((ret = bit_allocation(q, stream_format_code,
773+ if ((ret = bit_allocation(q, chctx, stream_format_code,
783774 512 - bitscount - get_bits_count(&q->gb),
784775 flag)) < 0) {
785776 av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n");
786− q->decoder_reset = 1;
777+ chctx->decoder_reset = 1;
787778 return ret;
788779 }
789780
790781 for (i = 0; i < BANDS; i++) {
791− q->sumLenArr[i] = 0;
792− q->skipFlagRaw[i] = 0;
782+ chctx->sumLenArr[i] = 0;
783+ chctx->skipFlagRaw[i] = 0;
793784 for (j = band_tab[i]; j < band_tab[i + 1]; j++)
794− q->sumLenArr[i] += q->CWlengthT[j];
795− if (q->bandFlagsBuf[i])
796− if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > q->sumLenArr[i]) && (q->sumLenArr[i] > 0))
797− q->skipFlagRaw[i] = 1;
785+ chctx->sumLenArr[i] += chctx->CWlengthT[j];
786+ if (chctx->bandFlagsBuf[i])
787+ if ((((band_tab[i + 1] - band_tab[i]) * 1.5) > chctx->sumLenArr[i]) && (chctx->sumLenArr[i] > 0))
788+ chctx->skipFlagRaw[i] = 1;
798789 }
799790
800− imc_get_skip_coeff(q);
791+ imc_get_skip_coeff(q, chctx);
801792
802793 for (i = 0; i < BANDS; i++) {
803− q->flcoeffs6[i] = q->flcoeffs1[i];
794+ chctx->flcoeffs6[i] = chctx->flcoeffs1[i];
804795 /* 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]) {
806− q->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])];
796+ if (chctx->bandFlagsBuf[i] && (band_tab[i + 1] - band_tab[i]) != chctx->skipFlagCount[i]) {
797+ chctx->flcoeffs6[i] *= q->sqrt_tab[ band_tab[i + 1] - band_tab[i]] /
798+ q->sqrt_tab[(band_tab[i + 1] - band_tab[i] - chctx->skipFlagCount[i])];
808799 }
809800 }
810801
@@ -812,49 +803,88 @@ static int imc_decode_frame(AVCodecContext *avctx, void *data, · 1 unmodified line
812803 bits = summer = 0;
813804
814805 for (i = 0; i < BANDS; i++) {
815− if (q->bandFlagsBuf[i]) {
806+ if (chctx->bandFlagsBuf[i]) {
816807 for (j = band_tab[i]; j < band_tab[i + 1]; j++) {
817− if (q->skipFlags[j]) {
818− summer += q->CWlengthT[j];
819− q->CWlengthT[j] = 0;
808+ if (chctx->skipFlags[j]) {
809+ summer += chctx->CWlengthT[j];
810+ chctx->CWlengthT[j] = 0;
820811 }
821812 }
822− bits += q->skipFlagBits[i];
823− summer -= q->skipFlagBits[i];
813+ bits += chctx->skipFlagBits[i];
814+ summer -= chctx->skipFlagBits[i];
824815 }
825816 }
826− imc_adjust_bit_allocation(q, summer);
817+ imc_adjust_bit_allocation(q, chctx, summer);
827818
828819 for (i = 0; i < BANDS; i++) {
829− q->sumLenArr[i] = 0;
820+ chctx->sumLenArr[i] = 0;
830821
831822 for (j = band_tab[i]; j < band_tab[i + 1]; j++)
832− if (!q->skipFlags[j])
833− q->sumLenArr[i] += q->CWlengthT[j];
823+ if (!chctx->skipFlags[j])
824+ chctx->sumLenArr[i] += chctx->CWlengthT[j];
834825 }
835826
836− memset(q->codewords, 0, sizeof(q->codewords));
827+ memset(chctx->codewords, 0, sizeof(chctx->codewords));
837828
838− if (imc_get_coeffs(q) < 0) {
829+ if (imc_get_coeffs(q, chctx) < 0) {
839830 av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n");
840− q->decoder_reset = 1;
831+ chctx->decoder_reset = 1;
841832 return AVERROR_INVALIDDATA;
842833 }
843834
844− if (inverse_quant_coeff(q, stream_format_code) < 0) {
835+ if (inverse_quant_coeff(q, chctx, stream_format_code) < 0) {
845836 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");
847861 return AVERROR_INVALIDDATA;
848862 }
849863
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+ }
851870
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+ }
853883
854884 *got_frame_ptr = 1;
855885 *(AVFrame *)data = q->frame;
856886
857− return IMC_BLOCK_SIZE;
887+ return IMC_BLOCK_SIZE * avctx->channels;
858888 }
859889
860890

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t