FFmpeg  2.6.3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 */
int ext_descr
extension audio descriptor flag
Definition: dca.h:83
const char * s
Definition: avisynth_c.h:669
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
int timestamp
embedded time stamp flag
Definition: dca.h:80
int amode
audio channels arrangement
Definition: dca.h:74
lossless extension in ExSS
Definition: dca.h:62
int transient_huffman[DCA_PRIM_CHANNELS_MAX]
transient mode code book
Definition: dca.h:104
int mix_config_num_ch[4]
number of channels in each mix out configuration
Definition: dca.h:184
FmtConvertContext fmt_conv
Definition: dca.h:193
int vq_start_subband[DCA_PRIM_CHANNELS_MAX]
high frequency vq start subband
Definition: dca.h:102
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
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
uint8_t core_downmix
embedded downmix coefficients available
Definition: dca.h:126
#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
SynthFilterContext synth
Definition: dca.h:191
float subband_fir_hist[DCA_PRIM_CHANNELS_MAX][512]
Definition: dca.h:137
float xxch_dmix_coeff[DCA_PRIM_CHANNELS_MAX][32]
Definition: dca.h:175
float * extra_channels[DCA_PRIM_CHANNELS_MAX+1]
Definition: dca.h:146
#define DCA_MAX_EXSS_HEADER_SIZE
Definition: dca.h:48
#define DCA_CHSETS_MAX
Definition: dca.h:44
int scalefactor_huffman[DCA_PRIM_CHANNELS_MAX]
scale factor code book
Definition: dca.h:105
AVFloatDSPContext * fdsp
Definition: dca.h:189
uint8_t
#define DCA_BLOCKS_MAX
Definition: dca.h:42
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_ABITS_MAX
Definition: dca.h:39
int dca_buffer_size
how much data is in the dca_buffer
Definition: dca.h:151
96/24 extension in core substream
Definition: dca.h:55
int8_t xxch_order_tab[32]
Definition: dca.h:177
int header_crc
header crc check bytes
Definition: dca.h:88
int transition_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
transition mode (transients)
Definition: dca.h:116
int sample_rate
audio sampling rate
Definition: dca.h:75
bitstream reader API header.
uint32_t xxch_spk_masks[4]
Definition: dca.h:170
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
AVCodecContext * avctx
Definition: dca.h:67
int lfe
low frequency effects flag
Definition: dca.h:86
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
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
float raXin[32]
Definition: dca.h:140
float subband_samples[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]
Definition: dca.h:144
int current_subsubframe
Definition: dca.h:157
int hdcd
source material is mastered in HDCD
Definition: dca.h:82
int mix_metadata
mixing metadata present
Definition: dca.h:182
core in ExSS (extension substream)
Definition: dca.h:57
int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
bit allocation index
Definition: dca.h:115
int debug_flag
used for suppressing repeated error messages output
Definition: dca.h:188
Libavcodec external API header.
#define DCA_BUFFER_PADDING_SIZE
Definition: dca.h:50
int ff_dca_xbr_parse_frame(DCAContext *s)
Definition: dcadec.c:1108
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
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
low bitrate component in ExSS
Definition: dca.h:61
Definition: fft.h:88
Definition: dca.h:65
XXCh channels extension in ExSS.
Definition: dca.h:59
#define DCA_LFE_MAX
Definition: dca.h:43
av_export const uint32_t avpriv_dca_sample_rates[16]
Definition: dca.c:34
96/24 extension in ExSS
Definition: dca.h:60
int surround_sum
surround sum/difference flag
Definition: dca.h:94
int32_t
uint8_t dca_buffer[DCA_MAX_FRAME_SIZE+DCA_MAX_EXSS_HEADER_SIZE+DCA_BUFFER_PADDING_SIZE]
Definition: dca.h:150
int joint_intensity[DCA_PRIM_CHANNELS_MAX]
joint intensity coding index
Definition: dca.h:103
int multirate_inter
multirate interpolator switch
Definition: dca.h:89
uint8_t core_downmix_amode
audio channel arrangement of embedded downmix
Definition: dca.h:127
int bit_rate
transmission bit rate
Definition: dca.h:76
int xch_present
XCh extension present and valid.
Definition: dca.h:162
int core_ext_mask
present extensions in the core substream
Definition: dca.h:159
int lfe_scale_factor
Definition: dca.h:133
#define av_export
Definition: internal.h:64
AVS_Value src
Definition: avisynth_c.h:524
int aux_data
auxiliary data flag
Definition: dca.h:81
int ext_coding
extended coding flag
Definition: dca.h:84
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
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
Describe the class of an AVClass context structure.
Definition: log.h:66
core in core substream
Definition: dca.h:53
extended bitrate extension in ExSS
Definition: dca.h:58
int32_t high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
VQ encoded high frequency subbands.
Definition: dca.h:130
int sample_blocks
number of PCM sample blocks
Definition: dca.h:72
#define DCA_SUBFRAMES_MAX
Definition: dca.h:41
GetBitContext gb
Definition: dca.h:154
int current_subframe
Definition: dca.h:156
int ff_dca_xxch_decode_frame(DCAContext *s)
Definition: dcadec.c:1286
int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]
prediction mode (ADPCM used or not)
Definition: dca.h:113
int num_mix_configs
number of mix out configurations
Definition: dca.h:183
int xxch_chset
Definition: dca.h:167
DCADSPContext dcadsp
Definition: dca.h:192
uint8_t * extra_channels_buffer
Definition: dca.h:147
int total_channels
number of channels including extensions
Definition: dca.h:99
DCAExtensionMask
Definition: dca.h:52
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_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
float * samples_chanptr[DCA_PRIM_CHANNELS_MAX+1]
Definition: dca.h:145
int subsubframes[DCA_SUBFRAMES_MAX]
number of subsubframes
Definition: dca.h:111
XCh channel extension in core substream.
Definition: dca.h:56
int frame_size
primary frame byte size
Definition: dca.h:73
float xxch_dmix_sf[DCA_CHSETS_MAX]
Definition: dca.h:172
int aspf
audio sync word insertion flag
Definition: dca.h:85
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
int output
type of output
Definition: dca.h:142
int xxch_nbits_spk_mask
Definition: dca.h:168
int partial_samples[DCA_SUBFRAMES_MAX]
partial subsubframe samples count
Definition: dca.h:112
uint32_t xxch_dmix_embedded
Definition: dca.h:174
int subframes
number of subframes
Definition: dca.h:98
unsigned int extra_channels_buffer_size
Definition: dca.h:148
#define DCA_PRIM_CHANNELS_MAX
Definition: dca.h:38
int static_fields
static fields present
Definition: dca.h:181
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