FFmpeg coverage


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