FFmpeg coverage


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