20 #include <fdk-aac/aacdecoder_lib.h>
30 #ifndef AACDECODER_LIB_VL0
31 #define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
55 #define DMX_ANC_BUFFSIZE 128
56 #define DECODER_MAX_CHANNELS 6
57 #define DECODER_BUFFSIZE 2048 * sizeof(INT_PCM)
59 #define OFFSET(x) offsetof(FDKAACDecContext, x)
60 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
66 {
"drc_boost",
"Dynamic Range Control: boost, where [0] is none and [127] is max boost",
68 {
"drc_cut",
"Dynamic Range Control: attenuation factor, where [0] is none and [127] is max compression",
70 {
"drc_level",
"Dynamic Range Control: reference level, quantized to 0.25dB steps where [0] is 0dB and [127] is -31.75dB",
72 {
"drc_heavy",
"Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
84 CStreamInfo *info = aacDecoder_GetStreamInfo(s->
handle);
85 int channel_counts[0x24] = { 0 };
87 uint64_t ch_layout = 0;
94 if (info->sampleRate <= 0) {
101 for (i = 0; i < info->numChannels; i++) {
102 AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
103 if (ctype <= ACT_NONE || ctype >
FF_ARRAY_ELEMS(channel_counts)) {
107 channel_counts[ctype]++;
110 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
112 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
113 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
114 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
115 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
117 switch (channel_counts[ACT_FRONT]) {
133 "unsupported number of front channels: %d\n",
134 channel_counts[ACT_FRONT]);
138 if (channel_counts[ACT_SIDE] > 0) {
139 if (channel_counts[ACT_SIDE] == 2) {
143 "unsupported number of side channels: %d\n",
144 channel_counts[ACT_SIDE]);
148 if (channel_counts[ACT_BACK] > 0) {
149 switch (channel_counts[ACT_BACK]) {
161 "unsupported number of back channels: %d\n",
162 channel_counts[ACT_BACK]);
167 if (channel_counts[ACT_LFE] > 0) {
168 if (channel_counts[ACT_LFE] == 1) {
172 "unsupported number of LFE channels: %d\n",
173 channel_counts[ACT_LFE]);
187 avctx->
channels = info->numChannels;
197 aacDecoder_Close(s->
handle);
207 AAC_DECODER_ERROR err;
224 if ((err = aacDecoder_SetParam(s->
handle, AAC_CONCEAL_METHOD,
232 int downmix_channels = -1;
237 downmix_channels = 2;
240 downmix_channels = 1;
247 if (downmix_channels != -1) {
249 downmix_channels) != AAC_DEC_OK) {
259 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
268 if (aacDecoder_SetParam(s->
handle, AAC_DRC_BOOST_FACTOR, s->
drc_boost) != AAC_DEC_OK) {
275 if (aacDecoder_SetParam(s->
handle, AAC_DRC_ATTENUATION_FACTOR, s->
drc_cut) != AAC_DEC_OK) {
282 if (aacDecoder_SetParam(s->
handle, AAC_DRC_REFERENCE_LEVEL, s->
drc_level) != AAC_DEC_OK) {
289 if (aacDecoder_SetParam(s->
handle, AAC_DRC_HEAVY_COMPRESSION, s->
drc_heavy) != AAC_DEC_OK) {
304 int *got_frame_ptr,
AVPacket *avpkt)
309 AAC_DECODER_ERROR err;
314 err = aacDecoder_Fill(s->
handle, &avpkt->
data, &avpkt->
size, &valid);
315 if (err != AAC_DEC_OK) {
344 err = aacDecoder_DecodeFrame(s->
handle, (INT_PCM *) buf, buf_size, 0);
345 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
346 ret = avpkt->
size - valid;
349 if (err != AAC_DEC_OK) {
351 "aacDecoder_DecodeFrame() failed: %x\n", err);
378 ret = avpkt->
size - valid;
387 AAC_DECODER_ERROR err;
392 if ((err = aacDecoder_SetParam(s->
handle,
393 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
398 .
name =
"libfdk_aac",
408 .priv_class = &fdk_aac_dec_class,