Go to the documentation of this file.
20 #include <fdk-aac/aacdecoder_lib.h>
29 #ifdef AACDECODER_LIB_VL0
30 #define FDKDEC_VER_AT_LEAST(vl0, vl1) \
31 ((AACDECODER_LIB_VL0 > vl0) || \
32 (AACDECODER_LIB_VL0 == vl0 && AACDECODER_LIB_VL1 >= vl1))
34 #define FDKDEC_VER_AT_LEAST(vl0, vl1) 0
37 #if !FDKDEC_VER_AT_LEAST(2, 5) // < 2.5.10
38 #define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
62 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
71 #define DMX_ANC_BUFFSIZE 128
72 #define DECODER_MAX_CHANNELS 8
73 #define DECODER_BUFFSIZE 2048 * sizeof(INT_PCM)
75 #define OFFSET(x) offsetof(FDKAACDecContext, x)
76 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
82 {
"drc_boost",
"Dynamic Range Control: boost, where [0] is none and [127] is max boost",
84 {
"drc_cut",
"Dynamic Range Control: attenuation factor, where [0] is none and [127] is max compression",
86 {
"drc_level",
"Dynamic Range Control: reference level, quantized to 0.25dB steps where [0] is 0dB and [127] is -31.75dB, -1 for auto, and -2 for disabled",
88 {
"drc_heavy",
"Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
90 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
91 {
"level_limit",
"Signal level limiting",
94 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
95 {
"drc_effect",
"Dynamic Range Control: effect type, where e.g. [0] is none and [6] is general",
98 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
99 {
"album_mode",
"Dynamic Range Control: album mode, where [0] is off and [1] is on",
116 CStreamInfo *
info = aacDecoder_GetStreamInfo(
s->handle);
117 int channel_counts[0x24] = { 0 };
119 uint64_t ch_layout = 0;
126 if (
info->sampleRate <= 0) {
132 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
133 if (!
s->output_delay_set &&
info->outputDelay) {
135 s->flush_samples =
info->outputDelay;
136 s->delay_samples =
info->outputDelay;
137 s->output_delay_set = 1;
141 for (
i = 0;
i <
info->numChannels;
i++) {
142 AUDIO_CHANNEL_TYPE
ctype =
info->pChannelType[
i];
143 if (ctype <= ACT_NONE || ctype >=
FF_ARRAY_ELEMS(channel_counts)) {
147 channel_counts[
ctype]++;
150 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
152 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
153 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
154 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
155 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
157 switch (channel_counts[ACT_FRONT]) {
173 "unsupported number of front channels: %d\n",
174 channel_counts[ACT_FRONT]);
178 if (channel_counts[ACT_SIDE] > 0) {
179 if (channel_counts[ACT_SIDE] == 2) {
183 "unsupported number of side channels: %d\n",
184 channel_counts[ACT_SIDE]);
188 if (channel_counts[ACT_BACK] > 0) {
189 switch (channel_counts[ACT_BACK]) {
201 "unsupported number of back channels: %d\n",
202 channel_counts[ACT_BACK]);
207 if (channel_counts[ACT_LFE] > 0) {
208 if (channel_counts[ACT_LFE] == 1) {
212 "unsupported number of LFE channels: %d\n",
213 channel_counts[ACT_LFE]);
235 aacDecoder_Close(
s->handle);
245 AAC_DECODER_ERROR err;
247 s->handle = aacDecoder_Open(avctx->
extradata_size ? TT_MP4_RAW : TT_MP4_ADTS, 1);
254 if ((err = aacDecoder_ConfigRaw(
s->handle, &avctx->
extradata,
261 if ((err = aacDecoder_SetParam(
s->handle, AAC_CONCEAL_METHOD,
262 s->conceal_method)) != AAC_DEC_OK) {
267 if (
s->downmix_layout.nb_channels > 0 &&
269 int downmix_channels = -1;
271 switch (
s->downmix_layout.u.mask) {
274 downmix_channels = 2;
277 downmix_channels = 1;
284 if (downmix_channels != -1) {
286 downmix_channels) != AAC_DEC_OK) {
290 if (!
s->anc_buffer) {
295 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
302 if (
s->drc_boost != -1) {
303 if (aacDecoder_SetParam(
s->handle, AAC_DRC_BOOST_FACTOR,
s->drc_boost) != AAC_DEC_OK) {
309 if (
s->drc_cut != -1) {
310 if (aacDecoder_SetParam(
s->handle, AAC_DRC_ATTENUATION_FACTOR,
s->drc_cut) != AAC_DEC_OK) {
316 if (
s->drc_level != -1) {
323 if (aacDecoder_SetParam(
s->handle, AAC_DRC_REFERENCE_LEVEL,
s->drc_level) != AAC_DEC_OK) {
329 if (
s->drc_heavy != -1) {
330 if (aacDecoder_SetParam(
s->handle, AAC_DRC_HEAVY_COMPRESSION,
s->drc_heavy) != AAC_DEC_OK) {
336 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
338 if (aacDecoder_SetParam(
s->handle, AAC_PCM_LIMITER_ENABLE,
s->level_limit) != AAC_DEC_OK) {
339 av_log(avctx,
AV_LOG_ERROR,
"Unable to set in signal level limiting in the decoder\n");
344 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
345 if (
s->drc_effect != -1) {
346 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_SET_EFFECT,
s->drc_effect) != AAC_DEC_OK) {
353 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
354 if (
s->album_mode != -1) {
355 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_ALBUM_MODE,
s->album_mode) != AAC_DEC_OK) {
365 s->decoder_buffer =
av_malloc(
s->decoder_buffer_size);
366 if (!
s->decoder_buffer)
373 int *got_frame_ptr,
AVPacket *avpkt)
377 AAC_DECODER_ERROR err;
378 UINT valid = avpkt->
size;
380 int input_offset = 0;
383 err = aacDecoder_Fill(
s->handle, &avpkt->
data, &avpkt->
size, &valid);
384 if (err != AAC_DEC_OK) {
389 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
391 if (
s->flush_samples > 0) {
392 flags |= AACDEC_FLUSH;
401 err = aacDecoder_DecodeFrame(
s->handle, (INT_PCM *)
s->decoder_buffer,
402 s->decoder_buffer_size /
sizeof(INT_PCM),
404 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
408 if (err != AAC_DEC_OK) {
410 "aacDecoder_DecodeFrame() failed: %x\n", err);
419 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
420 if (
flags & AACDEC_FLUSH) {
431 if (
s->delay_samples) {
434 drop_samples,
s->delay_samples);
435 s->delay_samples -= drop_samples;
461 AAC_DECODER_ERROR err;
466 if ((err = aacDecoder_SetParam(
s->handle,
467 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
472 .
p.
name =
"libfdk_aac",
482 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
488 .p.wrapper_name =
"libfdk",
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
int sample_rate
samples per second
#define AVERROR_EOF
End of file.
#define AV_CH_LAYOUT_MONO
This structure describes decoded (raw) audio or video data.
enum AVChannelOrder order
Channel order used in this layout.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int nb_channels
Number of channels in this layout.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
static int get_stream_info(AVCodecContext *avctx)
#define AV_CH_LAYOUT_STEREO
#define AAC_PCM_MAX_OUTPUT_CHANNELS
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define AV_CH_LOW_FREQUENCY
#define FF_CODEC_DECODE_CB(func)
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define CODEC_LONG_NAME(str)
static av_cold void fdk_aac_decode_flush(AVCodecContext *avctx)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const char * av_default_item_name(void *ptr)
Return the context name.
#define AV_CH_FRONT_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
An AVChannelLayout holds information about the channel layout of audio data.
static const AVOption fdk_aac_dec_options[]
enum AVSampleFormat sample_fmt
audio sample format
static const AVClass fdk_aac_dec_class
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
#define AV_CH_FRONT_RIGHT_OF_CENTER
@ CONCEAL_METHOD_ENERGY_INTERPOLATION
AVChannelLayout downmix_layout
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t ** extended_data
pointers to the data planes/channels.
#define AV_CH_BACK_CENTER
@ CONCEAL_METHOD_SPECTRAL_MUTING
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
@ CONCEAL_METHOD_NOISE_SUBSTITUTION
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static av_cold int fdk_aac_decode_close(AVCodecContext *avctx)
const FFCodec ff_libfdk_aac_decoder
main external API structure.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
This structure stores compressed data.
#define flags(name, subs,...)
#define DECODER_MAX_CHANNELS
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int fdk_aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)