FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dca.h
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 #ifndef AVCODEC_DCA_H
26 #define AVCODEC_DCA_H
27 
28 #include <stdint.h>
29 
30 #include "libavutil/float_dsp.h"
31 #include "libavutil/internal.h"
32 
33 #include "avcodec.h"
34 #include "dcadsp.h"
35 #include "fmtconvert.h"
36 #include "get_bits.h"
37 
38 #define DCA_PRIM_CHANNELS_MAX (7)
39 #define DCA_ABITS_MAX (32) /* Should be 28 */
40 #define DCA_SUBSUBFRAMES_MAX (4)
41 #define DCA_SUBFRAMES_MAX (16)
42 #define DCA_BLOCKS_MAX (16)
43 #define DCA_LFE_MAX (3)
44 #define DCA_CHSETS_MAX (4)
45 #define DCA_CHSET_CHANS_MAX (8)
46 
47 #define DCA_MAX_FRAME_SIZE 16384
48 #define DCA_MAX_EXSS_HEADER_SIZE 4096
49 
50 #define DCA_BUFFER_PADDING_SIZE 1024
51 
53  DCA_EXT_CORE = 0x001, ///< core in core substream
54  DCA_EXT_XXCH = 0x002, ///< XXCh channels extension in core substream
55  DCA_EXT_X96 = 0x004, ///< 96/24 extension in core substream
56  DCA_EXT_XCH = 0x008, ///< XCh channel extension in core substream
57  DCA_EXT_EXSS_CORE = 0x010, ///< core in ExSS (extension substream)
58  DCA_EXT_EXSS_XBR = 0x020, ///< extended bitrate extension in ExSS
59  DCA_EXT_EXSS_XXCH = 0x040, ///< XXCh channels extension in ExSS
60  DCA_EXT_EXSS_X96 = 0x080, ///< 96/24 extension in ExSS
61  DCA_EXT_EXSS_LBR = 0x100, ///< low bitrate component in ExSS
62  DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS
63 };
64 
65 typedef struct DCAContext {
66  const AVClass *class; ///< class for AVOptions
68  /* Frame header */
69  int frame_type; ///< type of the current frame
70  int samples_deficit; ///< deficit sample count
71  int crc_present; ///< crc is present in the bitstream
72  int sample_blocks; ///< number of PCM sample blocks
73  int frame_size; ///< primary frame byte size
74  int amode; ///< audio channels arrangement
75  int sample_rate; ///< audio sampling rate
76  int bit_rate; ///< transmission bit rate
77  int bit_rate_index; ///< transmission bit rate index
78 
79  int dynrange; ///< embedded dynamic range flag
80  int timestamp; ///< embedded time stamp flag
81  int aux_data; ///< auxiliary data flag
82  int hdcd; ///< source material is mastered in HDCD
83  int ext_descr; ///< extension audio descriptor flag
84  int ext_coding; ///< extended coding flag
85  int aspf; ///< audio sync word insertion flag
86  int lfe; ///< low frequency effects flag
87  int predictor_history; ///< predictor history flag
88  int header_crc; ///< header crc check bytes
89  int multirate_inter; ///< multirate interpolator switch
90  int version; ///< encoder software revision
91  int copy_history; ///< copy history
92  int source_pcm_res; ///< source pcm resolution
93  int front_sum; ///< front sum/difference flag
94  int surround_sum; ///< surround sum/difference flag
95  int dialog_norm; ///< dialog normalisation parameter
96 
97  /* Primary audio coding header */
98  int subframes; ///< number of subframes
99  int total_channels; ///< number of channels including extensions
100  int prim_channels; ///< number of primary audio channels
101  int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count
102  int vq_start_subband[DCA_PRIM_CHANNELS_MAX]; ///< high frequency vq start subband
103  int joint_intensity[DCA_PRIM_CHANNELS_MAX]; ///< joint intensity coding index
104  int transient_huffman[DCA_PRIM_CHANNELS_MAX]; ///< transient mode code book
105  int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]; ///< scale factor code book
106  int bitalloc_huffman[DCA_PRIM_CHANNELS_MAX]; ///< bit allocation quantizer select
107  int quant_index_huffman[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< quantization index codebook select
108  float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment
109 
110  /* Primary audio coding side information */
111  int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes
112  int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count
113  int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not)
114  int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs
115  int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index
116  int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< transition mode (transients)
117  int32_t scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];///< scale factors (2 if transient)
118  int joint_huff[DCA_PRIM_CHANNELS_MAX]; ///< joint subband scale factors codebook
119  int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
120  float downmix_coef[DCA_PRIM_CHANNELS_MAX + 1][2]; ///< stereo downmix coefficients
121  int dynrange_coef; ///< dynamic range coefficient
122 
123  /* Core substream's embedded downmix coefficients (cf. ETSI TS 102 114 V1.4.1)
124  * Input: primary audio channels (incl. LFE if present)
125  * Output: downmix audio channels (up to 4, no LFE) */
126  uint8_t core_downmix; ///< embedded downmix coefficients available
127  uint8_t core_downmix_amode; ///< audio channel arrangement of embedded downmix
128  uint16_t core_downmix_codes[DCA_PRIM_CHANNELS_MAX + 1][4]; ///< embedded downmix coefficients (9-bit codes)
129 
130  int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< VQ encoded high frequency subbands
131 
132  float lfe_data[2 * DCA_LFE_MAX * (DCA_BLOCKS_MAX + 4)]; ///< Low frequency effect data
134 
135  /* Subband samples history (for ADPCM) */
140  DECLARE_ALIGNED(32, float, raXin)[32];
141 
142  int output; ///< type of output
143 
149 
151  int dca_buffer_size; ///< how much data is in the dca_buffer
152 
153  const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe
155  /* Current position in DCA frame */
158 
159  int core_ext_mask; ///< present extensions in the core substream
160 
161  /* XCh extension information */
162  int xch_present; ///< XCh extension present and valid
163  int xch_base_channel; ///< index of first (only) channel containing XCH data
164  int xch_disable; ///< whether the XCh extension should be decoded or not
165 
166  /* XXCH extension information */
170  uint32_t xxch_spk_masks[4]; /* speaker masks, last element is core mask */
173 
174  uint32_t xxch_dmix_embedded; /* lower layer has mix pre-embedded, per chset */
175  float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]; /* worst case sizing */
176 
177  int8_t xxch_order_tab[32];
178  int8_t lfe_index;
179 
180  /* ExSS header parser */
181  int static_fields; ///< static fields present
182  int mix_metadata; ///< mixing metadata present
183  int num_mix_configs; ///< number of mix out configurations
184  int mix_config_num_ch[4]; ///< number of channels in each mix out configuration
185 
186  int profile;
187 
188  int debug_flag; ///< used for suppressing repeated error messages output
194 } DCAContext;
195 
196 extern av_export const uint32_t avpriv_dca_sample_rates[16];
197 
198 /**
199  * Convert bitstream to one representation based on sync marker
200  */
201 int avpriv_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
202  int max_size);
203 
206 
208 
209 #endif /* AVCODEC_DCA_H */