49 #define AAC_MAX_CHANNELS 6
51 #define ERROR_IF(cond, ...) \
53 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
54 return AVERROR(EINVAL); \
60 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8,
61 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44,
62 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
66 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
67 12, 12, 12, 16, 16, 16, 20, 24, 24, 28, 36,
68 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40
72 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
73 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
74 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
79 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8,
80 12, 12, 12, 12, 16, 16, 20, 20, 24, 24, 28, 28,
81 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32
85 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
86 12, 12, 12, 12, 16, 16, 16, 20, 20, 24, 24, 28, 28,
87 32, 36, 36, 40, 44, 48, 52, 52, 64, 64, 64, 64, 64
91 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
92 12, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 20, 20, 20, 24, 24, 28, 28,
93 32, 36, 40, 40, 44, 48, 52, 56, 60, 64, 64, 64
97 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
98 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 28, 28,
99 32, 36, 36, 40, 44, 48, 52, 56, 60, 64, 80
110 4, 4, 4, 4, 4, 4, 8, 8, 8, 16, 28, 36
114 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16
118 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 20
122 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 12, 12, 16, 20, 20
126 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 12, 16, 20, 20
157 { 2, 0, 1, 4, 5, 3 },
185 #define WINDOW_FUNC(type) \
186 static void apply_ ##type ##_window(DSPContext *dsp, AVFloatDSPContext *fdsp, \
187 SingleChannelElement *sce, \
194 float *out = sce->ret_buf;
196 fdsp->vector_fmul (out, audio, lwindow, 1024);
197 dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024);
204 float *out = sce->ret_buf;
206 fdsp->vector_fmul(out, audio, lwindow, 1024);
207 memcpy(out + 1024, audio + 1024,
sizeof(out[0]) * 448);
208 dsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128);
209 memset(out + 1024 + 576, 0,
sizeof(out[0]) * 448);
216 float *out = sce->ret_buf;
218 memset(out, 0,
sizeof(out[0]) * 448);
219 fdsp->vector_fmul(out + 448, audio + 448, swindow, 128);
220 memcpy(out + 576, audio + 576,
sizeof(out[0]) * 448);
221 dsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024);
228 const float *in = audio + 448;
229 float *out = sce->ret_buf;
232 for (w = 0; w < 8; w++) {
233 fdsp->vector_fmul (out, in, w ? pwindow : swindow, 128);
236 dsp->vector_fmul_reverse(out, in, swindow, 128);
243 const float *audio) = {
261 for (i = 0; i < 1024; i += 128)
263 memcpy(audio, audio + 1024,
sizeof(audio[0]) * 1024);
282 for (w = 1; w < 8; w++)
308 int start, maxsfb, cmaxsfb;
310 for (ch = 0; ch < chans; ch++) {
316 for (g = 0; g < ics->
num_swb; g++) {
326 for (cmaxsfb = ics->
num_swb; cmaxsfb > 0 && cpe->
ch[ch].
zeroes[w+cmaxsfb-1]; cmaxsfb--)
328 maxsfb =
FFMAX(maxsfb, cmaxsfb);
334 for (g = 0; g < ics->
max_sfb; g++) {
336 for (w2 = w; w2 < w + ics->
group_len[w]; w2++) {
337 if (!cpe->
ch[ch].
zeroes[w2*16 + g]) {
354 for (i = 0; i < ics0->
max_sfb; i++)
357 if (msc == 0 || ics0->
max_sfb == 0)
386 if (!sce->
zeroes[w*16 + i]) {
388 if (diff < 0 || diff > 120)
390 off = sce->
sf_idx[w*16 + i];
426 if (sce->
zeroes[w*16 + i]) {
465 int i, namelen, padbits;
467 namelen = strlen(name) + 2;
475 for (i = 0; i < namelen - 2; i++)
487 int end = 2048 + (frame ? frame->
nb_samples : 0);
491 for (ch = 0; ch < s->
channels; ch++) {
507 const AVFrame *frame,
int *got_packet_ptr)
512 int i, ch, w,
g, chans,
tag, start_ch, ret;
513 int chan_el_counter[4];
533 for (i = 0; i < s->
chan_map[0]; i++) {
538 for (ch = 0; ch < chans; ch++) {
540 int cur_channel = start_ch + ch;
541 overlap = &samples[cur_channel][0];
542 samples2 = overlap + 1024;
543 la = samples2 + (448+64);
588 memset(chan_el_counter, 0,
sizeof(chan_el_counter));
589 for (i = 0; i < s->
chan_map[0]; i++) {
597 for (ch = 0; ch < chans; ch++)
600 for (ch = 0; ch < chans; ch++) {
606 && wi[0].window_type[0] == wi[1].window_type[0]
607 && wi[0].window_shape == wi[1].window_shape) {
611 if (wi[0].grouping[w] != wi[1].grouping[w]) {
622 for (g = 0; g < ics->
num_swb; g++)
636 for (ch = 0; ch < chans; ch++) {
644 if (frame_bits <= 6144 * s->channels - 3) {
687 #if FF_API_OLD_ENCODE_AUDIO
744 for (i = 0; i < 16; i++)
751 "Unsupported sample rate %d\n", avctx->
sample_rate);
753 "Unsupported number of channels: %d\n", s->
channels);
755 "Unsupported profile %d\n", avctx->
profile);
757 "Too many bits per frame requested\n");
776 for (i = 0; i < s->
chan_map[0]; i++)
787 for (i = 0; i < 428; i++)
799 #define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
801 {
"stereo_mode",
"Stereo coding method", offsetof(
AACEncContext,
options.stereo_mode),
AV_OPT_TYPE_INT, {.i64 = 0}, -1, 1,
AACENC_FLAGS,
"stereo_mode"},
804 {
"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"},
static const int16_t coeffs[28]
static const uint8_t aac_chan_configs[6][5]
default channel configurations
av_cold void ff_dsputil_init(DSPContext *c, AVCodecContext *avctx)
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe, const float lambda)
#define CODEC_FLAG_BITEXACT
uint8_t use_kb_window[2]
If set, use Kaiser-Bessel window, otherwise use a sinus window.
This structure describes decoded (raw) audio or video data.
static const uint8_t swb_size_1024_64[]
int grouping[8]
window grouping (for e.g. AAC)
uint8_t ** bands
scalefactor band sizes for possible frame sizes
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static const AVClass aacenc_class
av_cold void ff_kbd_window_init(float *window, float alpha, int n)
Generate a Kaiser-Bessel Derived Window.
#define SCALE_DIFF_ZERO
codebook index corresponding to zero scalefactor indices difference
AVFrame * coded_frame
the picture in the bitstream
av_cold void ff_psy_preprocess_end(struct FFPsyPreprocessContext *ctx)
Cleanup audio preprocessing module.
struct AACEncContext::@3 buffer
AACCoefficientsEncoder * coder
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static void put_ics_info(AACEncContext *s, IndividualChannelStream *info)
Encode ics_info element.
int common_window
Set if channels share a common 'IndividualChannelStream' in bitstream.
av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, const uint8_t **bands, const int *num_bands, int num_groups, const uint8_t *group_map)
Initialize psychoacoustic model.
uint8_t ms_mask[128]
Set if mid/side stereo is used for each scalefactor window band.
static const uint8_t swb_size_128_8[]
static const uint8_t swb_size_1024_8[]
static const uint8_t swb_size_128_96[]
static void encode_spectral_coeffs(AACEncContext *s, SingleChannelElement *sce)
Encode spectral coefficients processed by psychoacoustic model.
int * num_bands
number of scalefactor bands for possible frame sizes
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const uint8_t ff_aac_num_swb_128[]
AACEncOptions options
encoding options
#define WINDOW_FUNC(type)
void(* quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
SingleChannelElement ch[2]
int samplerate_index
MPEG-4 samplerate index.
const uint8_t * chan_map
channel configuration map
const uint8_t ff_aac_scalefactor_bits[121]
#define CODEC_FLAG_QSCALE
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static const uint8_t swb_size_1024_48[]
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
static void adjust_frame_information(ChannelElement *cpe, int chans)
Produce integer coefficients from scalefactors provided by the model.
static int init(AVCodecParserContext *s)
static const AVOption aacenc_options[]
static const uint8_t swb_size_1024_24[]
float coeffs[1024]
coefficients for IMDCT
#define CODEC_CAP_SMALL_LAST_FRAME
static void(*const apply_window[4])(DSPContext *dsp, AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
static const int sizes[][2]
const uint8_t ff_aac_num_swb_1024[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
float ff_aac_kbd_long_1024[1024]
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
int num_windows
number of windows in a frame
static void copy_input_samples(AACEncContext *s, const AVFrame *frame)
uint8_t max_sfb
number of scalefactor bands per group
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
int num_swb
number of scalefactor window bands
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
static int put_bits_count(PutBitContext *s)
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
struct AACEncContext AACEncContext
AAC encoder context.
int bit_rate
the average bitrate
enum WindowSequence window_sequence[2]
static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
void(* analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi)
Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels...
static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS]
Table to remap channels from Libav's default order to AAC order.
#define CODEC_CAP_EXPERIMENTAL
int channels
channel count
int ff_alloc_packet(AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
AAC definitions and structures.
FFTContext mdct128
short (128 samples) frame transform context
float ff_aac_pow34sf_tab[428]
static const uint8_t swb_size_128_48[]
static const uint8_t swb_size_128_24[]
static const uint8_t swb_size_1024_16[]
static av_cold int aac_encode_end(AVCodecContext *avctx)
int frame_size
Number of samples per channel in an audio frame.
static const uint8_t swb_size_1024_32[]
static void put_audio_specific_config(AVCodecContext *avctx)
Make AAC audio config object.
int sample_rate
samples per second
float ff_aac_kbd_short_128[128]
static void encode_ms_info(PutBitContext *pb, ChannelElement *cpe)
Encode MS data.
FFPsyWindowInfo(* window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type)
Suggest window sequence for channel.
int frame_bits
number of bits used for the previously encoded frame
main external API structure.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
static void close(AVCodecParserContext *s)
int bits
number of bits used in the bitresevoir
IndividualChannelStream ics
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Describe the class of an AVClass context structure.
static void put_bitstream_info(AACEncContext *s, const char *name)
Write some auxiliary information about the created AAC file.
static const uint8_t swb_size_1024_96[]
int window_shape
window shape (sine/KBD/whatever)
static void encode_pulses(AACEncContext *s, Pulse *pulse)
Encode pulse data.
static const uint8_t swb_size_128_16[]
#define FF_INPUT_BUFFER_PADDING_SIZE
const uint8_t * swb_sizes
table of scalefactor band sizes for a particular window
struct FFPsyContext::@51 bitres
const uint32_t ff_aac_scalefactor_code[121]
static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s)
const struct FFPsyModel * model
encoder-specific model functions
int ms_mode
Signals mid/side stereo flags coding mode (used by encoder)
static const uint8_t * swb_size_1024[]
struct FFPsyPreprocessContext * psypp
int global_quality
Global quality for codecs which cannot change it per frame.
uint8_t zeroes[128]
band is not coded (used by encoder)
int sf_idx[128]
scalefactor indices (used by encoder)
#define FF_PROFILE_AAC_LOW
const int avpriv_mpeg4audio_sample_rates[16]
const OptionDef options[]
Y Spectral Band Replication.
static av_cold int aac_encode_init(AVCodecContext *avctx)
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Single Channel Element - used for both SCE and LFE elements.
windowing related information
av_cold struct FFPsyPreprocessContext * ff_psy_preprocess_init(AVCodecContext *avctx)
psychoacoustic model audio preprocessing initialization
AACCoefficientsEncoder ff_aac_coders[]
void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels)
Preprocess several channel in audio frame in order to compress it better.
static void encode_scale_factors(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce)
Encode scalefactors.
AVSampleFormat
Audio Sample Formats.
ChannelElement * cpe
channel elements
Individual Channel Stream.
float ff_aac_pow2sf_tab[428]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static const uint8_t * swb_size_128[]
channel element - generic struct for SCE/CPE/CCE/LFE
FFTContext mdct1024
long (1024 samples) frame transform context
#define ERROR_IF(cond,...)
void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int *duration)
Remove frame(s) from the queue.
int channels
number of audio channels
static void encode_band_info(AACEncContext *s, SingleChannelElement *sce)
Encode scalefactor band coding type.
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
enum BandType band_type[128]
band types
#define FF_API_OLD_ENCODE_AUDIO
int frame_number
Frame counter, set by libavcodec.
float ret_buf[2048]
PCM output buffer.
void ff_aac_tableinit(void)
static int encode_individual_channel(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, int common_window)
Encode one channel of audio data.
void avpriv_float_dsp_init(AVFloatDSPContext *fdsp, int bit_exact)
Initialize a float DSP context.
static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, float *audio)
uint8_t ** extended_data
pointers to the data planes/channels.
av_cold void ff_psy_end(FFPsyContext *ctx)
Cleanup model context at the end.
This structure stores compressed data.
int window_type[3]
window type (short/long/transitional, etc.) - current, previous and next
int nb_samples
number of audio samples (per channel) described by this frame
static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)
float * planar_samples[6]
saved preprocessed input
#define FF_PROFILE_UNKNOWN
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)