00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #ifndef AVCODEC_AAC_H
00031 #define AVCODEC_AAC_H
00032
00033 #include "avcodec.h"
00034 #include "dsputil.h"
00035 #include "fft.h"
00036 #include "mpeg4audio.h"
00037 #include "sbr.h"
00038 #include "fmtconvert.h"
00039
00040 #include <stdint.h>
00041
00042 #define MAX_CHANNELS 64
00043 #define MAX_ELEM_ID 16
00044
00045 #define TNS_MAX_ORDER 20
00046 #define MAX_LTP_LONG_SFB 40
00047
00048 enum RawDataBlockType {
00049 TYPE_SCE,
00050 TYPE_CPE,
00051 TYPE_CCE,
00052 TYPE_LFE,
00053 TYPE_DSE,
00054 TYPE_PCE,
00055 TYPE_FIL,
00056 TYPE_END,
00057 };
00058
00059 enum ExtensionPayloadID {
00060 EXT_FILL,
00061 EXT_FILL_DATA,
00062 EXT_DATA_ELEMENT,
00063 EXT_DYNAMIC_RANGE = 0xb,
00064 EXT_SBR_DATA = 0xd,
00065 EXT_SBR_DATA_CRC = 0xe,
00066 };
00067
00068 enum WindowSequence {
00069 ONLY_LONG_SEQUENCE,
00070 LONG_START_SEQUENCE,
00071 EIGHT_SHORT_SEQUENCE,
00072 LONG_STOP_SEQUENCE,
00073 };
00074
00075 enum BandType {
00076 ZERO_BT = 0,
00077 FIRST_PAIR_BT = 5,
00078 ESC_BT = 11,
00079 NOISE_BT = 13,
00080 INTENSITY_BT2 = 14,
00081 INTENSITY_BT = 15,
00082 };
00083
00084 #define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
00085
00086 enum ChannelPosition {
00087 AAC_CHANNEL_OFF = 0,
00088 AAC_CHANNEL_FRONT = 1,
00089 AAC_CHANNEL_SIDE = 2,
00090 AAC_CHANNEL_BACK = 3,
00091 AAC_CHANNEL_LFE = 4,
00092 AAC_CHANNEL_CC = 5,
00093 };
00094
00098 enum CouplingPoint {
00099 BEFORE_TNS,
00100 BETWEEN_TNS_AND_IMDCT,
00101 AFTER_IMDCT = 3,
00102 };
00103
00107 enum OCStatus {
00108 OC_NONE,
00109 OC_TRIAL_PCE,
00110 OC_TRIAL_FRAME,
00111 OC_GLOBAL_HDR,
00112 OC_LOCKED,
00113 };
00114
00115 typedef struct {
00116 MPEG4AudioConfig m4ac;
00117 uint8_t layout_map[MAX_ELEM_ID*4][3];
00118 int layout_map_tags;
00119 int channels;
00120 uint64_t channel_layout;
00121 enum OCStatus status;
00122 } OutputConfiguration;
00123
00127 typedef struct {
00128 float cor0;
00129 float cor1;
00130 float var0;
00131 float var1;
00132 float r0;
00133 float r1;
00134 } PredictorState;
00135
00136 #define MAX_PREDICTORS 672
00137
00138 #define SCALE_DIV_512 36
00139 #define SCALE_ONE_POS 140
00140 #define SCALE_MAX_POS 255
00141 #define SCALE_MAX_DIFF 60
00142 #define SCALE_DIFF_ZERO 60
00143 #define POW_SF2_ZERO 200
00144
00145
00148 typedef struct {
00149 int8_t present;
00150 int16_t lag;
00151 float coef;
00152 int8_t used[MAX_LTP_LONG_SFB];
00153 } LongTermPrediction;
00154
00158 typedef struct {
00159 uint8_t max_sfb;
00160 enum WindowSequence window_sequence[2];
00161 uint8_t use_kb_window[2];
00162 int num_window_groups;
00163 uint8_t group_len[8];
00164 LongTermPrediction ltp;
00165 const uint16_t *swb_offset;
00166 const uint8_t *swb_sizes;
00167 int num_swb;
00168 int num_windows;
00169 int tns_max_bands;
00170 int predictor_present;
00171 int predictor_initialized;
00172 int predictor_reset_group;
00173 uint8_t prediction_used[41];
00174 } IndividualChannelStream;
00175
00179 typedef struct {
00180 int present;
00181 int n_filt[8];
00182 int length[8][4];
00183 int direction[8][4];
00184 int order[8][4];
00185 float coef[8][4][TNS_MAX_ORDER];
00186 } TemporalNoiseShaping;
00187
00191 typedef struct {
00192 int pce_instance_tag;
00193 int dyn_rng_sgn[17];
00194 int dyn_rng_ctl[17];
00195 int exclude_mask[MAX_CHANNELS];
00196 int band_incr;
00197 int interpolation_scheme;
00198 int band_top[17];
00199 int prog_ref_level;
00202 } DynamicRangeControl;
00203
00204 typedef struct {
00205 int num_pulse;
00206 int start;
00207 int pos[4];
00208 int amp[4];
00209 } Pulse;
00210
00214 typedef struct {
00215 enum CouplingPoint coupling_point;
00216 int num_coupled;
00217 enum RawDataBlockType type[8];
00218 int id_select[8];
00219 int ch_select[8];
00222 float gain[16][120];
00223 } ChannelCoupling;
00224
00228 typedef struct {
00229 IndividualChannelStream ics;
00230 TemporalNoiseShaping tns;
00231 Pulse pulse;
00232 enum BandType band_type[128];
00233 int band_type_run_end[120];
00234 float sf[120];
00235 int sf_idx[128];
00236 uint8_t zeroes[128];
00237 DECLARE_ALIGNED(32, float, coeffs)[1024];
00238 DECLARE_ALIGNED(32, float, saved)[1024];
00239 DECLARE_ALIGNED(32, float, ret)[2048];
00240 DECLARE_ALIGNED(16, float, ltp_state)[3072];
00241 PredictorState predictor_state[MAX_PREDICTORS];
00242 } SingleChannelElement;
00243
00247 typedef struct {
00248
00249 int common_window;
00250 int ms_mode;
00251 uint8_t ms_mask[128];
00252
00253 SingleChannelElement ch[2];
00254
00255 ChannelCoupling coup;
00256 SpectralBandReplication sbr;
00257 } ChannelElement;
00258
00262 typedef struct {
00263 AVCodecContext *avctx;
00264 AVFrame frame;
00265
00266 int is_saved;
00267 DynamicRangeControl che_drc;
00268
00273 ChannelElement *che[4][MAX_ELEM_ID];
00274 ChannelElement *tag_che_map[4][MAX_ELEM_ID];
00275 int tags_mapped;
00283 DECLARE_ALIGNED(32, float, buf_mdct)[1024];
00290 FFTContext mdct;
00291 FFTContext mdct_small;
00292 FFTContext mdct_ltp;
00293 DSPContext dsp;
00294 FmtConvertContext fmt_conv;
00295 int random_state;
00302 float *output_data[MAX_CHANNELS];
00303
00305 DECLARE_ALIGNED(32, float, temp)[128];
00306
00307 OutputConfiguration oc[2];
00308 int warned_num_aac_frames;
00309 } AACContext;
00310
00311 #endif