FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
dcadec.c
Go to the documentation of this file.
1 /*
2  * DCA compatible decoder
3  * Copyright (C) 2004 Gildas Bazin
4  * Copyright (C) 2004 Benjamin Zores
5  * Copyright (C) 2006 Benjamin Larsson
6  * Copyright (C) 2007 Konstantin Shishkov
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 #include <math.h>
26 #include <stddef.h>
27 #include <stdio.h>
28 
30 #include "libavutil/common.h"
31 #include "libavutil/float_dsp.h"
32 #include "libavutil/internal.h"
33 #include "libavutil/intreadwrite.h"
34 #include "libavutil/mathematics.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/samplefmt.h"
37 
38 #include "avcodec.h"
39 #include "dca.h"
40 #include "dca_syncwords.h"
41 #include "dcadata.h"
42 #include "dcadsp.h"
43 #include "dcahuff.h"
44 #include "fft.h"
45 #include "fmtconvert.h"
46 #include "get_bits.h"
47 #include "internal.h"
48 #include "mathops.h"
49 #include "synth_filter.h"
50 
51 #if ARCH_ARM
52 # include "arm/dca.h"
53 #endif
54 
55 enum DCAMode {
56  DCA_MONO = 0,
67 };
68 
69 
71  DCA_XXCH_FRONT_CENTER = 0x0000001,
72  DCA_XXCH_FRONT_LEFT = 0x0000002,
73  DCA_XXCH_FRONT_RIGHT = 0x0000004,
76  DCA_XXCH_LFE1 = 0x0000020,
77  DCA_XXCH_REAR_CENTER = 0x0000040,
87  DCA_XXCH_LFE2 = 0x0010000,
90  DCA_XXCH_OVERHEAD = 0x0080000,
99 };
100 
101 #define DCA_DOLBY 101 /* FIXME */
102 
103 #define DCA_CHANNEL_BITS 6
104 #define DCA_CHANNEL_MASK 0x3F
105 
106 #define DCA_LFE 0x80
107 
108 #define HEADER_SIZE 14
109 
110 #define DCA_NSYNCAUX 0x9A1105A0
111 
112 
113 /** Bit allocation */
114 typedef struct BitAlloc {
115  int offset; ///< code values offset
116  int maxbits[8]; ///< max bits in VLC
117  int wrap; ///< wrap for get_vlc2()
118  VLC vlc[8]; ///< actual codes
119 } BitAlloc;
120 
121 static BitAlloc dca_bitalloc_index; ///< indexes for samples VLC select
122 static BitAlloc dca_tmode; ///< transition mode VLCs
123 static BitAlloc dca_scalefactor; ///< scalefactor VLCs
124 static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs
125 
127  int idx)
128 {
129  return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) +
130  ba->offset;
131 }
132 
133 static float dca_dmix_code(unsigned code);
134 
135 static av_cold void dca_init_vlcs(void)
136 {
137  static int vlcs_initialized = 0;
138  int i, j, c = 14;
139  static VLC_TYPE dca_table[23622][2];
140 
141  if (vlcs_initialized)
142  return;
143 
144  dca_bitalloc_index.offset = 1;
145  dca_bitalloc_index.wrap = 2;
146  for (i = 0; i < 5; i++) {
147  dca_bitalloc_index.vlc[i].table = &dca_table[ff_dca_vlc_offs[i]];
148  dca_bitalloc_index.vlc[i].table_allocated = ff_dca_vlc_offs[i + 1] - ff_dca_vlc_offs[i];
149  init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12,
150  bitalloc_12_bits[i], 1, 1,
152  }
153  dca_scalefactor.offset = -64;
154  dca_scalefactor.wrap = 2;
155  for (i = 0; i < 5; i++) {
156  dca_scalefactor.vlc[i].table = &dca_table[ff_dca_vlc_offs[i + 5]];
157  dca_scalefactor.vlc[i].table_allocated = ff_dca_vlc_offs[i + 6] - ff_dca_vlc_offs[i + 5];
158  init_vlc(&dca_scalefactor.vlc[i], SCALES_VLC_BITS, 129,
159  scales_bits[i], 1, 1,
161  }
162  dca_tmode.offset = 0;
163  dca_tmode.wrap = 1;
164  for (i = 0; i < 4; i++) {
165  dca_tmode.vlc[i].table = &dca_table[ff_dca_vlc_offs[i + 10]];
166  dca_tmode.vlc[i].table_allocated = ff_dca_vlc_offs[i + 11] - ff_dca_vlc_offs[i + 10];
167  init_vlc(&dca_tmode.vlc[i], tmode_vlc_bits[i], 4,
168  tmode_bits[i], 1, 1,
170  }
171 
172  for (i = 0; i < 10; i++)
173  for (j = 0; j < 7; j++) {
174  if (!bitalloc_codes[i][j])
175  break;
176  dca_smpl_bitalloc[i + 1].offset = bitalloc_offsets[i];
177  dca_smpl_bitalloc[i + 1].wrap = 1 + (j > 4);
178  dca_smpl_bitalloc[i + 1].vlc[j].table = &dca_table[ff_dca_vlc_offs[c]];
179  dca_smpl_bitalloc[i + 1].vlc[j].table_allocated = ff_dca_vlc_offs[c + 1] - ff_dca_vlc_offs[c];
180 
181  init_vlc(&dca_smpl_bitalloc[i + 1].vlc[j], bitalloc_maxbits[i][j],
182  bitalloc_sizes[i],
183  bitalloc_bits[i][j], 1, 1,
185  c++;
186  }
187  vlcs_initialized = 1;
188 }
189 
190 static inline void get_array(GetBitContext *gb, int *dst, int len, int bits)
191 {
192  while (len--)
193  *dst++ = get_bits(gb, bits);
194 }
195 
196 static inline int dca_xxch2index(DCAContext *s, int xxch_ch)
197 {
198  int i, base, mask;
199 
200  /* locate channel set containing the channel */
201  for (i = -1, base = 0, mask = (s->xxch_core_spkmask & ~DCA_XXCH_LFE1);
202  i <= s->xxch_chset && !(mask & xxch_ch); mask = s->xxch_spk_masks[++i])
203  base += av_popcount(mask);
204 
205  return base + av_popcount(mask & (xxch_ch - 1));
206 }
207 
208 static int dca_parse_audio_coding_header(DCAContext *s, int base_channel,
209  int xxch)
210 {
211  int i, j;
212  static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 };
213  static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 };
214  static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 };
215  int hdr_pos = 0, hdr_size = 0;
216  float scale_factor;
217  int this_chans, acc_mask;
218  int embedded_downmix;
219  int nchans, mask[8];
220  int coeff, ichan;
221 
222  /* xxch has arbitrary sized audio coding headers */
223  if (xxch) {
224  hdr_pos = get_bits_count(&s->gb);
225  hdr_size = get_bits(&s->gb, 7) + 1;
226  }
227 
228  nchans = get_bits(&s->gb, 3) + 1;
229  if (xxch && nchans >= 3) {
230  av_log(s->avctx, AV_LOG_ERROR, "nchans %d is too large\n", nchans);
231  return AVERROR_INVALIDDATA;
232  } else if (nchans + base_channel > DCA_PRIM_CHANNELS_MAX) {
233  av_log(s->avctx, AV_LOG_ERROR, "channel sum %d + %d is too large\n", nchans, base_channel);
234  return AVERROR_INVALIDDATA;
235  }
236 
237  s->total_channels = nchans + base_channel;
239 
240  /* obtain speaker layout mask & downmix coefficients for XXCH */
241  if (xxch) {
242  acc_mask = s->xxch_core_spkmask;
243 
244  this_chans = get_bits(&s->gb, s->xxch_nbits_spk_mask - 6) << 6;
245  s->xxch_spk_masks[s->xxch_chset] = this_chans;
246  s->xxch_chset_nch[s->xxch_chset] = nchans;
247 
248  for (i = 0; i <= s->xxch_chset; i++)
249  acc_mask |= s->xxch_spk_masks[i];
250 
251  /* check for downmixing information */
252  if (get_bits1(&s->gb)) {
253  embedded_downmix = get_bits1(&s->gb);
254  coeff = get_bits(&s->gb, 6);
255 
256  if (coeff<1 || coeff>61) {
257  av_log(s->avctx, AV_LOG_ERROR, "6bit coeff %d is out of range\n", coeff);
258  return AVERROR_INVALIDDATA;
259  }
260 
261  scale_factor = -1.0f / dca_dmix_code((coeff<<2)-3);
262 
263  s->xxch_dmix_sf[s->xxch_chset] = scale_factor;
264 
265  for (i = base_channel; i < s->prim_channels; i++) {
266  mask[i] = get_bits(&s->gb, s->xxch_nbits_spk_mask);
267  }
268 
269  for (j = base_channel; j < s->prim_channels; j++) {
270  memset(s->xxch_dmix_coeff[j], 0, sizeof(s->xxch_dmix_coeff[0]));
271  s->xxch_dmix_embedded |= (embedded_downmix << j);
272  for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
273  if (mask[j] & (1 << i)) {
274  if ((1 << i) == DCA_XXCH_LFE1) {
276  "DCA-XXCH: dmix to LFE1 not supported.\n");
277  continue;
278  }
279 
280  coeff = get_bits(&s->gb, 7);
281  ichan = dca_xxch2index(s, 1 << i);
282  if ((coeff&63)<1 || (coeff&63)>61) {
283  av_log(s->avctx, AV_LOG_ERROR, "7bit coeff %d is out of range\n", coeff);
284  return AVERROR_INVALIDDATA;
285  }
286  s->xxch_dmix_coeff[j][ichan] = dca_dmix_code((coeff<<2)-3);
287  }
288  }
289  }
290  }
291  }
292 
295 
296  for (i = base_channel; i < s->prim_channels; i++) {
297  s->subband_activity[i] = get_bits(&s->gb, 5) + 2;
298  if (s->subband_activity[i] > DCA_SUBBANDS)
300  }
301  for (i = base_channel; i < s->prim_channels; i++) {
302  s->vq_start_subband[i] = get_bits(&s->gb, 5) + 1;
303  if (s->vq_start_subband[i] > DCA_SUBBANDS)
305  }
306  get_array(&s->gb, s->joint_intensity + base_channel, s->prim_channels - base_channel, 3);
307  get_array(&s->gb, s->transient_huffman + base_channel, s->prim_channels - base_channel, 2);
308  get_array(&s->gb, s->scalefactor_huffman + base_channel, s->prim_channels - base_channel, 3);
309  get_array(&s->gb, s->bitalloc_huffman + base_channel, s->prim_channels - base_channel, 3);
310 
311  /* Get codebooks quantization indexes */
312  if (!base_channel)
313  memset(s->quant_index_huffman, 0, sizeof(s->quant_index_huffman));
314  for (j = 1; j < 11; j++)
315  for (i = base_channel; i < s->prim_channels; i++)
316  s->quant_index_huffman[i][j] = get_bits(&s->gb, bitlen[j]);
317 
318  /* Get scale factor adjustment */
319  for (j = 0; j < 11; j++)
320  for (i = base_channel; i < s->prim_channels; i++)
321  s->scalefactor_adj[i][j] = 1;
322 
323  for (j = 1; j < 11; j++)
324  for (i = base_channel; i < s->prim_channels; i++)
325  if (s->quant_index_huffman[i][j] < thr[j])
326  s->scalefactor_adj[i][j] = adj_table[get_bits(&s->gb, 2)];
327 
328  if (!xxch) {
329  if (s->crc_present) {
330  /* Audio header CRC check */
331  get_bits(&s->gb, 16);
332  }
333  } else {
334  /* Skip to the end of the header, also ignore CRC if present */
335  i = get_bits_count(&s->gb);
336  if (hdr_pos + 8 * hdr_size > i)
337  skip_bits_long(&s->gb, hdr_pos + 8 * hdr_size - i);
338  }
339 
340  s->current_subframe = 0;
341  s->current_subsubframe = 0;
342 
343  return 0;
344 }
345 
347 {
348  init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);
349 
350  /* Sync code */
351  skip_bits_long(&s->gb, 32);
352 
353  /* Frame header */
354  s->frame_type = get_bits(&s->gb, 1);
355  s->samples_deficit = get_bits(&s->gb, 5) + 1;
356  s->crc_present = get_bits(&s->gb, 1);
357  s->sample_blocks = get_bits(&s->gb, 7) + 1;
358  s->frame_size = get_bits(&s->gb, 14) + 1;
359  if (s->frame_size < 95)
360  return AVERROR_INVALIDDATA;
361  s->amode = get_bits(&s->gb, 6);
363  if (!s->sample_rate)
364  return AVERROR_INVALIDDATA;
365  s->bit_rate_index = get_bits(&s->gb, 5);
367  if (!s->bit_rate)
368  return AVERROR_INVALIDDATA;
369 
370  skip_bits1(&s->gb); // always 0 (reserved, cf. ETSI TS 102 114 V1.4.1)
371  s->dynrange = get_bits(&s->gb, 1);
372  s->timestamp = get_bits(&s->gb, 1);
373  s->aux_data = get_bits(&s->gb, 1);
374  s->hdcd = get_bits(&s->gb, 1);
375  s->ext_descr = get_bits(&s->gb, 3);
376  s->ext_coding = get_bits(&s->gb, 1);
377  s->aspf = get_bits(&s->gb, 1);
378  s->lfe = get_bits(&s->gb, 2);
379  s->predictor_history = get_bits(&s->gb, 1);
380 
381  if (s->lfe > 2) {
382  s->lfe = 0;
383  av_log(s->avctx, AV_LOG_ERROR, "Invalid LFE value: %d\n", s->lfe);
384  return AVERROR_INVALIDDATA;
385  }
386 
387  /* TODO: check CRC */
388  if (s->crc_present)
389  s->header_crc = get_bits(&s->gb, 16);
390 
391  s->multirate_inter = get_bits(&s->gb, 1);
392  s->version = get_bits(&s->gb, 4);
393  s->copy_history = get_bits(&s->gb, 2);
394  s->source_pcm_res = get_bits(&s->gb, 3);
395  s->front_sum = get_bits(&s->gb, 1);
396  s->surround_sum = get_bits(&s->gb, 1);
397  s->dialog_norm = get_bits(&s->gb, 4);
398 
399  /* FIXME: channels mixing levels */
400  s->output = s->amode;
401  if (s->lfe)
402  s->output |= DCA_LFE;
403 
404  /* Primary audio coding header */
405  s->subframes = get_bits(&s->gb, 4) + 1;
406 
407  return dca_parse_audio_coding_header(s, 0, 0);
408 }
409 
410 static inline int get_scale(GetBitContext *gb, int level, int value, int log2range)
411 {
412  if (level < 5) {
413  /* huffman encoded */
414  value += get_bitalloc(gb, &dca_scalefactor, level);
415  value = av_clip(value, 0, (1 << log2range) - 1);
416  } else if (level < 8) {
417  if (level + 1 > log2range) {
418  skip_bits(gb, level + 1 - log2range);
419  value = get_bits(gb, log2range);
420  } else {
421  value = get_bits(gb, level + 1);
422  }
423  }
424  return value;
425 }
426 
427 static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
428 {
429  /* Primary audio coding side information */
430  int j, k;
431 
432  if (get_bits_left(&s->gb) < 0)
433  return AVERROR_INVALIDDATA;
434 
435  if (!base_channel) {
436  s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;
437  if (block_index + s->subsubframes[s->current_subframe] > s->sample_blocks/8) {
438  s->subsubframes[s->current_subframe] = 1;
439  return AVERROR_INVALIDDATA;
440  }
441  s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);
442  }
443 
444  for (j = base_channel; j < s->prim_channels; j++) {
445  for (k = 0; k < s->subband_activity[j]; k++)
446  s->prediction_mode[j][k] = get_bits(&s->gb, 1);
447  }
448 
449  /* Get prediction codebook */
450  for (j = base_channel; j < s->prim_channels; j++) {
451  for (k = 0; k < s->subband_activity[j]; k++) {
452  if (s->prediction_mode[j][k] > 0) {
453  /* (Prediction coefficient VQ address) */
454  s->prediction_vq[j][k] = get_bits(&s->gb, 12);
455  }
456  }
457  }
458 
459  /* Bit allocation index */
460  for (j = base_channel; j < s->prim_channels; j++) {
461  for (k = 0; k < s->vq_start_subband[j]; k++) {
462  if (s->bitalloc_huffman[j] == 6)
463  s->bitalloc[j][k] = get_bits(&s->gb, 5);
464  else if (s->bitalloc_huffman[j] == 5)
465  s->bitalloc[j][k] = get_bits(&s->gb, 4);
466  else if (s->bitalloc_huffman[j] == 7) {
468  "Invalid bit allocation index\n");
469  return AVERROR_INVALIDDATA;
470  } else {
471  s->bitalloc[j][k] =
472  get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
473  }
474 
475  if (s->bitalloc[j][k] > 26) {
476  av_dlog(s->avctx, "bitalloc index [%i][%i] too big (%i)\n",
477  j, k, s->bitalloc[j][k]);
478  return AVERROR_INVALIDDATA;
479  }
480  }
481  }
482 
483  /* Transition mode */
484  for (j = base_channel; j < s->prim_channels; j++) {
485  for (k = 0; k < s->subband_activity[j]; k++) {
486  s->transition_mode[j][k] = 0;
487  if (s->subsubframes[s->current_subframe] > 1 &&
488  k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
489  s->transition_mode[j][k] =
490  get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
491  }
492  }
493  }
494 
495  if (get_bits_left(&s->gb) < 0)
496  return AVERROR_INVALIDDATA;
497 
498  for (j = base_channel; j < s->prim_channels; j++) {
499  const uint32_t *scale_table;
500  int scale_sum, log_size;
501 
502  memset(s->scale_factor[j], 0,
503  s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
504 
505  if (s->scalefactor_huffman[j] == 6) {
506  scale_table = ff_dca_scale_factor_quant7;
507  log_size = 7;
508  } else {
509  scale_table = ff_dca_scale_factor_quant6;
510  log_size = 6;
511  }
512 
513  /* When huffman coded, only the difference is encoded */
514  scale_sum = 0;
515 
516  for (k = 0; k < s->subband_activity[j]; k++) {
517  if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
518  scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size);
519  s->scale_factor[j][k][0] = scale_table[scale_sum];
520  }
521 
522  if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
523  /* Get second scale factor */
524  scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size);
525  s->scale_factor[j][k][1] = scale_table[scale_sum];
526  }
527  }
528  }
529 
530  /* Joint subband scale factor codebook select */
531  for (j = base_channel; j < s->prim_channels; j++) {
532  /* Transmitted only if joint subband coding enabled */
533  if (s->joint_intensity[j] > 0)
534  s->joint_huff[j] = get_bits(&s->gb, 3);
535  }
536 
537  if (get_bits_left(&s->gb) < 0)
538  return AVERROR_INVALIDDATA;
539 
540  /* Scale factors for joint subband coding */
541  for (j = base_channel; j < s->prim_channels; j++) {
542  int source_channel;
543 
544  /* Transmitted only if joint subband coding enabled */
545  if (s->joint_intensity[j] > 0) {
546  int scale = 0;
547  source_channel = s->joint_intensity[j] - 1;
548 
549  /* When huffman coded, only the difference is encoded
550  * (is this valid as well for joint scales ???) */
551 
552  for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
553  scale = get_scale(&s->gb, s->joint_huff[j], 64 /* bias */, 7);
554  s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */
555  }
556 
557  if (!(s->debug_flag & 0x02)) {
559  "Joint stereo coding not supported\n");
560  s->debug_flag |= 0x02;
561  }
562  }
563  }
564 
565  /* Dynamic range coefficient */
566  if (!base_channel && s->dynrange)
567  s->dynrange_coef = get_bits(&s->gb, 8);
568 
569  /* Side information CRC check word */
570  if (s->crc_present) {
571  get_bits(&s->gb, 16);
572  }
573 
574  /*
575  * Primary audio data arrays
576  */
577 
578  /* VQ encoded high frequency subbands */
579  for (j = base_channel; j < s->prim_channels; j++)
580  for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
581  /* 1 vector -> 32 samples */
582  s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
583 
584  /* Low frequency effect data */
585  if (!base_channel && s->lfe) {
586  int quant7;
587  /* LFE samples */
588  int lfe_samples = 2 * s->lfe * (4 + block_index);
589  int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
590  float lfe_scale;
591 
592  for (j = lfe_samples; j < lfe_end_sample; j++) {
593  /* Signed 8 bits int */
594  s->lfe_data[j] = get_sbits(&s->gb, 8);
595  }
596 
597  /* Scale factor index */
598  quant7 = get_bits(&s->gb, 8);
599  if (quant7 > 127) {
600  avpriv_request_sample(s->avctx, "LFEScaleIndex larger than 127");
601  return AVERROR_INVALIDDATA;
602  }
604 
605  /* Quantization step size * scale factor */
606  lfe_scale = 0.035 * s->lfe_scale_factor;
607 
608  for (j = lfe_samples; j < lfe_end_sample; j++)
609  s->lfe_data[j] *= lfe_scale;
610  }
611 
612  return 0;
613 }
614 
615 static void qmf_32_subbands(DCAContext *s, int chans,
616  float samples_in[32][8], float *samples_out,
617  float scale)
618 {
619  const float *prCoeff;
620 
621  int sb_act = s->subband_activity[chans];
622 
623  scale *= sqrt(1 / 8.0);
624 
625  /* Select filter */
626  if (!s->multirate_inter) /* Non-perfect reconstruction */
628  else /* Perfect reconstruction */
629  prCoeff = ff_dca_fir_32bands_perfect;
630 
631  s->dcadsp.qmf_32_subbands(samples_in, sb_act, &s->synth, &s->imdct,
632  s->subband_fir_hist[chans],
633  &s->hist_index[chans],
634  s->subband_fir_noidea[chans], prCoeff,
635  samples_out, s->raXin, scale);
636 }
637 
638 static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
639  int num_deci_sample, float *samples_in,
640  float *samples_out)
641 {
642  /* samples_in: An array holding decimated samples.
643  * Samples in current subframe starts from samples_in[0],
644  * while samples_in[-1], samples_in[-2], ..., stores samples
645  * from last subframe as history.
646  *
647  * samples_out: An array holding interpolated samples
648  */
649 
650  int idx;
651  const float *prCoeff;
652  int deciindex;
653 
654  /* Select decimation filter */
655  if (decimation_select == 1) {
656  idx = 1;
657  prCoeff = ff_dca_lfe_fir_128;
658  } else {
659  idx = 0;
660  prCoeff = ff_dca_lfe_fir_64;
661  }
662  /* Interpolation */
663  for (deciindex = 0; deciindex < num_deci_sample; deciindex++) {
664  s->dcadsp.lfe_fir[idx](samples_out, samples_in, prCoeff);
665  samples_in++;
666  samples_out += 2 * 32 * (1 + idx);
667  }
668 }
669 
670 /* downmixing routines */
671 #define MIX_REAR1(samples, s1, rs, coef) \
672  samples[0][i] += samples[s1][i] * coef[rs][0]; \
673  samples[1][i] += samples[s1][i] * coef[rs][1];
674 
675 #define MIX_REAR2(samples, s1, s2, rs, coef) \
676  samples[0][i] += samples[s1][i] * coef[rs][0] + samples[s2][i] * coef[rs + 1][0]; \
677  samples[1][i] += samples[s1][i] * coef[rs][1] + samples[s2][i] * coef[rs + 1][1];
678 
679 #define MIX_FRONT3(samples, coef) \
680  t = samples[c][i]; \
681  u = samples[l][i]; \
682  v = samples[r][i]; \
683  samples[0][i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \
684  samples[1][i] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1];
685 
686 #define DOWNMIX_TO_STEREO(op1, op2) \
687  for (i = 0; i < 256; i++) { \
688  op1 \
689  op2 \
690  }
691 
692 static void dca_downmix(float **samples, int srcfmt, int lfe_present,
693  float coef[DCA_PRIM_CHANNELS_MAX + 1][2],
694  const int8_t *channel_mapping)
695 {
696  int c, l, r, sl, sr, s;
697  int i;
698  float t, u, v;
699 
700  switch (srcfmt) {
701  case DCA_MONO:
702  case DCA_4F2R:
703  av_log(NULL, AV_LOG_ERROR, "Not implemented!\n");
704  break;
705  case DCA_CHANNEL:
706  case DCA_STEREO:
707  case DCA_STEREO_TOTAL:
708  case DCA_STEREO_SUMDIFF:
709  break;
710  case DCA_3F:
711  c = channel_mapping[0];
712  l = channel_mapping[1];
713  r = channel_mapping[2];
714  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef), );
715  break;
716  case DCA_2F1R:
717  s = channel_mapping[2];
718  DOWNMIX_TO_STEREO(MIX_REAR1(samples, s, 2, coef), );
719  break;
720  case DCA_3F1R:
721  c = channel_mapping[0];
722  l = channel_mapping[1];
723  r = channel_mapping[2];
724  s = channel_mapping[3];
725  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
726  MIX_REAR1(samples, s, 3, coef));
727  break;
728  case DCA_2F2R:
729  sl = channel_mapping[2];
730  sr = channel_mapping[3];
731  DOWNMIX_TO_STEREO(MIX_REAR2(samples, sl, sr, 2, coef), );
732  break;
733  case DCA_3F2R:
734  c = channel_mapping[0];
735  l = channel_mapping[1];
736  r = channel_mapping[2];
737  sl = channel_mapping[3];
738  sr = channel_mapping[4];
739  DOWNMIX_TO_STEREO(MIX_FRONT3(samples, coef),
740  MIX_REAR2(samples, sl, sr, 3, coef));
741  break;
742  }
743  if (lfe_present) {
744  int lf_buf = ff_dca_lfe_index[srcfmt];
745  int lf_idx = ff_dca_channels[srcfmt];
746  for (i = 0; i < 256; i++) {
747  samples[0][i] += samples[lf_buf][i] * coef[lf_idx][0];
748  samples[1][i] += samples[lf_buf][i] * coef[lf_idx][1];
749  }
750  }
751 }
752 
753 #ifndef decode_blockcodes
754 /* Very compact version of the block code decoder that does not use table
755  * look-up but is slightly slower */
756 static int decode_blockcode(int code, int levels, int32_t *values)
757 {
758  int i;
759  int offset = (levels - 1) >> 1;
760 
761  for (i = 0; i < 4; i++) {
762  int div = FASTDIV(code, levels);
763  values[i] = code - offset - div * levels;
764  code = div;
765  }
766 
767  return code;
768 }
769 
770 static int decode_blockcodes(int code1, int code2, int levels, int32_t *values)
771 {
772  return decode_blockcode(code1, levels, values) |
773  decode_blockcode(code2, levels, values + 4);
774 }
775 #endif
776 
777 static const uint8_t abits_sizes[7] = { 7, 10, 12, 13, 15, 17, 19 };
778 static const uint8_t abits_levels[7] = { 3, 5, 7, 9, 13, 17, 25 };
779 
780 static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
781 {
782  int k, l;
783  int subsubframe = s->current_subsubframe;
784 
785  const float *quant_step_table;
786 
787  /* FIXME */
788  float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];
790 
791  /*
792  * Audio data
793  */
794 
795  /* Select quantization step size table */
796  if (s->bit_rate_index == 0x1f)
797  quant_step_table = ff_dca_lossless_quant_d;
798  else
799  quant_step_table = ff_dca_lossy_quant_d;
800 
801  for (k = base_channel; k < s->prim_channels; k++) {
802  float rscale[DCA_SUBBANDS];
803 
804  if (get_bits_left(&s->gb) < 0)
805  return AVERROR_INVALIDDATA;
806 
807  for (l = 0; l < s->vq_start_subband[k]; l++) {
808  int m;
809 
810  /* Select the mid-tread linear quantizer */
811  int abits = s->bitalloc[k][l];
812 
813  float quant_step_size = quant_step_table[abits];
814 
815  /*
816  * Determine quantization index code book and its type
817  */
818 
819  /* Select quantization index code book */
820  int sel = s->quant_index_huffman[k][abits];
821 
822  /*
823  * Extract bits from the bit stream
824  */
825  if (!abits) {
826  rscale[l] = 0;
827  memset(block + 8 * l, 0, 8 * sizeof(block[0]));
828  } else {
829  /* Deal with transients */
830  int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l];
831  rscale[l] = quant_step_size * s->scale_factor[k][l][sfi] *
832  s->scalefactor_adj[k][sel];
833 
834  if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) {
835  if (abits <= 7) {
836  /* Block code */
837  int block_code1, block_code2, size, levels, err;
838 
839  size = abits_sizes[abits - 1];
840  levels = abits_levels[abits - 1];
841 
842  block_code1 = get_bits(&s->gb, size);
843  block_code2 = get_bits(&s->gb, size);
844  err = decode_blockcodes(block_code1, block_code2,
845  levels, block + 8 * l);
846  if (err) {
848  "ERROR: block code look-up failed\n");
849  return AVERROR_INVALIDDATA;
850  }
851  } else {
852  /* no coding */
853  for (m = 0; m < 8; m++)
854  block[8 * l + m] = get_sbits(&s->gb, abits - 3);
855  }
856  } else {
857  /* Huffman coded */
858  for (m = 0; m < 8; m++)
859  block[8 * l + m] = get_bitalloc(&s->gb,
860  &dca_smpl_bitalloc[abits], sel);
861  }
862  }
863  }
864 
865  s->fmt_conv.int32_to_float_fmul_array8(&s->fmt_conv, subband_samples[k][0],
866  block, rscale, 8 * s->vq_start_subband[k]);
867 
868  for (l = 0; l < s->vq_start_subband[k]; l++) {
869  int m;
870  /*
871  * Inverse ADPCM if in prediction mode
872  */
873  if (s->prediction_mode[k][l]) {
874  int n;
875  if (s->predictor_history)
876  subband_samples[k][l][0] += (ff_dca_adpcm_vb[s->prediction_vq[k][l]][0] *
877  s->subband_samples_hist[k][l][3] +
878  ff_dca_adpcm_vb[s->prediction_vq[k][l]][1] *
879  s->subband_samples_hist[k][l][2] +
880  ff_dca_adpcm_vb[s->prediction_vq[k][l]][2] *
881  s->subband_samples_hist[k][l][1] +
882  ff_dca_adpcm_vb[s->prediction_vq[k][l]][3] *
883  s->subband_samples_hist[k][l][0]) *
884  (1.0f / 8192);
885  for (m = 1; m < 8; m++) {
886  float sum = ff_dca_adpcm_vb[s->prediction_vq[k][l]][0] *
887  subband_samples[k][l][m - 1];
888  for (n = 2; n <= 4; n++)
889  if (m >= n)
890  sum += ff_dca_adpcm_vb[s->prediction_vq[k][l]][n - 1] *
891  subband_samples[k][l][m - n];
892  else if (s->predictor_history)
893  sum += ff_dca_adpcm_vb[s->prediction_vq[k][l]][n - 1] *
894  s->subband_samples_hist[k][l][m - n + 4];
895  subband_samples[k][l][m] += sum * (1.0f / 8192);
896  }
897  }
898  }
899 
900  /*
901  * Decode VQ encoded high frequencies
902  */
903  if (s->subband_activity[k] > s->vq_start_subband[k]) {
904  if (!(s->debug_flag & 0x01)) {
906  "Stream with high frequencies VQ coding\n");
907  s->debug_flag |= 0x01;
908  }
909  s->dcadsp.decode_hf(subband_samples[k], s->high_freq_vq[k],
910  ff_dca_high_freq_vq, subsubframe * 8,
911  s->scale_factor[k], s->vq_start_subband[k],
912  s->subband_activity[k]);
913  }
914  }
915 
916  /* Check for DSYNC after subsubframe */
917  if (s->aspf || subsubframe == s->subsubframes[s->current_subframe] - 1) {
918  if (get_bits(&s->gb, 16) != 0xFFFF) {
919  av_log(s->avctx, AV_LOG_ERROR, "Didn't get subframe DSYNC\n");
920  return AVERROR_INVALIDDATA;
921  }
922  }
923 
924  /* Backup predictor history for adpcm */
925  for (k = base_channel; k < s->prim_channels; k++)
926  for (l = 0; l < s->vq_start_subband[k]; l++)
927  AV_COPY128(s->subband_samples_hist[k][l], &subband_samples[k][l][4]);
928 
929  return 0;
930 }
931 
932 static int dca_filter_channels(DCAContext *s, int block_index)
933 {
934  float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index];
935  int k;
936 
937  /* 32 subbands QMF */
938  for (k = 0; k < s->prim_channels; k++) {
939  if (s->channel_order_tab[k] >= 0)
940  qmf_32_subbands(s, k, subband_samples[k],
942  M_SQRT1_2 / 32768.0);
943  }
944 
945  /* Generate LFE samples for this subsubframe FIXME!!! */
946  if (s->lfe) {
947  lfe_interpolation_fir(s, s->lfe, 2 * s->lfe,
948  s->lfe_data + 2 * s->lfe * (block_index + 4),
949  s->samples_chanptr[s->lfe_index]);
950  /* Outputs 20bits pcm samples */
951  }
952 
953  /* Downmixing to Stereo */
954  if (s->prim_channels + !!s->lfe > 2 &&
957  s->channel_order_tab);
958  }
959 
960  return 0;
961 }
962 
963 static int dca_subframe_footer(DCAContext *s, int base_channel)
964 {
965  int in, out, aux_data_count, aux_data_end, reserved;
966  uint32_t nsyncaux;
967 
968  /*
969  * Unpack optional information
970  */
971 
972  /* presumably optional information only appears in the core? */
973  if (!base_channel) {
974  if (s->timestamp)
975  skip_bits_long(&s->gb, 32);
976 
977  if (s->aux_data) {
978  aux_data_count = get_bits(&s->gb, 6);
979 
980  // align (32-bit)
981  skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
982 
983  aux_data_end = 8 * aux_data_count + get_bits_count(&s->gb);
984 
985  if ((nsyncaux = get_bits_long(&s->gb, 32)) != DCA_NSYNCAUX) {
986  av_log(s->avctx, AV_LOG_ERROR, "nSYNCAUX mismatch %#"PRIx32"\n",
987  nsyncaux);
988  return AVERROR_INVALIDDATA;
989  }
990 
991  if (get_bits1(&s->gb)) { // bAUXTimeStampFlag
993  "Auxiliary Decode Time Stamp Flag");
994  // align (4-bit)
995  skip_bits(&s->gb, (-get_bits_count(&s->gb)) & 4);
996  // 44 bits: nMSByte (8), nMarker (4), nLSByte (28), nMarker (4)
997  skip_bits_long(&s->gb, 44);
998  }
999 
1000  if ((s->core_downmix = get_bits1(&s->gb))) {
1001  int am = get_bits(&s->gb, 3);
1002  switch (am) {
1003  case 0:
1005  break;
1006  case 1:
1008  break;
1009  case 2:
1011  break;
1012  case 3:
1014  break;
1015  case 4:
1017  break;
1018  case 5:
1020  break;
1021  case 6:
1023  break;
1024  default:
1026  "Invalid mode %d for embedded downmix coefficients\n",
1027  am);
1028  return AVERROR_INVALIDDATA;
1029  }
1030  for (out = 0; out < ff_dca_channels[s->core_downmix_amode]; out++) {
1031  for (in = 0; in < s->prim_channels + !!s->lfe; in++) {
1032  uint16_t tmp = get_bits(&s->gb, 9);
1033  if ((tmp & 0xFF) > 241) {
1035  "Invalid downmix coefficient code %"PRIu16"\n",
1036  tmp);
1037  return AVERROR_INVALIDDATA;
1038  }
1039  s->core_downmix_codes[in][out] = tmp;
1040  }
1041  }
1042  }
1043 
1044  align_get_bits(&s->gb); // byte align
1045  skip_bits(&s->gb, 16); // nAUXCRC16
1046 
1047  // additional data (reserved, cf. ETSI TS 102 114 V1.4.1)
1048  if ((reserved = (aux_data_end - get_bits_count(&s->gb))) < 0) {
1050  "Overread auxiliary data by %d bits\n", -reserved);
1051  return AVERROR_INVALIDDATA;
1052  } else if (reserved) {
1054  "Core auxiliary data reserved content");
1055  skip_bits_long(&s->gb, reserved);
1056  }
1057  }
1058 
1059  if (s->crc_present && s->dynrange)
1060  get_bits(&s->gb, 16);
1061  }
1062 
1063  return 0;
1064 }
1065 
1066 /**
1067  * Decode a dca frame block
1068  *
1069  * @param s pointer to the DCAContext
1070  */
1071 
1072 static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
1073 {
1074  int ret;
1075 
1076  /* Sanity check */
1077  if (s->current_subframe >= s->subframes) {
1078  av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i",
1079  s->current_subframe, s->subframes);
1080  return AVERROR_INVALIDDATA;
1081  }
1082 
1083  if (!s->current_subsubframe) {
1084  /* Read subframe header */
1085  if ((ret = dca_subframe_header(s, base_channel, block_index)))
1086  return ret;
1087  }
1088 
1089  /* Read subsubframe */
1090  if ((ret = dca_subsubframe(s, base_channel, block_index)))
1091  return ret;
1092 
1093  /* Update state */
1094  s->current_subsubframe++;
1096  s->current_subsubframe = 0;
1097  s->current_subframe++;
1098  }
1099  if (s->current_subframe >= s->subframes) {
1100  /* Read subframe footer */
1101  if ((ret = dca_subframe_footer(s, base_channel)))
1102  return ret;
1103  }
1104 
1105  return 0;
1106 }
1107 
1109 {
1110  int scale_table_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS][2];
1111  int active_bands[DCA_CHSETS_MAX][DCA_CHSET_CHANS_MAX];
1112  int abits_high[DCA_CHSET_CHANS_MAX][DCA_SUBBANDS];
1113  int anctemp[DCA_CHSET_CHANS_MAX];
1114  int chset_fsize[DCA_CHSETS_MAX];
1115  int n_xbr_ch[DCA_CHSETS_MAX];
1116  int hdr_size, num_chsets, xbr_tmode, hdr_pos;
1117  int i, j, k, l, chset, chan_base;
1118 
1119  av_log(s->avctx, AV_LOG_DEBUG, "DTS-XBR: decoding XBR extension\n");
1120 
1121  /* get bit position of sync header */
1122  hdr_pos = get_bits_count(&s->gb) - 32;
1123 
1124  hdr_size = get_bits(&s->gb, 6) + 1;
1125  num_chsets = get_bits(&s->gb, 2) + 1;
1126 
1127  for(i = 0; i < num_chsets; i++)
1128  chset_fsize[i] = get_bits(&s->gb, 14) + 1;
1129 
1130  xbr_tmode = get_bits1(&s->gb);
1131 
1132  for(i = 0; i < num_chsets; i++) {
1133  n_xbr_ch[i] = get_bits(&s->gb, 3) + 1;
1134  k = get_bits(&s->gb, 2) + 5;
1135  for(j = 0; j < n_xbr_ch[i]; j++) {
1136  active_bands[i][j] = get_bits(&s->gb, k) + 1;
1137  if (active_bands[i][j] > DCA_SUBBANDS) {
1138  av_log(s->avctx, AV_LOG_ERROR, "too many active subbands (%d)\n", active_bands[i][j]);
1139  return AVERROR_INVALIDDATA;
1140  }
1141  }
1142  }
1143 
1144  /* skip to the end of the header */
1145  i = get_bits_count(&s->gb);
1146  if(hdr_pos + hdr_size * 8 > i)
1147  skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i);
1148 
1149  /* loop over the channel data sets */
1150  /* only decode as many channels as we've decoded base data for */
1151  for(chset = 0, chan_base = 0;
1152  chset < num_chsets && chan_base + n_xbr_ch[chset] <= s->prim_channels;
1153  chan_base += n_xbr_ch[chset++]) {
1154  int start_posn = get_bits_count(&s->gb);
1155  int subsubframe = 0;
1156  int subframe = 0;
1157 
1158  /* loop over subframes */
1159  for (k = 0; k < (s->sample_blocks / 8); k++) {
1160  /* parse header if we're on first subsubframe of a block */
1161  if(subsubframe == 0) {
1162  /* Parse subframe header */
1163  for(i = 0; i < n_xbr_ch[chset]; i++) {
1164  anctemp[i] = get_bits(&s->gb, 2) + 2;
1165  }
1166 
1167  for(i = 0; i < n_xbr_ch[chset]; i++) {
1168  get_array(&s->gb, abits_high[i], active_bands[chset][i], anctemp[i]);
1169  }
1170 
1171  for(i = 0; i < n_xbr_ch[chset]; i++) {
1172  anctemp[i] = get_bits(&s->gb, 3);
1173  if(anctemp[i] < 1) {
1174  av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: SYNC ERROR\n");
1175  return AVERROR_INVALIDDATA;
1176  }
1177  }
1178 
1179  /* generate scale factors */
1180  for(i = 0; i < n_xbr_ch[chset]; i++) {
1181  const uint32_t *scale_table;
1182  int nbits;
1183  int scale_table_size;
1184 
1185  if (s->scalefactor_huffman[chan_base+i] == 6) {
1186  scale_table = ff_dca_scale_factor_quant7;
1187  scale_table_size = FF_ARRAY_ELEMS(ff_dca_scale_factor_quant7);
1188  } else {
1189  scale_table = ff_dca_scale_factor_quant6;
1190  scale_table_size = FF_ARRAY_ELEMS(ff_dca_scale_factor_quant6);
1191  }
1192 
1193  nbits = anctemp[i];
1194 
1195  for(j = 0; j < active_bands[chset][i]; j++) {
1196  if(abits_high[i][j] > 0) {
1197  int index = get_bits(&s->gb, nbits);
1198  if (index >= scale_table_size) {
1199  av_log(s->avctx, AV_LOG_ERROR, "scale table index %d invalid\n", index);
1200  return AVERROR_INVALIDDATA;
1201  }
1202  scale_table_high[i][j][0] = scale_table[index];
1203 
1204  if(xbr_tmode && s->transition_mode[i][j]) {
1205  int index = get_bits(&s->gb, nbits);
1206  if (index >= scale_table_size) {
1207  av_log(s->avctx, AV_LOG_ERROR, "scale table index %d invalid\n", index);
1208  return AVERROR_INVALIDDATA;
1209  }
1210  scale_table_high[i][j][1] = scale_table[index];
1211  }
1212  }
1213  }
1214  }
1215  }
1216 
1217  /* decode audio array for this block */
1218  for(i = 0; i < n_xbr_ch[chset]; i++) {
1219  for(j = 0; j < active_bands[chset][i]; j++) {
1220  const int xbr_abits = abits_high[i][j];
1221  const float quant_step_size = ff_dca_lossless_quant_d[xbr_abits];
1222  const int sfi = xbr_tmode && s->transition_mode[i][j] && subsubframe >= s->transition_mode[i][j];
1223  const float rscale = quant_step_size * scale_table_high[i][j][sfi];
1224  float *subband_samples = s->subband_samples[k][chan_base+i][j];
1225  int block[8];
1226 
1227  if(xbr_abits <= 0)
1228  continue;
1229 
1230  if(xbr_abits > 7) {
1231  get_array(&s->gb, block, 8, xbr_abits - 3);
1232  } else {
1233  int block_code1, block_code2, size, levels, err;
1234 
1235  size = abits_sizes[xbr_abits - 1];
1236  levels = abits_levels[xbr_abits - 1];
1237 
1238  block_code1 = get_bits(&s->gb, size);
1239  block_code2 = get_bits(&s->gb, size);
1240  err = decode_blockcodes(block_code1, block_code2,
1241  levels, block);
1242  if (err) {
1244  "ERROR: DTS-XBR: block code look-up failed\n");
1245  return AVERROR_INVALIDDATA;
1246  }
1247  }
1248 
1249  /* scale & sum into subband */
1250  for(l = 0; l < 8; l++)
1251  subband_samples[l] += (float)block[l] * rscale;
1252  }
1253  }
1254 
1255  /* check DSYNC marker */
1256  if(s->aspf || subsubframe == s->subsubframes[subframe] - 1) {
1257  if(get_bits(&s->gb, 16) != 0xffff) {
1258  av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: Didn't get subframe DSYNC\n");
1259  return AVERROR_INVALIDDATA;
1260  }
1261  }
1262 
1263  /* advance sub-sub-frame index */
1264  if(++subsubframe >= s->subsubframes[subframe]) {
1265  subsubframe = 0;
1266  subframe++;
1267  }
1268  }
1269 
1270  /* skip to next channel set */
1271  i = get_bits_count(&s->gb);
1272  if(start_posn + chset_fsize[chset] * 8 != i) {
1273  j = start_posn + chset_fsize[chset] * 8 - i;
1274  if(j < 0 || j >= 8)
1275  av_log(s->avctx, AV_LOG_ERROR, "DTS-XBR: end of channel set,"
1276  " skipping further than expected (%d bits)\n", j);
1277  skip_bits_long(&s->gb, j);
1278  }
1279  }
1280 
1281  return 0;
1282 }
1283 
1284 
1285 /* parse initial header for XXCH and dump details */
1287 {
1288  int hdr_size, spkmsk_bits, num_chsets, core_spk, hdr_pos;
1289  int i, chset, base_channel, chstart, fsize[8];
1290 
1291  /* assume header word has already been parsed */
1292  hdr_pos = get_bits_count(&s->gb) - 32;
1293  hdr_size = get_bits(&s->gb, 6) + 1;
1294  /*chhdr_crc =*/ skip_bits1(&s->gb);
1295  spkmsk_bits = get_bits(&s->gb, 5) + 1;
1296  num_chsets = get_bits(&s->gb, 2) + 1;
1297 
1298  for (i = 0; i < num_chsets; i++)
1299  fsize[i] = get_bits(&s->gb, 14) + 1;
1300 
1301  core_spk = get_bits(&s->gb, spkmsk_bits);
1302  s->xxch_core_spkmask = core_spk;
1303  s->xxch_nbits_spk_mask = spkmsk_bits;
1304  s->xxch_dmix_embedded = 0;
1305 
1306  /* skip to the end of the header */
1307  i = get_bits_count(&s->gb);
1308  if (hdr_pos + hdr_size * 8 > i)
1309  skip_bits_long(&s->gb, hdr_pos + hdr_size * 8 - i);
1310 
1311  for (chset = 0; chset < num_chsets; chset++) {
1312  chstart = get_bits_count(&s->gb);
1313  base_channel = s->prim_channels;
1314  s->xxch_chset = chset;
1315 
1316  /* XXCH and Core headers differ, see 6.4.2 "XXCH Channel Set Header" vs.
1317  5.3.2 "Primary Audio Coding Header", DTS Spec 1.3.1 */
1318  dca_parse_audio_coding_header(s, base_channel, 1);
1319 
1320  /* decode channel data */
1321  for (i = 0; i < (s->sample_blocks / 8); i++) {
1322  if (dca_decode_block(s, base_channel, i)) {
1324  "Error decoding DTS-XXCH extension\n");
1325  continue;
1326  }
1327  }
1328 
1329  /* skip to end of this section */
1330  i = get_bits_count(&s->gb);
1331  if (chstart + fsize[chset] * 8 > i)
1332  skip_bits_long(&s->gb, chstart + fsize[chset] * 8 - i);
1333  }
1334  s->xxch_chset = num_chsets;
1335 
1336  return 0;
1337 }
1338 
1339 static float dca_dmix_code(unsigned code)
1340 {
1341  int sign = (code >> 8) - 1;
1342  code &= 0xff;
1343  return ((ff_dca_dmixtable[code] ^ sign) - sign) * (1.0 / (1 << 15));
1344 }
1345 
1346 /**
1347  * Main frame decoding function
1348  * FIXME add arguments
1349  */
1350 static int dca_decode_frame(AVCodecContext *avctx, void *data,
1351  int *got_frame_ptr, AVPacket *avpkt)
1352 {
1353  AVFrame *frame = data;
1354  const uint8_t *buf = avpkt->data;
1355  int buf_size = avpkt->size;
1356  int channel_mask;
1357  int channel_layout;
1358  int lfe_samples;
1359  int num_core_channels = 0;
1360  int i, ret;
1361  float **samples_flt;
1362  float *src_chan;
1363  float *dst_chan;
1364  DCAContext *s = avctx->priv_data;
1365  int core_ss_end;
1366  int channels, full_channels;
1367  float scale;
1368  int achan;
1369  int chset;
1370  int mask;
1371  int lavc;
1372  int posn;
1373  int j, k;
1374  int endch;
1375 
1376  s->xch_present = 0;
1377 
1381  av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");
1382  return AVERROR_INVALIDDATA;
1383  }
1384 
1385  if ((ret = dca_parse_frame_header(s)) < 0) {
1386  // seems like the frame is corrupt, try with the next one
1387  return ret;
1388  }
1389  // set AVCodec values with parsed data
1390  avctx->sample_rate = s->sample_rate;
1391  avctx->bit_rate = s->bit_rate;
1392 
1393  s->profile = FF_PROFILE_DTS;
1394 
1395  for (i = 0; i < (s->sample_blocks / 8); i++) {
1396  if ((ret = dca_decode_block(s, 0, i))) {
1397  av_log(avctx, AV_LOG_ERROR, "error decoding block\n");
1398  return ret;
1399  }
1400  }
1401 
1402  /* record number of core channels incase less than max channels are requested */
1403  num_core_channels = s->prim_channels;
1404 
1405  if (s->prim_channels + !!s->lfe > 2 &&
1407  /* Stereo downmix coefficients
1408  *
1409  * The decoder can only downmix to 2-channel, so we need to ensure
1410  * embedded downmix coefficients are actually targeting 2-channel.
1411  */
1412  if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
1414  for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1415  /* Range checked earlier */
1416  s->downmix_coef[i][0] = dca_dmix_code(s->core_downmix_codes[i][0]);
1417  s->downmix_coef[i][1] = dca_dmix_code(s->core_downmix_codes[i][1]);
1418  }
1419  s->output = s->core_downmix_amode;
1420  } else {
1421  int am = s->amode & DCA_CHANNEL_MASK;
1424  "Invalid channel mode %d\n", am);
1425  return AVERROR_INVALIDDATA;
1426  }
1427  if (num_core_channels + !!s->lfe >
1429  avpriv_request_sample(s->avctx, "Downmixing %d channels",
1430  s->prim_channels + !!s->lfe);
1431  return AVERROR_PATCHWELCOME;
1432  }
1433  for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1434  s->downmix_coef[i][0] = ff_dca_default_coeffs[am][i][0];
1435  s->downmix_coef[i][1] = ff_dca_default_coeffs[am][i][1];
1436  }
1437  }
1438  av_dlog(s->avctx, "Stereo downmix coeffs:\n");
1439  for (i = 0; i < num_core_channels + !!s->lfe; i++) {
1440  av_dlog(s->avctx, "L, input channel %d = %f\n", i,
1441  s->downmix_coef[i][0]);
1442  av_dlog(s->avctx, "R, input channel %d = %f\n", i,
1443  s->downmix_coef[i][1]);
1444  }
1445  av_dlog(s->avctx, "\n");
1446  }
1447 
1448  if (s->ext_coding)
1450  else
1451  s->core_ext_mask = 0;
1452 
1453  core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8;
1454 
1455  /* only scan for extensions if ext_descr was unknown or indicated a
1456  * supported XCh extension */
1457  if (s->core_ext_mask < 0 || s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) {
1458  /* if ext_descr was unknown, clear s->core_ext_mask so that the
1459  * extensions scan can fill it up */
1460  s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
1461 
1462  /* extensions start at 32-bit boundaries into bitstream */
1463  skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1464 
1465  while (core_ss_end - get_bits_count(&s->gb) >= 32) {
1466  uint32_t bits = get_bits_long(&s->gb, 32);
1467 
1468  switch (bits) {
1469  case DCA_SYNCWORD_XCH: {
1470  int ext_amode, xch_fsize;
1471 
1473 
1474  /* validate sync word using XCHFSIZE field */
1475  xch_fsize = show_bits(&s->gb, 10);
1476  if ((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) &&
1477  (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1))
1478  continue;
1479 
1480  /* skip length-to-end-of-frame field for the moment */
1481  skip_bits(&s->gb, 10);
1482 
1483  s->core_ext_mask |= DCA_EXT_XCH;
1484 
1485  /* extension amode(number of channels in extension) should be 1 */
1486  /* AFAIK XCh is not used for more channels */
1487  if ((ext_amode = get_bits(&s->gb, 4)) != 1) {
1488  av_log(avctx, AV_LOG_ERROR,
1489  "XCh extension amode %d not supported!\n",
1490  ext_amode);
1491  continue;
1492  }
1493 
1494  if (s->xch_base_channel < 2) {
1495  avpriv_request_sample(avctx, "XCh with fewer than 2 base channels");
1496  continue;
1497  }
1498 
1499  /* much like core primary audio coding header */
1501 
1502  for (i = 0; i < (s->sample_blocks / 8); i++)
1503  if ((ret = dca_decode_block(s, s->xch_base_channel, i))) {
1504  av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n");
1505  continue;
1506  }
1507 
1508  s->xch_present = 1;
1509  break;
1510  }
1511  case DCA_SYNCWORD_XXCH:
1512  /* XXCh: extended channels */
1513  /* usually found either in core or HD part in DTS-HD HRA streams,
1514  * but not in DTS-ES which contains XCh extensions instead */
1517  break;
1518 
1519  case 0x1d95f262: {
1520  int fsize96 = show_bits(&s->gb, 12) + 1;
1521  if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96)
1522  continue;
1523 
1524  av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n",
1525  get_bits_count(&s->gb));
1526  skip_bits(&s->gb, 12);
1527  av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96);
1528  av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4));
1529 
1530  s->core_ext_mask |= DCA_EXT_X96;
1531  break;
1532  }
1533  }
1534 
1535  skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31);
1536  }
1537  } else {
1538  /* no supported extensions, skip the rest of the core substream */
1539  skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb));
1540  }
1541 
1542  if (s->core_ext_mask & DCA_EXT_X96)
1544  else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH))
1546 
1547  /* check for ExSS (HD part) */
1548  if (s->dca_buffer_size - s->frame_size > 32 &&
1551 
1552  avctx->profile = s->profile;
1553 
1554  full_channels = channels = s->prim_channels + !!s->lfe;
1555 
1556  /* If we have XXCH then the channel layout is managed differently */
1557  /* note that XLL will also have another way to do things */
1558  if (!(s->core_ext_mask & DCA_EXT_XXCH)
1559  || (s->core_ext_mask & DCA_EXT_XXCH && avctx->request_channels > 0
1560  && avctx->request_channels
1561  < num_core_channels + !!s->lfe + s->xxch_chset_nch[0]))
1562  { /* xxx should also do MA extensions */
1563  if (s->amode < 16) {
1565 
1566  if (s->prim_channels + !!s->lfe > 2 &&
1568  /*
1569  * Neither the core's auxiliary data nor our default tables contain
1570  * downmix coefficients for the additional channel coded in the XCh
1571  * extension, so when we're doing a Stereo downmix, don't decode it.
1572  */
1573  s->xch_disable = 1;
1574  }
1575 
1576 #if FF_API_REQUEST_CHANNELS
1578  if (s->xch_present && !s->xch_disable &&
1579  (!avctx->request_channels ||
1580  avctx->request_channels > num_core_channels + !!s->lfe)) {
1582 #else
1583  if (s->xch_present && !s->xch_disable) {
1584 #endif
1585  if (avctx->channel_layout & AV_CH_BACK_CENTER) {
1586  avpriv_request_sample(avctx, "XCh with Back center channel");
1587  return AVERROR_INVALIDDATA;
1588  }
1590  if (s->lfe) {
1593  } else {
1595  }
1596  if (s->channel_order_tab[s->xch_base_channel] < 0)
1597  return AVERROR_INVALIDDATA;
1598  } else {
1599  channels = num_core_channels + !!s->lfe;
1600  s->xch_present = 0; /* disable further xch processing */
1601  if (s->lfe) {
1604  } else
1606  }
1607 
1608  if (channels > !!s->lfe &&
1609  s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
1610  return AVERROR_INVALIDDATA;
1611 
1612  if (av_get_channel_layout_nb_channels(avctx->channel_layout) != channels) {
1613  av_log(avctx, AV_LOG_ERROR, "Number of channels %d mismatches layout %d\n", channels, av_get_channel_layout_nb_channels(avctx->channel_layout));
1614  return AVERROR_INVALIDDATA;
1615  }
1616 
1617  if (num_core_channels + !!s->lfe > 2 &&
1619  channels = 2;
1620  s->output = s->prim_channels == 2 ? s->amode : DCA_STEREO;
1622  }
1623  else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
1624  static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
1625  s->channel_order_tab = dca_channel_order_native;
1626  }
1627  s->lfe_index = ff_dca_lfe_index[s->amode];
1628  } else {
1629  av_log(avctx, AV_LOG_ERROR,
1630  "Non standard configuration %d !\n", s->amode);
1631  return AVERROR_INVALIDDATA;
1632  }
1633 
1634  s->xxch_dmix_embedded = 0;
1635  } else {
1636  /* we only get here if an XXCH channel set can be added to the mix */
1637  channel_mask = s->xxch_core_spkmask;
1638 
1639  if (avctx->request_channels > 0
1640  && avctx->request_channels < s->prim_channels) {
1641  channels = num_core_channels + !!s->lfe;
1642  for (i = 0; i < s->xxch_chset && channels + s->xxch_chset_nch[i]
1643  <= avctx->request_channels; i++) {
1644  channels += s->xxch_chset_nch[i];
1645  channel_mask |= s->xxch_spk_masks[i];
1646  }
1647  } else {
1648  channels = s->prim_channels + !!s->lfe;
1649  for (i = 0; i < s->xxch_chset; i++) {
1650  channel_mask |= s->xxch_spk_masks[i];
1651  }
1652  }
1653 
1654  /* Given the DTS spec'ed channel mask, generate an avcodec version */
1655  channel_layout = 0;
1656  for (i = 0; i < s->xxch_nbits_spk_mask; ++i) {
1657  if (channel_mask & (1 << i)) {
1658  channel_layout |= ff_dca_map_xxch_to_native[i];
1659  }
1660  }
1661 
1662  /* make sure that we have managed to get equivalent dts/avcodec channel
1663  * masks in some sense -- unfortunately some channels could overlap */
1664  if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
1665  av_log(avctx, AV_LOG_DEBUG,
1666  "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
1667  return AVERROR_INVALIDDATA;
1668  }
1669 
1670  avctx->channel_layout = channel_layout;
1671 
1672  if (!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)) {
1673  /* Estimate DTS --> avcodec ordering table */
1674  for (chset = -1, j = 0; chset < s->xxch_chset; ++chset) {
1675  mask = chset >= 0 ? s->xxch_spk_masks[chset]
1676  : s->xxch_core_spkmask;
1677  for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
1678  if (mask & ~(DCA_XXCH_LFE1 | DCA_XXCH_LFE2) & (1 << i)) {
1679  lavc = ff_dca_map_xxch_to_native[i];
1680  posn = av_popcount(channel_layout & (lavc - 1));
1681  s->xxch_order_tab[j++] = posn;
1682  }
1683  }
1684 
1685  }
1686 
1687  s->lfe_index = av_popcount(channel_layout & (AV_CH_LOW_FREQUENCY-1));
1688  } else { /* native ordering */
1689  for (i = 0; i < channels; i++)
1690  s->xxch_order_tab[i] = i;
1691 
1692  s->lfe_index = channels - 1;
1693  }
1694 
1696  }
1697 
1698  if (avctx->channels != channels) {
1699  if (avctx->channels)
1700  av_log(avctx, AV_LOG_INFO, "Number of channels changed in DCA decoder (%d -> %d)\n", avctx->channels, channels);
1701  avctx->channels = channels;
1702  }
1703 
1704  /* get output buffer */
1705  frame->nb_samples = 256 * (s->sample_blocks / 8);
1706  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1707  return ret;
1708  samples_flt = (float **) frame->extended_data;
1709 
1710  /* allocate buffer for extra channels if downmixing */
1711  if (avctx->channels < full_channels) {
1712  ret = av_samples_get_buffer_size(NULL, full_channels - channels,
1713  frame->nb_samples,
1714  avctx->sample_fmt, 0);
1715  if (ret < 0)
1716  return ret;
1717 
1719  &s->extra_channels_buffer_size, ret);
1720  if (!s->extra_channels_buffer)
1721  return AVERROR(ENOMEM);
1722 
1725  full_channels - channels,
1726  frame->nb_samples, avctx->sample_fmt, 0);
1727  if (ret < 0)
1728  return ret;
1729  }
1730 
1731  /* filter to get final output */
1732  for (i = 0; i < (s->sample_blocks / 8); i++) {
1733  int ch;
1734 
1735  for (ch = 0; ch < channels; ch++)
1736  s->samples_chanptr[ch] = samples_flt[ch] + i * 256;
1737  for (; ch < full_channels; ch++)
1738  s->samples_chanptr[ch] = s->extra_channels[ch - channels] + i * 256;
1739 
1740  dca_filter_channels(s, i);
1741 
1742  /* If this was marked as a DTS-ES stream we need to subtract back- */
1743  /* channel from SL & SR to remove matrixed back-channel signal */
1744  if ((s->source_pcm_res & 1) && s->xch_present) {
1745  float *back_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel]];
1746  float *lt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 2]];
1747  float *rt_chan = s->samples_chanptr[s->channel_order_tab[s->xch_base_channel - 1]];
1748  s->fdsp->vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256);
1749  s->fdsp->vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256);
1750  }
1751 
1752  /* If stream contains XXCH, we might need to undo an embedded downmix */
1753  if (s->xxch_dmix_embedded) {
1754  /* Loop over channel sets in turn */
1755  ch = num_core_channels;
1756  for (chset = 0; chset < s->xxch_chset; chset++) {
1757  endch = ch + s->xxch_chset_nch[chset];
1758  mask = s->xxch_dmix_embedded;
1759 
1760  /* undo downmix */
1761  for (j = ch; j < endch; j++) {
1762  if (mask & (1 << j)) { /* this channel has been mixed-out */
1763  src_chan = s->samples_chanptr[s->channel_order_tab[j]];
1764  for (k = 0; k < endch; k++) {
1765  achan = s->channel_order_tab[k];
1766  scale = s->xxch_dmix_coeff[j][k];
1767  if (scale != 0.0) {
1768  dst_chan = s->samples_chanptr[achan];
1769  s->fdsp->vector_fmac_scalar(dst_chan, src_chan,
1770  -scale, 256);
1771  }
1772  }
1773  }
1774  }
1775 
1776  /* if a downmix has been embedded then undo the pre-scaling */
1777  if ((mask & (1 << ch)) && s->xxch_dmix_sf[chset] != 1.0f) {
1778  scale = s->xxch_dmix_sf[chset];
1779 
1780  for (j = 0; j < ch; j++) {
1781  src_chan = s->samples_chanptr[s->channel_order_tab[j]];
1782  for (k = 0; k < 256; k++)
1783  src_chan[k] *= scale;
1784  }
1785 
1786  /* LFE channel is always part of core, scale if it exists */
1787  if (s->lfe) {
1788  src_chan = s->samples_chanptr[s->lfe_index];
1789  for (k = 0; k < 256; k++)
1790  src_chan[k] *= scale;
1791  }
1792  }
1793 
1794  ch = endch;
1795  }
1796 
1797  }
1798  }
1799 
1800  /* update lfe history */
1801  lfe_samples = 2 * s->lfe * (s->sample_blocks / 8);
1802  for (i = 0; i < 2 * s->lfe * 4; i++)
1803  s->lfe_data[i] = s->lfe_data[i + lfe_samples];
1804 
1805  /* AVMatrixEncoding
1806  *
1807  * DCA_STEREO_TOTAL (Lt/Rt) is equivalent to Dolby Surround */
1809  (s->output & ~DCA_LFE) == DCA_STEREO_TOTAL ?
1811  if (ret < 0)
1812  return ret;
1813 
1814  *got_frame_ptr = 1;
1815 
1816  return buf_size;
1817 }
1818 
1819 /**
1820  * DCA initialization
1821  *
1822  * @param avctx pointer to the AVCodecContext
1823  */
1824 
1826 {
1827  DCAContext *s = avctx->priv_data;
1828 
1829  s->avctx = avctx;
1830  dca_init_vlcs();
1831 
1833  if (!s->fdsp)
1834  return AVERROR(ENOMEM);
1835 
1836  ff_mdct_init(&s->imdct, 6, 1, 1.0);
1838  ff_dcadsp_init(&s->dcadsp);
1839  ff_fmt_convert_init(&s->fmt_conv, avctx);
1840 
1841  avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
1842 
1843  /* allow downmixing to stereo */
1844 #if FF_API_REQUEST_CHANNELS
1846  if (avctx->request_channels == 2)
1849 #endif
1850  if (avctx->channels > 2 &&
1852  avctx->channels = 2;
1853 
1854  return 0;
1855 }
1856 
1858 {
1859  DCAContext *s = avctx->priv_data;
1860  ff_mdct_end(&s->imdct);
1862  av_freep(&s->fdsp);
1863  return 0;
1864 }
1865 
1866 static const AVProfile profiles[] = {
1867  { FF_PROFILE_DTS, "DTS" },
1868  { FF_PROFILE_DTS_ES, "DTS-ES" },
1869  { FF_PROFILE_DTS_96_24, "DTS 96/24" },
1870  { FF_PROFILE_DTS_HD_HRA, "DTS-HD HRA" },
1871  { FF_PROFILE_DTS_HD_MA, "DTS-HD MA" },
1872  { FF_PROFILE_UNKNOWN },
1873 };
1874 
1875 static const AVOption options[] = {
1876  { "disable_xch", "disable decoding of the XCh extension", offsetof(DCAContext, xch_disable), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM },
1877  { NULL },
1878 };
1879 
1880 static const AVClass dca_decoder_class = {
1881  .class_name = "DCA decoder",
1882  .item_name = av_default_item_name,
1883  .option = options,
1884  .version = LIBAVUTIL_VERSION_INT,
1885  .category = AV_CLASS_CATEGORY_DECODER,
1886 };
1887 
1889  .name = "dca",
1890  .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"),
1891  .type = AVMEDIA_TYPE_AUDIO,
1892  .id = AV_CODEC_ID_DTS,
1893  .priv_data_size = sizeof(DCAContext),
1894  .init = dca_decode_init,
1896  .close = dca_decode_end,
1897  .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1,
1898  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1900  .profiles = NULL_IF_CONFIG_SMALL(profiles),
1901  .priv_class = &dca_decoder_class,
1902 };
int wrap
wrap for get_vlc2()
Definition: dcadec.c:117
float, planar
Definition: samplefmt.h:70
int ext_descr
extension audio descriptor flag
Definition: dca.h:83
#define NULL
Definition: coverity.c:32
const float ff_dca_lossless_quant_d[32]
Definition: dcadata.c:4207
static const int8_t bitalloc_offsets[10]
Definition: dcahuff.h:988
float v
const char * s
Definition: avisynth_c.h:669
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
quantization index codebook select
Definition: dca.h:107
int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]
bit allocation quantizer select
Definition: dca.h:106
int crc_present
crc is present in the bitstream
Definition: dca.h:71
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
const int8_t ff_dca_channel_reorder_lfe_xch[16][9]
Definition: dcadata.c:7779
int timestamp
embedded time stamp flag
Definition: dca.h:80
int amode
audio channels arrangement
Definition: dca.h:74
AVOption.
Definition: opt.h:255
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static int decode_blockcodes(int code1, int code2, int levels, int32_t *values)
Definition: dcadec.c:770
static const AVProfile profiles[]
Definition: dcadec.c:1866
const float ff_dca_lossy_quant_d[32]
Definition: dcadata.c:4192
static const uint16_t tmode_codes[TMODE_COUNT][4]
Definition: dcahuff.h:31
int transient_huffman[DCA_PRIM_CHANNELS_MAX]
transient mode code book
Definition: dca.h:104
const uint32_t ff_dca_map_xxch_to_native[28]
Definition: dcadata.c:7667
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:260
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:217
attribute_deprecated int request_channels
Decoder should decode to this many channels if it can (0 for default)
Definition: avcodec.h:2036
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
FmtConvertContext fmt_conv
Definition: dca.h:193
static int dca_parse_frame_header(DCAContext *s)
Definition: dcadec.c:346
void(* lfe_fir[2])(float *out, const float *in, const float *coefs)
Definition: dcadsp.h:28
#define M_SQRT1_2
Definition: mathematics.h:52
int vq_start_subband[DCA_PRIM_CHANNELS_MAX]
high frequency vq start subband
Definition: dca.h:102
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:290
int size
Definition: avcodec.h:1161
float subband_fir_noidea[DCA_PRIM_CHANNELS_MAX][32]
Definition: dca.h:138
int hist_index[DCA_PRIM_CHANNELS_MAX]
Definition: dca.h:139
int samples_deficit
deficit sample count
Definition: dca.h:70
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
uint8_t core_downmix
embedded downmix coefficients available
Definition: dca.h:126
Definition: dcadec.c:61
#define DCA_MAX_FRAME_SIZE
Definition: dca.h:47
int dynrange
embedded dynamic range flag
Definition: dca.h:79
int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
joint subband scale factors
Definition: dca.h:119
int version
encoder software revision
Definition: dca.h:90
#define VLC_TYPE
Definition: get_bits.h:61
#define FF_ARRAY_ELEMS(a)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
#define AV_CH_LAYOUT_STEREO
static BitAlloc dca_scalefactor
scalefactor VLCs
Definition: dcadec.c:123
SynthFilterContext synth
Definition: dca.h:191
int profile
profile
Definition: avcodec.h:2833
int ff_dca_xbr_parse_frame(DCAContext *s)
Definition: dcadec.c:1108
AVCodec.
Definition: avcodec.h:3173
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:245
float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]
Definition: dca.h:137
const float ff_dca_fir_32bands_nonperfect[512]
Definition: dcadata.c:6785
int maxbits[8]
max bits in VLC
Definition: dcadec.c:116
float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]
Definition: dca.h:175
const int8_t ff_dca_high_freq_vq[1024][32]
Definition: dcadata.c:4217
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
float * extra_channels[DCA_PRIM_CHANNELS_MAX+1]
Definition: dca.h:146
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
Definition: float_dsp.h:54
static int dca_subframe_footer(DCAContext *s, int base_channel)
Definition: dcadec.c:963
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
static BitAlloc dca_tmode
transition mode VLCs
Definition: dcadec.c:122
#define DCA_MAX_EXSS_HEADER_SIZE
Definition: dca.h:48
#define MIX_FRONT3(samples, coef)
Definition: dcadec.c:679
#define FF_PROFILE_DTS_ES
Definition: avcodec.h:2849
#define DCA_CHSETS_MAX
Definition: dca.h:44
static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
Definition: dcadec.c:427
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]
scale factor code book
Definition: dca.h:105
static int dca_decode_block(DCAContext *s, int base_channel, int block_index)
Decode a dca frame block.
Definition: dcadec.c:1072
const uint32_t ff_dca_bit_rates[32]
Definition: dcadata.c:33
if()
Definition: avfilter.c:975
AVFloatDSPContext * fdsp
Definition: dca.h:189
static int dca_subsubframe(DCAContext *s, int base_channel, int block_index)
Definition: dcadec.c:780
uint8_t bits
Definition: crc.c:295
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1991
uint8_t
#define av_cold
Definition: attributes.h:74
uint32_t xxch_core_spkmask
Definition: dca.h:169
int8_t lfe_index
Definition: dca.h:178
int xch_base_channel
index of first (only) channel containing XCH data
Definition: dca.h:163
float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]
Definition: dca.h:136
#define DCA_LFE
Definition: dcadec.c:106
AVOptions.
static int dca_parse_audio_coding_header(DCAContext *s, int base_channel, int xxch)
Definition: dcadec.c:208
int dca_buffer_size
how much data is in the dca_buffer
Definition: dca.h:151
#define MIX_REAR2(samples, s1, s2, rs, coef)
Definition: dcadec.c:675
static void get_array(GetBitContext *gb, int *dst, int len, int bits)
Definition: dcadec.c:190
96/24 extension in core substream
Definition: dca.h:55
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2834
int8_t xxch_order_tab[32]
Definition: dca.h:177
static av_cold int dca_decode_end(AVCodecContext *avctx)
Definition: dcadec.c:1857
void(* int32_to_float_fmul_array8)(struct FmtConvertContext *c, float *dst, const int32_t *src, const float *mul, int len)
Convert an array of int32_t to float and multiply by a float value from another array, stepping along the float array once for each 8 integers.
Definition: fmtconvert.h:53
const uint16_t ff_dca_vlc_offs[63]
Definition: dcadata.c:7836
#define AV_CH_LOW_FREQUENCY
int header_crc
header crc check bytes
Definition: dca.h:88
DCAMode
Definition: dcadec.c:55
#define FF_PROFILE_DTS_96_24
Definition: avcodec.h:2850
int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
transition mode (transients)
Definition: dca.h:116
static int dca_xxch2index(DCAContext *s, int xxch_ch)
Definition: dcadec.c:196
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:787
static AVFrame * frame
av_cold void ff_dcadsp_init(DCADSPContext *s)
Definition: dcadsp.c:106
uint8_t * data
Definition: avcodec.h:1160
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:212
int sample_rate
audio sampling rate
Definition: dca.h:75
bitstream reader API header.
uint32_t xxch_spk_masks[4]
Definition: dca.h:170
AVCodecContext * avctx
Definition: dca.h:67
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:757
static BitAlloc dca_bitalloc_index
indexes for samples VLC select
Definition: dcadec.c:121
const int8_t ff_dca_channel_reorder_nolfe[16][9]
Definition: dcadata.c:7798
int lfe
low frequency effects flag
Definition: dca.h:86
ptrdiff_t size
Definition: opengl_enc.c:101
static BitAlloc dca_smpl_bitalloc[11]
samples VLCs
Definition: dcadec.c:124
static const uint8_t bitalloc_sizes[10]
Definition: dcahuff.h:984
#define av_log(a,...)
const uint16_t ff_dca_dmixtable[242]
Definition: dcadata.c:7513
unsigned m
Definition: audioconvert.c:187
static void dca_downmix(float **samples, int srcfmt, int lfe_present, float coef[DCA_PRIM_CHANNELS_MAX+1][2], const int8_t *channel_mapping)
Definition: dcadec.c:692
#define DCA_CHANNEL_MASK
Definition: dcadec.c:104
int predictor_history
predictor history flag
Definition: dca.h:87
int dynrange_coef
dynamic range coefficient
Definition: dca.h:121
int joint_huff[DCA_PRIM_CHANNELS_MAX]
joint subband scale factors codebook
Definition: dca.h:118
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX+1][4]
embedded downmix coefficients (9-bit codes)
Definition: dca.h:128
FFTContext imdct
Definition: dca.h:190
static void lfe_interpolation_fir(DCAContext *s, int decimation_select, int num_deci_sample, float *samples_in, float *samples_out)
Definition: dcadec.c:638
float raXin[32]
Definition: dca.h:140
const float ff_dca_lfe_fir_128[256]
Definition: dcadata.c:7433
void(* decode_hf)(float dst[DCA_SUBBANDS][8], const int32_t vq_num[DCA_SUBBANDS], const int8_t hf_vq[1024][32], intptr_t vq_offset, int32_t scale[DCA_SUBBANDS][2], intptr_t start, intptr_t end)
Definition: dcadsp.h:35
float subband_samples[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]
Definition: dca.h:144
static const uint16_t mask[17]
Definition: lzw.c:38
#define MIX_REAR1(samples, s1, rs, coef)
Definition: dcadec.c:671
av_default_item_name
static const uint16_t bitalloc_12_codes[BITALLOC_12_COUNT][12]
Definition: dcahuff.h:51
#define AVERROR(e)
Definition: error.h:43
#define FF_PROFILE_DTS
Definition: avcodec.h:2848
int current_subsubframe
Definition: dca.h:157
static const struct endianess table[]
int hdcd
source material is mastered in HDCD
Definition: dca.h:82
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
void(* qmf_32_subbands)(float samples_in[32][8], int sb_act, SynthFilterContext *synth, FFTContext *imdct, float synth_buf_ptr[512], int *synth_buf_offset, float synth_buf2[32], const float window[512], float *samples_out, float raXin[32], float scale)
Definition: dcadsp.h:29
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:196
const float ff_dca_lfe_fir_64[256]
Definition: dcadata.c:7302
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1333
static const uint8_t bitalloc_12_bits[BITALLOC_12_COUNT][12]
Definition: dcahuff.h:64
const char * name
Name of the codec implementation.
Definition: avcodec.h:3180
int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
bit allocation index
Definition: dca.h:115
static int dca_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Main frame decoding function FIXME add arguments.
Definition: dcadec.c:1350
#define ff_mdct_init
Definition: fft.h:167
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int debug_flag
used for suppressing repeated error messages output
Definition: dca.h:188
#define FFMAX(a, b)
Definition: common.h:79
Libavcodec external API header.
Definition: get_bits.h:63
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2044
const int8_t * channel_order_tab
channel reordering table, lfe and non lfe
Definition: dca.h:153
float lfe_data[2 *DCA_LFE_MAX *(DCA_BLOCKS_MAX+4)]
Low frequency effect data.
Definition: dca.h:132
common internal API header
static const uint8_t tmode_bits[TMODE_COUNT][4]
Definition: dcahuff.h:38
static void qmf_32_subbands(DCAContext *s, int chans, float samples_in[32][8], float *samples_out, float scale)
Definition: dcadec.c:615
int front_sum
front sum/difference flag
Definition: dca.h:93
int xch_disable
whether the XCh extension should be decoded or not
Definition: dca.h:164
int source_pcm_res
source pcm resolution
Definition: dca.h:92
#define FF_PROFILE_DTS_HD_HRA
Definition: avcodec.h:2851
int bit_rate
the average bitrate
Definition: avcodec.h:1303
audio channel layout utility functions
Definition: dca.h:65
#define FFMIN(a, b)
Definition: common.h:81
ret
Definition: avfilter.c:974
int surround_sum
surround sum/difference flag
Definition: dca.h:94
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
static av_cold void dca_init_vlcs(void)
Definition: dcadec.c:135
av_cold void ff_synth_filter_init(SynthFilterContext *c)
Definition: synth_filter.c:59
int32_t
uint8_t dca_buffer[DCA_MAX_FRAME_SIZE+DCA_MAX_EXSS_HEADER_SIZE+DCA_BUFFER_PADDING_SIZE]
Definition: dca.h:150
int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
Convert bitstream to one representation based on sync marker.
Definition: dca.c:39
static const uint8_t scales_bits[SCALES_COUNT][129]
Definition: dcahuff.h:162
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:287
int joint_intensity[DCA_PRIM_CHANNELS_MAX]
joint intensity coding index
Definition: dca.h:103
static const uint16_t *const bitalloc_codes[10][8]
Definition: dcahuff.h:1005
int multirate_inter
multirate interpolator switch
Definition: dca.h:89
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:555
float u
int n
Definition: avisynth_c.h:589
Bit allocation.
Definition: dcadec.c:114
uint8_t core_downmix_amode
audio channel arrangement of embedded downmix
Definition: dca.h:127
const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:34
int bit_rate
transmission bit rate
Definition: dca.h:76
const uint64_t ff_dca_core_channel_layout[16]
Definition: dcadata.c:7719
static const uint8_t *const bitalloc_bits[10][8]
Definition: dcahuff.h:1023
#define INIT_VLC_USE_NEW_STATIC
Definition: get_bits.h:474
int offset
code values offset
Definition: dcadec.c:115
static const uint8_t abits_levels[7]
Definition: dcadec.c:778
#define DCA_CHSET_CHANS_MAX
Definition: dca.h:45
int xch_present
XCh extension present and valid.
Definition: dca.h:162
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:259
int bits
Definition: get_bits.h:64
#define SCALES_VLC_BITS
Definition: dcahuff.h:73
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
const int16_t ff_dca_adpcm_vb[4096][4]
Definition: dcadata.c:53
int table_allocated
Definition: get_bits.h:66
const uint32_t ff_dca_scale_factor_quant7[128]
Definition: dcadata.c:4165
int core_ext_mask
present extensions in the core substream
Definition: dca.h:159
int lfe_scale_factor
Definition: dca.h:133
const uint8_t ff_dca_channels[16]
Definition: dcadata.c:42
#define AV_LOG_INFO
Standard information.
Definition: log.h:186
int aux_data
auxiliary data flag
Definition: dca.h:81
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
int sample_rate
samples per second
Definition: avcodec.h:1983
int ext_coding
extended coding flag
Definition: dca.h:84
#define AV_CH_LAYOUT_NATIVE
Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests ...
static float dca_dmix_code(unsigned code)
Definition: dcadec.c:1339
int32_t scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2]
scale factors (2 if transient)
Definition: dca.h:117
int xxch_chset_nch[4]
Definition: dca.h:171
int subband_activity[DCA_PRIM_CHANNELS_MAX]
subband activity count
Definition: dca.h:101
main external API structure.
Definition: avcodec.h:1239
#define FASTDIV(a, b)
Definition: mathops.h:211
const int ff_dca_ext_audio_descr_mask[8]
Definition: dcadata.c:7699
float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]
scale factor adjustment
Definition: dca.h:108
int copy_history
copy history
Definition: dca.h:91
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1032
const float ff_dca_default_coeffs[10][6][2]
Definition: dcadata.c:7547
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: get_bits.h:457
void * buf
Definition: avisynth_c.h:595
const int8_t ff_dca_channel_reorder_nolfe_xch[16][9]
Definition: dcadata.c:7817
DCAXxchSpeakerMask
Definition: dcadec.c:70
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:304
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:329
VLC vlc[8]
actual codes
Definition: dcadec.c:118
Describe the class of an AVClass context structure.
Definition: log.h:66
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:297
const uint32_t ff_dca_scale_factor_quant6[64]
Definition: dcadata.c:4154
int index
Definition: gxfenc.c:89
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:117
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:286
int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
VQ encoded high frequency subbands.
Definition: dca.h:130
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:410
int sample_blocks
number of PCM sample blocks
Definition: dca.h:72
static const uint8_t abits_sizes[7]
Definition: dcadec.c:777
const int8_t ff_dca_channel_reorder_lfe[16][9]
Definition: dcadata.c:7760
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:143
AVCodec ff_dca_decoder
Definition: dcadec.c:1888
GetBitContext gb
Definition: dca.h:154
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:337
int current_subframe
Definition: dca.h:156
static const AVOption options[]
Definition: dcadec.c:1875
static int decode_blockcode(int code, int levels, int32_t *values)
Definition: dcadec.c:756
#define AV_CH_BACK_CENTER
uint8_t level
Definition: svq3.c:150
int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction mode (ADPCM used or not)
Definition: dca.h:113
static av_cold int dca_decode_init(AVCodecContext *avctx)
DCA initialization.
Definition: dcadec.c:1825
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:520
int xxch_chset
Definition: dca.h:167
DCADSPContext dcadsp
Definition: dca.h:192
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:513
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
common internal api header.
common internal and external API header
#define AV_COPY128(d, s)
Definition: intreadwrite.h:594
uint8_t * extra_channels_buffer
Definition: dca.h:147
#define CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: avcodec.h:854
#define ff_mdct_end
Definition: fft.h:168
int total_channels
number of channels including extensions
Definition: dca.h:99
static double c[64]
static const uint16_t scales_codes[SCALES_COUNT][129]
Definition: dcahuff.h:74
static int dca_filter_channels(DCAContext *s, int block_index)
Definition: dcadec.c:932
int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction VQ coefs
Definition: dca.h:114
int dialog_norm
dialog normalisation parameter
Definition: dca.h:95
#define DCA_NSYNCAUX
Definition: dcadec.c:110
AVProfile.
Definition: avcodec.h:3161
#define FF_PROFILE_DTS_HD_MA
Definition: avcodec.h:2852
#define DCA_SUBBANDS
Definition: dcadsp.h:25
int bit_rate_index
transmission bit rate index
Definition: dca.h:77
void ff_dca_exss_parse_header(DCAContext *s)
Parse extension substream header (HD)
Definition: dca_exss.c:243
void * priv_data
Definition: avcodec.h:1281
int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, const uint8_t *buf, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Fill plane data pointers and linesize for samples with sample format sample_fmt.
Definition: samplefmt.c:149
static const uint8_t bitalloc_maxbits[10][7]
Definition: dcahuff.h:992
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
Definition: fmtconvert.c:44
int len
int channels
number of audio channels
Definition: avcodec.h:1984
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:65
float * samples_chanptr[DCA_PRIM_CHANNELS_MAX+1]
Definition: dca.h:145
int ff_dca_xxch_decode_frame(DCAContext *s)
Definition: dcadec.c:1286
int subsubframes[DCA_SUBFRAMES_MAX]
number of subsubframes
Definition: dca.h:111
static const double coeff[2][5]
Definition: vf_owdenoise.c:71
XCh channel extension in core substream.
Definition: dca.h:56
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:449
#define DOWNMIX_TO_STEREO(op1, op2)
Definition: dcadec.c:686
int frame_size
primary frame byte size
Definition: dca.h:73
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
float xxch_dmix_sf[DCA_CHSETS_MAX]
Definition: dca.h:172
int aspf
audio sync word insertion flag
Definition: dca.h:85
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:120
#define av_freep(p)
#define av_always_inline
Definition: attributes.h:37
int prim_channels
number of primary audio channels
Definition: dca.h:100
float downmix_coef[DCA_PRIM_CHANNELS_MAX+1][2]
stereo downmix coefficients
Definition: dca.h:120
static const uint8_t bitalloc_12_vlc_bits[BITALLOC_12_COUNT]
Definition: dcahuff.h:47
int output
type of output
Definition: dca.h:142
static int get_scale(GetBitContext *gb, int level, int value, int log2range)
Definition: dcadec.c:410
const float ff_dca_fir_32bands_perfect[512]
Definition: dcadata.c:6270
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:207
int xxch_nbits_spk_mask
Definition: dca.h:168
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
Definition: avcodec.h:2051
const int8_t ff_dca_lfe_index[16]
Definition: dcadata.c:7756
int partial_samples[DCA_SUBFRAMES_MAX]
partial subsubframe samples count
Definition: dca.h:112
static const AVClass dca_decoder_class
Definition: dcadec.c:1880
This structure stores compressed data.
Definition: avcodec.h:1137
uint32_t xxch_dmix_embedded
Definition: dca.h:174
int subframes
number of subframes
Definition: dca.h:98
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:217
unsigned int extra_channels_buffer_size
Definition: dca.h:148
for(j=16;j >0;--j)
static const uint8_t tmode_vlc_bits[TMODE_COUNT]
Definition: dcahuff.h:30
static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
Definition: dcadec.c:126
#define DCA_PRIM_CHANNELS_MAX
Definition: dca.h:38
int frame_type
type of the current frame
Definition: dca.h:69
XXCh channels extension in core substream.
Definition: dca.h:54
int profile
Definition: dca.h:186
static int16_t block[64]
Definition: dct-test.c:110