1 /*
2 * AAC decoder wrapper
3 * Copyright (c) 2012 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include <fdk-aac/aacdecoder_lib.h>
21
27
28 /* The version macro is introduced the same time as the setting enum was
29 * changed, so this check should suffice. */
30 #ifndef AACDECODER_LIB_VL0
31 #define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
32 #endif
33
39 };
40
54
55
56 #define DMX_ANC_BUFFSIZE 128
57 #define DECODER_MAX_CHANNELS 6
58 #define DECODER_BUFFSIZE 2048 * sizeof(INT_PCM)
59
60 #define OFFSET(x) offsetof(FDKAACDecContext, x)
61 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
67 { "drc_boost", "Dynamic Range Control: boost, where [0] is none and [127] is max boost",
69 { "drc_cut", "Dynamic Range Control: attenuation factor, where [0] is none and [127] is max compression",
71 { "drc_level", "Dynamic Range Control: reference level, quantized to 0.25dB steps where [0] is 0dB and [127] is -31.75dB",
73 { "drc_heavy", "Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
75 #ifdef AACDECODER_LIB_VL0
77 #endif
79 };
80
83 };
84
86 {
88 CStreamInfo *info = aacDecoder_GetStreamInfo(s->
handle);
89 int channel_counts[0x24] = { 0 };
90 int i, ch_error = 0;
91 uint64_t ch_layout = 0;
92
93 if (!info) {
96 }
97
98 if (info->sampleRate <= 0) {
101 }
104
105 for (i = 0; i < info->numChannels; i++) {
106 AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
107 if (ctype <= ACT_NONE || ctype >=
FF_ARRAY_ELEMS(channel_counts)) {
109 break;
110 }
111 channel_counts[ctype]++;
112 }
114 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
115 info->numChannels,
116 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
117 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
118 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
119 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
120
121 switch (channel_counts[ACT_FRONT]) {
122 case 4:
125 break;
126 case 3:
128 break;
129 case 2:
131 break;
132 case 1:
134 break;
135 default:
137 "unsupported number of front channels: %d\n",
138 channel_counts[ACT_FRONT]);
139 ch_error = 1;
140 break;
141 }
142 if (channel_counts[ACT_SIDE] > 0) {
143 if (channel_counts[ACT_SIDE] == 2) {
145 } else {
147 "unsupported number of side channels: %d\n",
148 channel_counts[ACT_SIDE]);
149 ch_error = 1;
150 }
151 }
152 if (channel_counts[ACT_BACK] > 0) {
153 switch (channel_counts[ACT_BACK]) {
154 case 3:
156 break;
157 case 2:
159 break;
160 case 1:
162 break;
163 default:
165 "unsupported number of back channels: %d\n",
166 channel_counts[ACT_BACK]);
167 ch_error = 1;
168 break;
169 }
170 }
171 if (channel_counts[ACT_LFE] > 0) {
172 if (channel_counts[ACT_LFE] == 1) {
174 } else {
176 "unsupported number of LFE channels: %d\n",
177 channel_counts[ACT_LFE]);
178 ch_error = 1;
179 }
180 }
181 if (!ch_error &&
184 ch_error = 1;
185 }
186 if (ch_error)
188 else
190
191 avctx->
channels = info->numChannels;
192
193 return 0;
194 }
195
197 {
199
201 aacDecoder_Close(s->
handle);
204
205 return 0;
206 }
207
209 {
211 AAC_DECODER_ERROR err;
213
218 }
219
225 }
226 }
227
228 if ((err = aacDecoder_SetParam(s->
handle, AAC_CONCEAL_METHOD,
232 }
233
236 int downmix_channels = -1;
237
241 downmix_channels = 2;
242 break;
244 downmix_channels = 1;
245 break;
246 default:
248 break;
249 }
250
251 if (downmix_channels != -1) {
253 downmix_channels) != AAC_DEC_OK) {
255 } else {
260 goto fail;
261 }
263 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
265 goto fail;
266 }
267 }
268 }
269 }
270
272 if (aacDecoder_SetParam(s->
handle, AAC_DRC_BOOST_FACTOR, s->
drc_boost) != AAC_DEC_OK) {
275 }
276 }
277
279 if (aacDecoder_SetParam(s->
handle, AAC_DRC_ATTENUATION_FACTOR, s->
drc_cut) != AAC_DEC_OK) {
282 }
283 }
284
286 if (aacDecoder_SetParam(s->
handle, AAC_DRC_REFERENCE_LEVEL, s->
drc_level) != AAC_DEC_OK) {
289 }
290 }
291
293 if (aacDecoder_SetParam(s->
handle, AAC_DRC_HEAVY_COMPRESSION, s->
drc_heavy) != AAC_DEC_OK) {
296 }
297 }
298
299 #ifdef AACDECODER_LIB_VL0
300 if (aacDecoder_SetParam(s->
handle, AAC_PCM_LIMITER_ENABLE, s->
level_limit) != AAC_DEC_OK) {
301 av_log(avctx,
AV_LOG_ERROR,
"Unable to set in signal level limiting in the decoder\n");
303 }
304 #endif
305
307
308 return 0;
309 fail:
312 }
313
315 int *got_frame_ptr,
AVPacket *avpkt)
316 {
320 AAC_DECODER_ERROR err;
323 int buf_size;
324
325 err = aacDecoder_Fill(s->
handle, &avpkt->
data, &avpkt->
size, &valid);
326 if (err != AAC_DEC_OK) {
329 }
330
335
339 } else {
343 }
344 } else {
346
351
353 }
354
355 err = aacDecoder_DecodeFrame(s->
handle, (INT_PCM *) buf, buf_size, 0);
356 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
357 ret = avpkt->
size - valid;
359 }
360 if (err != AAC_DEC_OK) {
362 "aacDecoder_DecodeFrame() failed: %x\n", err);
365 }
366
372 }
373
374 if (tmpptr) {
378 }
383
386 }
387
388 *got_frame_ptr = 1;
389 ret = avpkt->
size - valid;
390
393 }
394
396 {
398 AAC_DECODER_ERROR err;
399
401 return;
402
403 if ((err = aacDecoder_SetParam(s->
handle,
404 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
406 }
407
409 .
name =
"libfdk_aac",
419 .priv_class = &fdk_aac_dec_class,
420 };