29 #define MIN_PACKET_SIZE 16
30 #define MAX_PACKET_SIZE 0x104000
34 static const uint8_t dca2wav_norm[28] = {
35 2, 0, 1, 9, 10, 3, 8, 4, 5, 9, 10, 6, 7, 12,
36 13, 14, 3, 6, 7, 11, 12, 14, 16, 15, 17, 8, 4, 5,
39 static const uint8_t dca2wav_wide[28] = {
40 2, 0, 1, 4, 5, 3, 8, 4, 5, 9, 10, 6, 7, 12,
41 13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4, 5,
44 int dca_ch, wav_ch, nchannels = 0;
48 if (dca_mask & (1
U << dca_ch))
49 ch_remap[nchannels++] = dca_ch;
57 dca2wav = dca2wav_wide;
59 dca2wav = dca2wav_norm;
60 for (dca_ch = 0; dca_ch < 28; dca_ch++) {
61 if (dca_mask & (1 << dca_ch)) {
62 wav_ch = dca2wav[dca_ch];
63 if (!(wav_mask & (1 << wav_ch))) {
64 wav_map[wav_ch] = dca_ch;
65 wav_mask |= 1 << wav_ch;
69 for (wav_ch = 0; wav_ch < 18; wav_ch++)
70 if (wav_mask & (1 << wav_ch))
71 ch_remap[nchannels++] = wav_map[wav_ch];
81 static const uint16_t crctab[16] = {
82 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
83 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
86 uint16_t res = 0xffff;
89 for (i = 0; i <
size; i++) {
90 res = (res << 4) ^ crctab[(data[i] >> 4) ^ (res >> 12)];
91 res = (res << 4) ^ crctab[(data[i] & 15) ^ (res >> 12)];
99 if (((p1 | p2) & 7) || p1 < 0 || p2 > s->
size_in_bits || p2 - p1 < 16)
107 int *coeff_l,
int nsamples,
int ch_mask)
109 int pos, spkr, max_spkr =
av_log2(ch_mask);
110 int *coeff_r = coeff_l + av_popcount(ch_mask);
120 for (spkr = 0; spkr <= max_spkr; spkr++) {
121 if (!(ch_mask & (1
U << spkr)))
124 if (*coeff_l && spkr != DCA_SPEAKER_L)
125 dcadsp->
dmix_add(samples[DCA_SPEAKER_L], samples[spkr],
128 if (*coeff_r && spkr != DCA_SPEAKER_R)
129 dcadsp->
dmix_add(samples[DCA_SPEAKER_R], samples[spkr],
138 int *coeff_l,
int nsamples,
int ch_mask)
140 int pos, spkr, max_spkr =
av_log2(ch_mask);
141 int *coeff_r = coeff_l + av_popcount(ch_mask);
142 const float scale = 1.0f / (1 << 15);
149 coeff_l[pos ] * scale, nsamples);
151 coeff_r[pos + 1] * scale, nsamples);
154 for (spkr = 0; spkr <= max_spkr; spkr++) {
155 if (!(ch_mask & (1
U << spkr)))
158 if (*coeff_l && spkr != DCA_SPEAKER_L)
160 *coeff_l * scale, nsamples);
162 if (*coeff_r && spkr != DCA_SPEAKER_R)
164 *coeff_r * scale, nsamples);
176 memcpy(dst, src, src_size);
188 int *got_frame_ptr,
AVPacket *avpkt)
193 int input_size = avpkt->
size;
194 int i, ret, prev_packet = s->
packet;
230 if (input_size - 4 > frame_size) {
385 #define OFFSET(x) offsetof(DCAContext, x)
386 #define PARAM AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_dca_core_filter_fixed(DCACoreDecoder *s, int x96_synth)
DCACoreDecoder core
Core decoder context.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
static const AVClass dcadec_class
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
int ff_dca_check_crc(GetBitContext *s, int p1, int p2)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
static av_cold int init(AVCodecContext *avctx)
static av_cold int dcadec_init(AVCodecContext *avctx)
#define DCA_PACKET_RECOVERY
int ff_dca_core_parse_exss(DCACoreDecoder *s, uint8_t *data, DCAExssAsset *asset)
int frame_size
Primary frame byte size.
av_cold void ff_dca_core_close(DCACoreDecoder *s)
static av_cold int dcadec_close(AVCodecContext *avctx)
int core_only
Core only decoding flag.
#define DCA_FILTER_MODE_FIXED
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
uint8_t * buffer
Packet buffer.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_CH_LAYOUT_STEREO
int freq
Original sampling frequency (max. 96000 Hz)
#define AV_CH_LAYOUT_5POINT0
static uint16_t crc16(const uint8_t *data, int size)
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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
enum AVSampleFormat sample_fmt
audio sample format
static av_cold void dcadec_flush(AVCodecContext *avctx)
int ff_dca_core_parse(DCACoreDecoder *s, uint8_t *data, int size)
#define DCA_SYNCWORD_CORE_14B_BE
static int dcadec_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
int filter_mode
Previous filtering mode for detecting changes.
int extension_mask
Coding components used in asset.
void(* dmix_add)(int32_t *dst, const int32_t *src, int coeff, ptrdiff_t len)
av_cold void ff_dcadsp_init(DCADSPContext *s)
DCAExssParser exss
EXSS parser context.
#define DCA_SYNCWORD_CORE_BE
#define AV_CH_LAYOUT_5POINT1
void ff_dca_downmix_to_stereo_fixed(DCADSPContext *dcadsp, int32_t **samples, int *coeff_l, int nsamples, int ch_mask)
static const AVOption dcadec_options[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const char * name
Name of the codec implementation.
#define DCA_SPEAKER_LAYOUT_STEREO
#define DCA_SYNCWORD_CORE_14B_LE
#define DCA_BUFFER_PADDING_SIZE
uint64_t channel_layout
Audio channel layout.
int sample_rate
Core audio sampling frequency.
audio channel layout utility functions
#define AV_CH_LAYOUT_STEREO_DOWNMIX
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
void(* dmix_scale)(int32_t *dst, int scale, ptrdiff_t len)
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.
#define DCA_HAS_STEREO(mask)
DCAXllDecoder xll
XLL decoder context.
int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask)
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
av_cold void ff_dca_core_flush(DCACoreDecoder *s)
#define AV_EF_EXPLODE
abort decoding on minor error detection
DCAExssAsset assets[1]
Audio asset descriptors.
int core_residual_valid
Core valid for residual decoding.
void ff_dca_downmix_to_stereo_float(AVFloatDSPContext *fdsp, float **samples, int *coeff_l, int nsamples, int ch_mask)
AVSampleFormat
Audio sample formats.
#define AV_CH_LAYOUT_NATIVE
Channel mask value used for AVCodecContext.request_channel_layout to indicate that the user requests ...
#define DCA_SYNCWORD_CORE_LE
main external API structure.
#define DCA_SPEAKER_LAYOUT_7POINT0_WIDE
Describe the class of an AVClass context structure.
av_cold int ff_dca_core_init(DCACoreDecoder *s)
int nreschsets
Number of channel sets that have residual encoded channels.
#define DCA_SPEAKER_LAYOUT_5POINT1
#define DCA_SPEAKER_LAYOUT_5POINT0
const AVProfile ff_dca_profiles[]
int ff_dca_core_filter_frame(DCACoreDecoder *s, AVFrame *frame)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
av_cold void ff_dca_xll_flush(DCAXllDecoder *s)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
DCAXllChSet chset[DCA_XLL_CHSETS_MAX]
Channel sets.
int request_channel_layout
Converted from avctx.request_channel_layout.
static int convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, int max_size)
av_cold void ff_dca_xll_close(DCAXllDecoder *s)
int channels
number of audio channels
#define DCA_SYNCWORD_SUBSTREAM
int ff_dca_xll_parse(DCAXllDecoder *s, uint8_t *data, DCAExssAsset *asset)
int ff_dca_exss_parse(DCAExssParser *s, uint8_t *data, int size)
static enum AVSampleFormat sample_fmts[]
int nchsets
Number of channels sets per frame.
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
This structure stores compressed data.
#define DCA_SPEAKER_LAYOUT_7POINT1_WIDE
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.