FFmpeg: libavcodec/aacdec.c Source File
Go to the documentation of this file. 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
36 #define TX_TYPE AV_TX_FLOAT_MDCT
37
46
57
58 #include <errno.h>
59 #include <math.h>
60 #include <stdint.h>
61 #include <string.h>
62
63 #if ARCH_ARM
65 #elif ARCH_MIPS
67 #endif
68
73
75 {
82 }
83
84 #ifndef VMUL2
85 static inline float *
VMUL2(
float *dst,
const float *v,
unsigned idx,
87 {
89 *dst++ = v[idx & 15] *
s;
90 *dst++ = v[idx>>4 & 15] *
s;
91 return dst;
92 }
93 #endif
94
95 #ifndef VMUL4
96 static inline float *
VMUL4(
float *dst,
const float *v,
unsigned idx,
98 {
100 *dst++ = v[idx & 3] *
s;
101 *dst++ = v[idx>>2 & 3] *
s;
102 *dst++ = v[idx>>4 & 3] *
s;
103 *dst++ = v[idx>>6 & 3] *
s;
104 return dst;
105 }
106 #endif
107
108 #ifndef VMUL2S
109 static inline float *
VMUL2S(
float *dst,
const float *v,
unsigned idx,
110 unsigned sign,
const float *
scale)
111 {
113
115 s0.i ^= sign >> 1 << 31;
117
118 *dst++ = v[idx & 15] *
s0.f;
119 *dst++ = v[idx>>4 & 15] *
s1.f;
120
121 return dst;
122 }
123 #endif
124
125 #ifndef VMUL4S
126 static inline float *
VMUL4S(
float *dst,
const float *v,
unsigned idx,
127 unsigned sign,
const float *
scale)
128 {
129 unsigned nz = idx >> 12;
132
133 t.
i =
s.i ^ (sign & 1
U<<31);
134 *dst++ = v[idx & 3] * t.
f;
135
136 sign <<= nz & 1; nz >>= 1;
137 t.
i =
s.i ^ (sign & 1
U<<31);
138 *dst++ = v[idx>>2 & 3] * t.
f;
139
140 sign <<= nz & 1; nz >>= 1;
141 t.
i =
s.i ^ (sign & 1
U<<31);
142 *dst++ = v[idx>>4 & 3] * t.
f;
143
144 sign <<= nz & 1;
145 t.
i =
s.i ^ (sign & 1
U<<31);
146 *dst++ = v[idx>>6 & 3] * t.
f;
147
148 return dst;
149 }
150 #endif
151
153 {
156 tmp.i = (
tmp.i + 0x00008000
U) & 0xFFFF0000U;
158 }
159
161 {
164 tmp.i = (
tmp.i + 0x00007FFF
U + (
tmp.i & 0x00010000
U >> 16)) & 0xFFFF0000
U;
166 }
167
169 {
172 pun.
i &= 0xFFFF0000
U;
174 }
175
177 int output_enable)
178 {
179 const float a = 0.953125;
// 61.0 / 64
180 const float alpha = 0.90625;
// 29.0 / 32
181 float e0, e1;
183 float k1, k2;
184 float r0 = ps->
r0, r1 = ps->
r1;
185 float cor0 = ps->
cor0, cor1 = ps->
cor1;
186 float var0 = ps->
var0, var1 = ps->
var1;
187
190
192 if (output_enable)
194
195 e0 = *coef;
196 e1 = e0 - k1 * r0;
197
202
205 }
206
207 /**
208 * Apply dependent channel coupling (applied before IMDCT).
209 *
210 * @param index index into coupling gain array
211 */
215 {
218 float *dest = target->
coeffs;
220 int g,
i, group, k, idx = 0;
223 "Dependent coupling is not supported together with LTP\n");
224 return;
225 }
230 for (group = 0; group < ics->
group_len[
g]; group++) {
232 // FIXME: SIMDify
233 dest[group * 128 + k] += gain *
src[group * 128 + k];
234 }
235 }
236 }
237 }
240 }
241 }
242
243 /**
244 * Apply independent channel coupling (applied after IMDCT).
245 *
246 * @param index index into coupling gain array
247 */
251 {
254 float *dest = target->
ret;
256
258 }
259
261
262 #define LOAS_SYNC_WORD 0x2b7 ///< 11 bits LOAS sync word
263
266 int initialized;
///< initialized after a valid extradata was seen
267
268 // parser data
272 };
273
275 {
277
279 }
280
283 {
289 int sync_extension = 0;
290 int bits_consumed, esize,
i;
291
292 if (asclen > 0) {
293 sync_extension = 1;
297 } else if (asclen == 0) {
298 gbc = *gb;
299 } else {
301 }
302
305
307 &gbc, config_start_bit,
308 sync_extension);
309
310 if (bits_consumed < config_start_bit)
312 bits_consumed -= config_start_bit;
313
314 if (asclen == 0)
315 asclen = bits_consumed;
316
320
323 } else {
325 }
327
328 esize = (asclen + 7) / 8;
329
335 }
336
338 gbc = *gb;
339 for (
i = 0;
i < esize;
i++) {
341 }
343 }
345
346 return 0;
347 }
348
351 {
353
355 if (audio_mux_version)
357
359
360 if (audio_mux_version)
362
363 skip_bits(gb, 1);
// allStreamSameTimeFraming
365 // numPrograms
366 if (
get_bits(gb, 4)) {
// numPrograms
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)
377 }
378
379 // for all but first stream: use_same_config = get_bits(gb, 1);
380 if (!audio_mux_version) {
383 } else {
387 }
388
391 case 0:
393 break;
394 case 1:
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 if (
get_bits(gb, 1)) {
// other data
409 if (audio_mux_version) {
411 } else {
412 int esc;
413 do {
418 } while (esc);
419 }
420 }
421
424 }
425
426 return 0;
427 }
428
430 {
432
433 if (
ctx->frame_length_type == 0) {
434 int mux_slot_length = 0;
435 do {
439 mux_slot_length +=
tmp;
440 }
while (
tmp == 255);
441 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
454 {
455 int err;
456 uint8_t use_same_mux =
get_bits(gb, 1);
457 if (!use_same_mux) {
459 return err;
462 "no decoder config found\n");
463 return 1;
464 }
467 if (mux_slot_length_bytes < 0 || mux_slot_length_bytes * 8LL >
get_bits_left(gb)) {
470 }
else if (mux_slot_length_bytes * 8 + 256 <
get_bits_left(gb)) {
472 "frame length mismatch %d << %d\n",
475 }
476 }
477 return 0;
478 }
479
480
482 int *got_frame_ptr,
AVPacket *avpkt)
483 {
485 int muxlength, err;
487
489 return err;
490
491 // check for LOAS sync word
494
496 // not enough data, the parser should have sorted this out
497 if (muxlength > avpkt->
size)
499
501 return (err < 0) ? err : avpkt->
size;
502
505 *got_frame_ptr = 0;
507 } else {
513 return err;
514 }
516 }
517 }
518
521 "ADTS header detected, probably as result of configuration "
522 "misparsing\n");
524 }
525
532 break;
533 default:
535 }
536 if (err < 0)
537 return err;
538
539 return muxlength;
540 }
541
543 {
546
549
551 }
552
564 },
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 */
580 .
p.
name =
"aac_latm",
590 },
597 };
@ AV_SAMPLE_FMT_FLTP
float, planar
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
int frame_length_type
0/1 variable/fixed frame length
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int get_bits_left(GetBitContext *gb)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_cold int aac_decode_init(AVCodecContext *avctx)
static INTFLOAT aac_kbd_short_120[120]
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_count(const GetBitContext *s)
This structure describes decoded (raw) audio or video data.
static void apply_dependent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply dependent channel coupling (applied before IMDCT).
AACContext aac_ctx
containing AACContext
@ AOT_ER_AAC_LTP
N Error Resilient Long Term Prediction.
const AVProfile ff_aac_profiles[]
const FFCodec ff_aac_decoder
static void pop_output_configuration(AACContext *ac)
Restore the previous output configuration if and only if the current configuration is unlocked.
INTFLOAT * ret
PCM output.
static int latm_decode_audio_specific_config(struct LATMContext *latmctx, GetBitContext *gb, int asclen)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
static av_cold int latm_decode_init(AVCodecContext *avctx)
static int read_audio_mux_element(struct LATMContext *latmctx, GetBitContext *gb)
static float * VMUL2(float *dst, const float *v, unsigned idx, const float *scale)
static av_always_inline float scale(float x, float s)
IndividualChannelStream ics
static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
@ AOT_ER_AAC_LC
N Error Resilient Low Complexity.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ ZERO_BT
Scalefactors and spectral data are all zero.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
@ AOT_ER_AAC_LD
N Error Resilient Low Delay.
#define FF_CODEC_DECODE_CB(func)
static const AVClass aac_decoder_class
INTFLOAT coeffs[1024]
coefficients for IMDCT, maybe processed
static av_always_inline void reset_predict_state(PredictorState *ps)
static const int offsets[]
static const AVChannelLayout aac_ch_layout[]
int(* init)(AVBSFContext *ctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int frame_length
frame length for fixed frame length
static int aac_decode_er_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb)
Individual Channel Stream.
const uint16_t * swb_offset
table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular wind...
#define CODEC_LONG_NAME(str)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_cold int aac_decode_close(AVCodecContext *avctx)
static av_always_inline float flt16_trunc(float pf)
static av_always_inline float flt16_even(float pf)
int initialized
initialized after a valid extradata was seen
static int decode_audio_specific_config(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, const uint8_t *data, int64_t bit_size, int sync_extension)
static av_always_inline float flt16_round(float pf)
static float * VMUL2S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
static float * VMUL4(float *dst, const float *v, unsigned idx, const float *scale)
static float * VMUL4S(float *dst, const float *v, unsigned idx, unsigned sign, const float *scale)
static int decode_audio_specific_config_gb(AACContext *ac, AVCodecContext *avctx, MPEG4AudioConfig *m4ac, GetBitContext *gb, int get_bit_alignment, int sync_extension)
Decode audio specific configuration; reference: table 1.13.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
SingleChannelElement ch[2]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define DECLARE_ALIGNED(n, t, v)
static INTFLOAT sine_120[120]
static INTFLOAT sine_960[960]
static int push_output_configuration(AACContext *ac)
Save current output configuration if and only if it has been locked.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define AV_LOG_INFO
Standard information.
static INTFLOAT aac_kbd_long_960[960]
#define CODEC_OLD_CHANNEL_LAYOUTS_ARRAY(array)
Single Channel Element - used for both SCE and LFE elements.
#define i(width, name, range_min, range_max)
void(* vector_fmac_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float and add to destination vector.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
channel element - generic struct for SCE/CPE/CCE/LFE
@ AOT_ER_AAC_ELD
N Error Resilient Enhanced Low Delay.
static void apply_independent_coupling(AACContext *ac, SingleChannelElement *target, ChannelElement *cce, int index)
Apply independent channel coupling (applied after IMDCT).
static av_always_inline void predict(PredictorState *ps, float *coef, int output_enable)
AVSampleFormat
Audio sample formats.
const char * name
Name of the codec implementation.
static int latm_decode_frame(AVCodecContext *avctx, AVFrame *out, int *got_frame_ptr, AVPacket *avpkt)
OutputConfiguration oc[2]
#define AV_INPUT_BUFFER_PADDING_SIZE
int audio_mux_version_A
LATM syntax version.
main external API structure.
const FFCodec ff_aac_latm_decoder
int sbr
-1 implicit, 1 presence
static int read_stream_mux_config(struct LATMContext *latmctx, GetBitContext *gb)
void(* flush)(AVBSFContext *ctx)
#define avpriv_request_sample(...)
#define LOAS_SYNC_WORD
11 bits LOAS sync word
static const int16_t alpha[]
This structure stores compressed data.
static uint32_t latm_get_value(GetBitContext *b)
uint8_t max_sfb
number of scalefactor bands per group
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int read_payload_length_info(struct LATMContext *ctx, GetBitContext *gb)
static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, GetBitContext *gb, const AVPacket *avpkt)
enum BandType band_type[128]
band types
@ AOT_AAC_LTP
Y Long Term Prediction.
Generated on Tue Feb 28 2023 21:33:05 for FFmpeg by
doxygen
1.8.17