FFmpeg
aacenc.h
Go to the documentation of this file.
1 /*
2  * AAC encoder
3  * Copyright (C) 2008 Konstantin Shishkov
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef AVCODEC_AACENC_H
23 #define AVCODEC_AACENC_H
24 
26 #include "libavutil/float_dsp.h"
27 #include "libavutil/mem_internal.h"
28 
29 #include "avcodec.h"
30 #include "put_bits.h"
31 
32 #include "aac.h"
33 #include "audio_frame_queue.h"
34 #include "psymodel.h"
35 
36 #include "lpc.h"
37 
38 typedef enum AACCoder {
42 
44 }AACCoder;
45 
46 typedef struct AACEncOptions {
47  int coder;
48  int pns;
49  int tns;
50  int ltp;
51  int pce;
52  int pred;
53  int mid_side;
56 
57 struct AACEncContext;
58 
59 typedef struct AACCoefficientsEncoder {
61  SingleChannelElement *sce, const float lambda);
63  int win, int group_len, const float lambda);
64  void (*quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size,
65  int scale_idx, int cb, const float lambda, int rtz);
67  void (*encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
79  void (*search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window);
84 
86 
88  float rd;
89  float energy;
90  int bits;
91  char cb;
92  char rtz;
93  uint16_t generation;
95 
96 typedef struct AACPCEInfo {
98  int num_ele[4]; ///< front, side, back, lfe
99  int pairing[3][8]; ///< front, side, back
100  int index[4][8]; ///< front, side, back, lfe
101  uint8_t config_map[16]; ///< configs the encoder's channel specific settings
102  uint8_t reorder_map[16]; ///< maps channels from lavc to aac order
103 } AACPCEInfo;
104 
105 /**
106  * AAC encoder context
107  */
108 typedef struct AACEncContext {
110  AACEncOptions options; ///< encoding options
112  AVTXContext *mdct1024; ///< long (1024 samples) frame transform context
114  AVTXContext *mdct128; ///< short (128 samples) frame transform context
117  AACPCEInfo pce; ///< PCE data, if needed
118  float *planar_samples[16]; ///< saved preprocessed input
119 
120  int profile; ///< copied from avctx
121  int needs_pce; ///< flag for non-standard layout
122  LPCContext lpc; ///< used by TNS
123  int samplerate_index; ///< MPEG-4 samplerate index
124  int channels; ///< channel count
125  const uint8_t *reorder_map; ///< lavc to aac reorder map
126  const uint8_t *chan_map; ///< channel configuration map
127 
128  ChannelElement *cpe; ///< channel elements
132  int cur_channel; ///< current channel for coder context
134  float lambda;
135  int last_frame_pb_count; ///< number of bits for the previous frame
136  float lambda_sum; ///< sum(lambda), for Qvg reporting
137  int lambda_count; ///< count(lambda), for Qvg reporting
138  enum RawDataBlockType cur_type; ///< channel group type cur_channel belongs to
139 
141  DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients
142  DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients
143 
145  AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost
146 
147  void (*abs_pow34)(float *out, const float *in, const int size);
148  void (*quant_bands)(int *out, const float *in, const float *scaled,
149  int size, int is_signed, int maxval, const float Q34,
150  const float rounding);
151 
152  struct {
153  float *samples;
154  } buffer;
155 } AACEncContext;
156 
160 
161 
162 #endif /* AVCODEC_AACENC_H */
AACQuantizeBandCostCacheEntry
Definition: aacenc.h:87
AACCoefficientsEncoder::apply_tns_filt
void(* apply_tns_filt)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:72
AACEncOptions::ltp
int ltp
Definition: aacenc.h:50
AACCoefficientsEncoder::encode_window_bands_info
void(* encode_window_bands_info)(struct AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Definition: aacenc.h:62
AACEncContext::planar_samples
float * planar_samples[16]
saved preprocessed input
Definition: aacenc.h:118
AACCoefficientsEncoder::search_for_quantizers
void(* search_for_quantizers)(AVCodecContext *avctx, struct AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aacenc.h:60
AACQuantizeBandCostCacheEntry::cb
char cb
Definition: aacenc.h:91
AACEncContext::needs_pce
int needs_pce
flag for non-standard layout
Definition: aacenc.h:121
mem_internal.h
AACEncOptions::coder
int coder
Definition: aacenc.h:47
out
FILE * out
Definition: movenc.c:54
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:239
AACEncContext::av_class
AVClass * av_class
Definition: aacenc.h:109
AVTXContext
Definition: tx_priv.h:228
AACEncContext::abs_pow34
void(* abs_pow34)(float *out, const float *in, const int size)
Definition: aacenc.h:147
AACCoefficientsEncoder::search_for_pns
void(* search_for_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:76
AACCoefficientsEncoder::search_for_ms
void(* search_for_ms)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:80
AACEncContext::samplerate_index
int samplerate_index
MPEG-4 samplerate index.
Definition: aacenc.h:123
AACCoefficientsEncoder::search_for_tns
void(* search_for_tns)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:78
AAC_CODER_NB
@ AAC_CODER_NB
Definition: aacenc.h:43
lpc.h
AACQuantizeBandCostCacheEntry::generation
uint16_t generation
Definition: aacenc.h:93
AACCoefficientsEncoder::update_ltp
void(* update_ltp)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:73
AACEncContext::chan_map
const uint8_t * chan_map
channel configuration map
Definition: aacenc.h:126
AAC_CODER_FAST
@ AAC_CODER_FAST
Definition: aacenc.h:41
AACEncContext::buffer
struct AACEncContext::@8 buffer
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
LPCContext
Definition: lpc.h:53
ff_quantize_band_cost_cache_init
void ff_quantize_band_cost_cache_init(struct AACEncContext *s)
Definition: aacenc.c:400
AACEncContext::psy
FFPsyContext psy
Definition: aacenc.h:129
audio_frame_queue.h
AACEncContext::options
AACEncOptions options
encoding options
Definition: aacenc.h:110
AACEncOptions::pce
int pce
Definition: aacenc.h:51
AACPCEInfo::num_ele
int num_ele[4]
front, side, back, lfe
Definition: aacenc.h:98
AACEncContext::fdsp
AVFloatDSPContext * fdsp
Definition: aacenc.h:116
AACEncContext::lambda_count
int lambda_count
count(lambda), for Qvg reporting
Definition: aacenc.h:137
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:127
AACEncContext::lambda_sum
float lambda_sum
sum(lambda), for Qvg reporting
Definition: aacenc.h:136
ff_aac_coders
const AACCoefficientsEncoder ff_aac_coders[]
Definition: aaccoder.c:1119
s
#define s(width, name)
Definition: cbs_vp9.c:256
AudioFrameQueue
Definition: audio_frame_queue.h:32
AACEncContext::reorder_map
const uint8_t * reorder_map
lavc to aac reorder map
Definition: aacenc.h:125
AACCoefficientsEncoder::adjust_common_ltp
void(* adjust_common_ltp)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:70
AACPCEInfo::reorder_map
uint8_t reorder_map[16]
maps channels from lavc to aac order
Definition: aacenc.h:102
AACQuantizeBandCostCacheEntry::energy
float energy
Definition: aacenc.h:89
AACCoefficientsEncoder::encode_ltp_info
void(* encode_ltp_info)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
Definition: aacenc.h:67
PutBitContext
Definition: put_bits.h:50
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AACEncContext::cur_type
enum RawDataBlockType cur_type
channel group type cur_channel belongs to
Definition: aacenc.h:138
AACCoefficientsEncoder::search_for_pred
void(* search_for_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:82
aac.h
AACEncContext::mdct128_fn
av_tx_fn mdct128_fn
Definition: aacenc.h:115
AACEncContext::random_state
int random_state
Definition: aacenc.h:133
AACCoefficientsEncoder::ltp_insert_new_frame
void(* ltp_insert_new_frame)(struct AACEncContext *s)
Definition: aacenc.h:74
AACEncContext::quantize_band_cost_cache_generation
uint16_t quantize_band_cost_cache_generation
Definition: aacenc.h:144
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AACCoefficientsEncoder::adjust_common_pred
void(* adjust_common_pred)(struct AACEncContext *s, ChannelElement *cpe)
Definition: aacenc.h:69
AACEncContext::qcoefs
int qcoefs[96]
quantized coefficients
Definition: aacenc.h:141
float_dsp.h
AACCoefficientsEncoder::apply_main_pred
void(* apply_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:71
AACEncOptions::tns
int tns
Definition: aacenc.h:49
AACPCEInfo
Definition: aacenc.h:96
AACEncContext::samples
float * samples
Definition: aacenc.h:153
AAC_CODER_ANMR
@ AAC_CODER_ANMR
Definition: aacenc.h:39
AACCoefficientsEncoder::set_special_band_scalefactors
void(* set_special_band_scalefactors)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:75
AACEncContext::channels
int channels
channel count
Definition: aacenc.h:124
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
size
int size
Definition: twinvq_data.h:10344
AACCoefficientsEncoder::quantize_and_encode_band
void(* quantize_and_encode_band)(struct AACEncContext *s, PutBitContext *pb, const float *in, float *out, int size, int scale_idx, int cb, const float lambda, int rtz)
Definition: aacenc.h:64
FFPsyPreprocessContext
Definition: psymodel.c:93
AVFloatDSPContext
Definition: float_dsp.h:24
AACEncContext::quant_bands
void(* quant_bands)(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding)
Definition: aacenc.h:148
AAC_CODER_TWOLOOP
@ AAC_CODER_TWOLOOP
Definition: aacenc.h:40
ff_aac_coder_init_mips
void ff_aac_coder_init_mips(AACEncContext *c)
Definition: aaccoder_mips.c:2484
AACCoefficientsEncoder::mark_pns
void(* mark_pns)(struct AACEncContext *s, AVCodecContext *avctx, SingleChannelElement *sce)
Definition: aacenc.h:77
AACPCEInfo::index
int index[4][8]
front, side, back, lfe
Definition: aacenc.h:100
AACEncContext::mdct1024
AVTXContext * mdct1024
long (1024 samples) frame transform context
Definition: aacenc.h:112
AACEncContext::cur_channel
int cur_channel
current channel for coder context
Definition: aacenc.h:132
AACCoder
AACCoder
Definition: aacenc.h:38
AACPCEInfo::config_map
uint8_t config_map[16]
configs the encoder's channel specific settings
Definition: aacenc.h:101
AACEncOptions::intensity_stereo
int intensity_stereo
Definition: aacenc.h:54
AACCoefficientsEncoder::encode_main_pred
void(* encode_main_pred)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:68
RawDataBlockType
RawDataBlockType
Definition: aac.h:54
SingleChannelElement
Single Channel Element - used for both SCE and LFE elements.
Definition: aac.h:246
AACQuantizeBandCostCacheEntry::rd
float rd
Definition: aacenc.h:88
AACCoefficientsEncoder::search_for_is
void(* search_for_is)(struct AACEncContext *s, AVCodecContext *avctx, ChannelElement *cpe)
Definition: aacenc.h:81
ChannelElement
channel element - generic struct for SCE/CPE/CCE/LFE
Definition: aac.h:273
AACPCEInfo::pairing
int pairing[3][8]
front, side, back
Definition: aacenc.h:99
AACQuantizeBandCostCacheEntry::bits
int bits
Definition: aacenc.h:90
ff_aac_dsp_init_x86
void ff_aac_dsp_init_x86(AACEncContext *s)
Definition: aacencdsp_init.c:35
AACEncContext::quantize_band_cost_cache
AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]
memoization area for quantize_band_cost
Definition: aacenc.h:145
AACEncContext::psypp
struct FFPsyPreprocessContext * psypp
Definition: aacenc.h:130
AACCoefficientsEncoder
Definition: aacenc.h:59
AACEncOptions::pns
int pns
Definition: aacenc.h:48
avcodec.h
AACEncOptions::mid_side
int mid_side
Definition: aacenc.h:53
AACEncContext::profile
int profile
copied from avctx
Definition: aacenc.h:120
AACEncContext::lpc
LPCContext lpc
used by TNS
Definition: aacenc.h:122
AACEncContext::afq
AudioFrameQueue afq
Definition: aacenc.h:140
AACEncContext::pce
AACPCEInfo pce
PCE data, if needed.
Definition: aacenc.h:117
AACEncContext
AAC encoder context.
Definition: aacenc.h:108
AACQuantizeBandCostCacheEntry::rtz
char rtz
Definition: aacenc.h:92
AACCoefficientsEncoder::encode_tns_info
void(* encode_tns_info)(struct AACEncContext *s, SingleChannelElement *sce)
Definition: aacenc.h:66
AACEncContext::last_frame_pb_count
int last_frame_pb_count
number of bits for the previous frame
Definition: aacenc.h:135
AVCodecContext
main external API structure.
Definition: avcodec.h:426
AACCoefficientsEncoder::search_for_ltp
void(* search_for_ltp)(struct AACEncContext *s, SingleChannelElement *sce, int common_window)
Definition: aacenc.h:79
AACEncContext::mdct128
AVTXContext * mdct128
short (128 samples) frame transform context
Definition: aacenc.h:114
AACEncContext::scoefs
float scoefs[1024]
scaled coefficients
Definition: aacenc.h:142
channel_layout.h
AACEncContext::coder
const AACCoefficientsEncoder * coder
Definition: aacenc.h:131
AACEncContext::pb
PutBitContext pb
Definition: aacenc.h:111
AACEncOptions::pred
int pred
Definition: aacenc.h:52
AACEncContext::mdct1024_fn
av_tx_fn mdct1024_fn
Definition: aacenc.h:113
AACEncContext::lambda
float lambda
Definition: aacenc.h:134
put_bits.h
FFPsyContext
context used by psychoacoustic model
Definition: psymodel.h:89
AACEncOptions
Definition: aacenc.h:46
psymodel.h
AACEncContext::cpe
ChannelElement * cpe
channel elements
Definition: aacenc.h:128
AACPCEInfo::layout
AVChannelLayout layout
Definition: aacenc.h:97