FFmpeg
dca_xll.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 foo86
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_DCA_XLL_H
22 #define AVCODEC_DCA_XLL_H
23 
24 #include "libavutil/mem_internal.h"
25 
26 #include "avcodec.h"
27 #include "get_bits.h"
28 #include "dca.h"
29 #include "dcadsp.h"
30 #include "dca_exss.h"
31 
32 #define DCA_XLL_CHSETS_MAX 3
33 #define DCA_XLL_CHANNELS_MAX 8
34 #define DCA_XLL_BANDS_MAX 2
35 #define DCA_XLL_ADAPT_PRED_ORDER_MAX 16
36 #define DCA_XLL_DECI_HISTORY_MAX 8
37 #define DCA_XLL_DMIX_SCALES_MAX ((DCA_XLL_CHSETS_MAX - 1) * DCA_XLL_CHANNELS_MAX)
38 #define DCA_XLL_DMIX_COEFFS_MAX (DCA_XLL_DMIX_SCALES_MAX * DCA_XLL_CHANNELS_MAX)
39 #define DCA_XLL_PBR_BUFFER_MAX (240 << 10)
40 #define DCA_XLL_SAMPLE_BUFFERS_MAX 3
41 
42 typedef struct DCAXllBand {
43  int decor_enabled; ///< Pairwise channel decorrelation flag
44  int orig_order[DCA_XLL_CHANNELS_MAX]; ///< Original channel order
45  int decor_coeff[DCA_XLL_CHANNELS_MAX / 2]; ///< Pairwise channel coefficients
46 
47  int adapt_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Adaptive predictor order
48  int highest_pred_order; ///< Highest adaptive predictor order
49  int fixed_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Fixed predictor order
50  int adapt_refl_coeff[DCA_XLL_CHANNELS_MAX][DCA_XLL_ADAPT_PRED_ORDER_MAX]; ///< Adaptive predictor reflection coefficients
51 
52  int dmix_embedded; ///< Downmix performed by encoder in frequency band
53 
54  int lsb_section_size; ///< Size of LSB section in any segment
55  int nscalablelsbs[DCA_XLL_CHANNELS_MAX]; ///< Number of bits to represent the samples in LSB part
56  int bit_width_adjust[DCA_XLL_CHANNELS_MAX]; ///< Number of bits discarded by authoring
57 
58  int32_t *msb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< MSB sample buffer pointers
59  int32_t *lsb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< LSB sample buffer pointers or NULL
60 } DCAXllBand;
61 
62 typedef struct DCAXllChSet {
63  // Channel set header
64  int nchannels; ///< Number of channels in the channel set (N)
65  int residual_encode; ///< Residual encoding mask (0 - residual, 1 - full channel)
66  int pcm_bit_res; ///< PCM bit resolution (variable)
67  int storage_bit_res; ///< Storage bit resolution (16 or 24)
68  int freq; ///< Original sampling frequency (max. 96000 Hz)
69 
70  int primary_chset; ///< Primary channel set flag
71  int dmix_coeffs_present; ///< Downmix coefficients present in stream
72  int dmix_embedded; ///< Downmix already performed by encoder
73  int dmix_type; ///< Primary channel set downmix type
74  int hier_chset; ///< Whether the channel set is part of a hierarchy
75  int hier_ofs; ///< Number of preceding channels in a hierarchy (M)
76  int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]; ///< Downmixing coefficients
77  int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]; ///< Downmixing scales
78  int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]; ///< Inverse downmixing scales
79  int ch_mask; ///< Channel mask for set
80  int ch_remap[DCA_XLL_CHANNELS_MAX]; ///< Channel to speaker map
81 
82  int nfreqbands; ///< Number of frequency bands (1 or 2)
83  int nabits; ///< Number of bits to read bit allocation coding parameter
84 
85  DCAXllBand bands[DCA_XLL_BANDS_MAX]; ///< Frequency bands
86 
87  // Frequency band coding parameters
88  int seg_common; ///< Segment type
89  int rice_code_flag[DCA_XLL_CHANNELS_MAX]; ///< Rice coding flag
90  int bitalloc_hybrid_linear[DCA_XLL_CHANNELS_MAX]; ///< Binary code length for isolated samples
91  int bitalloc_part_a[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part A of segment
92  int bitalloc_part_b[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part B of segment
93  int nsamples_part_a[DCA_XLL_CHANNELS_MAX]; ///< Number of samples in part A of segment
94 
95  // Decimator history
96  DECLARE_ALIGNED(32, int32_t, deci_history)[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]; ///< Decimator history for frequency band 1
97 
98  // Sample buffers
101 } DCAXllChSet;
102 
103 typedef struct DCAXllDecoder {
106 
107  int frame_size; ///< Number of bytes in a lossless frame
108  int nchsets; ///< Number of channels sets per frame
109  int nframesegs; ///< Number of segments per frame
110  int nsegsamples_log2; ///< log2(nsegsamples)
111  int nsegsamples; ///< Samples in segment per one frequency band
112  int nframesamples_log2; ///< log2(nframesamples)
113  int nframesamples; ///< Samples in frame per one frequency band
114  int seg_size_nbits; ///< Number of bits used to read segment size
115  int band_crc_present; ///< Presence of CRC16 within each frequency band
116  int scalable_lsbs; ///< MSB/LSB split flag
117  int ch_mask_nbits; ///< Number of bits used to read channel mask
118  int fixed_lsb_width; ///< Fixed LSB width
119 
121 
122  int *navi; ///< NAVI table
123  unsigned int navi_size;
124 
125  int nfreqbands; ///< Highest number of frequency bands
126  int nchannels; ///< Total number of channels in a hierarchy
127  int nreschsets; ///< Number of channel sets that have residual encoded channels
128  int nactivechsets; ///< Number of active channel sets to decode
129 
130  int hd_stream_id; ///< Previous DTS-HD stream ID for detecting changes
131 
132  uint8_t *pbr_buffer; ///< Peak bit rate (PBR) smoothing buffer
133  int pbr_length; ///< Length in bytes of data currently buffered
134  int pbr_delay; ///< Delay in frames before decoding buffered data
135 
137 
138  int x_syncword_present; ///< Syncword for extension data at end of frame (DTS:X) is present
139  int x_imax_syncword_present; ///< Syncword for extension data at end of frame (DTS:X IMAX) is present
140 
143 } DCAXllDecoder;
144 
145 int ff_dca_xll_parse(DCAXllDecoder *s, const uint8_t *data, DCAExssAsset *asset);
149 
150 #endif
DCAXllChSet::ch_remap
int ch_remap[DCA_XLL_CHANNELS_MAX]
Channel to speaker map.
Definition: dca_xll.h:80
DCAXllDecoder::nchannels
int nchannels
Total number of channels in a hierarchy.
Definition: dca_xll.h:126
DCAXllDecoder::navi_size
unsigned int navi_size
Definition: dca_xll.h:123
DCAXllChSet::nabits
int nabits
Number of bits to read bit allocation coding parameter.
Definition: dca_xll.h:83
DCA_XLL_DECI_HISTORY_MAX
#define DCA_XLL_DECI_HISTORY_MAX
Definition: dca_xll.h:36
DCAXllBand::adapt_pred_order
int adapt_pred_order[DCA_XLL_CHANNELS_MAX]
Adaptive predictor order.
Definition: dca_xll.h:47
mem_internal.h
dca.h
DCAXllBand::bit_width_adjust
int bit_width_adjust[DCA_XLL_CHANNELS_MAX]
Number of bits discarded by authoring.
Definition: dca_xll.h:56
DCAXllChSet::seg_common
int seg_common
Segment type.
Definition: dca_xll.h:88
DCAXllDecoder::hd_stream_id
int hd_stream_id
Previous DTS-HD stream ID for detecting changes.
Definition: dca_xll.h:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
DCAXllBand::dmix_embedded
int dmix_embedded
Downmix performed by encoder in frequency band.
Definition: dca_xll.h:52
ff_dca_xll_flush
av_cold void ff_dca_xll_flush(DCAXllDecoder *s)
Definition: dca_xll.c:1497
DCAXllBand::fixed_pred_order
int fixed_pred_order[DCA_XLL_CHANNELS_MAX]
Fixed predictor order.
Definition: dca_xll.h:49
data
const char data[16]
Definition: mxf.c:148
DCAXllChSet::rice_code_flag
int rice_code_flag[DCA_XLL_CHANNELS_MAX]
Rice coding flag.
Definition: dca_xll.h:89
DCAXllDecoder::scalable_lsbs
int scalable_lsbs
MSB/LSB split flag.
Definition: dca_xll.h:116
DCAXllDecoder::x_syncword_present
int x_syncword_present
Syncword for extension data at end of frame (DTS:X) is present.
Definition: dca_xll.h:138
DCAXllDecoder::band_crc_present
int band_crc_present
Presence of CRC16 within each frequency band.
Definition: dca_xll.h:115
DCAXllBand::lsb_sample_buffer
int32_t * lsb_sample_buffer[DCA_XLL_CHANNELS_MAX]
LSB sample buffer pointers or NULL.
Definition: dca_xll.h:59
DCAXllDecoder::pbr_delay
int pbr_delay
Delay in frames before decoding buffered data.
Definition: dca_xll.h:134
ff_dca_xll_close
av_cold void ff_dca_xll_close(DCAXllDecoder *s)
Definition: dca_xll.c:1502
DCAXllChSet::hier_ofs
int hier_ofs
Number of preceding channels in a hierarchy (M)
Definition: dca_xll.h:75
DCAXllChSet::sample_size
unsigned int sample_size[DCA_XLL_SAMPLE_BUFFERS_MAX]
Definition: dca_xll.h:99
DCAExssAsset
Definition: dca_exss.h:29
DCAXllBand::orig_order
int orig_order[DCA_XLL_CHANNELS_MAX]
Original channel order.
Definition: dca_xll.h:44
DCAXllChSet::dmix_coeff
int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]
Downmixing coefficients.
Definition: dca_xll.h:76
GetBitContext
Definition: get_bits.h:108
DCAXllBand
Definition: dca_xll.h:42
ff_dca_xll_parse
int ff_dca_xll_parse(DCAXllDecoder *s, const uint8_t *data, DCAExssAsset *asset)
Definition: dca_xll.c:1180
DCAXllDecoder::frame_size
int frame_size
Number of bytes in a lossless frame.
Definition: dca_xll.h:107
DCAXllDecoder::output_mask
int output_mask
Definition: dca_xll.h:141
DCAXllDecoder::dcadsp
DCADSPContext * dcadsp
Definition: dca_xll.h:136
DCAXllDecoder::gb
GetBitContext gb
Definition: dca_xll.h:105
DCAXllChSet::nchannels
int nchannels
Number of channels in the channel set (N)
Definition: dca_xll.h:64
DCAXllBand::highest_pred_order
int highest_pred_order
Highest adaptive predictor order.
Definition: dca_xll.h:48
DCAXllDecoder::seg_size_nbits
int seg_size_nbits
Number of bits used to read segment size.
Definition: dca_xll.h:114
av_cold
#define av_cold
Definition: attributes.h:90
DCA_XLL_ADAPT_PRED_ORDER_MAX
#define DCA_XLL_ADAPT_PRED_ORDER_MAX
Definition: dca_xll.h:35
DCAXllDecoder::pbr_buffer
uint8_t * pbr_buffer
Peak bit rate (PBR) smoothing buffer.
Definition: dca_xll.h:132
s
#define s(width, name)
Definition: cbs_vp9.c:198
get_bits.h
DCAXllBand::decor_enabled
int decor_enabled
Pairwise channel decorrelation flag.
Definition: dca_xll.h:43
DCAXllChSet::storage_bit_res
int storage_bit_res
Storage bit resolution (16 or 24)
Definition: dca_xll.h:67
DCA_XLL_DMIX_COEFFS_MAX
#define DCA_XLL_DMIX_COEFFS_MAX
Definition: dca_xll.h:38
DCAXllChSet::dmix_type
int dmix_type
Primary channel set downmix type.
Definition: dca_xll.h:73
DCAXllChSet::dmix_embedded
int dmix_embedded
Downmix already performed by encoder.
Definition: dca_xll.h:72
dca_exss.h
frame
static AVFrame * frame
Definition: demux_decode.c:54
DCAXllDecoder::ch_mask_nbits
int ch_mask_nbits
Number of bits used to read channel mask.
Definition: dca_xll.h:117
DCAXllDecoder::pbr_length
int pbr_length
Length in bytes of data currently buffered.
Definition: dca_xll.h:133
DCAXllDecoder::x_imax_syncword_present
int x_imax_syncword_present
Syncword for extension data at end of frame (DTS:X IMAX) is present.
Definition: dca_xll.h:139
DCAXllDecoder::nactivechsets
int nactivechsets
Number of active channel sets to decode.
Definition: dca_xll.h:128
DCAXllDecoder::nframesamples_log2
int nframesamples_log2
log2(nframesamples)
Definition: dca_xll.h:112
DCA_XLL_SAMPLE_BUFFERS_MAX
#define DCA_XLL_SAMPLE_BUFFERS_MAX
Definition: dca_xll.h:40
DCAXllBand::adapt_refl_coeff
int adapt_refl_coeff[DCA_XLL_CHANNELS_MAX][DCA_XLL_ADAPT_PRED_ORDER_MAX]
Adaptive predictor reflection coefficients.
Definition: dca_xll.h:50
DCAXllBand::lsb_section_size
int lsb_section_size
Size of LSB section in any segment.
Definition: dca_xll.h:54
DCAXllDecoder::navi
int * navi
NAVI table.
Definition: dca_xll.h:122
DCADSPContext
Definition: dcadsp.h:30
DCAXllChSet::sample_buffer
int32_t * sample_buffer[DCA_XLL_SAMPLE_BUFFERS_MAX]
Definition: dca_xll.h:100
DCAXllDecoder::nframesegs
int nframesegs
Number of segments per frame.
Definition: dca_xll.h:109
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
DCAXllDecoder::chset
DCAXllChSet chset[DCA_XLL_CHSETS_MAX]
Channel sets.
Definition: dca_xll.h:120
DCA_XLL_BANDS_MAX
#define DCA_XLL_BANDS_MAX
Definition: dca_xll.h:34
DCAXllChSet::bitalloc_hybrid_linear
int bitalloc_hybrid_linear[DCA_XLL_CHANNELS_MAX]
Binary code length for isolated samples.
Definition: dca_xll.h:90
DCA_XLL_DMIX_SCALES_MAX
#define DCA_XLL_DMIX_SCALES_MAX
Definition: dca_xll.h:37
DCAXllDecoder::avctx
AVCodecContext * avctx
Definition: dca_xll.h:104
DCAXllChSet::residual_encode
int residual_encode
Residual encoding mask (0 - residual, 1 - full channel)
Definition: dca_xll.h:65
DCAXllDecoder::nchsets
int nchsets
Number of channels sets per frame.
Definition: dca_xll.h:108
DCAXllChSet::bitalloc_part_b
int bitalloc_part_b[DCA_XLL_CHANNELS_MAX]
Coding parameter for part B of segment.
Definition: dca_xll.h:92
dcadsp.h
DCAXllChSet
Definition: dca_xll.h:62
DCAXllChSet::dmix_coeffs_present
int dmix_coeffs_present
Downmix coefficients present in stream.
Definition: dca_xll.h:71
DCA_XLL_CHANNELS_MAX
#define DCA_XLL_CHANNELS_MAX
Definition: dca_xll.h:33
DCAXllBand::msb_sample_buffer
int32_t * msb_sample_buffer[DCA_XLL_CHANNELS_MAX]
MSB sample buffer pointers.
Definition: dca_xll.h:58
DCAXllChSet::pcm_bit_res
int pcm_bit_res
PCM bit resolution (variable)
Definition: dca_xll.h:66
avcodec.h
DCAXllChSet::deci_history
int32_t deci_history[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]
Decimator history for frequency band 1.
Definition: dca_xll.h:96
DCAXllDecoder::nfreqbands
int nfreqbands
Highest number of frequency bands.
Definition: dca_xll.h:125
DCAXllChSet::dmix_scale_inv
int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]
Inverse downmixing scales.
Definition: dca_xll.h:78
DCAXllDecoder
Definition: dca_xll.h:103
DCAXllChSet::nfreqbands
int nfreqbands
Number of frequency bands (1 or 2)
Definition: dca_xll.h:82
DCAXllChSet::bands
DCAXllBand bands[DCA_XLL_BANDS_MAX]
Frequency bands.
Definition: dca_xll.h:85
DCA_XLL_CHSETS_MAX
#define DCA_XLL_CHSETS_MAX
Definition: dca_xll.h:32
DCAXllDecoder::nsegsamples
int nsegsamples
Samples in segment per one frequency band.
Definition: dca_xll.h:111
AVCodecContext
main external API structure.
Definition: avcodec.h:445
DCAXllChSet::dmix_scale
int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]
Downmixing scales.
Definition: dca_xll.h:77
DCAXllChSet::bitalloc_part_a
int bitalloc_part_a[DCA_XLL_CHANNELS_MAX]
Coding parameter for part A of segment.
Definition: dca_xll.h:91
DCAXllBand::decor_coeff
int decor_coeff[DCA_XLL_CHANNELS_MAX/2]
Pairwise channel coefficients.
Definition: dca_xll.h:45
DCAXllChSet::freq
int freq
Original sampling frequency (max. 96000 Hz)
Definition: dca_xll.h:68
DCAXllDecoder::nsegsamples_log2
int nsegsamples_log2
log2(nsegsamples)
Definition: dca_xll.h:110
DCAXllBand::nscalablelsbs
int nscalablelsbs[DCA_XLL_CHANNELS_MAX]
Number of bits to represent the samples in LSB part.
Definition: dca_xll.h:55
ff_dca_xll_filter_frame
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
Definition: dca_xll.c:1341
DCAXllDecoder::output_samples
int32_t * output_samples[DCA_SPEAKER_COUNT]
Definition: dca_xll.h:142
DCAXllChSet::ch_mask
int ch_mask
Channel mask for set.
Definition: dca_xll.h:79
int32_t
int32_t
Definition: audioconvert.c:56
DCAXllChSet::hier_chset
int hier_chset
Whether the channel set is part of a hierarchy.
Definition: dca_xll.h:74
DCA_SPEAKER_COUNT
@ DCA_SPEAKER_COUNT
Definition: dca.h:87
DCAXllDecoder::fixed_lsb_width
int fixed_lsb_width
Fixed LSB width.
Definition: dca_xll.h:118
DCAXllChSet::nsamples_part_a
int nsamples_part_a[DCA_XLL_CHANNELS_MAX]
Number of samples in part A of segment.
Definition: dca_xll.h:93
DCAXllChSet::primary_chset
int primary_chset
Primary channel set flag.
Definition: dca_xll.h:70
DCAXllDecoder::nreschsets
int nreschsets
Number of channel sets that have residual encoded channels.
Definition: dca_xll.h:127
DCAXllDecoder::nframesamples
int nframesamples
Samples in frame per one frequency band.
Definition: dca_xll.h:113