Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: patched-ffmpeg-mt/libavcodec/alsdec.c

Issue 789004: ffmpeg roll of source to mar 9 version... (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/ffmpeg/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * MPEG-4 ALS decoder 2 * MPEG-4 ALS decoder
3 * Copyright (c) 2009 Thilo Borgmann <thilo.borgmann _at_ googlemail.com> 3 * Copyright (c) 2009 Thilo Borgmann <thilo.borgmann _at_ googlemail.com>
4 * 4 *
5 * This file is part of FFmpeg. 5 * This file is part of FFmpeg.
6 * 6 *
7 * FFmpeg is free software; you can redistribute it and/or 7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version. 10 * version 2.1 of the License, or (at your option) any later version.
(...skipping 16 matching lines...) Expand all
27 27
28 28
29 //#define DEBUG 29 //#define DEBUG
30 30
31 31
32 #include "avcodec.h" 32 #include "avcodec.h"
33 #include "get_bits.h" 33 #include "get_bits.h"
34 #include "unary.h" 34 #include "unary.h"
35 #include "mpeg4audio.h" 35 #include "mpeg4audio.h"
36 #include "bytestream.h" 36 #include "bytestream.h"
37 #include "bgmc.h"
37 38
38 #include <stdint.h> 39 #include <stdint.h>
39 40
40 /** Rice parameters and corresponding index offsets for decoding the 41 /** Rice parameters and corresponding index offsets for decoding the
41 * indices of scaled PARCOR values. The table choosen is set globally 42 * indices of scaled PARCOR values. The table choosen is set globally
42 * by the encoder and stored in ALSSpecificConfig. 43 * by the encoder and stored in ALSSpecificConfig.
43 */ 44 */
44 static const int8_t parcor_rice_table[3][20][2] = { 45 static const int8_t parcor_rice_table[3][20][2] = {
45 { {-52, 4}, {-29, 5}, {-31, 4}, { 19, 4}, {-16, 4}, 46 { {-52, 4}, {-29, 5}, {-31, 4}, { 19, 4}, {-16, 4},
46 { 12, 3}, { -7, 3}, { 9, 3}, { -5, 3}, { 6, 3}, 47 { 12, 3}, { -7, 3}, { 9, 3}, { -5, 3}, { 6, 3},
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 * To be indexed by the Rice coded indices. 114 * To be indexed by the Rice coded indices.
114 */ 115 */
115 static const int16_t mcc_weightings[] = { 116 static const int16_t mcc_weightings[] = {
116 204, 192, 179, 166, 153, 140, 128, 115, 117 204, 192, 179, 166, 153, 140, 128, 115,
117 102, 89, 76, 64, 51, 38, 25, 12, 118 102, 89, 76, 64, 51, 38, 25, 12,
118 0, -12, -25, -38, -51, -64, -76, -89, 119 0, -12, -25, -38, -51, -64, -76, -89,
119 -102, -115, -128, -140, -153, -166, -179, -192 120 -102, -115, -128, -140, -153, -166, -179, -192
120 }; 121 };
121 122
122 123
124 /** Tail codes used in arithmetic coding using block Gilbert-Moore codes.
125 */
126 static const uint8_t tail_code[16][6] = {
127 { 74, 44, 25, 13, 7, 3},
128 { 68, 42, 24, 13, 7, 3},
129 { 58, 39, 23, 13, 7, 3},
130 {126, 70, 37, 19, 10, 5},
131 {132, 70, 37, 20, 10, 5},
132 {124, 70, 38, 20, 10, 5},
133 {120, 69, 37, 20, 11, 5},
134 {116, 67, 37, 20, 11, 5},
135 {108, 66, 36, 20, 10, 5},
136 {102, 62, 36, 20, 10, 5},
137 { 88, 58, 34, 19, 10, 5},
138 {162, 89, 49, 25, 13, 7},
139 {156, 87, 49, 26, 14, 7},
140 {150, 86, 47, 26, 14, 7},
141 {142, 84, 47, 26, 14, 7},
142 {131, 79, 46, 26, 14, 7}
143 };
144
145
123 enum RA_Flag { 146 enum RA_Flag {
124 RA_FLAG_NONE, 147 RA_FLAG_NONE,
125 RA_FLAG_FRAMES, 148 RA_FLAG_FRAMES,
126 RA_FLAG_HEADER 149 RA_FLAG_HEADER
127 }; 150 };
128 151
129 152
130 typedef struct { 153 typedef struct {
131 uint32_t samples; ///< number of samples, 0xFFFFFFFF if unknown 154 uint32_t samples; ///< number of samples, 0xFFFFFFFF if unknown
132 int resolution; ///< 000 = 8-bit; 001 = 16-bit; 010 = 24-bit; 011 = 32-bit 155 int resolution; ///< 000 = 8-bit; 001 = 16-bit; 010 = 24-bit; 011 = 32-bit
(...skipping 29 matching lines...) Expand all
162 185
163 186
164 typedef struct { 187 typedef struct {
165 AVCodecContext *avctx; 188 AVCodecContext *avctx;
166 ALSSpecificConfig sconf; 189 ALSSpecificConfig sconf;
167 GetBitContext gb; 190 GetBitContext gb;
168 unsigned int cur_frame_length; ///< length of the current frame to decode 191 unsigned int cur_frame_length; ///< length of the current frame to decode
169 unsigned int frame_id; ///< the frame ID / number of the current fr ame 192 unsigned int frame_id; ///< the frame ID / number of the current fr ame
170 unsigned int js_switch; ///< if true, joint-stereo decoding is enfor ced 193 unsigned int js_switch; ///< if true, joint-stereo decoding is enfor ced
171 unsigned int num_blocks; ///< number of blocks used in the current fr ame 194 unsigned int num_blocks; ///< number of blocks used in the current fr ame
195 unsigned int s_max; ///< maximum Rice parameter allowed in entro py coding
196 uint8_t *bgmc_lut; ///< pointer at lookup tables used for BGMC
197 unsigned int *bgmc_lut_status; ///< pointer at lookup table status flags us ed for BGMC
172 int ltp_lag_length; ///< number of bits used for ltp lag value 198 int ltp_lag_length; ///< number of bits used for ltp lag value
173 int *use_ltp; ///< contains use_ltp flags for all channels 199 int *use_ltp; ///< contains use_ltp flags for all channels
174 int *ltp_lag; ///< contains ltp lag values for all channel s 200 int *ltp_lag; ///< contains ltp lag values for all channel s
175 int **ltp_gain; ///< gain values for ltp 5-tap filter for a channel 201 int **ltp_gain; ///< gain values for ltp 5-tap filter for a channel
176 int *ltp_gain_buffer; ///< contains all gain values for ltp 5-tap filter 202 int *ltp_gain_buffer; ///< contains all gain values for ltp 5-tap filter
177 int32_t **quant_cof; ///< quantized parcor coefficients for a cha nnel 203 int32_t **quant_cof; ///< quantized parcor coefficients for a cha nnel
178 int32_t *quant_cof_buffer; ///< contains all quantized parcor coefficie nts 204 int32_t *quant_cof_buffer; ///< contains all quantized parcor coefficie nts
179 int32_t **lpc_cof; ///< coefficients of the direct form predict ion filter for a channel 205 int32_t **lpc_cof; ///< coefficients of the direct form predict ion filter for a channel
180 int32_t *lpc_cof_buffer; ///< contains all coefficients of the direct form prediction filter 206 int32_t *lpc_cof_buffer; ///< contains all coefficients of the direct form prediction filter
181 int32_t *lpc_cof_reversed_buffer; ///< temporary buffer to set up a reversed versio of lpc_cof_buffer 207 int32_t *lpc_cof_reversed_buffer; ///< temporary buffer to set up a reversed versio of lpc_cof_buffer
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // report unsupported feature and set error value 402 // report unsupported feature and set error value
377 #define MISSING_ERR(cond, str, errval) \ 403 #define MISSING_ERR(cond, str, errval) \
378 { \ 404 { \
379 if (cond) { \ 405 if (cond) { \
380 av_log_missing_feature(ctx->avctx, str, 0); \ 406 av_log_missing_feature(ctx->avctx, str, 0); \
381 error = errval; \ 407 error = errval; \
382 } \ 408 } \
383 } 409 }
384 410
385 MISSING_ERR(sconf->floating, "Floating point decoding", -1); 411 MISSING_ERR(sconf->floating, "Floating point decoding", -1);
386 MISSING_ERR(sconf->bgmc, "BGMC entropy decoding", -1);
387 MISSING_ERR(sconf->rlslms, "Adaptive RLS-LMS prediction", -1); 412 MISSING_ERR(sconf->rlslms, "Adaptive RLS-LMS prediction", -1);
388 MISSING_ERR(sconf->chan_sort, "Channel sorting", 0); 413 MISSING_ERR(sconf->chan_sort, "Channel sorting", 0);
389 414
390 return error; 415 return error;
391 } 416 }
392 417
393 418
394 /** Parses the bs_info field to extract the block partitioning used in 419 /** Parses the bs_info field to extract the block partitioning used in
395 * block switching mode, refer to ISO/IEC 14496-3, section 11.6.2. 420 * block switching mode, refer to ISO/IEC 14496-3, section 11.6.2.
396 */ 421 */
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 // The ALS conformance files feature an odd number of samples in the last 512 // The ALS conformance files feature an odd number of samples in the last
488 // frame. 513 // frame.
489 514
490 for (b = 0; b < ctx->num_blocks; b++) 515 for (b = 0; b < ctx->num_blocks; b++)
491 div_blocks[b] = ctx->sconf.frame_length >> div_blocks[b]; 516 div_blocks[b] = ctx->sconf.frame_length >> div_blocks[b];
492 517
493 if (ctx->cur_frame_length != ctx->sconf.frame_length) { 518 if (ctx->cur_frame_length != ctx->sconf.frame_length) {
494 unsigned int remaining = ctx->cur_frame_length; 519 unsigned int remaining = ctx->cur_frame_length;
495 520
496 for (b = 0; b < ctx->num_blocks; b++) { 521 for (b = 0; b < ctx->num_blocks; b++) {
497 if (remaining < div_blocks[b]) { 522 if (remaining <= div_blocks[b]) {
498 div_blocks[b] = remaining; 523 div_blocks[b] = remaining;
499 ctx->num_blocks = b + 1; 524 ctx->num_blocks = b + 1;
500 break; 525 break;
501 } 526 }
502 527
503 remaining -= div_blocks[b]; 528 remaining -= div_blocks[b];
504 } 529 }
505 } 530 }
506 } 531 }
507 532
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 572
548 /** Reads the block data for a non-constant block 573 /** Reads the block data for a non-constant block
549 */ 574 */
550 static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) 575 static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd)
551 { 576 {
552 ALSSpecificConfig *sconf = &ctx->sconf; 577 ALSSpecificConfig *sconf = &ctx->sconf;
553 AVCodecContext *avctx = ctx->avctx; 578 AVCodecContext *avctx = ctx->avctx;
554 GetBitContext *gb = &ctx->gb; 579 GetBitContext *gb = &ctx->gb;
555 unsigned int k; 580 unsigned int k;
556 unsigned int s[8]; 581 unsigned int s[8];
582 unsigned int sx[8];
557 unsigned int sub_blocks, log2_sub_blocks, sb_length; 583 unsigned int sub_blocks, log2_sub_blocks, sb_length;
558 unsigned int start = 0; 584 unsigned int start = 0;
559 unsigned int opt_order; 585 unsigned int opt_order;
560 int sb; 586 int sb;
561 int32_t *quant_cof = bd->quant_cof; 587 int32_t *quant_cof = bd->quant_cof;
588 int32_t *current_res;
562 589
563 590
564 // ensure variable block decoding by reusing this field 591 // ensure variable block decoding by reusing this field
565 bd->const_block = 0; 592 bd->const_block = 0;
566 593
567 bd->opt_order = 1; 594 bd->opt_order = 1;
568 bd->js_blocks = get_bits1(gb); 595 bd->js_blocks = get_bits1(gb);
569 596
570 opt_order = bd->opt_order; 597 opt_order = bd->opt_order;
571 598
(...skipping 12 matching lines...) Expand all
584 // do not continue in case of a damaged stream since 611 // do not continue in case of a damaged stream since
585 // block_length must be evenly divisible by sub_blocks 612 // block_length must be evenly divisible by sub_blocks
586 if (bd->block_length & (sub_blocks - 1)) { 613 if (bd->block_length & (sub_blocks - 1)) {
587 av_log(avctx, AV_LOG_WARNING, 614 av_log(avctx, AV_LOG_WARNING,
588 "Block length is not evenly divisible by the number of subblocks. \n"); 615 "Block length is not evenly divisible by the number of subblocks. \n");
589 return -1; 616 return -1;
590 } 617 }
591 618
592 sb_length = bd->block_length >> log2_sub_blocks; 619 sb_length = bd->block_length >> log2_sub_blocks;
593 620
621 if (sconf->bgmc) {
622 s[0] = get_bits(gb, 8 + (sconf->resolution > 1));
623 for (k = 1; k < sub_blocks; k++)
624 s[k] = s[k - 1] + decode_rice(gb, 2);
594 625
595 if (sconf->bgmc) { 626 for (k = 0; k < sub_blocks; k++) {
596 // TODO: BGMC mode 627 sx[k] = s[k] & 0x0F;
628 s [k] >>= 4;
629 }
597 } else { 630 } else {
598 s[0] = get_bits(gb, 4 + (sconf->resolution > 1)); 631 s[0] = get_bits(gb, 4 + (sconf->resolution > 1));
599 for (k = 1; k < sub_blocks; k++) 632 for (k = 1; k < sub_blocks; k++)
600 s[k] = s[k - 1] + decode_rice(gb, 0); 633 s[k] = s[k - 1] + decode_rice(gb, 0);
601 } 634 }
602 635
603 if (get_bits1(gb)) 636 if (get_bits1(gb))
604 bd->shift_lsbs = get_bits(gb, 4) + 1; 637 bd->shift_lsbs = get_bits(gb, 4) + 1;
605 638
606 bd->store_prev_samples = (bd->js_blocks && bd->raw_other) || bd->shift_lsbs; 639 bd->store_prev_samples = (bd->js_blocks && bd->raw_other) || bd->shift_lsbs;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 for (k = 2; k < opt_order; k++) 696 for (k = 2; k < opt_order; k++)
664 quant_cof[k] = (quant_cof[k] << 14) + (add_base << 13); 697 quant_cof[k] = (quant_cof[k] << 14) + (add_base << 13);
665 } 698 }
666 } 699 }
667 700
668 // read LTP gain and lag values 701 // read LTP gain and lag values
669 if (sconf->long_term_prediction) { 702 if (sconf->long_term_prediction) {
670 *bd->use_ltp = get_bits1(gb); 703 *bd->use_ltp = get_bits1(gb);
671 704
672 if (*bd->use_ltp) { 705 if (*bd->use_ltp) {
706 int r, c;
707
673 bd->ltp_gain[0] = decode_rice(gb, 1) << 3; 708 bd->ltp_gain[0] = decode_rice(gb, 1) << 3;
674 bd->ltp_gain[1] = decode_rice(gb, 2) << 3; 709 bd->ltp_gain[1] = decode_rice(gb, 2) << 3;
675 710
676 bd->ltp_gain[2] = ltp_gain_values[get_unary(gb, 0, 4)][get_bits(gb , 2)]; 711 r = get_unary(gb, 0, 4);
712 c = get_bits(gb, 2);
713 bd->ltp_gain[2] = ltp_gain_values[r][c];
677 714
678 bd->ltp_gain[3] = decode_rice(gb, 2) << 3; 715 bd->ltp_gain[3] = decode_rice(gb, 2) << 3;
679 bd->ltp_gain[4] = decode_rice(gb, 1) << 3; 716 bd->ltp_gain[4] = decode_rice(gb, 1) << 3;
680 717
681 *bd->ltp_lag = get_bits(gb, ctx->ltp_lag_length); 718 *bd->ltp_lag = get_bits(gb, ctx->ltp_lag_length);
682 *bd->ltp_lag += FFMAX(4, opt_order + 1); 719 *bd->ltp_lag += FFMAX(4, opt_order + 1);
683 } 720 }
684 } 721 }
685 722
686 // read first value and residuals in case of a random access block 723 // read first value and residuals in case of a random access block
687 if (bd->ra_block) { 724 if (bd->ra_block) {
688 if (opt_order) 725 if (opt_order)
689 bd->raw_samples[0] = decode_rice(gb, avctx->bits_per_raw_sample - 4) ; 726 bd->raw_samples[0] = decode_rice(gb, avctx->bits_per_raw_sample - 4) ;
690 if (opt_order > 1) 727 if (opt_order > 1)
691 bd->raw_samples[1] = decode_rice(gb, s[0] + 3); 728 bd->raw_samples[1] = decode_rice(gb, FFMIN(s[0] + 3, ctx->s_max));
692 if (opt_order > 2) 729 if (opt_order > 2)
693 bd->raw_samples[2] = decode_rice(gb, s[0] + 1); 730 bd->raw_samples[2] = decode_rice(gb, FFMIN(s[0] + 1, ctx->s_max));
694 731
695 start = FFMIN(opt_order, 3); 732 start = FFMIN(opt_order, 3);
696 } 733 }
697 734
698 // read all residuals 735 // read all residuals
699 if (sconf->bgmc) { 736 if (sconf->bgmc) {
700 // TODO: BGMC mode 737 unsigned int delta[sub_blocks];
738 unsigned int k [sub_blocks];
739 unsigned int b = av_clip((av_ceil_log2(bd->block_length) - 3) >> 1, 0, 5 );
740 unsigned int i = start;
741
742 // read most significant bits
743 unsigned int high;
744 unsigned int low;
745 unsigned int value;
746
747 ff_bgmc_decode_init(gb, &high, &low, &value);
748
749 current_res = bd->raw_samples + start;
750
751 for (sb = 0; sb < sub_blocks; sb++, i = 0) {
752 k [sb] = s[sb] > b ? s[sb] - b : 0;
753 delta[sb] = 5 - s[sb] + k[sb];
754
755 ff_bgmc_decode(gb, sb_length, current_res,
756 delta[sb], sx[sb], &high, &low, &value, ctx->bgmc_lut, c tx->bgmc_lut_status);
757
758 current_res += sb_length;
759 }
760
761 ff_bgmc_decode_end(gb);
762
763
764 // read least significant bits and tails
765 i = start;
766 current_res = bd->raw_samples + start;
767
768 for (sb = 0; sb < sub_blocks; sb++, i = 0) {
769 unsigned int cur_tail_code = tail_code[sx[sb]][delta[sb]];
770 unsigned int cur_k = k[sb];
771 unsigned int cur_s = s[sb];
772
773 for (; i < sb_length; i++) {
774 int32_t res = *current_res;
775
776 if (res == cur_tail_code) {
777 unsigned int max_msb = (2 + (sx[sb] > 2) + (sx[sb] > 10))
778 << (5 - delta[sb]);
779
780 res = decode_rice(gb, cur_s);
781
782 if (res >= 0) {
783 res += (max_msb ) << cur_k;
784 } else {
785 res -= (max_msb - 1) << cur_k;
786 }
787 } else {
788 if (res > cur_tail_code)
789 res--;
790
791 if (res & 1)
792 res = -res;
793
794 res >>= 1;
795
796 if (cur_k) {
797 res <<= cur_k;
798 res |= get_bits_long(gb, cur_k);
799 }
800 }
801
802 *current_res++ = res;
803 }
804 }
701 } else { 805 } else {
702 int32_t *current_res = bd->raw_samples + start; 806 current_res = bd->raw_samples + start;
703 807
704 for (sb = 0; sb < sub_blocks; sb++, start = 0) 808 for (sb = 0; sb < sub_blocks; sb++, start = 0)
705 for (; start < sb_length; start++) 809 for (; start < sb_length; start++)
706 *current_res++ = decode_rice(gb, s[sb]); 810 *current_res++ = decode_rice(gb, s[sb]);
707 } 811 }
708 812
709 if (!sconf->mc_coding || ctx->js_switch) 813 if (!sconf->mc_coding || ctx->js_switch)
710 align_get_bits(gb); 814 align_get_bits(gb);
711 815
712 return 0; 816 return 0;
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1445
1342 1446
1343 /** Uninitializes the ALS decoder. 1447 /** Uninitializes the ALS decoder.
1344 */ 1448 */
1345 static av_cold int decode_end(AVCodecContext *avctx) 1449 static av_cold int decode_end(AVCodecContext *avctx)
1346 { 1450 {
1347 ALSDecContext *ctx = avctx->priv_data; 1451 ALSDecContext *ctx = avctx->priv_data;
1348 1452
1349 av_freep(&ctx->sconf.chan_pos); 1453 av_freep(&ctx->sconf.chan_pos);
1350 1454
1455 ff_bgmc_end(&ctx->bgmc_lut, &ctx->bgmc_lut_status);
1456
1351 av_freep(&ctx->use_ltp); 1457 av_freep(&ctx->use_ltp);
1352 av_freep(&ctx->ltp_lag); 1458 av_freep(&ctx->ltp_lag);
1353 av_freep(&ctx->ltp_gain); 1459 av_freep(&ctx->ltp_gain);
1354 av_freep(&ctx->ltp_gain_buffer); 1460 av_freep(&ctx->ltp_gain_buffer);
1355 av_freep(&ctx->quant_cof); 1461 av_freep(&ctx->quant_cof);
1356 av_freep(&ctx->lpc_cof); 1462 av_freep(&ctx->lpc_cof);
1357 av_freep(&ctx->quant_cof_buffer); 1463 av_freep(&ctx->quant_cof_buffer);
1358 av_freep(&ctx->lpc_cof_buffer); 1464 av_freep(&ctx->lpc_cof_buffer);
1359 av_freep(&ctx->lpc_cof_reversed_buffer); 1465 av_freep(&ctx->lpc_cof_reversed_buffer);
1360 av_freep(&ctx->prev_raw_samples); 1466 av_freep(&ctx->prev_raw_samples);
(...skipping 27 matching lines...) Expand all
1388 av_log(avctx, AV_LOG_ERROR, "Reading ALSSpecificConfig failed.\n"); 1494 av_log(avctx, AV_LOG_ERROR, "Reading ALSSpecificConfig failed.\n");
1389 decode_end(avctx); 1495 decode_end(avctx);
1390 return -1; 1496 return -1;
1391 } 1497 }
1392 1498
1393 if (check_specific_config(ctx)) { 1499 if (check_specific_config(ctx)) {
1394 decode_end(avctx); 1500 decode_end(avctx);
1395 return -1; 1501 return -1;
1396 } 1502 }
1397 1503
1504 if (sconf->bgmc)
1505 ff_bgmc_init(avctx, &ctx->bgmc_lut, &ctx->bgmc_lut_status);
1506
1398 if (sconf->floating) { 1507 if (sconf->floating) {
1399 avctx->sample_fmt = SAMPLE_FMT_FLT; 1508 avctx->sample_fmt = SAMPLE_FMT_FLT;
1400 avctx->bits_per_raw_sample = 32; 1509 avctx->bits_per_raw_sample = 32;
1401 } else { 1510 } else {
1402 avctx->sample_fmt = sconf->resolution > 1 1511 avctx->sample_fmt = sconf->resolution > 1
1403 ? SAMPLE_FMT_S32 : SAMPLE_FMT_S16; 1512 ? SAMPLE_FMT_S32 : SAMPLE_FMT_S16;
1404 avctx->bits_per_raw_sample = (sconf->resolution + 1) * 8; 1513 avctx->bits_per_raw_sample = (sconf->resolution + 1) * 8;
1405 } 1514 }
1406 1515
1516 // set maximum Rice parameter for progressive decoding based on resolution
1517 // This is not specified in 14496-3 but actually done by the reference
1518 // codec RM22 revision 2.
1519 ctx->s_max = sconf->resolution > 1 ? 31 : 15;
1520
1407 // set lag value for long-term prediction 1521 // set lag value for long-term prediction
1408 ctx->ltp_lag_length = 8 + (avctx->sample_rate >= 96000) + 1522 ctx->ltp_lag_length = 8 + (avctx->sample_rate >= 96000) +
1409 (avctx->sample_rate >= 192000); 1523 (avctx->sample_rate >= 192000);
1410 1524
1411 // allocate quantized parcor coefficient buffer 1525 // allocate quantized parcor coefficient buffer
1412 num_buffers = sconf->mc_coding ? avctx->channels : 1; 1526 num_buffers = sconf->mc_coding ? avctx->channels : 1;
1413 1527
1414 ctx->quant_cof = av_malloc(sizeof(*ctx->quant_cof) * num_buffers); 1528 ctx->quant_cof = av_malloc(sizeof(*ctx->quant_cof) * num_buffers);
1415 ctx->lpc_cof = av_malloc(sizeof(*ctx->lpc_cof) * num_buffers); 1529 ctx->lpc_cof = av_malloc(sizeof(*ctx->lpc_cof) * num_buffers);
1416 ctx->quant_cof_buffer = av_malloc(sizeof(*ctx->quant_cof_buffer) * 1530 ctx->quant_cof_buffer = av_malloc(sizeof(*ctx->quant_cof_buffer) *
(...skipping 29 matching lines...) Expand all
1446 decode_end(avctx); 1560 decode_end(avctx);
1447 return AVERROR(ENOMEM); 1561 return AVERROR(ENOMEM);
1448 } 1562 }
1449 1563
1450 for (c = 0; c < num_buffers; c++) 1564 for (c = 0; c < num_buffers; c++)
1451 ctx->ltp_gain[c] = ctx->ltp_gain_buffer + c * 5; 1565 ctx->ltp_gain[c] = ctx->ltp_gain_buffer + c * 5;
1452 1566
1453 // allocate and assign channel data buffer for mcc mode 1567 // allocate and assign channel data buffer for mcc mode
1454 if (sconf->mc_coding) { 1568 if (sconf->mc_coding) {
1455 ctx->chan_data_buffer = av_malloc(sizeof(*ctx->chan_data_buffer) * 1569 ctx->chan_data_buffer = av_malloc(sizeof(*ctx->chan_data_buffer) *
1456 num_buffers); 1570 num_buffers * num_buffers);
1457 ctx->chan_data = av_malloc(sizeof(ALSChannelData) * 1571 ctx->chan_data = av_malloc(sizeof(*ctx->chan_data) *
1458 num_buffers); 1572 num_buffers);
1459 ctx->reverted_channels = av_malloc(sizeof(*ctx->reverted_channels) * 1573 ctx->reverted_channels = av_malloc(sizeof(*ctx->reverted_channels) *
1460 num_buffers); 1574 num_buffers);
1461 1575
1462 if (!ctx->chan_data_buffer || !ctx->chan_data || !ctx->reverted_channels ) { 1576 if (!ctx->chan_data_buffer || !ctx->chan_data || !ctx->reverted_channels ) {
1463 av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); 1577 av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
1464 decode_end(avctx); 1578 decode_end(avctx);
1465 return AVERROR(ENOMEM); 1579 return AVERROR(ENOMEM);
1466 } 1580 }
1467 1581
1468 for (c = 0; c < num_buffers; c++) 1582 for (c = 0; c < num_buffers; c++)
1469 ctx->chan_data[c] = ctx->chan_data_buffer + c; 1583 ctx->chan_data[c] = ctx->chan_data_buffer + c * num_buffers;
1470 } else { 1584 } else {
1471 ctx->chan_data = NULL; 1585 ctx->chan_data = NULL;
1472 ctx->chan_data_buffer = NULL; 1586 ctx->chan_data_buffer = NULL;
1473 ctx->reverted_channels = NULL; 1587 ctx->reverted_channels = NULL;
1474 } 1588 }
1475 1589
1476 avctx->frame_size = sconf->frame_length; 1590 avctx->frame_size = sconf->frame_length;
1477 channel_size = sconf->frame_length + sconf->max_order; 1591 channel_size = sconf->frame_length + sconf->max_order;
1478 1592
1479 ctx->prev_raw_samples = av_malloc (sizeof(*ctx->prev_raw_samples) * sconf->m ax_order); 1593 ctx->prev_raw_samples = av_malloc (sizeof(*ctx->prev_raw_samples) * sconf->m ax_order);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 sizeof(ALSDecContext), 1627 sizeof(ALSDecContext),
1514 decode_init, 1628 decode_init,
1515 NULL, 1629 NULL,
1516 decode_end, 1630 decode_end,
1517 decode_frame, 1631 decode_frame,
1518 .flush = flush, 1632 .flush = flush,
1519 .capabilities = CODEC_CAP_SUBFRAMES, 1633 .capabilities = CODEC_CAP_SUBFRAMES,
1520 .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Audio Lossless Coding (ALS)"), 1634 .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Audio Lossless Coding (ALS)"),
1521 }; 1635 };
1522 1636
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698