aacenc.c File Reference

AAC encoder. More...

#include "libavutil/float_dsp.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "put_bits.h"
#include "internal.h"
#include "mpeg4audio.h"
#include "kbdwin.h"
#include "sinewin.h"
#include "aac.h"
#include "aactab.h"
#include "aacenc.h"
#include "psymodel.h"
Include dependency graph for aacenc.c:

Go to the source code of this file.

Macros

#define AAC_MAX_CHANNELS   6
 
#define ERROR_IF(cond, ...)
 
#define WINDOW_FUNC(type)
 
#define AACENC_FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 

Functions

static void put_audio_specific_config (AVCodecContext *avctx)
 Make AAC audio config object. More...
 
 WINDOW_FUNC (only_long)
 
 WINDOW_FUNC (long_start)
 
 WINDOW_FUNC (long_stop)
 
 WINDOW_FUNC (eight_short)
 
static void apply_window_and_mdct (AACEncContext *s, SingleChannelElement *sce, float *audio)
 
static void put_ics_info (AACEncContext *s, IndividualChannelStream *info)
 Encode ics_info element. More...
 
static void encode_ms_info (PutBitContext *pb, ChannelElement *cpe)
 Encode MS data. More...
 
static void adjust_frame_information (ChannelElement *cpe, int chans)
 Produce integer coefficients from scalefactors provided by the model. More...
 
static void encode_band_info (AACEncContext *s, SingleChannelElement *sce)
 Encode scalefactor band coding type. More...
 
static void encode_scale_factors (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce)
 Encode scalefactors. More...
 
static void encode_pulses (AACEncContext *s, Pulse *pulse)
 Encode pulse data. More...
 
static void encode_spectral_coeffs (AACEncContext *s, SingleChannelElement *sce)
 Encode spectral coefficients processed by psychoacoustic model. More...
 
static int encode_individual_channel (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
 Encode one channel of audio data. More...
 
static void put_bitstream_info (AACEncContext *s, const char *name)
 Write some auxiliary information about the created AAC file. More...
 
static void copy_input_samples (AACEncContext *s, const AVFrame *frame)
 
static int aac_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
static av_cold int aac_encode_end (AVCodecContext *avctx)
 
static av_cold int dsp_init (AVCodecContext *avctx, AACEncContext *s)
 
static av_cold int alloc_buffers (AVCodecContext *avctx, AACEncContext *s)
 
static av_cold int aac_encode_init (AVCodecContext *avctx)
 

Variables

float ff_aac_pow34sf_tab [428]
 
static const uint8_t swb_size_1024_96 []
 
static const uint8_t swb_size_1024_64 []
 
static const uint8_t swb_size_1024_48 []
 
static const uint8_t swb_size_1024_32 []
 
static const uint8_t swb_size_1024_24 []
 
static const uint8_t swb_size_1024_16 []
 
static const uint8_t swb_size_1024_8 []
 
static const uint8_tswb_size_1024 []
 
static const uint8_t swb_size_128_96 []
 
static const uint8_t swb_size_128_48 []
 
static const uint8_t swb_size_128_24 []
 
static const uint8_t swb_size_128_16 []
 
static const uint8_t swb_size_128_8 []
 
static const uint8_tswb_size_128 []
 
static const uint8_t aac_chan_configs [6][5]
 default channel configurations More...
 
static const uint8_t aac_chan_maps [AAC_MAX_CHANNELS][AAC_MAX_CHANNELS]
 Table to remap channels from libavcodec's default order to AAC order. More...
 
static void(*const apply_window [4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
 
static const AVOption aacenc_options []
 
static const AVClass aacenc_class
 
static const int mpeg4audio_sample_rates [16]
 
AVCodec ff_aac_encoder
 

Detailed Description

AAC encoder.

Definition in file aacenc.c.

Macro Definition Documentation

#define AAC_MAX_CHANNELS   6

Definition at line 48 of file aacenc.c.

Referenced by aac_encode_frame(), and aac_encode_init().

Definition at line 788 of file aacenc.c.

#define ERROR_IF (   cond,
  ... 
)
Value:
if (cond) { \
av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
return AVERROR(EINVAL); \
}
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
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 This method is called when a frame is wanted on an output For an 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 it should return

Definition at line 50 of file aacenc.c.

Referenced by aac_encode_init().

#define WINDOW_FUNC (   type)
Value:
static void apply_ ##type ##_window(AVFloatDSPContext *fdsp, \
const float *audio)
#define type
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:227

Definition at line 184 of file aacenc.c.

Function Documentation

static av_cold int aac_encode_end ( AVCodecContext avctx)
static

Definition at line 670 of file aacenc.c.

Referenced by aac_encode_init().

static int aac_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int *  got_packet_ptr 
)
static

Definition at line 504 of file aacenc.c.

static av_cold int aac_encode_init ( AVCodecContext avctx)
static

Definition at line 720 of file aacenc.c.

static void adjust_frame_information ( ChannelElement cpe,
int  chans 
)
static

Produce integer coefficients from scalefactors provided by the model.

Definition at line 304 of file aacenc.c.

Referenced by aac_encode_frame().

static av_cold int alloc_buffers ( AVCodecContext avctx,
AACEncContext s 
)
static

Definition at line 705 of file aacenc.c.

Referenced by aac_encode_init().

static void apply_window_and_mdct ( AACEncContext s,
SingleChannelElement sce,
float *  audio 
)
static

Definition at line 249 of file aacenc.c.

Referenced by aac_encode_frame().

static void copy_input_samples ( AACEncContext s,
const AVFrame frame 
)
static

Definition at line 482 of file aacenc.c.

Referenced by aac_encode_frame().

static av_cold int dsp_init ( AVCodecContext avctx,
AACEncContext s 
)
static

Definition at line 685 of file aacenc.c.

Referenced by aac_encode_init().

static void encode_band_info ( AACEncContext s,
SingleChannelElement sce 
)
static

Encode scalefactor band coding type.

Definition at line 366 of file aacenc.c.

Referenced by encode_individual_channel().

static int encode_individual_channel ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
int  common_window 
)
static

Encode one channel of audio data.

Definition at line 442 of file aacenc.c.

Referenced by aac_encode_frame().

static void encode_ms_info ( PutBitContext pb,
ChannelElement cpe 
)
static

Encode MS data.

See also
4.6.8.1 "Joint Coding - M/S Stereo"

Definition at line 290 of file aacenc.c.

Referenced by aac_encode_frame().

static void encode_pulses ( AACEncContext s,
Pulse pulse 
)
static

Encode pulse data.

Definition at line 398 of file aacenc.c.

Referenced by encode_individual_channel().

static void encode_scale_factors ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce 
)
static

Encode scalefactors.

Definition at line 377 of file aacenc.c.

Referenced by encode_individual_channel().

static void encode_spectral_coeffs ( AACEncContext s,
SingleChannelElement sce 
)
static

Encode spectral coefficients processed by psychoacoustic model.

Definition at line 417 of file aacenc.c.

Referenced by encode_individual_channel().

static void put_audio_specific_config ( AVCodecContext avctx)
static

Make AAC audio config object.

See also
1.6.2.1 "Syntax - AudioSpecificConfig"

Definition at line 163 of file aacenc.c.

Referenced by aac_encode_init().

static void put_bitstream_info ( AACEncContext s,
const char *  name 
)
static

Write some auxiliary information about the created AAC file.

Definition at line 461 of file aacenc.c.

Referenced by aac_encode_frame().

static void put_ics_info ( AACEncContext s,
IndividualChannelStream info 
)
static

Encode ics_info element.

See also
Table 4.6 (syntax of ics_info)

Definition at line 269 of file aacenc.c.

Referenced by aac_encode_frame(), and encode_individual_channel().

WINDOW_FUNC ( only_long  )

Definition at line 189 of file aacenc.c.

WINDOW_FUNC ( long_start  )

Definition at line 199 of file aacenc.c.

WINDOW_FUNC ( long_stop  )

Definition at line 211 of file aacenc.c.

WINDOW_FUNC ( eight_short  )

Definition at line 223 of file aacenc.c.

Variable Documentation

const uint8_t aac_chan_configs[6][5]
static
Initial value:
= {
{1, TYPE_SCE},
{1, TYPE_CPE},
{3, TYPE_SCE, TYPE_CPE, TYPE_CPE},
}
Definition: aac.h:49
Definition: aac.h:50
Definition: aac.h:52

default channel configurations

Definition at line 138 of file aacenc.c.

Referenced by aac_encode_init().

const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS]
static
Initial value:
= {
{ 0 },
{ 0, 1 },
{ 2, 0, 1 },
{ 2, 0, 1, 3 },
{ 2, 0, 1, 3, 4 },
{ 2, 0, 1, 4, 5, 3 },
}

Table to remap channels from libavcodec's default order to AAC order.

Definition at line 150 of file aacenc.c.

Referenced by copy_input_samples().

const AVClass aacenc_class
static
Initial value:
= {
"AAC encoder",
}
av_default_item_name
static const AVOption aacenc_options[]
Definition: aacenc.c:789
LIBAVUTIL_VERSION_INT
Definition: eval.c:55

Definition at line 798 of file aacenc.c.

const AVOption aacenc_options[]
static
Initial value:
= {
{"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), AV_OPT_TYPE_INT, {.i64 = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"},
{"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.i64 = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
{"ms_off", "Disable Mid/Side coding", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
{"ms_force", "Force Mid/Side for the whole frame if possible", 0, AV_OPT_TYPE_CONST, {.i64 = 1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"},
{"aac_coder", "", offsetof(AACEncContext, options.aac_coder), AV_OPT_TYPE_INT, {.i64 = 2}, 0, AAC_CODER_NB-1, AACENC_FLAGS},
{NULL}
}
AAC encoder context.
Definition: aacenc.h:57
const OptionDef options[]
Definition: ffserver.c:4697
#define AACENC_FLAGS
Definition: aacenc.c:788
NULL
Definition: eval.c:55
#define AAC_CODER_NB
Definition: aacenc.h:33

Definition at line 789 of file aacenc.c.

void(*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
static
Initial value:
= {
[ONLY_LONG_SEQUENCE] = apply_only_long_window,
[LONG_START_SEQUENCE] = apply_long_start_window,
[EIGHT_SHORT_SEQUENCE] = apply_eight_short_window,
[LONG_STOP_SEQUENCE] = apply_long_stop_window
}

Definition at line 240 of file aacenc.c.

Referenced by apply_window_and_mdct(), and ff_mpa_synth_filter().

AVCodec ff_aac_encoder
Initial value:
= {
.name = "aac",
.priv_data_size = sizeof(AACEncContext),
.encode2 = aac_encode_frame,
.long_name = NULL_IF_CONFIG_SMALL("AAC (Advanced Audio Coding)"),
.priv_class = &aacenc_class,
}
static const AVClass aacenc_class
Definition: aacenc.c:798
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static const int mpeg4audio_sample_rates[16]
Definition: aacenc.c:807
supported_samplerates
float, planar
Definition: samplefmt.h:60
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct AACEncContext AACEncContext
AAC encoder context.
static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: aacenc.c:504
static av_cold int aac_encode_end(AVCodecContext *avctx)
Definition: aacenc.c:670
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static av_cold int aac_encode_init(AVCodecContext *avctx)
Definition: aacenc.c:720
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
#define CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:700

Definition at line 812 of file aacenc.c.

float ff_aac_pow34sf_tab[428]

Definition at line 56 of file aacenc.c.

Referenced by aac_encode_init(), and quantize_and_encode_band_cost_template().

const int mpeg4audio_sample_rates[16]
static
Initial value:
= {
96000, 88200, 64000, 48000, 44100, 32000,
24000, 22050, 16000, 12000, 11025, 8000, 7350
}

Definition at line 807 of file aacenc.c.

const uint8_t* swb_size_1024[]
static
Initial value:
= {
}
static const uint8_t swb_size_1024_64[]
Definition: aacenc.c:64
static const uint8_t swb_size_1024_8[]
Definition: aacenc.c:95
static const uint8_t swb_size_1024_48[]
Definition: aacenc.c:70
static const uint8_t swb_size_1024_24[]
Definition: aacenc.c:83
static const uint8_t swb_size_1024_16[]
Definition: aacenc.c:89
static const uint8_t swb_size_1024_32[]
Definition: aacenc.c:77
static const uint8_t swb_size_1024_96[]
Definition: aacenc.c:58

Definition at line 101 of file aacenc.c.

Referenced by aac_encode_init().

const uint8_t swb_size_1024_16[]
static
Initial value:
= {
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 24, 28, 28,
32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
}

Definition at line 89 of file aacenc.c.

const uint8_t swb_size_1024_24[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28,
32, 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
}

Definition at line 83 of file aacenc.c.

const uint8_t swb_size_1024_32[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
}

Definition at line 77 of file aacenc.c.

const uint8_t swb_size_1024_48[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
96
}

Definition at line 70 of file aacenc.c.

const uint8_t swb_size_1024_64[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
12, 12, 12, 16, 16, 16, 20, 24, 24, 28, 36,
40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40
}

Definition at line 64 of file aacenc.c.

const uint8_t swb_size_1024_8[]
static
Initial value:
= {
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 28,
32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
}

Definition at line 95 of file aacenc.c.

const uint8_t swb_size_1024_96[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
}

Definition at line 58 of file aacenc.c.

const uint8_t* swb_size_128[]
static
Initial value:
= {
}
static const uint8_t swb_size_128_8[]
Definition: aacenc.c:124
static const uint8_t swb_size_128_96[]
Definition: aacenc.c:108
static const uint8_t swb_size_128_48[]
Definition: aacenc.c:112
static const uint8_t swb_size_128_24[]
Definition: aacenc.c:116
static const uint8_t swb_size_128_16[]
Definition: aacenc.c:120

Definition at line 128 of file aacenc.c.

Referenced by aac_encode_init().

const uint8_t swb_size_128_16[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
}

Definition at line 120 of file aacenc.c.

const uint8_t swb_size_128_24[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
}

Definition at line 116 of file aacenc.c.

const uint8_t swb_size_128_48[]
static
Initial value:
= {
4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
}

Definition at line 112 of file aacenc.c.

const uint8_t swb_size_128_8[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
}

Definition at line 124 of file aacenc.c.

const uint8_t swb_size_128_96[]
static
Initial value:
= {
4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
}

Definition at line 108 of file aacenc.c.