FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/aacdec.c
Date: 2024-04-18 10:05:09
Exec Total Coverage
Lines: 198 263 75.3%
Functions: 17 18 94.4%
Branches: 74 129 57.4%

Line Branch Exec Source
1 /*
2 * AAC decoder
3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5 * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6 *
7 * AAC LATM decoder
8 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9 * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10 *
11 * This file is part of FFmpeg.
12 *
13 * FFmpeg is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * FFmpeg is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with FFmpeg; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /**
29 * @file
30 * AAC decoder
31 * @author Oded Shimon ( ods15 ods15 dyndns org )
32 * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
33 */
34
35 #define USE_FIXED 0
36 #define TX_TYPE AV_TX_FLOAT_MDCT
37
38 #include "libavutil/float_dsp.h"
39 #include "libavutil/mem.h"
40 #include "libavutil/opt.h"
41 #include "avcodec.h"
42 #include "codec_internal.h"
43 #include "get_bits.h"
44 #include "kbdwin.h"
45 #include "sinewin.h"
46
47 #include "aac.h"
48 #include "aacdec.h"
49 #include "aactab.h"
50 #include "aacdectab.h"
51 #include "adts_header.h"
52 #include "cbrt_data.h"
53 #include "sbr.h"
54 #include "aacsbr.h"
55 #include "mpeg4audio.h"
56 #include "profiles.h"
57 #include "libavutil/intfloat.h"
58
59 #include <errno.h>
60 #include <math.h>
61 #include <stdint.h>
62 #include <string.h>
63
64 #if ARCH_ARM
65 # include "arm/aac.h"
66 #elif ARCH_MIPS
67 # include "mips/aacdec_mips.h"
68 #endif
69
70 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_120))[120];
71 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(sine_960))[960];
72 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(aac_kbd_long_960))[960];
73 DECLARE_ALIGNED(32, static INTFLOAT, AAC_RENAME(aac_kbd_short_120))[120];
74
75 38542 static av_always_inline void reset_predict_state(PredictorState *ps)
76 {
77 38542 ps->r0 = 0.0f;
78 38542 ps->r1 = 0.0f;
79 38542 ps->cor0 = 0.0f;
80 38542 ps->cor1 = 0.0f;
81 38542 ps->var0 = 1.0f;
82 38542 ps->var1 = 1.0f;
83 38542 }
84
85 #ifndef VMUL2
86 1815116 static inline float *VMUL2(float *dst, const float *v, unsigned idx,
87 const float *scale)
88 {
89 1815116 float s = *scale;
90 1815116 *dst++ = v[idx & 15] * s;
91 1815116 *dst++ = v[idx>>4 & 15] * s;
92 1815116 return dst;
93 }
94 #endif
95
96 #ifndef VMUL4
97 2273024 static inline float *VMUL4(float *dst, const float *v, unsigned idx,
98 const float *scale)
99 {
100 2273024 float s = *scale;
101 2273024 *dst++ = v[idx & 3] * s;
102 2273024 *dst++ = v[idx>>2 & 3] * s;
103 2273024 *dst++ = v[idx>>4 & 3] * s;
104 2273024 *dst++ = v[idx>>6 & 3] * s;
105 2273024 return dst;
106 }
107 #endif
108
109 #ifndef VMUL2S
110 2274420 static inline float *VMUL2S(float *dst, const float *v, unsigned idx,
111 unsigned sign, const float *scale)
112 {
113 union av_intfloat32 s0, s1;
114
115 2274420 s0.f = s1.f = *scale;
116 2274420 s0.i ^= sign >> 1 << 31;
117 2274420 s1.i ^= sign << 31;
118
119 2274420 *dst++ = v[idx & 15] * s0.f;
120 2274420 *dst++ = v[idx>>4 & 15] * s1.f;
121
122 2274420 return dst;
123 }
124 #endif
125
126 #ifndef VMUL4S
127 1809834 static inline float *VMUL4S(float *dst, const float *v, unsigned idx,
128 unsigned sign, const float *scale)
129 {
130 1809834 unsigned nz = idx >> 12;
131 1809834 union av_intfloat32 s = { .f = *scale };
132 union av_intfloat32 t;
133
134 1809834 t.i = s.i ^ (sign & 1U<<31);
135 1809834 *dst++ = v[idx & 3] * t.f;
136
137 1809834 sign <<= nz & 1; nz >>= 1;
138 1809834 t.i = s.i ^ (sign & 1U<<31);
139 1809834 *dst++ = v[idx>>2 & 3] * t.f;
140
141 1809834 sign <<= nz & 1; nz >>= 1;
142 1809834 t.i = s.i ^ (sign & 1U<<31);
143 1809834 *dst++ = v[idx>>4 & 3] * t.f;
144
145 1809834 sign <<= nz & 1;
146 1809834 t.i = s.i ^ (sign & 1U<<31);
147 1809834 *dst++ = v[idx>>6 & 3] * t.f;
148
149 1809834 return dst;
150 }
151 #endif
152
153 4047936 static av_always_inline float flt16_round(float pf)
154 {
155 union av_intfloat32 tmp;
156 4047936 tmp.f = pf;
157 4047936 tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
158 4047936 return tmp.f;
159 }
160
161 5085872 static av_always_inline float flt16_even(float pf)
162 {
163 union av_intfloat32 tmp;
164 5085872 tmp.f = pf;
165 5085872 tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U;
166 5085872 return tmp.f;
167 }
168
169 24287616 static av_always_inline float flt16_trunc(float pf)
170 {
171 union av_intfloat32 pun;
172 24287616 pun.f = pf;
173 24287616 pun.i &= 0xFFFF0000U;
174 24287616 return pun.f;
175 }
176
177 4047936 static av_always_inline void predict(PredictorState *ps, float *coef,
178 int output_enable)
179 {
180 4047936 const float a = 0.953125; // 61.0 / 64
181 4047936 const float alpha = 0.90625; // 29.0 / 32
182 float e0, e1;
183 float pv;
184 float k1, k2;
185 4047936 float r0 = ps->r0, r1 = ps->r1;
186 4047936 float cor0 = ps->cor0, cor1 = ps->cor1;
187 4047936 float var0 = ps->var0, var1 = ps->var1;
188
189
2/2
✓ Branch 0 taken 2542772 times.
✓ Branch 1 taken 1505164 times.
4047936 k1 = var0 > 1 ? cor0 * flt16_even(a / var0) : 0;
190
2/2
✓ Branch 0 taken 2543100 times.
✓ Branch 1 taken 1504836 times.
4047936 k2 = var1 > 1 ? cor1 * flt16_even(a / var1) : 0;
191
192 4047936 pv = flt16_round(k1 * r0 + k2 * r1);
193
2/2
✓ Branch 0 taken 271896 times.
✓ Branch 1 taken 3776040 times.
4047936 if (output_enable)
194 271896 *coef += pv;
195
196 4047936 e0 = *coef;
197 4047936 e1 = e0 - k1 * r0;
198
199 4047936 ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1);
200 4047936 ps->var1 = flt16_trunc(alpha * var1 + 0.5f * (r1 * r1 + e1 * e1));
201 4047936 ps->cor0 = flt16_trunc(alpha * cor0 + r0 * e0);
202 4047936 ps->var0 = flt16_trunc(alpha * var0 + 0.5f * (r0 * r0 + e0 * e0));
203
204 4047936 ps->r1 = flt16_trunc(a * (r0 - k1 * e0));
205 4047936 ps->r0 = flt16_trunc(a * e0);
206 4047936 }
207
208 /**
209 * Apply dependent channel coupling (applied before IMDCT).
210 *
211 * @param index index into coupling gain array
212 */
213 2743 static void apply_dependent_coupling(AACDecContext *ac,
214 SingleChannelElement *target,
215 ChannelElement *cce, int index)
216 {
217 2743 IndividualChannelStream *ics = &cce->ch[0].ics;
218 2743 const uint16_t *offsets = ics->swb_offset;
219 2743 float *dest = target->coeffs;
220 2743 const float *src = cce->ch[0].coeffs;
221 2743 int g, i, group, k, idx = 0;
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2743 times.
2743 if (ac->oc[1].m4ac.object_type == AOT_AAC_LTP) {
223 av_log(ac->avctx, AV_LOG_ERROR,
224 "Dependent coupling is not supported together with LTP\n");
225 return;
226 }
227
2/2
✓ Branch 0 taken 2743 times.
✓ Branch 1 taken 2743 times.
5486 for (g = 0; g < ics->num_window_groups; g++) {
228
2/2
✓ Branch 0 taken 109720 times.
✓ Branch 1 taken 2743 times.
112463 for (i = 0; i < ics->max_sfb; i++, idx++) {
229
2/2
✓ Branch 0 taken 5196 times.
✓ Branch 1 taken 104524 times.
109720 if (cce->ch[0].band_type[idx] != ZERO_BT) {
230 5196 const float gain = cce->coup.gain[index][idx];
231
2/2
✓ Branch 0 taken 5196 times.
✓ Branch 1 taken 5196 times.
10392 for (group = 0; group < ics->group_len[g]; group++) {
232
2/2
✓ Branch 0 taken 76768 times.
✓ Branch 1 taken 5196 times.
81964 for (k = offsets[i]; k < offsets[i + 1]; k++) {
233 // FIXME: SIMDify
234 76768 dest[group * 128 + k] += gain * src[group * 128 + k];
235 }
236 }
237 }
238 }
239 2743 dest += ics->group_len[g] * 128;
240 2743 src += ics->group_len[g] * 128;
241 }
242 }
243
244 /**
245 * Apply independent channel coupling (applied after IMDCT).
246 *
247 * @param index index into coupling gain array
248 */
249 1315 static void apply_independent_coupling(AACDecContext *ac,
250 SingleChannelElement *target,
251 ChannelElement *cce, int index)
252 {
253 1315 const float gain = cce->coup.gain[index][0];
254 1315 const float *src = cce->ch[0].ret;
255 1315 float *dest = target->ret;
256
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1315 times.
1315 const int len = 1024 << (ac->oc[1].m4ac.sbr == 1);
257
258 1315 ac->fdsp->vector_fmac_scalar(dest, src, gain, len);
259 1315 }
260
261 #include "aacdec_template.c"
262
263 #define LOAS_SYNC_WORD 0x2b7 ///< 11 bits LOAS sync word
264
265 struct LATMContext {
266 AACDecContext aac_ctx; ///< containing AACContext
267 int initialized; ///< initialized after a valid extradata was seen
268
269 // parser data
270 int audio_mux_version_A; ///< LATM syntax version
271 int frame_length_type; ///< 0/1 variable/fixed frame length
272 int frame_length; ///< frame length for fixed frame length
273 };
274
275 static inline uint32_t latm_get_value(GetBitContext *b)
276 {
277 int length = get_bits(b, 2);
278
279 return get_bits_long(b, (length+1)*8);
280 }
281
282 322 static int latm_decode_audio_specific_config(struct LATMContext *latmctx,
283 GetBitContext *gb, int asclen)
284 {
285 322 AACDecContext *ac = &latmctx->aac_ctx;
286 322 AVCodecContext *avctx = ac->avctx;
287 322 MPEG4AudioConfig m4ac = { 0 };
288 GetBitContext gbc;
289 322 int config_start_bit = get_bits_count(gb);
290 322 int sync_extension = 0;
291 int bits_consumed, esize, i;
292
293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 if (asclen > 0) {
294 sync_extension = 1;
295 asclen = FFMIN(asclen, get_bits_left(gb));
296 init_get_bits(&gbc, gb->buffer, config_start_bit + asclen);
297 skip_bits_long(&gbc, config_start_bit);
298
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 } else if (asclen == 0) {
299 322 gbc = *gb;
300 } else {
301 return AVERROR_INVALIDDATA;
302 }
303
304
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if (get_bits_left(gb) <= 0)
305 return AVERROR_INVALIDDATA;
306
307 322 bits_consumed = decode_audio_specific_config_gb(NULL, avctx, &m4ac,
308 &gbc, config_start_bit,
309 sync_extension);
310
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 if (bits_consumed < config_start_bit)
312 return AVERROR_INVALIDDATA;
313 322 bits_consumed -= config_start_bit;
314
315
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 if (asclen == 0)
316 322 asclen = bits_consumed;
317
318
2/2
✓ Branch 0 taken 316 times.
✓ Branch 1 taken 6 times.
322 if (!latmctx->initialized ||
319
1/2
✓ Branch 0 taken 316 times.
✗ Branch 1 not taken.
316 ac->oc[1].m4ac.sample_rate != m4ac.sample_rate ||
320
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 315 times.
316 ac->oc[1].m4ac.chan_config != m4ac.chan_config) {
321
322
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (latmctx->initialized) {
323 1 av_log(avctx, AV_LOG_INFO, "audio config changed (sample_rate=%d, chan_config=%d)\n", m4ac.sample_rate, m4ac.chan_config);
324 } else {
325 6 av_log(avctx, AV_LOG_DEBUG, "initializing latmctx\n");
326 }
327 7 latmctx->initialized = 0;
328
329 7 esize = (asclen + 7) / 8;
330
331
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (avctx->extradata_size < esize) {
332 6 av_free(avctx->extradata);
333 6 avctx->extradata = av_malloc(esize + AV_INPUT_BUFFER_PADDING_SIZE);
334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (!avctx->extradata)
335 return AVERROR(ENOMEM);
336 }
337
338 7 avctx->extradata_size = esize;
339 7 gbc = *gb;
340
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
28 for (i = 0; i < esize; i++) {
341 21 avctx->extradata[i] = get_bits(&gbc, 8);
342 }
343 7 memset(avctx->extradata+esize, 0, AV_INPUT_BUFFER_PADDING_SIZE);
344 }
345 322 skip_bits_long(gb, asclen);
346
347 322 return 0;
348 }
349
350 322 static int read_stream_mux_config(struct LATMContext *latmctx,
351 GetBitContext *gb)
352 {
353 322 int ret, audio_mux_version = get_bits(gb, 1);
354
355 322 latmctx->audio_mux_version_A = 0;
356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 if (audio_mux_version)
357 latmctx->audio_mux_version_A = get_bits(gb, 1);
358
359
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 if (!latmctx->audio_mux_version_A) {
360
361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 if (audio_mux_version)
362 latm_get_value(gb); // taraFullness
363
364 322 skip_bits(gb, 1); // allStreamSameTimeFraming
365 322 skip_bits(gb, 6); // numSubFrames
366 // numPrograms
367
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if (get_bits(gb, 4)) { // numPrograms
368 avpriv_request_sample(latmctx->aac_ctx.avctx, "Multiple programs");
369 return AVERROR_PATCHWELCOME;
370 }
371
372 // for each program (which there is only one in DVB)
373
374 // for each layer (which there is only one in DVB)
375
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if (get_bits(gb, 3)) { // numLayer
376 avpriv_request_sample(latmctx->aac_ctx.avctx, "Multiple layers");
377 return AVERROR_PATCHWELCOME;
378 }
379
380 // for all but first stream: use_same_config = get_bits(gb, 1);
381
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 if (!audio_mux_version) {
382
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0)
383 return ret;
384 } else {
385 int ascLen = latm_get_value(gb);
386 if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0)
387 return ret;
388 }
389
390 322 latmctx->frame_length_type = get_bits(gb, 3);
391
1/5
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
322 switch (latmctx->frame_length_type) {
392 322 case 0:
393 322 skip_bits(gb, 8); // latmBufferFullness
394 322 break;
395 case 1:
396 latmctx->frame_length = get_bits(gb, 9);
397 break;
398 case 3:
399 case 4:
400 case 5:
401 skip_bits(gb, 6); // CELP frame length table index
402 break;
403 case 6:
404 case 7:
405 skip_bits(gb, 1); // HVXC frame length table index
406 break;
407 }
408
409
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if (get_bits(gb, 1)) { // other data
410 if (audio_mux_version) {
411 latm_get_value(gb); // other_data_bits
412 } else {
413 int esc;
414 do {
415 if (get_bits_left(gb) < 9)
416 return AVERROR_INVALIDDATA;
417 esc = get_bits(gb, 1);
418 skip_bits(gb, 8);
419 } while (esc);
420 }
421 }
422
423
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if (get_bits(gb, 1)) // crc present
424 skip_bits(gb, 8); // config_crc
425 }
426
427 322 return 0;
428 }
429
430 515 static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
431 {
432 uint8_t tmp;
433
434
1/2
✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
515 if (ctx->frame_length_type == 0) {
435 515 int mux_slot_length = 0;
436 do {
437
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1504 times.
1504 if (get_bits_left(gb) < 8)
438 return AVERROR_INVALIDDATA;
439 1504 tmp = get_bits(gb, 8);
440 1504 mux_slot_length += tmp;
441
2/2
✓ Branch 0 taken 989 times.
✓ Branch 1 taken 515 times.
1504 } while (tmp == 255);
442 515 return mux_slot_length;
443 } else if (ctx->frame_length_type == 1) {
444 return ctx->frame_length;
445 } else if (ctx->frame_length_type == 3 ||
446 ctx->frame_length_type == 5 ||
447 ctx->frame_length_type == 7) {
448 skip_bits(gb, 2); // mux_slot_length_coded
449 }
450 return 0;
451 }
452
453 521 static int read_audio_mux_element(struct LATMContext *latmctx,
454 GetBitContext *gb)
455 {
456 int err;
457 521 uint8_t use_same_mux = get_bits(gb, 1);
458
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 199 times.
521 if (!use_same_mux) {
459
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 322 times.
322 if ((err = read_stream_mux_config(latmctx, gb)) < 0)
460 return err;
461
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 193 times.
199 } else if (!latmctx->aac_ctx.avctx->extradata) {
462 6 av_log(latmctx->aac_ctx.avctx, AV_LOG_DEBUG,
463 "no decoder config found\n");
464 6 return 1;
465 }
466
1/2
✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
515 if (latmctx->audio_mux_version_A == 0) {
467 515 int mux_slot_length_bytes = read_payload_length_info(latmctx, gb);
468
2/4
✓ Branch 0 taken 515 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 515 times.
515 if (mux_slot_length_bytes < 0 || mux_slot_length_bytes * 8LL > get_bits_left(gb)) {
469 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR, "incomplete frame\n");
470 return AVERROR_INVALIDDATA;
471
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 515 times.
515 } else if (mux_slot_length_bytes * 8 + 256 < get_bits_left(gb)) {
472 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,
473 "frame length mismatch %d << %d\n",
474 mux_slot_length_bytes * 8, get_bits_left(gb));
475 return AVERROR_INVALIDDATA;
476 }
477 }
478 515 return 0;
479 }
480
481
482 523 static int latm_decode_frame(AVCodecContext *avctx, AVFrame *out,
483 int *got_frame_ptr, AVPacket *avpkt)
484 {
485 523 struct LATMContext *latmctx = avctx->priv_data;
486 int muxlength, err;
487 GetBitContext gb;
488
489
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 523 times.
523 if ((err = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)
490 return err;
491
492 // check for LOAS sync word
493
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 523 times.
523 if (get_bits(&gb, 11) != LOAS_SYNC_WORD)
494 return AVERROR_INVALIDDATA;
495
496 523 muxlength = get_bits(&gb, 13) + 3;
497 // not enough data, the parser should have sorted this out
498
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 521 times.
523 if (muxlength > avpkt->size)
499 2 return AVERROR_INVALIDDATA;
500
501
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 515 times.
521 if ((err = read_audio_mux_element(latmctx, &gb)))
502
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 return (err < 0) ? err : avpkt->size;
503
504
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 508 times.
515 if (!latmctx->initialized) {
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (!avctx->extradata) {
506 *got_frame_ptr = 0;
507 return avpkt->size;
508 } else {
509 7 push_output_configuration(&latmctx->aac_ctx);
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if ((err = decode_audio_specific_config(
511 &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.oc[1].m4ac,
512 7 avctx->extradata, avctx->extradata_size*8LL, 1)) < 0) {
513 pop_output_configuration(&latmctx->aac_ctx);
514 return err;
515 }
516 7 latmctx->initialized = 1;
517 }
518 }
519
520
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 515 times.
515 if (show_bits(&gb, 12) == 0xfff) {
521 av_log(latmctx->aac_ctx.avctx, AV_LOG_ERROR,
522 "ADTS header detected, probably as result of configuration "
523 "misparsing\n");
524 return AVERROR_INVALIDDATA;
525 }
526
527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 515 times.
515 switch (latmctx->aac_ctx.oc[1].m4ac.object_type) {
528 case AOT_ER_AAC_LC:
529 case AOT_ER_AAC_LTP:
530 case AOT_ER_AAC_LD:
531 case AOT_ER_AAC_ELD:
532 err = aac_decode_er_frame(avctx, out, got_frame_ptr, &gb);
533 break;
534 515 default:
535 515 err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb, avpkt);
536 }
537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 515 times.
515 if (err < 0)
538 return err;
539
540 515 return muxlength;
541 }
542
543 11 static av_cold int latm_decode_init(AVCodecContext *avctx)
544 {
545 11 struct LATMContext *latmctx = avctx->priv_data;
546 11 int ret = aac_decode_init(avctx);
547
548
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
11 if (avctx->extradata_size > 0)
549 5 latmctx->initialized = !ret;
550
551 11 return ret;
552 }
553
554 const FFCodec ff_aac_decoder = {
555 .p.name = "aac",
556 CODEC_LONG_NAME("AAC (Advanced Audio Coding)"),
557 .p.type = AVMEDIA_TYPE_AUDIO,
558 .p.id = AV_CODEC_ID_AAC,
559 .priv_data_size = sizeof(AACDecContext),
560 .init = aac_decode_init,
561 .close = aac_decode_close,
562 FF_CODEC_DECODE_CB(aac_decode_frame),
563 .p.sample_fmts = (const enum AVSampleFormat[]) {
564 AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE
565 },
566 .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
567 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
568 .p.ch_layouts = ff_aac_ch_layout,
569 .flush = flush,
570 .p.priv_class = &aac_decoder_class,
571 .p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
572 };
573
574 /*
575 Note: This decoder filter is intended to decode LATM streams transferred
576 in MPEG transport streams which only contain one program.
577 To do a more complex LATM demuxing a separate LATM demuxer should be used.
578 */
579 const FFCodec ff_aac_latm_decoder = {
580 .p.name = "aac_latm",
581 CODEC_LONG_NAME("AAC LATM (Advanced Audio Coding LATM syntax)"),
582 .p.type = AVMEDIA_TYPE_AUDIO,
583 .p.id = AV_CODEC_ID_AAC_LATM,
584 .priv_data_size = sizeof(struct LATMContext),
585 .init = latm_decode_init,
586 .close = aac_decode_close,
587 FF_CODEC_DECODE_CB(latm_decode_frame),
588 .p.sample_fmts = (const enum AVSampleFormat[]) {
589 AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE
590 },
591 .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
592 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
593 .p.ch_layouts = ff_aac_ch_layout,
594 .flush = flush,
595 .p.profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
596 };
597