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 FF_API_OLD_CHANNEL_LAYOUT
269 if (avctx->request_channel_layout) {
275 if (
s->downmix_layout.nb_channels > 0 &&
277 int downmix_channels = -1;
279 switch (
s->downmix_layout.u.mask) {
282 downmix_channels = 2;
285 downmix_channels = 1;
292 if (downmix_channels != -1) {
294 downmix_channels) != AAC_DEC_OK) {
298 if (!
s->anc_buffer) {
303 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
310 if (
s->drc_boost != -1) {
311 if (aacDecoder_SetParam(
s->handle, AAC_DRC_BOOST_FACTOR,
s->drc_boost) != AAC_DEC_OK) {
317 if (
s->drc_cut != -1) {
318 if (aacDecoder_SetParam(
s->handle, AAC_DRC_ATTENUATION_FACTOR,
s->drc_cut) != AAC_DEC_OK) {
324 if (
s->drc_level != -1) {
331 if (aacDecoder_SetParam(
s->handle, AAC_DRC_REFERENCE_LEVEL,
s->drc_level) != AAC_DEC_OK) {
337 if (
s->drc_heavy != -1) {
338 if (aacDecoder_SetParam(
s->handle, AAC_DRC_HEAVY_COMPRESSION,
s->drc_heavy) != AAC_DEC_OK) {
344 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
346 if (aacDecoder_SetParam(
s->handle, AAC_PCM_LIMITER_ENABLE,
s->level_limit) != AAC_DEC_OK) {
347 av_log(avctx,
AV_LOG_ERROR,
"Unable to set in signal level limiting in the decoder\n");
352 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
353 if (
s->drc_effect != -1) {
354 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_SET_EFFECT,
s->drc_effect) != AAC_DEC_OK) {
361 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
362 if (
s->album_mode != -1) {
363 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_ALBUM_MODE,
s->album_mode) != AAC_DEC_OK) {
373 s->decoder_buffer =
av_malloc(
s->decoder_buffer_size);
374 if (!
s->decoder_buffer)
381 int *got_frame_ptr,
AVPacket *avpkt)
385 AAC_DECODER_ERROR err;
386 UINT valid = avpkt->
size;
388 int input_offset = 0;
391 err = aacDecoder_Fill(
s->handle, &avpkt->
data, &avpkt->
size, &valid);
392 if (err != AAC_DEC_OK) {
397 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
399 if (
s->flush_samples > 0) {
400 flags |= AACDEC_FLUSH;
409 err = aacDecoder_DecodeFrame(
s->handle, (INT_PCM *)
s->decoder_buffer,
410 s->decoder_buffer_size /
sizeof(INT_PCM),
412 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
416 if (err != AAC_DEC_OK) {
418 "aacDecoder_DecodeFrame() failed: %x\n", err);
427 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
428 if (
flags & AACDEC_FLUSH) {
433 frame->nb_samples,
s->flush_samples);
434 s->flush_samples -=
frame->nb_samples;
439 if (
s->delay_samples) {
440 int drop_samples =
FFMIN(
s->delay_samples,
frame->nb_samples);
442 drop_samples,
s->delay_samples);
443 s->delay_samples -= drop_samples;
444 frame->nb_samples -= drop_samples;
446 if (
frame->nb_samples <= 0)
455 memcpy(
frame->extended_data[0],
s->decoder_buffer + input_offset,
469 AAC_DECODER_ERROR err;
474 if ((err = aacDecoder_SetParam(
s->handle,
475 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
480 .
p.
name =
"libfdk_aac",
490 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
497 .p.wrapper_name =
"libfdk",
int frame_size
Number of samples per channel in an audio frame.
#define FF_ENABLE_DEPRECATION_WARNINGS
#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)
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
#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.
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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
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_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.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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
#define AV_CH_FRONT_RIGHT_OF_CENTER
@ CONCEAL_METHOD_ENERGY_INTERPOLATION
AVChannelLayout downmix_layout
#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.
#define AV_CH_BACK_CENTER
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
@ CONCEAL_METHOD_SPECTRAL_MUTING
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
@ CONCEAL_METHOD_NOISE_SUBSTITUTION
FF_ENABLE_DEPRECATION_WARNINGS 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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static av_cold int fdk_aac_decode_close(AVCodecContext *avctx)
const FFCodec ff_libfdk_aac_decoder
main external API structure.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define FF_DISABLE_DEPRECATION_WARNINGS
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)