Go to the documentation of this file.
20 #include <fdk-aac/aacdecoder_lib.h>
30 #ifdef AACDECODER_LIB_VL0
31 #define FDKDEC_VER_AT_LEAST(vl0, vl1) \
32 ((AACDECODER_LIB_VL0 > vl0) || \
33 (AACDECODER_LIB_VL0 == vl0 && AACDECODER_LIB_VL1 >= vl1))
35 #define FDKDEC_VER_AT_LEAST(vl0, vl1) 0
38 #if !FDKDEC_VER_AT_LEAST(2, 5) // < 2.5.10
39 #define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
63 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
72 #define DMX_ANC_BUFFSIZE 128
73 #define DECODER_MAX_CHANNELS 8
74 #define DECODER_BUFFSIZE 2048 * sizeof(INT_PCM)
76 #define OFFSET(x) offsetof(FDKAACDecContext, x)
77 #define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM
83 {
"drc_boost",
"Dynamic Range Control: boost, where [0] is none and [127] is max boost",
85 {
"drc_cut",
"Dynamic Range Control: attenuation factor, where [0] is none and [127] is max compression",
87 {
"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",
89 {
"drc_heavy",
"Dynamic Range Control: heavy compression, where [1] is on (RF mode) and [0] is off",
91 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
92 {
"level_limit",
"Signal level limiting",
95 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
96 {
"drc_effect",
"Dynamic Range Control: effect type, where e.g. [0] is none and [6] is general",
99 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
100 {
"album_mode",
"Dynamic Range Control: album mode, where [0] is off and [1] is on",
117 CStreamInfo *
info = aacDecoder_GetStreamInfo(
s->handle);
118 int channel_counts[0x24] = { 0 };
120 uint64_t ch_layout = 0;
127 if (
info->sampleRate <= 0) {
133 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
134 if (!
s->output_delay_set &&
info->outputDelay) {
136 s->flush_samples =
info->outputDelay;
137 s->delay_samples =
info->outputDelay;
138 s->output_delay_set = 1;
142 for (
i = 0;
i <
info->numChannels;
i++) {
143 AUDIO_CHANNEL_TYPE
ctype =
info->pChannelType[
i];
144 if (ctype <= ACT_NONE || ctype >=
FF_ARRAY_ELEMS(channel_counts)) {
148 channel_counts[
ctype]++;
151 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
153 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
154 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
155 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
156 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
158 switch (channel_counts[ACT_FRONT]) {
174 "unsupported number of front channels: %d\n",
175 channel_counts[ACT_FRONT]);
179 if (channel_counts[ACT_SIDE] > 0) {
180 if (channel_counts[ACT_SIDE] == 2) {
184 "unsupported number of side channels: %d\n",
185 channel_counts[ACT_SIDE]);
189 if (channel_counts[ACT_BACK] > 0) {
190 switch (channel_counts[ACT_BACK]) {
202 "unsupported number of back channels: %d\n",
203 channel_counts[ACT_BACK]);
208 if (channel_counts[ACT_LFE] > 0) {
209 if (channel_counts[ACT_LFE] == 1) {
213 "unsupported number of LFE channels: %d\n",
214 channel_counts[ACT_LFE]);
236 aacDecoder_Close(
s->handle);
246 AAC_DECODER_ERROR err;
248 s->handle = aacDecoder_Open(avctx->
extradata_size ? TT_MP4_RAW : TT_MP4_ADTS, 1);
255 if ((err = aacDecoder_ConfigRaw(
s->handle, &avctx->
extradata,
262 if ((err = aacDecoder_SetParam(
s->handle, AAC_CONCEAL_METHOD,
263 s->conceal_method)) != AAC_DEC_OK) {
268 if (
s->downmix_layout.nb_channels > 0 &&
270 int downmix_channels = -1;
272 switch (
s->downmix_layout.u.mask) {
275 downmix_channels = 2;
278 downmix_channels = 1;
285 if (downmix_channels != -1) {
287 downmix_channels) != AAC_DEC_OK) {
291 if (!
s->anc_buffer) {
296 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
303 if (
s->drc_boost != -1) {
304 if (aacDecoder_SetParam(
s->handle, AAC_DRC_BOOST_FACTOR,
s->drc_boost) != AAC_DEC_OK) {
310 if (
s->drc_cut != -1) {
311 if (aacDecoder_SetParam(
s->handle, AAC_DRC_ATTENUATION_FACTOR,
s->drc_cut) != AAC_DEC_OK) {
317 if (
s->drc_level != -1) {
324 if (aacDecoder_SetParam(
s->handle, AAC_DRC_REFERENCE_LEVEL,
s->drc_level) != AAC_DEC_OK) {
330 if (
s->drc_heavy != -1) {
331 if (aacDecoder_SetParam(
s->handle, AAC_DRC_HEAVY_COMPRESSION,
s->drc_heavy) != AAC_DEC_OK) {
337 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
339 if (aacDecoder_SetParam(
s->handle, AAC_PCM_LIMITER_ENABLE,
s->level_limit) != AAC_DEC_OK) {
340 av_log(avctx,
AV_LOG_ERROR,
"Unable to set in signal level limiting in the decoder\n");
345 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
346 if (
s->drc_effect != -1) {
347 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_SET_EFFECT,
s->drc_effect) != AAC_DEC_OK) {
354 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
355 if (
s->album_mode != -1) {
356 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_ALBUM_MODE,
s->album_mode) != AAC_DEC_OK) {
366 s->decoder_buffer =
av_malloc(
s->decoder_buffer_size);
367 if (!
s->decoder_buffer)
374 int *got_frame_ptr,
AVPacket *avpkt)
378 AAC_DECODER_ERROR err;
379 UINT valid = avpkt->
size;
381 int input_offset = 0;
384 err = aacDecoder_Fill(
s->handle, &avpkt->
data, &avpkt->
size, &valid);
385 if (err != AAC_DEC_OK) {
390 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
392 if (
s->flush_samples > 0) {
393 flags |= AACDEC_FLUSH;
402 err = aacDecoder_DecodeFrame(
s->handle, (INT_PCM *)
s->decoder_buffer,
403 s->decoder_buffer_size /
sizeof(INT_PCM),
405 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
409 if (err != AAC_DEC_OK) {
411 "aacDecoder_DecodeFrame() failed: %x\n", err);
420 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
421 if (
flags & AACDEC_FLUSH) {
426 frame->nb_samples,
s->flush_samples);
427 s->flush_samples -=
frame->nb_samples;
432 if (
s->delay_samples) {
433 int drop_samples =
FFMIN(
s->delay_samples,
frame->nb_samples);
435 drop_samples,
s->delay_samples);
436 s->delay_samples -= drop_samples;
437 frame->nb_samples -= drop_samples;
439 if (
frame->nb_samples <= 0)
448 memcpy(
frame->extended_data[0],
s->decoder_buffer + input_offset,
462 AAC_DECODER_ERROR err;
467 if ((err = aacDecoder_SetParam(
s->handle,
468 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
473 .
p.
name =
"libfdk_aac",
483 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
489 .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.
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
#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
#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
@ 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...
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.
@ AV_OPT_TYPE_INT
Underlying C type is int.
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.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#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)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
static av_cold int fdk_aac_decode_init(AVCodecContext *avctx)