FFmpeg  4.4.7
dca_xll.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 foo86
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "dcadec.h"
22 #include "dcadata.h"
23 #include "dcamath.h"
24 #include "dca_syncwords.h"
25 #include "unary.h"
26 
27 static int get_linear(GetBitContext *gb, int n)
28 {
29  unsigned int v = get_bits_long(gb, n);
30  return (v >> 1) ^ -(v & 1);
31 }
32 
33 static int get_rice_un(GetBitContext *gb, int k)
34 {
35  unsigned int v = get_unary(gb, 1, get_bits_left(gb));
36  return (v << k) | get_bits_long(gb, k);
37 }
38 
39 static int get_rice(GetBitContext *gb, int k)
40 {
41  unsigned int v = get_rice_un(gb, k);
42  return (v >> 1) ^ -(v & 1);
43 }
44 
45 static void get_array(GetBitContext *gb, int32_t *array, int size, int n)
46 {
47  int i;
48 
49  for (i = 0; i < size; i++)
50  array[i] = get_bits(gb, n);
51 }
52 
53 static void get_linear_array(GetBitContext *gb, int32_t *array, int size, int n)
54 {
55  int i;
56 
57  if (n == 0)
58  memset(array, 0, sizeof(*array) * size);
59  else for (i = 0; i < size; i++)
60  array[i] = get_linear(gb, n);
61 }
62 
63 static int get_rice_array(GetBitContext *gb, int32_t *array, int size, int k)
64 {
65  int i;
66 
67  for (i = 0; i < size && get_bits_left(gb) > k; i++)
68  array[i] = get_rice(gb, k);
69 
70  if (i < size)
71  return AVERROR_INVALIDDATA;
72  return 0;
73 }
74 
76 {
77  // Size of downmix coefficient matrix
78  int m = c->primary_chset ? ff_dca_dmix_primary_nch[c->dmix_type] : c->hier_ofs;
79  int i, j, *coeff_ptr = c->dmix_coeff;
80 
81  for (i = 0; i < m; i++) {
82  int code, sign, coeff, scale, scale_inv = 0;
83  unsigned int index;
84 
85  // Downmix scale (only for non-primary channel sets)
86  if (!c->primary_chset) {
87  code = get_bits(&s->gb, 9);
88  sign = (code >> 8) - 1;
89  index = (code & 0xff) - FF_DCA_DMIXTABLE_OFFSET;
91  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix scale index\n");
92  return AVERROR_INVALIDDATA;
93  }
95  scale_inv = ff_dca_inv_dmixtable[index];
96  c->dmix_scale[i] = (scale ^ sign) - sign;
97  c->dmix_scale_inv[i] = (scale_inv ^ sign) - sign;
98  }
99 
100  // Downmix coefficients
101  for (j = 0; j < c->nchannels; j++) {
102  code = get_bits(&s->gb, 9);
103  sign = (code >> 8) - 1;
104  index = code & 0xff;
105  if (index >= FF_DCA_DMIXTABLE_SIZE) {
106  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL downmix coefficient index\n");
107  return AVERROR_INVALIDDATA;
108  }
110  if (!c->primary_chset)
111  // Multiply by |InvDmixScale| to get |UndoDmixScale|
112  coeff = mul16(scale_inv, coeff);
113  *coeff_ptr++ = (coeff ^ sign) - sign;
114  }
115  }
116 
117  return 0;
118 }
119 
121 {
122  int i, j, k, ret, band, header_size, header_pos = get_bits_count(&s->gb);
123  DCAXllChSet *p = &s->chset[0];
124  DCAXllBand *b;
125 
126  // Size of channel set sub-header
127  header_size = get_bits(&s->gb, 10) + 1;
128 
129  // Check CRC
130  if (ff_dca_check_crc(s->avctx, &s->gb, header_pos, header_pos + header_size * 8)) {
131  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL sub-header checksum\n");
132  return AVERROR_INVALIDDATA;
133  }
134 
135  // Number of channels in the channel set
136  c->nchannels = get_bits(&s->gb, 4) + 1;
137  if (c->nchannels > DCA_XLL_CHANNELS_MAX) {
138  avpriv_request_sample(s->avctx, "%d XLL channels", c->nchannels);
139  return AVERROR_PATCHWELCOME;
140  }
141 
142  // Residual type
143  c->residual_encode = get_bits(&s->gb, c->nchannels);
144 
145  // PCM bit resolution
146  c->pcm_bit_res = get_bits(&s->gb, 5) + 1;
147 
148  // Storage unit width
149  c->storage_bit_res = get_bits(&s->gb, 5) + 1;
150  if (c->storage_bit_res != 16 && c->storage_bit_res != 20 && c->storage_bit_res != 24) {
151  avpriv_request_sample(s->avctx, "%d-bit XLL storage resolution", c->storage_bit_res);
152  return AVERROR_PATCHWELCOME;
153  }
154 
155  if (c->pcm_bit_res > c->storage_bit_res) {
156  av_log(s->avctx, AV_LOG_ERROR, "Invalid PCM bit resolution for XLL channel set (%d > %d)\n", c->pcm_bit_res, c->storage_bit_res);
157  return AVERROR_INVALIDDATA;
158  }
159 
160  // Original sampling frequency
161  c->freq = ff_dca_sampling_freqs[get_bits(&s->gb, 4)];
162  if (c->freq > 192000) {
163  avpriv_request_sample(s->avctx, "%d Hz XLL sampling frequency", c->freq);
164  return AVERROR_PATCHWELCOME;
165  }
166 
167  // Sampling frequency modifier
168  if (get_bits(&s->gb, 2)) {
169  avpriv_request_sample(s->avctx, "XLL sampling frequency modifier");
170  return AVERROR_PATCHWELCOME;
171  }
172 
173  // Which replacement set this channel set is member of
174  if (get_bits(&s->gb, 2)) {
175  avpriv_request_sample(s->avctx, "XLL replacement set");
176  return AVERROR_PATCHWELCOME;
177  }
178 
179  if (asset->one_to_one_map_ch_to_spkr) {
180  // Primary channel set flag
181  c->primary_chset = get_bits1(&s->gb);
182  if (c->primary_chset != (c == p)) {
183  av_log(s->avctx, AV_LOG_ERROR, "The first (and only) XLL channel set must be primary\n");
184  return AVERROR_INVALIDDATA;
185  }
186 
187  // Downmix coefficients present in stream
188  c->dmix_coeffs_present = get_bits1(&s->gb);
189 
190  // Downmix already performed by encoder
191  c->dmix_embedded = c->dmix_coeffs_present && get_bits1(&s->gb);
192 
193  // Downmix type
194  if (c->dmix_coeffs_present && c->primary_chset) {
195  c->dmix_type = get_bits(&s->gb, 3);
196  if (c->dmix_type >= DCA_DMIX_TYPE_COUNT) {
197  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL primary channel set downmix type\n");
198  return AVERROR_INVALIDDATA;
199  }
200  }
201 
202  // Whether the channel set is part of a hierarchy
203  c->hier_chset = get_bits1(&s->gb);
204  if (!c->hier_chset && s->nchsets != 1) {
205  avpriv_request_sample(s->avctx, "XLL channel set outside of hierarchy");
206  return AVERROR_PATCHWELCOME;
207  }
208 
209  // Downmix coefficients
210  if (c->dmix_coeffs_present && (ret = parse_dmix_coeffs(s, c)) < 0)
211  return ret;
212 
213  // Channel mask enabled
214  if (!get_bits1(&s->gb)) {
215  avpriv_request_sample(s->avctx, "Disabled XLL channel mask");
216  return AVERROR_PATCHWELCOME;
217  }
218 
219  // Channel mask for set
220  c->ch_mask = get_bits_long(&s->gb, s->ch_mask_nbits);
221  if (av_popcount(c->ch_mask) != c->nchannels) {
222  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL channel mask\n");
223  return AVERROR_INVALIDDATA;
224  }
225 
226  // Build the channel to speaker map
227  for (i = 0, j = 0; i < s->ch_mask_nbits; i++)
228  if (c->ch_mask & (1U << i))
229  c->ch_remap[j++] = i;
230  } else {
231  // Mapping coeffs present flag
232  if (c->nchannels != 2 || s->nchsets != 1 || get_bits1(&s->gb)) {
233  avpriv_request_sample(s->avctx, "Custom XLL channel to speaker mapping");
234  return AVERROR_PATCHWELCOME;
235  }
236 
237  // Setup for LtRt decoding
238  c->primary_chset = 1;
239  c->dmix_coeffs_present = 0;
240  c->dmix_embedded = 0;
241  c->hier_chset = 0;
242  c->ch_mask = DCA_SPEAKER_LAYOUT_STEREO;
243  c->ch_remap[0] = DCA_SPEAKER_L;
244  c->ch_remap[1] = DCA_SPEAKER_R;
245  }
246 
247  if (c->freq > 96000) {
248  // Extra frequency bands flag
249  if (get_bits1(&s->gb)) {
250  avpriv_request_sample(s->avctx, "Extra XLL frequency bands");
251  return AVERROR_PATCHWELCOME;
252  }
253  c->nfreqbands = 2;
254  } else {
255  c->nfreqbands = 1;
256  }
257 
258  // Set the sampling frequency to that of the first frequency band.
259  // Frequency will be doubled again after bands assembly.
260  c->freq >>= c->nfreqbands - 1;
261 
262  // Verify that all channel sets have the same audio characteristics
263  if (c != p && (c->nfreqbands != p->nfreqbands || c->freq != p->freq
264  || c->pcm_bit_res != p->pcm_bit_res
265  || c->storage_bit_res != p->storage_bit_res)) {
266  avpriv_request_sample(s->avctx, "Different XLL audio characteristics");
267  return AVERROR_PATCHWELCOME;
268  }
269 
270  // Determine number of bits to read bit allocation coding parameter
271  if (c->storage_bit_res > 16)
272  c->nabits = 5;
273  else if (c->storage_bit_res > 8)
274  c->nabits = 4;
275  else
276  c->nabits = 3;
277 
278  // Account for embedded downmix and decimator saturation
279  if ((s->nchsets > 1 || c->nfreqbands > 1) && c->nabits < 5)
280  c->nabits++;
281 
282  for (band = 0, b = c->bands; band < c->nfreqbands; band++, b++) {
283  // Pairwise channel decorrelation
284  if ((b->decor_enabled = get_bits1(&s->gb)) && c->nchannels > 1) {
285  int ch_nbits = av_ceil_log2(c->nchannels);
286 
287  // Original channel order
288  for (i = 0; i < c->nchannels; i++) {
289  b->orig_order[i] = get_bits(&s->gb, ch_nbits);
290  if (b->orig_order[i] >= c->nchannels) {
291  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL original channel order\n");
292  return AVERROR_INVALIDDATA;
293  }
294  }
295 
296  // Pairwise channel coefficients
297  for (i = 0; i < c->nchannels / 2; i++)
298  b->decor_coeff[i] = get_bits1(&s->gb) ? get_linear(&s->gb, 7) : 0;
299  } else {
300  for (i = 0; i < c->nchannels; i++)
301  b->orig_order[i] = i;
302  for (i = 0; i < c->nchannels / 2; i++)
303  b->decor_coeff[i] = 0;
304  }
305 
306  // Adaptive predictor order
307  b->highest_pred_order = 0;
308  for (i = 0; i < c->nchannels; i++) {
309  b->adapt_pred_order[i] = get_bits(&s->gb, 4);
310  if (b->adapt_pred_order[i] > b->highest_pred_order)
311  b->highest_pred_order = b->adapt_pred_order[i];
312  }
313  if (b->highest_pred_order > s->nsegsamples) {
314  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL adaptive predicition order\n");
315  return AVERROR_INVALIDDATA;
316  }
317 
318  // Fixed predictor order
319  for (i = 0; i < c->nchannels; i++)
320  b->fixed_pred_order[i] = b->adapt_pred_order[i] ? 0 : get_bits(&s->gb, 2);
321 
322  // Adaptive predictor quantized reflection coefficients
323  for (i = 0; i < c->nchannels; i++) {
324  for (j = 0; j < b->adapt_pred_order[i]; j++) {
325  k = get_linear(&s->gb, 8);
326  if (k == -128) {
327  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL reflection coefficient index\n");
328  return AVERROR_INVALIDDATA;
329  }
330  if (k < 0)
331  b->adapt_refl_coeff[i][j] = -(int)ff_dca_xll_refl_coeff[-k];
332  else
333  b->adapt_refl_coeff[i][j] = (int)ff_dca_xll_refl_coeff[ k];
334  }
335  }
336 
337  // Downmix performed by encoder in extension frequency band
338  b->dmix_embedded = c->dmix_embedded && (band == 0 || get_bits1(&s->gb));
339 
340  // MSB/LSB split flag in extension frequency band
341  if ((band == 0 && s->scalable_lsbs) || (band != 0 && get_bits1(&s->gb))) {
342  // Size of LSB section in any segment
343  b->lsb_section_size = get_bits_long(&s->gb, s->seg_size_nbits);
344  if (b->lsb_section_size < 0 || b->lsb_section_size > s->frame_size) {
345  av_log(s->avctx, AV_LOG_ERROR, "Invalid LSB section size\n");
346  return AVERROR_INVALIDDATA;
347  }
348 
349  // Account for optional CRC bytes after LSB section
350  if (b->lsb_section_size && (s->band_crc_present > 2 ||
351  (band == 0 && s->band_crc_present > 1)))
352  b->lsb_section_size += 2;
353 
354  // Number of bits to represent the samples in LSB part
355  for (i = 0; i < c->nchannels; i++) {
356  b->nscalablelsbs[i] = get_bits(&s->gb, 4);
357  if (b->nscalablelsbs[i] && !b->lsb_section_size) {
358  av_log(s->avctx, AV_LOG_ERROR, "LSB section missing with non-zero LSB width\n");
359  return AVERROR_INVALIDDATA;
360  }
361  }
362  } else {
363  b->lsb_section_size = 0;
364  for (i = 0; i < c->nchannels; i++)
365  b->nscalablelsbs[i] = 0;
366  }
367 
368  // Scalable resolution flag in extension frequency band
369  if ((band == 0 && s->scalable_lsbs) || (band != 0 && get_bits1(&s->gb))) {
370  // Number of bits discarded by authoring
371  for (i = 0; i < c->nchannels; i++)
372  b->bit_width_adjust[i] = get_bits(&s->gb, 4);
373  } else {
374  for (i = 0; i < c->nchannels; i++)
375  b->bit_width_adjust[i] = 0;
376  }
377  }
378 
379  // Reserved
380  // Byte align
381  // CRC16 of channel set sub-header
382  if (ff_dca_seek_bits(&s->gb, header_pos + header_size * 8)) {
383  av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL sub-header\n");
384  return AVERROR_INVALIDDATA;
385  }
386 
387  return 0;
388 }
389 
391 {
392  int ndecisamples = c->nfreqbands > 1 ? DCA_XLL_DECI_HISTORY_MAX : 0;
393  int nchsamples = s->nframesamples + ndecisamples;
394  int i, j, nsamples = nchsamples * c->nchannels * c->nfreqbands;
395  int32_t *ptr;
396 
397  // Reallocate MSB sample buffer
398  av_fast_malloc(&c->sample_buffer[0], &c->sample_size[0], nsamples * sizeof(int32_t));
399  if (!c->sample_buffer[0])
400  return AVERROR(ENOMEM);
401 
402  ptr = c->sample_buffer[0] + ndecisamples;
403  for (i = 0; i < c->nfreqbands; i++) {
404  for (j = 0; j < c->nchannels; j++) {
405  c->bands[i].msb_sample_buffer[j] = ptr;
406  ptr += nchsamples;
407  }
408  }
409 
410  return 0;
411 }
412 
414 {
415  int i, j, nsamples = 0;
416  int32_t *ptr;
417 
418  // Determine number of frequency bands that have MSB/LSB split
419  for (i = 0; i < c->nfreqbands; i++)
420  if (c->bands[i].lsb_section_size)
421  nsamples += s->nframesamples * c->nchannels;
422  if (!nsamples)
423  return 0;
424 
425  // Reallocate LSB sample buffer
426  av_fast_malloc(&c->sample_buffer[1], &c->sample_size[1], nsamples * sizeof(int32_t));
427  if (!c->sample_buffer[1])
428  return AVERROR(ENOMEM);
429 
430  ptr = c->sample_buffer[1];
431  for (i = 0; i < c->nfreqbands; i++) {
432  if (c->bands[i].lsb_section_size) {
433  for (j = 0; j < c->nchannels; j++) {
434  c->bands[i].lsb_sample_buffer[j] = ptr;
435  ptr += s->nframesamples;
436  }
437  } else {
438  for (j = 0; j < c->nchannels; j++)
439  c->bands[i].lsb_sample_buffer[j] = NULL;
440  }
441  }
442 
443  return 0;
444 }
445 
446 static int chs_parse_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg, int band_data_end)
447 {
448  DCAXllBand *b = &c->bands[band];
449  int i, j, k;
450 
451  // Start unpacking MSB portion of the segment
452  if (!(seg && get_bits1(&s->gb))) {
453  // Unpack segment type
454  // 0 - distinct coding parameters for each channel
455  // 1 - common coding parameters for all channels
456  c->seg_common = get_bits1(&s->gb);
457 
458  // Determine number of coding parameters encoded in segment
459  k = c->seg_common ? 1 : c->nchannels;
460 
461  // Unpack Rice coding parameters
462  for (i = 0; i < k; i++) {
463  // Unpack Rice coding flag
464  // 0 - linear code, 1 - Rice code
465  c->rice_code_flag[i] = get_bits1(&s->gb);
466  // Unpack Hybrid Rice coding flag
467  // 0 - Rice code, 1 - Hybrid Rice code
468  if (!c->seg_common && c->rice_code_flag[i] && get_bits1(&s->gb))
469  // Unpack binary code length for isolated samples
470  c->bitalloc_hybrid_linear[i] = get_bits(&s->gb, c->nabits) + 1;
471  else
472  // 0 indicates no Hybrid Rice coding
473  c->bitalloc_hybrid_linear[i] = 0;
474  }
475 
476  // Unpack coding parameters
477  for (i = 0; i < k; i++) {
478  if (seg == 0) {
479  // Unpack coding parameter for part A of segment 0
480  c->bitalloc_part_a[i] = get_bits(&s->gb, c->nabits);
481 
482  // Adjust for the linear code
483  if (!c->rice_code_flag[i] && c->bitalloc_part_a[i])
484  c->bitalloc_part_a[i]++;
485 
486  if (!c->seg_common)
487  c->nsamples_part_a[i] = b->adapt_pred_order[i];
488  else
489  c->nsamples_part_a[i] = b->highest_pred_order;
490  } else {
491  c->bitalloc_part_a[i] = 0;
492  c->nsamples_part_a[i] = 0;
493  }
494 
495  // Unpack coding parameter for part B of segment
496  c->bitalloc_part_b[i] = get_bits(&s->gb, c->nabits);
497 
498  // Adjust for the linear code
499  if (!c->rice_code_flag[i] && c->bitalloc_part_b[i])
500  c->bitalloc_part_b[i]++;
501  }
502  }
503 
504  // Unpack entropy codes
505  for (i = 0; i < c->nchannels; i++) {
506  int32_t *part_a, *part_b;
507  int nsamples_part_b;
508 
509  // Select index of coding parameters
510  k = c->seg_common ? 0 : i;
511 
512  // Slice the segment into parts A and B
513  part_a = b->msb_sample_buffer[i] + seg * s->nsegsamples;
514  part_b = part_a + c->nsamples_part_a[k];
515  nsamples_part_b = s->nsegsamples - c->nsamples_part_a[k];
516 
517  if (get_bits_left(&s->gb) < 0)
518  return AVERROR_INVALIDDATA;
519 
520  if (!c->rice_code_flag[k]) {
521  // Linear codes
522  // Unpack all residuals of part A of segment 0
523  get_linear_array(&s->gb, part_a, c->nsamples_part_a[k],
524  c->bitalloc_part_a[k]);
525 
526  // Unpack all residuals of part B of segment 0 and others
527  get_linear_array(&s->gb, part_b, nsamples_part_b,
528  c->bitalloc_part_b[k]);
529  } else {
530  // Rice codes
531  // Unpack all residuals of part A of segment 0
532  int ret = get_rice_array(&s->gb, part_a, c->nsamples_part_a[k],
533  c->bitalloc_part_a[k]);
534  if (ret < 0)
535  return ret;
536 
537  if (c->bitalloc_hybrid_linear[k]) {
538  // Hybrid Rice codes
539  // Unpack the number of isolated samples
540  int nisosamples = get_bits(&s->gb, s->nsegsamples_log2);
541 
542  // Set all locations to 0
543  memset(part_b, 0, sizeof(*part_b) * nsamples_part_b);
544 
545  // Extract the locations of isolated samples and flag by -1
546  for (j = 0; j < nisosamples; j++) {
547  int loc = get_bits(&s->gb, s->nsegsamples_log2);
548  if (loc >= nsamples_part_b) {
549  av_log(s->avctx, AV_LOG_ERROR, "Invalid isolated sample location\n");
550  return AVERROR_INVALIDDATA;
551  }
552  part_b[loc] = -1;
553  }
554 
555  // Unpack all residuals of part B of segment 0 and others
556  for (j = 0; j < nsamples_part_b; j++) {
557  if (part_b[j])
558  part_b[j] = get_linear(&s->gb, c->bitalloc_hybrid_linear[k]);
559  else
560  part_b[j] = get_rice(&s->gb, c->bitalloc_part_b[k]);
561  }
562  } else {
563  // Rice codes
564  // Unpack all residuals of part B of segment 0 and others
565  ret = get_rice_array(&s->gb, part_b, nsamples_part_b, c->bitalloc_part_b[k]);
566  if (ret < 0)
567  return ret;
568  }
569  }
570  }
571 
572  // Unpack decimator history for frequency band 1
573  if (seg == 0 && band == 1) {
574  int nbits = get_bits(&s->gb, 5) + 1;
575  for (i = 0; i < c->nchannels; i++)
576  for (j = 1; j < DCA_XLL_DECI_HISTORY_MAX; j++)
577  c->deci_history[i][j] = get_sbits_long(&s->gb, nbits);
578  }
579 
580  // Start unpacking LSB portion of the segment
581  if (b->lsb_section_size) {
582  // Skip to the start of LSB portion
583  if (ff_dca_seek_bits(&s->gb, band_data_end - b->lsb_section_size * 8)) {
584  av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
585  return AVERROR_INVALIDDATA;
586  }
587 
588  // Unpack all LSB parts of residuals of this segment
589  for (i = 0; i < c->nchannels; i++) {
590  if (b->nscalablelsbs[i]) {
591  get_array(&s->gb,
592  b->lsb_sample_buffer[i] + seg * s->nsegsamples,
593  s->nsegsamples, b->nscalablelsbs[i]);
594  }
595  }
596  }
597 
598  // Skip to the end of band data
599  if (ff_dca_seek_bits(&s->gb, band_data_end)) {
600  av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL band data\n");
601  return AVERROR_INVALIDDATA;
602  }
603 
604  return 0;
605 }
606 
607 static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg)
608 {
609  DCAXllBand *b = &c->bands[band];
610  int i, offset, nsamples;
611 
612  if (seg < 0) {
613  offset = 0;
614  nsamples = s->nframesamples;
615  } else {
616  offset = seg * s->nsegsamples;
617  nsamples = s->nsegsamples;
618  }
619 
620  for (i = 0; i < c->nchannels; i++) {
621  memset(b->msb_sample_buffer[i] + offset, 0, nsamples * sizeof(int32_t));
622  if (b->lsb_section_size)
623  memset(b->lsb_sample_buffer[i] + offset, 0, nsamples * sizeof(int32_t));
624  }
625 
626  if (seg <= 0 && band)
627  memset(c->deci_history, 0, sizeof(c->deci_history));
628 
629  if (seg < 0) {
630  memset(b->nscalablelsbs, 0, sizeof(b->nscalablelsbs));
631  memset(b->bit_width_adjust, 0, sizeof(b->bit_width_adjust));
632  }
633 }
634 
636 {
637  DCAXllBand *b = &c->bands[band];
638  int nsamples = s->nframesamples;
639  int i, j, k;
640 
641  // Inverse adaptive or fixed prediction
642  for (i = 0; i < c->nchannels; i++) {
643  int32_t *buf = b->msb_sample_buffer[i];
644  int order = b->adapt_pred_order[i];
645  if (order > 0) {
647  // Conversion from reflection coefficients to direct form coefficients
648  for (j = 0; j < order; j++) {
649  int rc = b->adapt_refl_coeff[i][j];
650  for (k = 0; k < (j + 1) / 2; k++) {
651  int tmp1 = coeff[ k ];
652  int tmp2 = coeff[j - k - 1];
653  coeff[ k ] = tmp1 + mul16(rc, tmp2);
654  coeff[j - k - 1] = tmp2 + mul16(rc, tmp1);
655  }
656  coeff[j] = rc;
657  }
658  // Inverse adaptive prediction
659  for (j = 0; j < nsamples - order; j++) {
660  int64_t err = 0;
661  for (k = 0; k < order; k++)
662  err += (int64_t)buf[j + k] * coeff[order - k - 1];
663  buf[j + k] -= (SUINT)clip23(norm16(err));
664  }
665  } else {
666  // Inverse fixed coefficient prediction
667  for (j = 0; j < b->fixed_pred_order[i]; j++)
668  for (k = 1; k < nsamples; k++)
669  buf[k] += (unsigned)buf[k - 1];
670  }
671  }
672 
673  // Inverse pairwise channel decorrellation
674  if (b->decor_enabled) {
676 
677  for (i = 0; i < c->nchannels / 2; i++) {
678  int coeff = b->decor_coeff[i];
679  if (coeff) {
680  s->dcadsp->decor(b->msb_sample_buffer[i * 2 + 1],
681  b->msb_sample_buffer[i * 2 ],
682  coeff, nsamples);
683  }
684  }
685 
686  // Reorder channel pointers to the original order
687  for (i = 0; i < c->nchannels; i++)
688  tmp[i] = b->msb_sample_buffer[i];
689 
690  for (i = 0; i < c->nchannels; i++)
691  b->msb_sample_buffer[b->orig_order[i]] = tmp[i];
692  }
693 
694  // Map output channel pointers for frequency band 0
695  if (c->nfreqbands == 1)
696  for (i = 0; i < c->nchannels; i++)
697  s->output_samples[c->ch_remap[i]] = b->msb_sample_buffer[i];
698 }
699 
700 static int chs_get_lsb_width(DCAXllDecoder *s, DCAXllChSet *c, int band, int ch)
701 {
702  int adj = c->bands[band].bit_width_adjust[ch];
703  int shift = c->bands[band].nscalablelsbs[ch];
704 
705  if (s->fixed_lsb_width)
706  shift = s->fixed_lsb_width;
707  else if (shift && adj)
708  shift += adj - 1;
709  else
710  shift += adj;
711 
712  return shift;
713 }
714 
716 {
717  DCAXllBand *b = &c->bands[band];
718  int n, ch, nsamples = s->nframesamples;
719 
720  for (ch = 0; ch < c->nchannels; ch++) {
721  int shift = chs_get_lsb_width(s, c, band, ch);
722  if (shift) {
723  int32_t *msb = b->msb_sample_buffer[ch];
724  if (b->nscalablelsbs[ch]) {
725  int32_t *lsb = b->lsb_sample_buffer[ch];
726  int adj = b->bit_width_adjust[ch];
727  for (n = 0; n < nsamples; n++)
728  msb[n] = msb[n] * (SUINT)(1 << shift) + (lsb[n] << adj);
729  } else {
730  for (n = 0; n < nsamples; n++)
731  msb[n] = msb[n] * (SUINT)(1 << shift);
732  }
733  }
734  }
735 }
736 
738 {
739  int ch, nsamples = s->nframesamples;
740  int32_t *ptr;
741 
742  av_assert1(c->nfreqbands > 1);
743 
744  // Reallocate frequency band assembly buffer
745  av_fast_malloc(&c->sample_buffer[2], &c->sample_size[2],
746  2 * nsamples * c->nchannels * sizeof(int32_t));
747  if (!c->sample_buffer[2])
748  return AVERROR(ENOMEM);
749 
750  // Assemble frequency bands 0 and 1
751  ptr = c->sample_buffer[2];
752  for (ch = 0; ch < c->nchannels; ch++) {
753  int32_t *band0 = c->bands[0].msb_sample_buffer[ch];
754  int32_t *band1 = c->bands[1].msb_sample_buffer[ch];
755 
756  // Copy decimator history
757  memcpy(band0 - DCA_XLL_DECI_HISTORY_MAX,
758  c->deci_history[ch], sizeof(c->deci_history[0]));
759 
760  // Filter
761  s->dcadsp->assemble_freq_bands(ptr, band0, band1,
763  nsamples);
764 
765  // Remap output channel pointer to assembly buffer
766  s->output_samples[c->ch_remap[ch]] = ptr;
767  ptr += nsamples * 2;
768  }
769 
770  return 0;
771 }
772 
774 {
775  int stream_ver, header_size, frame_size_nbits, nframesegs_log2;
776 
777  // XLL extension sync word
778  if (get_bits_long(&s->gb, 32) != DCA_SYNCWORD_XLL) {
779  av_log(s->avctx, AV_LOG_VERBOSE, "Invalid XLL sync word\n");
780  return AVERROR(EAGAIN);
781  }
782 
783  // Version number
784  stream_ver = get_bits(&s->gb, 4) + 1;
785  if (stream_ver > 1) {
786  avpriv_request_sample(s->avctx, "XLL stream version %d", stream_ver);
787  return AVERROR_PATCHWELCOME;
788  }
789 
790  // Lossless frame header length
791  header_size = get_bits(&s->gb, 8) + 1;
792 
793  // Check CRC
794  if (ff_dca_check_crc(s->avctx, &s->gb, 32, header_size * 8)) {
795  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL common header checksum\n");
796  return AVERROR_INVALIDDATA;
797  }
798 
799  // Number of bits used to read frame size
800  frame_size_nbits = get_bits(&s->gb, 5) + 1;
801 
802  // Number of bytes in a lossless frame
803  s->frame_size = get_bits_long(&s->gb, frame_size_nbits);
804  if (s->frame_size < 0 || s->frame_size >= DCA_XLL_PBR_BUFFER_MAX) {
805  av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL frame size (%d bytes)\n", s->frame_size);
806  return AVERROR_INVALIDDATA;
807  }
808  s->frame_size++;
809 
810  // Number of channels sets per frame
811  s->nchsets = get_bits(&s->gb, 4) + 1;
812  if (s->nchsets > DCA_XLL_CHSETS_MAX) {
813  avpriv_request_sample(s->avctx, "%d XLL channel sets", s->nchsets);
814  return AVERROR_PATCHWELCOME;
815  }
816 
817  // Number of segments per frame
818  nframesegs_log2 = get_bits(&s->gb, 4);
819  s->nframesegs = 1 << nframesegs_log2;
820  if (s->nframesegs > 1024) {
821  av_log(s->avctx, AV_LOG_ERROR, "Too many segments per XLL frame\n");
822  return AVERROR_INVALIDDATA;
823  }
824 
825  // Samples in segment per one frequency band for the first channel set
826  // Maximum value is 256 for sampling frequencies <= 48 kHz
827  // Maximum value is 512 for sampling frequencies > 48 kHz
828  s->nsegsamples_log2 = get_bits(&s->gb, 4);
829  if (!s->nsegsamples_log2) {
830  av_log(s->avctx, AV_LOG_ERROR, "Too few samples per XLL segment\n");
831  return AVERROR_INVALIDDATA;
832  }
833  s->nsegsamples = 1 << s->nsegsamples_log2;
834  if (s->nsegsamples > 512) {
835  av_log(s->avctx, AV_LOG_ERROR, "Too many samples per XLL segment\n");
836  return AVERROR_INVALIDDATA;
837  }
838 
839  // Samples in frame per one frequency band for the first channel set
840  s->nframesamples_log2 = s->nsegsamples_log2 + nframesegs_log2;
841  s->nframesamples = 1 << s->nframesamples_log2;
842  if (s->nframesamples > 65536) {
843  av_log(s->avctx, AV_LOG_ERROR, "Too many samples per XLL frame\n");
844  return AVERROR_INVALIDDATA;
845  }
846 
847  // Number of bits used to read segment size
848  s->seg_size_nbits = get_bits(&s->gb, 5) + 1;
849 
850  // Presence of CRC16 within each frequency band
851  // 0 - No CRC16 within band
852  // 1 - CRC16 placed at the end of MSB0
853  // 2 - CRC16 placed at the end of MSB0 and LSB0
854  // 3 - CRC16 placed at the end of MSB0 and LSB0 and other frequency bands
855  s->band_crc_present = get_bits(&s->gb, 2);
856 
857  // MSB/LSB split flag
858  s->scalable_lsbs = get_bits1(&s->gb);
859 
860  // Channel position mask
861  s->ch_mask_nbits = get_bits(&s->gb, 5) + 1;
862 
863  // Fixed LSB width
864  if (s->scalable_lsbs)
865  s->fixed_lsb_width = get_bits(&s->gb, 4);
866  else
867  s->fixed_lsb_width = 0;
868 
869  // Reserved
870  // Byte align
871  // Header CRC16 protection
872  if (ff_dca_seek_bits(&s->gb, header_size * 8)) {
873  av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL common header\n");
874  return AVERROR_INVALIDDATA;
875  }
876 
877  return 0;
878 }
879 
881 {
882  return !c->primary_chset && c->dmix_embedded && c->hier_chset;
883 }
884 
886 {
887  if (c->hier_chset)
888  while (++c < &s->chset[s->nchsets])
889  if (is_hier_dmix_chset(c))
890  return c;
891 
892  return NULL;
893 }
894 
896 {
897  int i, j, *coeff_ptr = c->dmix_coeff;
898 
899  for (i = 0; i < c->hier_ofs; i++) {
900  int scale = o->dmix_scale[i];
901  int scale_inv = o->dmix_scale_inv[i];
902  c->dmix_scale[i] = mul15(c->dmix_scale[i], scale);
903  c->dmix_scale_inv[i] = mul16(c->dmix_scale_inv[i], scale_inv);
904  for (j = 0; j < c->nchannels; j++) {
905  int coeff = mul16(*coeff_ptr, scale_inv);
906  *coeff_ptr++ = mul15(coeff, o->dmix_scale[c->hier_ofs + j]);
907  }
908  }
909 }
910 
912 {
913  DCAContext *dca = s->avctx->priv_data;
914  DCAXllChSet *c;
915  int i, ret;
916 
917  // Parse channel set headers
918  s->nfreqbands = 0;
919  s->nchannels = 0;
920  s->nreschsets = 0;
921  for (i = 0, c = s->chset; i < s->nchsets; i++, c++) {
922  c->hier_ofs = s->nchannels;
923  if ((ret = chs_parse_header(s, c, asset)) < 0)
924  return ret;
925  if (c->nfreqbands > s->nfreqbands)
926  s->nfreqbands = c->nfreqbands;
927  if (c->hier_chset)
928  s->nchannels += c->nchannels;
929  if (c->residual_encode != (1 << c->nchannels) - 1)
930  s->nreschsets++;
931  }
932 
933  // Pre-scale downmixing coefficients for all non-primary channel sets
934  for (i = s->nchsets - 1, c = &s->chset[i]; i > 0; i--, c--) {
935  if (is_hier_dmix_chset(c)) {
937  if (o)
938  prescale_down_mix(c, o);
939  }
940  }
941 
942  // Determine number of active channel sets to decode
943  switch (dca->request_channel_layout) {
945  s->nactivechsets = 1;
946  break;
949  s->nactivechsets = (s->chset[0].nchannels < 5 && s->nchsets > 1) ? 2 : 1;
950  break;
951  default:
952  s->nactivechsets = s->nchsets;
953  break;
954  }
955 
956  return 0;
957 }
958 
960 {
961  int chs, seg, band, navi_nb, navi_pos, *navi_ptr;
962  DCAXllChSet *c;
963 
964  // Determine size of NAVI table
965  navi_nb = s->nfreqbands * s->nframesegs * s->nchsets;
966  if (navi_nb > 1024) {
967  av_log(s->avctx, AV_LOG_ERROR, "Too many NAVI entries (%d)\n", navi_nb);
968  return AVERROR_INVALIDDATA;
969  }
970 
971  // Reallocate NAVI table
972  av_fast_malloc(&s->navi, &s->navi_size, navi_nb * sizeof(*s->navi));
973  if (!s->navi)
974  return AVERROR(ENOMEM);
975 
976  // Parse NAVI
977  navi_pos = get_bits_count(&s->gb);
978  navi_ptr = s->navi;
979  for (band = 0; band < s->nfreqbands; band++) {
980  for (seg = 0; seg < s->nframesegs; seg++) {
981  for (chs = 0, c = s->chset; chs < s->nchsets; chs++, c++) {
982  int size = 0;
983  if (c->nfreqbands > band) {
984  size = get_bits_long(&s->gb, s->seg_size_nbits);
985  if (size < 0 || size >= s->frame_size) {
986  av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI segment size (%d bytes)\n", size);
987  return AVERROR_INVALIDDATA;
988  }
989  size++;
990  }
991  *navi_ptr++ = size;
992  }
993  }
994  }
995 
996  // Byte align
997  // CRC16
998  skip_bits(&s->gb, -get_bits_count(&s->gb) & 7);
999  skip_bits(&s->gb, 16);
1000 
1001  // Check CRC
1002  if (ff_dca_check_crc(s->avctx, &s->gb, navi_pos, get_bits_count(&s->gb))) {
1003  av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI checksum\n");
1004  return AVERROR_INVALIDDATA;
1005  }
1006 
1007  return 0;
1008 }
1009 
1011 {
1012  int ret, chs, seg, band, navi_pos, *navi_ptr;
1013  DCAXllChSet *c;
1014 
1015  for (chs = 0, c = s->chset; chs < s->nactivechsets; chs++, c++) {
1016  if ((ret = chs_alloc_msb_band_data(s, c)) < 0)
1017  return ret;
1018  if ((ret = chs_alloc_lsb_band_data(s, c)) < 0)
1019  return ret;
1020  }
1021 
1022  navi_pos = get_bits_count(&s->gb);
1023  navi_ptr = s->navi;
1024  for (band = 0; band < s->nfreqbands; band++) {
1025  for (seg = 0; seg < s->nframesegs; seg++) {
1026  for (chs = 0, c = s->chset; chs < s->nchsets; chs++, c++) {
1027  if (c->nfreqbands > band) {
1028  navi_pos += *navi_ptr * 8;
1029  if (navi_pos > s->gb.size_in_bits) {
1030  av_log(s->avctx, AV_LOG_ERROR, "Invalid NAVI position\n");
1031  return AVERROR_INVALIDDATA;
1032  }
1033  if (chs < s->nactivechsets &&
1034  (ret = chs_parse_band_data(s, c, band, seg, navi_pos)) < 0) {
1035  if (s->avctx->err_recognition & AV_EF_EXPLODE)
1036  return ret;
1037  chs_clear_band_data(s, c, band, seg);
1038  }
1039  skip_bits_long(&s->gb, navi_pos - get_bits_count(&s->gb));
1040  }
1041  navi_ptr++;
1042  }
1043  }
1044  }
1045 
1046  return 0;
1047 }
1048 
1050 {
1051  int ret;
1052 
1053  if ((ret = init_get_bits8(&s->gb, data, size)) < 0)
1054  return ret;
1055  if ((ret = parse_common_header(s)) < 0)
1056  return ret;
1057  if ((ret = parse_sub_headers(s, asset)) < 0)
1058  return ret;
1059  if ((ret = parse_navi_table(s)) < 0)
1060  return ret;
1061  if ((ret = parse_band_data(s)) < 0)
1062  return ret;
1063  if (ff_dca_seek_bits(&s->gb, s->frame_size * 8)) {
1064  av_log(s->avctx, AV_LOG_ERROR, "Read past end of XLL frame\n");
1065  return AVERROR_INVALIDDATA;
1066  }
1067  return ret;
1068 }
1069 
1071 {
1072  s->pbr_length = 0;
1073  s->pbr_delay = 0;
1074 }
1075 
1076 static int copy_to_pbr(DCAXllDecoder *s, uint8_t *data, int size, int delay)
1077 {
1079  return AVERROR(ENOSPC);
1080 
1081  if (!s->pbr_buffer && !(s->pbr_buffer = av_malloc(DCA_XLL_PBR_BUFFER_MAX + AV_INPUT_BUFFER_PADDING_SIZE)))
1082  return AVERROR(ENOMEM);
1083 
1084  memcpy(s->pbr_buffer, data, size);
1085  memset(s->pbr_buffer + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1086  s->pbr_length = size;
1087  s->pbr_delay = delay;
1088  return 0;
1089 }
1090 
1092 {
1093  int ret = parse_frame(s, data, size, asset);
1094 
1095  // If XLL packet data didn't start with a sync word, we must have jumped
1096  // right into the middle of PBR smoothing period
1097  if (ret == AVERROR(EAGAIN) && asset->xll_sync_present && asset->xll_sync_offset < size) {
1098  // Skip to the next sync word in this packet
1099  data += asset->xll_sync_offset;
1100  size -= asset->xll_sync_offset;
1101 
1102  // If decoding delay is set, put the frame into PBR buffer and return
1103  // failure code. Higher level decoder is expected to switch to lossy
1104  // core decoding or mute its output until decoding delay expires.
1105  if (asset->xll_delay_nframes > 0) {
1106  if ((ret = copy_to_pbr(s, data, size, asset->xll_delay_nframes)) < 0)
1107  return ret;
1108  return AVERROR(EAGAIN);
1109  }
1110 
1111  // No decoding delay, just parse the frame in place
1112  ret = parse_frame(s, data, size, asset);
1113  }
1114 
1115  if (ret < 0)
1116  return ret;
1117 
1118  if (s->frame_size > size)
1119  return AVERROR(EINVAL);
1120 
1121  // If the XLL decoder didn't consume full packet, start PBR smoothing period
1122  if (s->frame_size < size)
1123  if ((ret = copy_to_pbr(s, data + s->frame_size, size - s->frame_size, 0)) < 0)
1124  return ret;
1125 
1126  return 0;
1127 }
1128 
1130 {
1131  int ret;
1132 
1133  if (size > DCA_XLL_PBR_BUFFER_MAX - s->pbr_length) {
1134  ret = AVERROR(ENOSPC);
1135  goto fail;
1136  }
1137 
1138  memcpy(s->pbr_buffer + s->pbr_length, data, size);
1139  s->pbr_length += size;
1140  memset(s->pbr_buffer + s->pbr_length, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1141 
1142  // Respect decoding delay after synchronization error
1143  if (s->pbr_delay > 0 && --s->pbr_delay)
1144  return AVERROR(EAGAIN);
1145 
1146  if ((ret = parse_frame(s, s->pbr_buffer, s->pbr_length, asset)) < 0)
1147  goto fail;
1148 
1149  if (s->frame_size > s->pbr_length) {
1150  ret = AVERROR(EINVAL);
1151  goto fail;
1152  }
1153 
1154  if (s->frame_size == s->pbr_length) {
1155  // End of PBR smoothing period
1156  clear_pbr(s);
1157  } else {
1158  s->pbr_length -= s->frame_size;
1159  memmove(s->pbr_buffer, s->pbr_buffer + s->frame_size, s->pbr_length);
1160  }
1161 
1162  return 0;
1163 
1164 fail:
1165  // For now, throw out all PBR state on failure.
1166  // Perhaps we can be smarter and try to resync somehow.
1167  clear_pbr(s);
1168  return ret;
1169 }
1170 
1172 {
1173  int ret;
1174 
1175  if (s->hd_stream_id != asset->hd_stream_id) {
1176  clear_pbr(s);
1177  s->hd_stream_id = asset->hd_stream_id;
1178  }
1179 
1180  if (s->pbr_length)
1181  ret = parse_frame_pbr(s, data + asset->xll_offset, asset->xll_size, asset);
1182  else
1183  ret = parse_frame_no_pbr(s, data + asset->xll_offset, asset->xll_size, asset);
1184 
1185  return ret;
1186 }
1187 
1188 static void undo_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
1189 {
1190  int i, j, k, nchannels = 0, *coeff_ptr = o->dmix_coeff;
1191  DCAXllChSet *c;
1192 
1193  for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1194  if (!c->hier_chset)
1195  continue;
1196 
1197  av_assert1(band < c->nfreqbands);
1198  for (j = 0; j < c->nchannels; j++) {
1199  for (k = 0; k < o->nchannels; k++) {
1200  int coeff = *coeff_ptr++;
1201  if (coeff) {
1202  s->dcadsp->dmix_sub(c->bands[band].msb_sample_buffer[j],
1203  o->bands[band].msb_sample_buffer[k],
1204  coeff, s->nframesamples);
1205  if (band)
1206  s->dcadsp->dmix_sub(c->deci_history[j],
1207  o->deci_history[k],
1209  }
1210  }
1211  }
1212 
1213  nchannels += c->nchannels;
1214  if (nchannels >= o->hier_ofs)
1215  break;
1216  }
1217 }
1218 
1219 static void scale_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
1220 {
1221  int i, j, nchannels = 0;
1222  DCAXllChSet *c;
1223 
1224  for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1225  if (!c->hier_chset)
1226  continue;
1227 
1228  av_assert1(band < c->nfreqbands);
1229  for (j = 0; j < c->nchannels; j++) {
1230  int scale = o->dmix_scale[nchannels++];
1231  if (scale != (1 << 15)) {
1232  s->dcadsp->dmix_scale(c->bands[band].msb_sample_buffer[j],
1233  scale, s->nframesamples);
1234  if (band)
1235  s->dcadsp->dmix_scale(c->deci_history[j],
1236  scale, DCA_XLL_DECI_HISTORY_MAX);
1237  }
1238  }
1239 
1240  if (nchannels >= o->hier_ofs)
1241  break;
1242  }
1243 }
1244 
1245 // Clear all band data and replace non-residual encoded channels with lossy
1246 // counterparts
1248 {
1249  DCAContext *dca = s->avctx->priv_data;
1250  int band, ch;
1251 
1252  for (band = 0; band < c->nfreqbands; band++)
1253  chs_clear_band_data(s, c, band, -1);
1254 
1255  for (ch = 0; ch < c->nchannels; ch++) {
1256  if (!(c->residual_encode & (1 << ch)))
1257  continue;
1258  if (ff_dca_core_map_spkr(&dca->core, c->ch_remap[ch]) < 0)
1259  continue;
1260  c->residual_encode &= ~(1 << ch);
1261  }
1262 }
1263 
1265 {
1266  DCAContext *dca = s->avctx->priv_data;
1267  int ch, nsamples = s->nframesamples;
1268  DCAXllChSet *o;
1269 
1270  // Verify that core is compatible
1271  if (!(dca->packet & DCA_PACKET_CORE)) {
1272  av_log(s->avctx, AV_LOG_ERROR, "Residual encoded channels are present without core\n");
1273  return AVERROR(EINVAL);
1274  }
1275 
1276  if (c->freq != dca->core.output_rate) {
1277  av_log(s->avctx, AV_LOG_WARNING, "Sample rate mismatch between core (%d Hz) and XLL (%d Hz)\n", dca->core.output_rate, c->freq);
1278  return AVERROR_INVALIDDATA;
1279  }
1280 
1281  if (nsamples != dca->core.npcmsamples) {
1282  av_log(s->avctx, AV_LOG_WARNING, "Number of samples per frame mismatch between core (%d) and XLL (%d)\n", dca->core.npcmsamples, nsamples);
1283  return AVERROR_INVALIDDATA;
1284  }
1285 
1286  // See if this channel set is downmixed and find the next channel set in
1287  // hierarchy. If downmixed, undo core pre-scaling before combining with
1288  // residual (residual is not scaled).
1290 
1291  // Reduce core bit width and combine with residual
1292  for (ch = 0; ch < c->nchannels; ch++) {
1293  int n, spkr, shift, round;
1294  int32_t *src, *dst;
1295 
1296  if (c->residual_encode & (1 << ch))
1297  continue;
1298 
1299  // Map this channel to core speaker
1300  spkr = ff_dca_core_map_spkr(&dca->core, c->ch_remap[ch]);
1301  if (spkr < 0) {
1302  av_log(s->avctx, AV_LOG_WARNING, "Residual encoded channel (%d) references unavailable core channel\n", c->ch_remap[ch]);
1303  return AVERROR_INVALIDDATA;
1304  }
1305 
1306  // Account for LSB width
1307  shift = 24 - c->pcm_bit_res + chs_get_lsb_width(s, c, 0, ch);
1308  if (shift > 24) {
1309  av_log(s->avctx, AV_LOG_WARNING, "Invalid core shift (%d bits)\n", shift);
1310  return AVERROR_INVALIDDATA;
1311  }
1312 
1313  round = shift > 0 ? 1 << (shift - 1) : 0;
1314 
1315  src = dca->core.output_samples[spkr];
1316  dst = c->bands[0].msb_sample_buffer[ch];
1317  if (o) {
1318  // Undo embedded core downmix pre-scaling
1319  int scale_inv = o->dmix_scale_inv[c->hier_ofs + ch];
1320  for (n = 0; n < nsamples; n++)
1321  dst[n] += (SUINT)clip23((mul16(src[n], scale_inv) + round) >> shift);
1322  } else {
1323  // No downmix scaling
1324  for (n = 0; n < nsamples; n++)
1325  dst[n] += (unsigned)((src[n] + round) >> shift);
1326  }
1327  }
1328 
1329  return 0;
1330 }
1331 
1333 {
1334  AVCodecContext *avctx = s->avctx;
1335  DCAContext *dca = avctx->priv_data;
1336  DCAExssAsset *asset = &dca->exss.assets[0];
1337  DCAXllChSet *p = &s->chset[0], *c;
1338  enum AVMatrixEncoding matrix_encoding = AV_MATRIX_ENCODING_NONE;
1339  int i, j, k, ret, shift, nsamples, request_mask;
1340  int ch_remap[DCA_SPEAKER_COUNT];
1341 
1342  // Force lossy downmixed output during recovery
1343  if (dca->packet & DCA_PACKET_RECOVERY) {
1344  for (i = 0, c = s->chset; i < s->nchsets; i++, c++) {
1345  if (i < s->nactivechsets)
1347 
1348  if (!c->primary_chset)
1349  c->dmix_embedded = 0;
1350  }
1351 
1352  s->scalable_lsbs = 0;
1353  s->fixed_lsb_width = 0;
1354  }
1355 
1356  // Filter frequency bands for active channel sets
1357  s->output_mask = 0;
1358  for (i = 0, c = s->chset; i < s->nactivechsets; i++, c++) {
1359  chs_filter_band_data(s, c, 0);
1360 
1361  if (c->residual_encode != (1 << c->nchannels) - 1
1362  && (ret = combine_residual_frame(s, c)) < 0)
1363  return ret;
1364 
1365  if (s->scalable_lsbs)
1366  chs_assemble_msbs_lsbs(s, c, 0);
1367 
1368  if (c->nfreqbands > 1) {
1369  chs_filter_band_data(s, c, 1);
1370  chs_assemble_msbs_lsbs(s, c, 1);
1371  }
1372 
1373  s->output_mask |= c->ch_mask;
1374  }
1375 
1376  // Undo hierarchial downmix and/or apply scaling
1377  for (i = 1, c = &s->chset[1]; i < s->nchsets; i++, c++) {
1378  if (!is_hier_dmix_chset(c))
1379  continue;
1380 
1381  if (i >= s->nactivechsets) {
1382  for (j = 0; j < c->nfreqbands; j++)
1383  if (c->bands[j].dmix_embedded)
1384  scale_down_mix(s, c, j);
1385  break;
1386  }
1387 
1388  for (j = 0; j < c->nfreqbands; j++)
1389  if (c->bands[j].dmix_embedded)
1390  undo_down_mix(s, c, j);
1391  }
1392 
1393  // Assemble frequency bands for active channel sets
1394  if (s->nfreqbands > 1) {
1395  for (i = 0; i < s->nactivechsets; i++)
1396  if ((ret = chs_assemble_freq_bands(s, &s->chset[i])) < 0)
1397  return ret;
1398  }
1399 
1400  // Normalize to regular 5.1 layout if downmixing
1401  if (dca->request_channel_layout) {
1402  if (s->output_mask & DCA_SPEAKER_MASK_Lss) {
1403  s->output_samples[DCA_SPEAKER_Ls] = s->output_samples[DCA_SPEAKER_Lss];
1404  s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Lss) | DCA_SPEAKER_MASK_Ls;
1405  }
1406  if (s->output_mask & DCA_SPEAKER_MASK_Rss) {
1407  s->output_samples[DCA_SPEAKER_Rs] = s->output_samples[DCA_SPEAKER_Rss];
1408  s->output_mask = (s->output_mask & ~DCA_SPEAKER_MASK_Rss) | DCA_SPEAKER_MASK_Rs;
1409  }
1410  }
1411 
1412  // Handle downmixing to stereo request
1414  && DCA_HAS_STEREO(s->output_mask) && p->dmix_embedded
1415  && (p->dmix_type == DCA_DMIX_TYPE_LoRo ||
1417  request_mask = DCA_SPEAKER_LAYOUT_STEREO;
1418  else
1419  request_mask = s->output_mask;
1420  if (!ff_dca_set_channel_layout(avctx, ch_remap, request_mask))
1421  return AVERROR(EINVAL);
1422 
1423  avctx->sample_rate = p->freq << (s->nfreqbands - 1);
1424 
1425  switch (p->storage_bit_res) {
1426  case 16:
1427  avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
1428  shift = 16 - p->pcm_bit_res;
1429  break;
1430  case 20:
1431  case 24:
1432  avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
1433  shift = 24 - p->pcm_bit_res;
1434  break;
1435  default:
1436  return AVERROR(EINVAL);
1437  }
1438 
1440  avctx->profile = FF_PROFILE_DTS_HD_MA;
1441  avctx->bit_rate = 0;
1442 
1443  frame->nb_samples = nsamples = s->nframesamples << (s->nfreqbands - 1);
1444  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1445  return ret;
1446 
1447  // Downmix primary channel set to stereo
1448  if (request_mask != s->output_mask) {
1449  ff_dca_downmix_to_stereo_fixed(s->dcadsp, s->output_samples,
1450  p->dmix_coeff, nsamples,
1451  s->output_mask);
1452  }
1453 
1454  for (i = 0; i < avctx->channels; i++) {
1455  int32_t *samples = s->output_samples[ch_remap[i]];
1456  if (frame->format == AV_SAMPLE_FMT_S16P) {
1457  int16_t *plane = (int16_t *)frame->extended_data[i];
1458  for (k = 0; k < nsamples; k++)
1459  plane[k] = av_clip_int16(samples[k] * (SUINT)(1 << shift));
1460  } else {
1461  int32_t *plane = (int32_t *)frame->extended_data[i];
1462  for (k = 0; k < nsamples; k++)
1463  plane[k] = clip23(samples[k] * (SUINT)(1 << shift)) * (1 << 8);
1464  }
1465  }
1466 
1467  if (!asset->one_to_one_map_ch_to_spkr) {
1469  matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
1470  else if (asset->representation_type == DCA_REPR_TYPE_LhRh)
1471  matrix_encoding = AV_MATRIX_ENCODING_DOLBYHEADPHONE;
1472  } else if (request_mask != s->output_mask && p->dmix_type == DCA_DMIX_TYPE_LtRt) {
1473  matrix_encoding = AV_MATRIX_ENCODING_DOLBY;
1474  }
1475  if ((ret = ff_side_data_update_matrix_encoding(frame, matrix_encoding)) < 0)
1476  return ret;
1477 
1478  return 0;
1479 }
1480 
1482 {
1483  clear_pbr(s);
1484 }
1485 
1487 {
1488  DCAXllChSet *c;
1489  int i, j;
1490 
1491  for (i = 0, c = s->chset; i < DCA_XLL_CHSETS_MAX; i++, c++) {
1492  for (j = 0; j < DCA_XLL_SAMPLE_BUFFERS_MAX; j++) {
1493  av_freep(&c->sample_buffer[j]);
1494  c->sample_size[j] = 0;
1495  }
1496  }
1497 
1498  av_freep(&s->navi);
1499  s->navi_size = 0;
1500 
1501  av_freep(&s->pbr_buffer);
1502  clear_pbr(s);
1503 }
#define av_cold
Definition: attributes.h:88
uint8_t
int32_t
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1660
#define FF_PROFILE_DTS_HD_MA
Definition: avcodec.h:1888
#define s(width, name)
Definition: cbs_vp9.c:257
#define fail()
Definition: checkasm.h:133
#define av_popcount
Definition: common.h:176
#define av_clip_int16
Definition: common.h:137
#define av_ceil_log2
Definition: common.h:119
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
const uint32_t ff_dca_sampling_freqs[16]
Definition: dca.c:41
@ DCA_SPEAKER_L
Definition: dca.h:79
@ DCA_SPEAKER_Rs
Definition: dca.h:80
@ DCA_SPEAKER_COUNT
Definition: dca.h:88
@ DCA_SPEAKER_Lss
Definition: dca.h:81
@ DCA_SPEAKER_Rss
Definition: dca.h:81
@ DCA_SPEAKER_Ls
Definition: dca.h:79
@ DCA_SPEAKER_R
Definition: dca.h:79
#define DCA_SPEAKER_LAYOUT_5POINT0
Definition: dca.h:129
@ DCA_DMIX_TYPE_COUNT
Definition: dca.h:195
@ DCA_DMIX_TYPE_LoRo
Definition: dca.h:188
@ DCA_DMIX_TYPE_LtRt
Definition: dca.h:189
#define DCA_SPEAKER_LAYOUT_STEREO
Definition: dca.h:123
#define DCA_HAS_STEREO(mask)
Definition: dca.h:134
@ DCA_REPR_TYPE_LtRt
Definition: dca.h:165
@ DCA_REPR_TYPE_LhRh
Definition: dca.h:166
#define DCA_SPEAKER_LAYOUT_5POINT1
Definition: dca.h:130
@ DCA_SPEAKER_MASK_Ls
Definition: dca.h:95
@ DCA_SPEAKER_MASK_Rs
Definition: dca.h:96
@ DCA_SPEAKER_MASK_Rss
Definition: dca.h:102
@ DCA_SPEAKER_MASK_Lss
Definition: dca.h:101
static int ff_dca_core_map_spkr(DCACoreDecoder *core, int spkr)
Definition: dca_core.h:216
#define DCA_SYNCWORD_XLL
Definition: dca_syncwords.h:31
static int combine_residual_frame(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:1264
static int parse_frame(DCAXllDecoder *s, uint8_t *data, int size, DCAExssAsset *asset)
Definition: dca_xll.c:1049
static int get_rice(GetBitContext *gb, int k)
Definition: dca_xll.c:39
static int parse_navi_table(DCAXllDecoder *s)
Definition: dca_xll.c:959
static int parse_frame_no_pbr(DCAXllDecoder *s, uint8_t *data, int size, DCAExssAsset *asset)
Definition: dca_xll.c:1091
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
Definition: dca_xll.c:1332
static int parse_sub_headers(DCAXllDecoder *s, DCAExssAsset *asset)
Definition: dca_xll.c:911
static void prescale_down_mix(DCAXllChSet *c, DCAXllChSet *o)
Definition: dca_xll.c:895
static int get_rice_array(GetBitContext *gb, int32_t *array, int size, int k)
Definition: dca_xll.c:63
static void chs_filter_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band)
Definition: dca_xll.c:635
static int chs_assemble_freq_bands(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:737
static int parse_dmix_coeffs(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:75
static int chs_parse_header(DCAXllDecoder *s, DCAXllChSet *c, DCAExssAsset *asset)
Definition: dca_xll.c:120
static void clear_pbr(DCAXllDecoder *s)
Definition: dca_xll.c:1070
static int chs_alloc_msb_band_data(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:390
static int get_linear(GetBitContext *gb, int n)
Definition: dca_xll.c:27
static int get_rice_un(GetBitContext *gb, int k)
Definition: dca_xll.c:33
av_cold void ff_dca_xll_flush(DCAXllDecoder *s)
Definition: dca_xll.c:1481
static void get_linear_array(GetBitContext *gb, int32_t *array, int size, int n)
Definition: dca_xll.c:53
static int copy_to_pbr(DCAXllDecoder *s, uint8_t *data, int size, int delay)
Definition: dca_xll.c:1076
static DCAXllChSet * find_next_hier_dmix_chset(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:885
static av_cold void chs_clear_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg)
Definition: dca_xll.c:607
static int chs_get_lsb_width(DCAXllDecoder *s, DCAXllChSet *c, int band, int ch)
Definition: dca_xll.c:700
static void scale_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
Definition: dca_xll.c:1219
static void get_array(GetBitContext *gb, int32_t *array, int size, int n)
Definition: dca_xll.c:45
int ff_dca_xll_parse(DCAXllDecoder *s, uint8_t *data, DCAExssAsset *asset)
Definition: dca_xll.c:1171
static void undo_down_mix(DCAXllDecoder *s, DCAXllChSet *o, int band)
Definition: dca_xll.c:1188
static int parse_common_header(DCAXllDecoder *s)
Definition: dca_xll.c:773
static av_cold void force_lossy_output(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:1247
static void chs_assemble_msbs_lsbs(DCAXllDecoder *s, DCAXllChSet *c, int band)
Definition: dca_xll.c:715
static int is_hier_dmix_chset(DCAXllChSet *c)
Definition: dca_xll.c:880
static int chs_alloc_lsb_band_data(DCAXllDecoder *s, DCAXllChSet *c)
Definition: dca_xll.c:413
static int parse_frame_pbr(DCAXllDecoder *s, uint8_t *data, int size, DCAExssAsset *asset)
Definition: dca_xll.c:1129
static int parse_band_data(DCAXllDecoder *s)
Definition: dca_xll.c:1010
av_cold void ff_dca_xll_close(DCAXllDecoder *s)
Definition: dca_xll.c:1486
static int chs_parse_band_data(DCAXllDecoder *s, DCAXllChSet *c, int band, int seg, int band_data_end)
Definition: dca_xll.c:446
#define DCA_XLL_CHANNELS_MAX
Definition: dca_xll.h:35
#define DCA_XLL_DECI_HISTORY_MAX
Definition: dca_xll.h:38
#define DCA_XLL_CHSETS_MAX
Definition: dca_xll.h:34
#define DCA_XLL_SAMPLE_BUFFERS_MAX
Definition: dca_xll.h:42
#define DCA_XLL_PBR_BUFFER_MAX
Definition: dca_xll.h:41
#define DCA_XLL_ADAPT_PRED_ORDER_MAX
Definition: dca_xll.h:37
const uint16_t ff_dca_dmixtable[FF_DCA_DMIXTABLE_SIZE]
Definition: dcadata.c:8642
const uint16_t ff_dca_xll_refl_coeff[128]
Definition: dcadata.c:8705
const int32_t ff_dca_xll_band_coeff[20]
Definition: dcadata.c:8724
const uint8_t ff_dca_dmix_primary_nch[8]
Definition: dcadata.c:45
const uint32_t ff_dca_inv_dmixtable[FF_DCA_INV_DMIXTABLE_SIZE]
Definition: dcadata.c:8676
#define FF_DCA_INV_DMIXTABLE_SIZE
Definition: dcadata.h:70
#define FF_DCA_DMIXTABLE_SIZE
Definition: dcadata.h:69
#define FF_DCA_DMIXTABLE_OFFSET
Definition: dcadata.h:71
int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask)
Definition: dcadec.c:32
void ff_dca_downmix_to_stereo_fixed(DCADSPContext *dcadsp, int32_t **samples, int *coeff_l, int nsamples, int ch_mask)
Definition: dcadec.c:79
#define DCA_PACKET_CORE
Definition: dcadec.h:37
#define DCA_PACKET_RECOVERY
Sync error recovery flag.
Definition: dcadec.h:43
static int ff_dca_check_crc(AVCodecContext *avctx, GetBitContext *s, int p1, int p2)
Definition: dcadec.h:75
static int ff_dca_seek_bits(GetBitContext *s, int p)
Definition: dcadec.h:89
static int32_t mul16(int32_t a, int32_t b)
Definition: dcamath.h:47
static int32_t norm16(int64_t a)
Definition: dcamath.h:41
static int32_t clip23(int32_t a)
Definition: dcamath.h:54
static int32_t mul15(int32_t a, int32_t b)
Definition: dcamath.h:46
#define SUINT
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1900
static AVFrame * frame
int
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:590
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:291
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
AVMatrixEncoding
@ AV_MATRIX_ENCODING_NONE
@ AV_MATRIX_ENCODING_DOLBY
@ AV_MATRIX_ENCODING_DOLBYHEADPHONE
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:502
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:68
int index
Definition: gxfenc.c:89
for(j=16;j >0;--j)
int i
Definition: input.c:407
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
Definition: utils.c:114
static av_always_inline av_const double round(double x)
Definition: libm.h:444
const char data[16]
Definition: mxf.c:142
static int shift(int a, int b)
Definition: sonic.c:82
const uint8_t * code
Definition: spdifenc.c:413
main external API structure.
Definition: avcodec.h:536
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1204
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
int profile
profile
Definition: avcodec.h:1862
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1751
int sample_rate
samples per second
Definition: avcodec.h:1196
int channels
number of audio channels
Definition: avcodec.h:1197
void * priv_data
Definition: avcodec.h:563
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:384
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:365
DCACoreDecoder core
Core decoder context.
Definition: dcadec.h:50
DCAExssParser exss
EXSS parser context.
Definition: dcadec.h:51
int packet
Packet flags.
Definition: dcadec.h:62
int request_channel_layout
Converted from avctx.request_channel_layout.
Definition: dcadec.h:64
int npcmsamples
Number of PCM samples per channel.
Definition: dca_core.h:210
int output_rate
Output sample rate (1x or 2x header rate)
Definition: dca_core.h:211
int32_t * output_samples[DCA_SPEAKER_COUNT]
PCM output for fixed point mode.
Definition: dca_core.h:203
int xll_offset
Offset to XLL data from start of substream.
Definition: dca_exss.h:62
int hd_stream_id
DTS-HD stream ID.
Definition: dca_exss.h:68
int xll_sync_present
XLL sync word present flag.
Definition: dca_exss.h:64
int xll_size
Size of XLL data in extension substream.
Definition: dca_exss.h:63
int xll_delay_nframes
Initial XLL decoding delay in frames.
Definition: dca_exss.h:65
int representation_type
Representation type.
Definition: dca_exss.h:42
int xll_sync_offset
Number of bytes offset to XLL sync.
Definition: dca_exss.h:66
int one_to_one_map_ch_to_spkr
One to one channel to speaker mapping flag.
Definition: dca_exss.h:37
DCAExssAsset assets[1]
Audio asset descriptors.
Definition: dca_exss.h:87
int32_t * msb_sample_buffer[DCA_XLL_CHANNELS_MAX]
MSB sample buffer pointers.
Definition: dca_xll.h:60
int nfreqbands
Number of frequency bands (1 or 2)
Definition: dca_xll.h:84
int32_t deci_history[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]
Decimator history for frequency band 1.
Definition: dca_xll.h:98
int freq
Original sampling frequency (max. 96000 Hz)
Definition: dca_xll.h:70
int dmix_type
Primary channel set downmix type.
Definition: dca_xll.h:75
int nchannels
Number of channels in the channel set (N)
Definition: dca_xll.h:66
int pcm_bit_res
PCM bit resolution (variable)
Definition: dca_xll.h:68
int dmix_embedded
Downmix already performed by encoder.
Definition: dca_xll.h:74
int storage_bit_res
Storage bit resolution (16 or 24)
Definition: dca_xll.h:69
DCAXllBand bands[DCA_XLL_BANDS_MAX]
Frequency bands.
Definition: dca_xll.h:87
int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]
Downmixing scales.
Definition: dca_xll.h:79
int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]
Downmixing coefficients.
Definition: dca_xll.h:78
int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]
Inverse downmixing scales.
Definition: dca_xll.h:80
int hier_ofs
Number of preceding channels in a hierarchy (M)
Definition: dca_xll.h:77
#define avpriv_request_sample(...)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
static uint8_t tmp[11]
Definition: aes_ctr.c:27
#define src
Definition: vp8dsp.c:255
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
int size
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
const char * b
Definition: vf_curves.c:118
static const double coeff[2][5]
Definition: vf_owdenoise.c:73
static const uint8_t offset[127][2]
Definition: vf_spp.c:107
static double c[64]