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) {
136 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
137 if (!
s->output_delay_set &&
info->outputDelay) {
139 s->flush_samples =
info->outputDelay;
140 s->delay_samples =
info->outputDelay;
141 s->output_delay_set = 1;
145 for (
i = 0;
i <
info->numChannels;
i++) {
146 AUDIO_CHANNEL_TYPE
ctype =
info->pChannelType[
i];
147 if (ctype <= ACT_NONE || ctype >=
FF_ARRAY_ELEMS(channel_counts)) {
151 channel_counts[
ctype]++;
154 "%d channels - front:%d side:%d back:%d lfe:%d top:%d\n",
156 channel_counts[ACT_FRONT], channel_counts[ACT_SIDE],
157 channel_counts[ACT_BACK], channel_counts[ACT_LFE],
158 channel_counts[ACT_FRONT_TOP] + channel_counts[ACT_SIDE_TOP] +
159 channel_counts[ACT_BACK_TOP] + channel_counts[ACT_TOP]);
161 switch (channel_counts[ACT_FRONT]) {
177 "unsupported number of front channels: %d\n",
178 channel_counts[ACT_FRONT]);
182 if (channel_counts[ACT_SIDE] > 0) {
183 if (channel_counts[ACT_SIDE] == 2) {
187 "unsupported number of side channels: %d\n",
188 channel_counts[ACT_SIDE]);
192 if (channel_counts[ACT_BACK] > 0) {
193 switch (channel_counts[ACT_BACK]) {
205 "unsupported number of back channels: %d\n",
206 channel_counts[ACT_BACK]);
211 if (channel_counts[ACT_LFE] > 0) {
212 if (channel_counts[ACT_LFE] == 1) {
216 "unsupported number of LFE channels: %d\n",
217 channel_counts[ACT_LFE]);
239 aacDecoder_Close(
s->handle);
249 AAC_DECODER_ERROR err;
251 s->handle = aacDecoder_Open(avctx->
extradata_size ? TT_MP4_RAW : TT_MP4_ADTS, 1);
258 if ((err = aacDecoder_ConfigRaw(
s->handle, &avctx->
extradata,
265 if ((err = aacDecoder_SetParam(
s->handle, AAC_CONCEAL_METHOD,
266 s->conceal_method)) != AAC_DEC_OK) {
271 if (
s->downmix_layout.nb_channels > 0 &&
273 int downmix_channels = -1;
275 switch (
s->downmix_layout.u.mask) {
278 downmix_channels = 2;
281 downmix_channels = 1;
288 if (downmix_channels != -1) {
290 downmix_channels) != AAC_DEC_OK) {
294 if (!
s->anc_buffer) {
299 av_log(avctx,
AV_LOG_ERROR,
"Unable to register downmix ancillary buffer in the decoder\n");
306 if (
s->drc_boost != -1) {
307 if (aacDecoder_SetParam(
s->handle, AAC_DRC_BOOST_FACTOR,
s->drc_boost) != AAC_DEC_OK) {
313 if (
s->drc_cut != -1) {
314 if (aacDecoder_SetParam(
s->handle, AAC_DRC_ATTENUATION_FACTOR,
s->drc_cut) != AAC_DEC_OK) {
320 if (
s->drc_level != -1) {
327 if (aacDecoder_SetParam(
s->handle, AAC_DRC_REFERENCE_LEVEL,
s->drc_level) != AAC_DEC_OK) {
333 if (
s->drc_heavy != -1) {
334 if (aacDecoder_SetParam(
s->handle, AAC_DRC_HEAVY_COMPRESSION,
s->drc_heavy) != AAC_DEC_OK) {
340 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
342 if (aacDecoder_SetParam(
s->handle, AAC_PCM_LIMITER_ENABLE,
s->level_limit) != AAC_DEC_OK) {
343 av_log(avctx,
AV_LOG_ERROR,
"Unable to set in signal level limiting in the decoder\n");
348 #if FDKDEC_VER_AT_LEAST(3, 0) // 3.0.0
349 if (
s->drc_effect != -1) {
350 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_SET_EFFECT,
s->drc_effect) != AAC_DEC_OK) {
357 #if FDKDEC_VER_AT_LEAST(3, 1) // 3.1.0
358 if (
s->album_mode != -1) {
359 if (aacDecoder_SetParam(
s->handle, AAC_UNIDRC_ALBUM_MODE,
s->album_mode) != AAC_DEC_OK) {
369 s->decoder_buffer =
av_malloc(
s->decoder_buffer_size);
370 if (!
s->decoder_buffer)
377 int *got_frame_ptr,
AVPacket *avpkt)
381 AAC_DECODER_ERROR err;
382 UINT valid = avpkt->
size;
384 int input_offset = 0;
387 err = aacDecoder_Fill(
s->handle, &avpkt->
data, &avpkt->
size, &valid);
388 if (err != AAC_DEC_OK) {
393 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
395 if (
s->flush_samples > 0) {
396 flags |= AACDEC_FLUSH;
405 err = aacDecoder_DecodeFrame(
s->handle, (INT_PCM *)
s->decoder_buffer,
406 s->decoder_buffer_size /
sizeof(INT_PCM),
408 if (err == AAC_DEC_NOT_ENOUGH_BITS) {
412 if (err != AAC_DEC_OK) {
414 "aacDecoder_DecodeFrame() failed: %x\n", err);
423 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
424 if (
flags & AACDEC_FLUSH) {
429 frame->nb_samples,
s->flush_samples);
430 s->flush_samples -=
frame->nb_samples;
435 if (
s->delay_samples) {
436 int drop_samples =
FFMIN(
s->delay_samples,
frame->nb_samples);
438 drop_samples,
s->delay_samples);
439 s->delay_samples -= drop_samples;
440 frame->nb_samples -= drop_samples;
442 if (
frame->nb_samples <= 0)
451 memcpy(
frame->extended_data[0],
s->decoder_buffer + input_offset,
465 AAC_DECODER_ERROR err;
470 if ((err = aacDecoder_SetParam(
s->handle,
471 AAC_TPDEC_CLEAR_BUFFER, 1)) != AAC_DEC_OK)
476 .
p.
name =
"libfdk_aac",
486 #if FDKDEC_VER_AT_LEAST(2, 5) // 2.5.10
492 .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.
#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_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#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
static int get_stream_info(AVCodecContext *avctx, AVFrame *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.
#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)