2 * Copyright (C) 2016 foo86
4 * This file is part of FFmpeg.
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.
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.
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
21 #ifndef AVCODEC_DCADEC_H
22 #define AVCODEC_DCADEC_H
24 #include "libavutil/common.h"
25 #include "libavutil/crc.h"
26 #include "libavutil/float_dsp.h"
36 #define DCA_BUFFER_PADDING_SIZE 1024
38 #define DCA_PACKET_CORE 0x01
39 #define DCA_PACKET_EXSS 0x02
40 #define DCA_PACKET_XLL 0x04
41 #define DCA_PACKET_RECOVERY 0x08
43 typedef struct DCAContext {
44 const AVClass *class; ///< class for AVOptions
45 AVCodecContext *avctx;
47 DCACoreDecoder core; ///< Core decoder context
48 DCAExssParser exss; ///< EXSS parser context
49 DCAXllDecoder xll; ///< XLL decoder context
55 uint8_t *buffer; ///< Packet buffer
56 unsigned int buffer_size;
58 int packet; ///< Packet flags
60 int core_residual_valid; ///< Core valid for residual decoding
62 int request_channel_layout; ///< Converted from avctx.request_channel_layout
63 int core_only; ///< Core only decoding flag
66 int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask);
68 void ff_dca_downmix_to_stereo_fixed(DCADSPContext *dcadsp, int32_t **samples,
69 int *coeff_l, int nsamples, int ch_mask);
70 void ff_dca_downmix_to_stereo_float(AVFloatDSPContext *fdsp, float **samples,
71 int *coeff_l, int nsamples, int ch_mask);
73 static inline int ff_dca_check_crc(AVCodecContext *avctx, GetBitContext *s,
76 DCAContext *dca = avctx->priv_data;
78 if (!(avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_CAREFUL)))
80 if (((p1 | p2) & 7) || p1 < 0 || p2 > s->size_in_bits || p2 - p1 < 16)
82 if (av_crc(dca->crctab, 0xffff, s->buffer + p1 / 8, (p2 - p1) / 8))
87 static inline int ff_dca_seek_bits(GetBitContext *s, int p)
89 if (p < s->index || p > s->size_in_bits)