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/common.h"
25 #include "libavutil/mem.h"
26 
27 #include "avcodec.h"
28 #include "internal.h"
29 #include "get_bits.h"
30 #include "dca.h"
31 #include "dcadsp.h"
32 #include "dca_exss.h"
33 
34 #define DCA_XLL_CHSETS_MAX 3
35 #define DCA_XLL_CHANNELS_MAX 8
36 #define DCA_XLL_BANDS_MAX 2
37 #define DCA_XLL_ADAPT_PRED_ORDER_MAX 16
38 #define DCA_XLL_DECI_HISTORY_MAX 8
39 #define DCA_XLL_DMIX_SCALES_MAX ((DCA_XLL_CHSETS_MAX - 1) * DCA_XLL_CHANNELS_MAX)
40 #define DCA_XLL_DMIX_COEFFS_MAX (DCA_XLL_DMIX_SCALES_MAX * DCA_XLL_CHANNELS_MAX)
41 #define DCA_XLL_PBR_BUFFER_MAX (240 << 10)
42 #define DCA_XLL_SAMPLE_BUFFERS_MAX 3
43 
44 typedef struct DCAXllBand {
45  int decor_enabled; ///< Pairwise channel decorrelation flag
46  int orig_order[DCA_XLL_CHANNELS_MAX]; ///< Original channel order
47  int decor_coeff[DCA_XLL_CHANNELS_MAX / 2]; ///< Pairwise channel coefficients
48 
49  int adapt_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Adaptive predictor order
50  int highest_pred_order; ///< Highest adaptive predictor order
51  int fixed_pred_order[DCA_XLL_CHANNELS_MAX]; ///< Fixed predictor order
52  int adapt_refl_coeff[DCA_XLL_CHANNELS_MAX][DCA_XLL_ADAPT_PRED_ORDER_MAX]; ///< Adaptive predictor reflection coefficients
53 
54  int dmix_embedded; ///< Downmix performed by encoder in frequency band
55 
56  int lsb_section_size; ///< Size of LSB section in any segment
57  int nscalablelsbs[DCA_XLL_CHANNELS_MAX]; ///< Number of bits to represent the samples in LSB part
58  int bit_width_adjust[DCA_XLL_CHANNELS_MAX]; ///< Number of bits discarded by authoring
59 
60  int32_t *msb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< MSB sample buffer pointers
61  int32_t *lsb_sample_buffer[DCA_XLL_CHANNELS_MAX]; ///< LSB sample buffer pointers or NULL
62 } DCAXllBand;
63 
64 typedef struct DCAXllChSet {
65  // Channel set header
66  int nchannels; ///< Number of channels in the channel set (N)
67  int residual_encode; ///< Residual encoding mask (0 - residual, 1 - full channel)
68  int pcm_bit_res; ///< PCM bit resolution (variable)
69  int storage_bit_res; ///< Storage bit resolution (16 or 24)
70  int freq; ///< Original sampling frequency (max. 96000 Hz)
71 
72  int primary_chset; ///< Primary channel set flag
73  int dmix_coeffs_present; ///< Downmix coefficients present in stream
74  int dmix_embedded; ///< Downmix already performed by encoder
75  int dmix_type; ///< Primary channel set downmix type
76  int hier_chset; ///< Whether the channel set is part of a hierarchy
77  int hier_ofs; ///< Number of preceding channels in a hierarchy (M)
78  int dmix_coeff[DCA_XLL_DMIX_COEFFS_MAX]; ///< Downmixing coefficients
79  int dmix_scale[DCA_XLL_DMIX_SCALES_MAX]; ///< Downmixing scales
80  int dmix_scale_inv[DCA_XLL_DMIX_SCALES_MAX]; ///< Inverse downmixing scales
81  int ch_mask; ///< Channel mask for set
82  int ch_remap[DCA_XLL_CHANNELS_MAX]; ///< Channel to speaker map
83 
84  int nfreqbands; ///< Number of frequency bands (1 or 2)
85  int nabits; ///< Number of bits to read bit allocation coding parameter
86 
87  DCAXllBand bands[DCA_XLL_BANDS_MAX]; ///< Frequency bands
88 
89  // Frequency band coding parameters
90  int seg_common; ///< Segment type
91  int rice_code_flag[DCA_XLL_CHANNELS_MAX]; ///< Rice coding flag
92  int bitalloc_hybrid_linear[DCA_XLL_CHANNELS_MAX]; ///< Binary code length for isolated samples
93  int bitalloc_part_a[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part A of segment
94  int bitalloc_part_b[DCA_XLL_CHANNELS_MAX]; ///< Coding parameter for part B of segment
95  int nsamples_part_a[DCA_XLL_CHANNELS_MAX]; ///< Number of samples in part A of segment
96 
97  // Decimator history
98  DECLARE_ALIGNED(32, int32_t, deci_history)[DCA_XLL_CHANNELS_MAX][DCA_XLL_DECI_HISTORY_MAX]; ///< Decimator history for frequency band 1
99 
100  // Sample buffers
101  unsigned int sample_size[DCA_XLL_SAMPLE_BUFFERS_MAX];
103 } DCAXllChSet;
104 
105 typedef struct DCAXllDecoder {
108 
109  int frame_size; ///< Number of bytes in a lossless frame
110  int nchsets; ///< Number of channels sets per frame
111  int nframesegs; ///< Number of segments per frame
112  int nsegsamples_log2; ///< log2(nsegsamples)
113  int nsegsamples; ///< Samples in segment per one frequency band
114  int nframesamples_log2; ///< log2(nframesamples)
115  int nframesamples; ///< Samples in frame per one frequency band
116  int seg_size_nbits; ///< Number of bits used to read segment size
117  int band_crc_present; ///< Presence of CRC16 within each frequency band
118  int scalable_lsbs; ///< MSB/LSB split flag
119  int ch_mask_nbits; ///< Number of bits used to read channel mask
120  int fixed_lsb_width; ///< Fixed LSB width
121 
122  DCAXllChSet chset[DCA_XLL_CHSETS_MAX]; ///< Channel sets
123 
124  int *navi; ///< NAVI table
125  unsigned int navi_size;
126 
127  int nfreqbands; ///< Highest number of frequency bands
128  int nchannels; ///< Total number of channels in a hierarchy
129  int nreschsets; ///< Number of channel sets that have residual encoded channels
130  int nactivechsets; ///< Number of active channel sets to decode
131 
132  int hd_stream_id; ///< Previous DTS-HD stream ID for detecting changes
133 
134  uint8_t *pbr_buffer; ///< Peak bit rate (PBR) smoothing buffer
135  int pbr_length; ///< Length in bytes of data currently buffered
136  int pbr_delay; ///< Delay in frames before decoding buffered data
137 
139 
141  int32_t *output_samples[DCA_SPEAKER_COUNT];
142 } DCAXllDecoder;
143 
148 
149 #endif
int adapt_pred_order[DCA_XLL_CHANNELS_MAX]
Adaptive predictor order.
Definition: dca_xll.h:49
int frame_size
Number of bytes in a lossless frame.
Definition: dca_xll.h:109
av_cold void ff_dca_xll_flush(DCAXllDecoder *s)
Definition: dca_xll.c:1471
#define DCA_XLL_CHSETS_MAX
Definition: dca_xll.h:34
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
int primary_chset
Primary channel set flag.
Definition: dca_xll.h:72
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
int pbr_delay
Delay in frames before decoding buffered data.
Definition: dca_xll.h:136
Memory handling functions.
AVCodecContext * avctx
Definition: dca_xll.h:106
int nchannels
Number of channels in the channel set (N)
Definition: dca_xll.h:66
av_cold void ff_dca_xll_close(DCAXllDecoder *s)
Definition: dca_xll.c:1476
int pbr_length
Length in bytes of data currently buffered.
Definition: dca_xll.h:135
int * navi
NAVI table.
Definition: dca_xll.h:124
int freq
Original sampling frequency (max. 96000 Hz)
Definition: dca_xll.h:70
int band_crc_present
Presence of CRC16 within each frequency band.
Definition: dca_xll.h:117
int highest_pred_order
Highest adaptive predictor order.
Definition: dca_xll.h:50
#define DCA_XLL_DMIX_COEFFS_MAX
Definition: dca_xll.h:40
uint8_t
#define av_cold
Definition: attributes.h:82
int dmix_coeffs_present
Downmix coefficients present in stream.
Definition: dca_xll.h:73
int nfreqbands
Highest number of frequency bands.
Definition: dca_xll.h:127
#define DCA_XLL_SAMPLE_BUFFERS_MAX
Definition: dca_xll.h:42
int fixed_lsb_width
Fixed LSB width.
Definition: dca_xll.h:120
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
int fixed_pred_order[DCA_XLL_CHANNELS_MAX]
Fixed predictor order.
Definition: dca_xll.h:51
int nfreqbands
Number of frequency bands (1 or 2)
Definition: dca_xll.h:84
int ff_dca_xll_parse(DCAXllDecoder *s, uint8_t *data, DCAExssAsset *asset)
Definition: dca_xll.c:1161
bitstream reader API header.
int32_t * lsb_sample_buffer[DCA_XLL_CHANNELS_MAX]
LSB sample buffer pointers or NULL.
Definition: dca_xll.h:61
unsigned int navi_size
Definition: dca_xll.h:125
int adapt_refl_coeff[DCA_XLL_CHANNELS_MAX][DCA_XLL_ADAPT_PRED_ORDER_MAX]
Adaptive predictor reflection coefficients.
Definition: dca_xll.h:52
int orig_order[DCA_XLL_CHANNELS_MAX]
Original channel order.
Definition: dca_xll.h:46
#define DCA_XLL_DMIX_SCALES_MAX
Definition: dca_xll.h:39
int scalable_lsbs
MSB/LSB split flag.
Definition: dca_xll.h:118
int nsegsamples_log2
log2(nsegsamples)
Definition: dca_xll.h:112
DCADSPContext * dcadsp
Definition: dca_xll.h:138
int pcm_bit_res
PCM bit resolution (variable)
Definition: dca_xll.h:68
int hier_chset
Whether the channel set is part of a hierarchy.
Definition: dca_xll.h:76
int decor_enabled
Pairwise channel decorrelation flag.
Definition: dca_xll.h:45
int hier_ofs
Number of preceding channels in a hierarchy (M)
Definition: dca_xll.h:77
int nchannels
Total number of channels in a hierarchy.
Definition: dca_xll.h:128
#define DCA_XLL_BANDS_MAX
Definition: dca_xll.h:36
int seg_size_nbits
Number of bits used to read segment size.
Definition: dca_xll.h:116
int dmix_type
Primary channel set downmix type.
Definition: dca_xll.h:75
int nframesamples
Samples in frame per one frequency band.
Definition: dca_xll.h:115
int nabits
Number of bits to read bit allocation coding parameter.
Definition: dca_xll.h:85
int32_t
#define DCA_XLL_ADAPT_PRED_ORDER_MAX
Definition: dca_xll.h:37
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
int nsegsamples
Samples in segment per one frequency band.
Definition: dca_xll.h:113
int output_mask
Definition: dca_xll.h:140
int residual_encode
Residual encoding mask (0 - residual, 1 - full channel)
Definition: dca_xll.h:67
Libavcodec external API header.
int hd_stream_id
Previous DTS-HD stream ID for detecting changes.
Definition: dca_xll.h:132
main external API structure.
Definition: avcodec.h:1568
int lsb_section_size
Size of LSB section in any segment.
Definition: dca_xll.h:56
static const float bands[]
GetBitContext gb
Definition: dca_xll.h:107
int nreschsets
Number of channel sets that have residual encoded channels.
Definition: dca_xll.h:129
int nframesegs
Number of segments per frame.
Definition: dca_xll.h:111
int ch_mask
Channel mask for set.
Definition: dca_xll.h:81
int32_t * msb_sample_buffer[DCA_XLL_CHANNELS_MAX]
MSB sample buffer pointers.
Definition: dca_xll.h:60
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
Definition: dca_xll.c:1322
#define DCA_XLL_DECI_HISTORY_MAX
Definition: dca_xll.h:38
common internal api header.
common internal and external API header
int dmix_embedded
Downmix already performed by encoder.
Definition: dca_xll.h:74
int storage_bit_res
Storage bit resolution (16 or 24)
Definition: dca_xll.h:69
uint8_t * pbr_buffer
Peak bit rate (PBR) smoothing buffer.
Definition: dca_xll.h:134
int seg_common
Segment type.
Definition: dca_xll.h:90
int ch_mask_nbits
Number of bits used to read channel mask.
Definition: dca_xll.h:119
#define DCA_XLL_CHANNELS_MAX
Definition: dca_xll.h:35
int bit_width_adjust[DCA_XLL_CHANNELS_MAX]
Number of bits discarded by authoring.
Definition: dca_xll.h:58
int nframesamples_log2
log2(nframesamples)
Definition: dca_xll.h:114
int nscalablelsbs[DCA_XLL_CHANNELS_MAX]
Number of bits to represent the samples in LSB part.
Definition: dca_xll.h:57
int nchsets
Number of channels sets per frame.
Definition: dca_xll.h:110
int dmix_embedded
Downmix performed by encoder in frequency band.
Definition: dca_xll.h:54
int decor_coeff[DCA_XLL_CHANNELS_MAX/2]
Pairwise channel coefficients.
Definition: dca_xll.h:47
int nactivechsets
Number of active channel sets to decode.
Definition: dca_xll.h:130