1 /*
2 * AAC decoder wrapper
3 * Copyright (c) 2012 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <fdk-aac/aacdecoder_lib.h>
23
29
36 };
37
44
45 #define OFFSET(x) offsetof(FDKAACDecContext, x)
46 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
53 { NULL }
54 };
55
58 };
59
61 {
63 CStreamInfo *info = aacDecoder_GetStreamInfo(s->
handle);
64 int channel_counts[9] = { 0 };
65 int i, ch_error = 0;
66 uint64_t ch_layout = 0;
67
68 if (!info) {
71 }
72
73 if (info->sampleRate <= 0) {
76 }
79
80 for (i = 0; i < info->numChannels; i++) {
81 AUDIO_CHANNEL_TYPE ctype = info->pChannelType[i];
82 if (ctype <= ACT_NONE || ctype > ACT_TOP) {
84 break;
85 }
86 channel_counts[ctype]++;
87 }
89 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
90 info->numChannels,
91 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
92 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
93 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
94 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
95
96 switch (channel_counts[ACT_FRONT]) {
97 case 4:
100 break;
101 case 3:
103 break;
104 case 2:
106 break;
107 case 1:
109 break;
110 default:
112 "unsupported number of front channels: %d\n",
113 channel_counts[ACT_FRONT]);
114 ch_error = 1;
115 break;
116 }
117 if (channel_counts[ACT_SIDE] > 0) {
118 if (channel_counts[ACT_SIDE] == 2) {
120 } else {
122 "unsupported number of side channels: %d\n",
123 channel_counts[ACT_SIDE]);
124 ch_error = 1;
125 }
126 }
127 if (channel_counts[ACT_BACK] > 0) {
128 switch (channel_counts[ACT_BACK]) {
129 case 3:
131 break;
132 case 2:
134 break;
135 case 1:
137 break;
138 default:
140 "unsupported number of back channels: %d\n",
141 channel_counts[ACT_BACK]);
142 ch_error = 1;
143 break;
144 }
145 }
146 if (channel_counts[ACT_LFE] > 0) {
147 if (channel_counts[ACT_LFE] == 1) {
149 } else {
151 "unsupported number of LFE channels: %d\n",
152 channel_counts[ACT_LFE]);
153 ch_error = 1;
154 }
155 }
156 if (!ch_error &&
159 ch_error = 1;
160 }
161 if (ch_error)
163 else
165
166 avctx->
channels = info->numChannels;
167
168 return 0;
169 }
170
172 {
174
176 aacDecoder_Close(s->
handle);
177
178 return 0;
179 }
180
182 {
184 AAC_DECODER_ERROR err;
185
190 }
191
197 }
198 }
199
201 if ((err = aacDecoder_SetParam(s->
handle, AAC_CONCEAL_METHOD,
205 }
206 }
207
209
210 return 0;
211 }
212
214 int *got_frame_ptr,
AVPacket *avpkt)
215 {
219 AAC_DECODER_ERROR err;
222 int buf_size;
223
224 err = aacDecoder_Fill(s->
handle, &avpkt->
data, &avpkt->
size, &valid);
225 if (err != AAC_DEC_OK) {
228 }
229
235 }
239 } else {
240 buf_size = 50 * 1024;
242 if (!buf)
244 }
245
246 err = aacDecoder_DecodeFrame(s->
handle, (INT_PCM *) buf, buf_size, 0);
247 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
248 ret = avpkt->
size - valid;
250 }
251 if (err != AAC_DEC_OK) {
253 "aacDecoder_DecodeFrame() failed: %x\n", err);
256 }
257
263 }
264
265 if (tmpptr) {
270 }
274 }
275
276 *got_frame_ptr = 1;
277 ret = avpkt->
size - valid;
278
282 }
283
285 {
287 AAC_DECODER_ERROR err;
288
290 return;
291
292 if ((err = aacDecoder_SetParam(s->
handle,
293 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
295 }
296
298 .
name =
"libfdk_aac",
308 .priv_class = &fdk_aac_dec_class,
309 };