43 "Please file a bug report following the instructions at "
44 "http://libav.org/bugreports.html and include "
45 "a sample of this file.";
78 #define PARAM_BLOCKSIZE (1 << 7)
79 #define PARAM_MATRIX (1 << 6)
80 #define PARAM_OUTSHIFT (1 << 5)
81 #define PARAM_QUANTSTEP (1 << 4)
82 #define PARAM_FIR (1 << 3)
83 #define PARAM_IIR (1 << 2)
84 #define PARAM_HUFFOFFSET (1 << 1)
85 #define PARAM_PRESENCE (1 << 0)
160 if (!huff_vlc[0].
bits) {
176 unsigned int substr,
unsigned int ch)
185 sign_huff_offset -= 7 << lsb_bits;
188 sign_huff_offset -= 1 << sign_shift;
190 return sign_huff_offset;
197 unsigned int substr,
unsigned int pos)
200 unsigned int mat, channel;
206 for (channel = s->
min_channel; channel <= s->max_channel; channel++) {
210 int lsb_bits = cp->
huff_lsbs - quant_step_size;
214 result =
get_vlc2(gbp, huff_vlc[codebook-1].table,
221 result = (result << lsb_bits) +
get_bits(gbp, lsb_bits);
224 result <<= quant_step_size;
268 "Channel group 2 cannot have more bits per sample than group 1.\n");
274 "Channel groups with differing sample rates are not currently supported.\n");
284 "Sampling rate %d is greater than the supported maximum (%d).\n",
290 "Block size %d is greater than the supported maximum (%d).\n",
296 "Block size pow2 %d is greater than the supported maximum (%d).\n",
309 "Number of substreams %d is larger than the maximum supported "
341 const uint8_t *buf,
unsigned int substr)
347 uint8_t lossless_check;
355 if (sync_word != 0x31ea >> 1) {
357 "restart header sync incorrect (got 0x%04x)\n", sync_word);
376 "Max matrix channel cannot be greater than %d.\n",
383 "Max channel must be equal max matrix channel.\n");
391 "Number of channels %d is larger than the maximum supported "
398 "Substream min channel cannot be greater than max channel.\n");
402 if (m->
avctx->request_channels > 0
404 && substr < m->max_decoded_substream) {
406 "Extracting %d channel downmix from substream %d. "
407 "Further substreams will be skipped.\n",
422 if (tmp != lossless_check)
424 "Lossless check failed - expected %02x, calculated %02x.\n",
425 lossless_check, tmp);
436 "Assignment of matrix channel %d to invalid output channel %d. %s\n",
457 for (ch = s->
min_channel; ch <= s->max_channel; ch++) {
480 unsigned int substr,
unsigned int channel,
486 const char fchar = filter ?
'I' :
'F';
498 if (order > max_order) {
500 "%cIR filter order %d is greater than maximum %d.\n",
501 fchar, order, max_order);
508 int coeff_bits, coeff_shift;
514 if (coeff_bits < 1 || coeff_bits > 16) {
516 "%cIR filter coeff_bits must be between 1 and 16.\n",
520 if (coeff_bits + coeff_shift > 16) {
522 "Sum of coeff_bits and coeff_shift for %cIR filter must be 16 or less.\n",
527 for (i = 0; i < order; i++)
528 fcoeff[i] =
get_sbits(gbp, coeff_bits) << coeff_shift;
531 int state_bits, state_shift;
535 "FIR filter has state data specified.\n");
544 for (i = 0; i < order; i++)
557 unsigned int mat, ch;
571 "Number of primitive matrices cannot be greater than %d.\n",
572 max_primitive_matrices);
577 int frac_bits, max_chan;
584 "Invalid channel %d specified as output from matrix.\n",
588 if (frac_bits > 14) {
590 "Too many fractional bits specified.\n");
598 for (ch = 0; ch <= max_chan; ch++) {
601 coeff_val =
get_sbits(gbp, frac_bits + 2);
603 s->
matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits);
644 "FIR and IIR filters must use the same precision.\n");
716 for (ch = s->
min_channel; ch <= s->max_channel; ch++)
724 #define MSB_MASK(bits) (-1u << bits)
730 unsigned int channel)
739 unsigned int filter_shift = fir->
shift;
760 unsigned int i, ch, expected_stream_pos = 0;
765 expected_stream_pos +=
get_bits(gbp, 16);
782 for (ch = s->
min_channel; ch <= s->max_channel; ch++)
799 30, 51, 22, 54, 3, 7, -4, 38, 14, 55, 46, 81, 22, 58, -3, 2,
800 52, 31, -7, 51, 15, 44, 74, 30, 85, -17, 10, 33, 18, 80, 28, 62,
801 10, 32, 23, 69, 72, 26, 35, 17, 73, 60, 8, 56, 2, 6, -2, -5,
802 51, 4, 11, 50, 66, 76, 21, 44, 33, 47, 1, 26, 64, 48, 57, 40,
803 38, 16, -10, -28, 92, 22, -18, 29, -10, 5, -13, 49, 19, 24, 70, 34,
804 61, 48, 30, 14, -6, 25, 58, 33, 42, 60, 67, 17, 54, 17, 22, 30,
805 67, 44, -9, 50, -11, 43, 40, 32, 59, 82, 13, 49, -14, 55, 60, 36,
806 48, 49, 31, 47, 15, 12, 4, 65, 1, 23, 29, 39, 45, -2, 84, 69,
807 0, 72, 37, 57, 27, 41, -15, -16, 35, 31, 14, 61, 24, 0, 27, 24,
808 16, 41, 55, 34, 53, 9, 56, 12, 25, 29, 53, 5, 20, -20, -8, 20,
809 13, 28, -3, 78, 38, 16, 11, 62, 46, 29, 21, 24, 46, 65, 43, -23,
810 89, 18, 74, 21, 38, -12, 19, 12, -19, 8, 15, 33, 4, 57, 9, -8,
811 36, 35, 26, 28, 7, 83, 63, 79, 75, 11, 3, 87, 37, 47, 34, 40,
812 39, 19, 20, 42, 27, 34, 39, 77, 13, 42, 59, 64, 45, -1, 32, 37,
813 45, -5, 53, -6, 7, 36, 50, 23, 6, 32, 9, -21, 18, 71, 27, 52,
814 -25, 31, 35, 42, -1, 68, 63, 52, 26, 43, 66, 37, 41, 25, 40, 70,
835 uint16_t seed_shr7 = seed >> 7;
839 seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
854 uint8_t seed_shr15 = seed >> 15;
856 seed = (seed << 8) ^ seed_shr15 ^ (seed_shr15 << 5);
869 unsigned int mat, src_ch, i;
870 unsigned int maxchan;
886 int index2 = 2 * index + 1;
895 for (src_ch = 0; src_ch <= maxchan; src_ch++)
896 accum += (int64_t) samples[src_ch] * coeffs[src_ch];
898 if (matrix_noise_shift) {
904 samples[dest_ch] = ((accum >> 14) & mask) + bypassed_lsb;
912 void *
data,
int *got_frame_ptr)
916 unsigned int i, out_ch = 0;
942 if (is32) *data_32++ = sample << 8;
943 else *data_16++ = sample >> 8;
958 int *got_frame_ptr,
AVPacket *avpkt)
960 const uint8_t *buf = avpkt->
data;
961 int buf_size = avpkt->
size;
964 unsigned int length, substr;
965 unsigned int substream_start;
966 unsigned int header_size = 4;
967 unsigned int substr_header_size = 0;
976 length = (
AV_RB16(buf) & 0xfff) * 2;
978 if (length < 4 || length > buf_size)
993 "Stream parameters not seen; skipping frame.\n");
1001 int extraword_present, checkdata_present, end, nonrestart_substr;
1010 substr_header_size += 2;
1012 if (extraword_present) {
1018 substr_header_size += 2;
1026 if (end + header_size + substr_header_size > length) {
1028 "Indicated length of substream %d data goes off end of "
1029 "packet.\n", substr);
1030 end = length - header_size - substr_header_size;
1033 if (end < substream_start) {
1035 "Indicated end offset of substream %d data "
1036 "is smaller than calculated start offset.\n",
1044 substream_parity_present[substr] = checkdata_present;
1045 substream_data_len[substr] = end - substream_start;
1046 substream_start = end;
1052 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
1057 buf += header_size + substr_header_size;
1089 goto substream_length_mismatch;
1095 if (substream_data_len[substr] * 8 -
get_bits_count(&gb) >= 32) {
1111 if (substream_parity_present[substr]) {
1112 uint8_t parity, checksum;
1115 goto substream_length_mismatch;
1120 if ((
get_bits(&gb, 8) ^ parity) != 0xa9 )
1127 goto substream_length_mismatch;
1132 "No restart header present in substream %d.\n", substr);
1134 buf += substream_data_len[substr];
1144 substream_length_mismatch:
1164 #if CONFIG_TRUEHD_DECODER