blob: 4d99267b0da9612ca648619ab16fe38d96c00739 [file] [log] [blame]
xingri.gaoc18d4472023-02-28 02:51:02 +00001/*
2** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18**
19** Any non-GPL usage of this software or parts of this software is strictly
20** forbidden.
21**
22** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24**
25** Commercial non-GPL licensing of this software is possible.
26** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27**
28** $Id: structs.h,v 1.49 2009/01/26 23:51:15 menno Exp $
29**/
30
31#ifndef __STRUCTS_H__
32#define __STRUCTS_H__
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include "cfft.h"
39#ifdef SBR_DEC
40#include "sbr_dec.h"
41#endif
42
43#define MAX_CHANNELS 64
44#define MAX_SYNTAX_ELEMENTS 48
45#define MAX_WINDOW_GROUPS 8
46#define MAX_SFB 51
47#define MAX_LTP_SFB 40
48#define MAX_LTP_SFB_S 8
49#define DEC_BUF_SIZE 6 * 1024
50#define OUT_BUF_SIZE 8 * 1024
51#define TMP_BUF_SIZE 20 * 1024
52
53 /* used to save the prediction state */
54 typedef struct {
55 int16_t r[2];
56 int16_t COR[2];
57 int16_t VAR[2];
58 } pred_state;
59
60 typedef struct {
61 uint16_t N;
62 cfft_info *cfft;
63 complex_t *sincos;
64#ifdef PROFILE
65 int64_t cycles;
66 int64_t fft_cycles;
67#endif
68 } mdct_info;
69
70 typedef struct {
71 const real_t *long_window[2];
72 const real_t *short_window[2];
73#ifdef LD_DEC
74 const real_t *ld_window[2];
75#endif
76
77 mdct_info *mdct256;
78#ifdef LD_DEC
79 mdct_info *mdct1024;
80#endif
81 mdct_info *mdct2048;
82#ifdef PROFILE
83 int64_t cycles;
84#endif
85 } fb_info;
86
87 typedef struct {
88 uint8_t present;
89
90 uint8_t num_bands;
91 uint8_t pce_instance_tag;
92 uint8_t excluded_chns_present;
93 uint8_t band_top[17];
94 uint8_t prog_ref_level;
95 uint8_t dyn_rng_sgn[17];
96 uint8_t dyn_rng_ctl[17];
97 uint8_t exclude_mask[MAX_CHANNELS];
98 uint8_t additional_excluded_chns[MAX_CHANNELS];
99
100 real_t ctrl1;
101 real_t ctrl2;
102 } drc_info;
103
104 typedef struct {
105 uint8_t element_instance_tag;
106 uint8_t object_type;
107 uint8_t sf_index;
108 uint8_t num_front_channel_elements;
109 uint8_t num_side_channel_elements;
110 uint8_t num_back_channel_elements;
111 uint8_t num_lfe_channel_elements;
112 uint8_t num_assoc_data_elements;
113 uint8_t num_valid_cc_elements;
114 uint8_t mono_mixdown_present;
115 uint8_t mono_mixdown_element_number;
116 uint8_t stereo_mixdown_present;
117 uint8_t stereo_mixdown_element_number;
118 uint8_t matrix_mixdown_idx_present;
119 uint8_t pseudo_surround_enable;
120 uint8_t matrix_mixdown_idx;
121 uint8_t front_element_is_cpe[16];
122 uint8_t front_element_tag_select[16];
123 uint8_t side_element_is_cpe[16];
124 uint8_t side_element_tag_select[16];
125 uint8_t back_element_is_cpe[16];
126 uint8_t back_element_tag_select[16];
127 uint8_t lfe_element_tag_select[16];
128 uint8_t assoc_data_element_tag_select[16];
129 uint8_t cc_element_is_ind_sw[16];
130 uint8_t valid_cc_element_tag_select[16];
131
132 uint8_t channels;
133
134 uint8_t comment_field_bytes;
135 uint8_t comment_field_data[257];
136
137 /* extra added values */
138 uint8_t num_front_channels;
139 uint8_t num_side_channels;
140 uint8_t num_back_channels;
141 uint8_t num_lfe_channels;
142 uint8_t sce_channel[16];
143 uint8_t cpe_channel[16];
144 } program_config;
145
146 typedef struct {
147 uint16_t syncword;
148 uint8_t id;
149 uint8_t layer;
150 uint8_t protection_absent;
151 uint8_t profile;
152 uint8_t sf_index;
153 uint8_t private_bit;
154 uint8_t channel_configuration;
155 uint8_t original;
156 uint8_t home;
157 uint8_t emphasis;
158 uint8_t copyright_identification_bit;
159 uint8_t copyright_identification_start;
160 uint16_t aac_frame_length;
161 uint16_t adts_buffer_fullness;
162 uint8_t no_raw_data_blocks_in_frame;
163 uint16_t crc_check;
164
165 /* control param */
166 uint8_t old_format;
167 } adts_header;
168
169 typedef struct {
170 uint8_t copyright_id_present;
171 int8_t copyright_id[10];
172 uint8_t original_copy;
173 uint8_t home;
174 uint8_t bitstream_type;
175 uint32_t bitrate;
176 uint8_t num_program_config_elements;
177 uint32_t adif_buffer_fullness;
178
179 /* maximum of 16 PCEs */
180 program_config pce[16];
181 } adif_header;
182
183#ifdef LTP_DEC
184 typedef struct {
185 uint8_t last_band;
186 uint8_t data_present;
187 uint16_t lag;
188 uint8_t lag_update;
189 uint8_t coef;
190 uint8_t long_used[MAX_SFB];
191 uint8_t short_used[8];
192 uint8_t short_lag_present[8];
193 uint8_t short_lag[8];
194 } ltp_info;
195#endif
196
197#ifdef MAIN_DEC
198 typedef struct {
199 uint8_t limit;
200 uint8_t predictor_reset;
201 uint8_t predictor_reset_group_number;
202 uint8_t prediction_used[MAX_SFB];
203 } pred_info;
204#endif
205
206 typedef struct {
207 uint8_t number_pulse;
208 uint8_t pulse_start_sfb;
209 uint8_t pulse_offset[4];
210 uint8_t pulse_amp[4];
211 } pulse_info;
212
213 typedef struct {
214 uint8_t n_filt[8];
215 uint8_t coef_res[8];
216 uint8_t length[8][4];
217 uint8_t order[8][4];
218 uint8_t direction[8][4];
219 uint8_t coef_compress[8][4];
220 uint8_t coef[8][4][32];
221 } tns_info;
222
223#ifdef SSR_DEC
224 typedef struct {
225 uint8_t max_band;
226
227 uint8_t adjust_num[4][8];
228 uint8_t alevcode[4][8][8];
229 uint8_t aloccode[4][8][8];
230 } ssr_info;
231#endif
232
233 typedef struct {
234 uint8_t max_sfb;
235
236 uint8_t num_swb;
237 uint8_t num_window_groups;
238 uint8_t num_windows;
239 uint8_t window_sequence;
240 uint8_t window_group_length[8];
241 uint8_t window_shape;
242 uint8_t scale_factor_grouping;
243 uint16_t sect_sfb_offset[8][15 * 8];
244 uint16_t swb_offset[52];
245 uint16_t swb_offset_max;
246
247 uint8_t sect_cb[8][15 * 8];
248 uint16_t sect_start[8][15 * 8];
249 uint16_t sect_end[8][15 * 8];
250 uint8_t sfb_cb[8][8 * 15];
251 uint8_t num_sec[8]; /* number of sections in a group */
252
253 uint8_t global_gain;
254 int16_t scale_factors[8][51]; /* [0..255] */
255
256 uint8_t ms_mask_present;
257 uint8_t ms_used[MAX_WINDOW_GROUPS][MAX_SFB];
258
259 uint8_t noise_used;
260 uint8_t is_used;
261
262 uint8_t pulse_data_present;
263 uint8_t tns_data_present;
264 uint8_t gain_control_data_present;
265 uint8_t predictor_data_present;
266
267 pulse_info pul;
268 tns_info tns;
269#ifdef MAIN_DEC
270 pred_info pred;
271#endif
272#ifdef LTP_DEC
273 ltp_info ltp;
274 ltp_info ltp2;
275#endif
276#ifdef SSR_DEC
277 ssr_info ssr;
278#endif
279
280#ifdef ERROR_RESILIENCE
281 /* ER HCR data */
282 uint16_t length_of_reordered_spectral_data;
283 uint8_t length_of_longest_codeword;
284 /* ER RLVC data */
285 uint8_t sf_concealment;
286 uint8_t rev_global_gain;
287 uint16_t length_of_rvlc_sf;
288 uint16_t dpcm_noise_nrg;
289 uint8_t sf_escapes_present;
290 uint8_t length_of_rvlc_escapes;
291 uint16_t dpcm_noise_last_position;
292#endif
293 } ic_stream; /* individual channel stream */
294
295 typedef struct {
296 uint8_t channel;
297 int16_t paired_channel;
298
299 uint8_t element_instance_tag;
300 uint8_t common_window;
301
302 ic_stream ics1;
303 ic_stream ics2;
304 } element; /* syntax element (SCE, CPE, LFE) */
305
306#define MAX_ASC_BYTES 64
307 typedef struct {
308 int inited;
309 int version, versionA;
310 int framelen_type;
311 int useSameStreamMux;
312 int allStreamsSameTimeFraming;
313 int numSubFrames;
314 int numPrograms;
315 int numLayers;
316 int otherDataPresent;
317 uint32_t otherDataLenBits;
318 uint32_t frameLength;
319 uint8_t ASC[MAX_ASC_BYTES];
320 uint32_t ASCbits;
321 } latm_header;
322
323#define NEW_CODE_CHECK_LATM
324#ifdef NEW_CODE_CHECK_LATM
325#define LOAS_HEADER_SIZE 3
326 /****************************************************************************
327 * LOAS helpers
328 ****************************************************************************/
329#define LATM_MAX_EXTRA_SIZE 64
330 typedef struct {
331 int i_object_type;
332 int i_samplerate;
333 int i_channel;
334 int i_sbr; // 0: no sbr, 1: sbr, -1: unknown
335 int i_ps; // 0: no ps, 1: ps, -1: unknown
336
337 struct {
338 int i_object_type;
339 int i_samplerate;
340 } extension;
341
342 /* GASpecific */
343 int i_frame_length; // 1024 or 960
344
345 } mpeg4_cfg_t;
346 typedef struct {
347 int i_program;
348 int i_layer;
349
350 int i_frame_length_type;
351 int i_frame_length; // type 1
352 int i_frame_length_index; // type 3 4 5 6 7
353
354 mpeg4_cfg_t cfg;
355
356 /* Raw configuration */
357 int i_extra;
358 uint8_t extra[LATM_MAX_EXTRA_SIZE];
359
360 } latm_stream_t;
361
362#define LATM_MAX_LAYER (8)
363#define LATM_MAX_PROGRAM (16)
364 typedef struct {
365 int b_same_time_framing;
366 int i_sub_frames;
367 int i_programs;
368
369 int pi_layers[LATM_MAX_PROGRAM];
370
371 int pi_stream[LATM_MAX_PROGRAM][LATM_MAX_LAYER];
372
373 int i_streams;
374 latm_stream_t stream[LATM_MAX_PROGRAM*LATM_MAX_LAYER];
375
376 int i_other_data;
377 int i_crc; /* -1 if not set */
378 } latm_mux_t;
379
380 typedef struct {
381 /*
382 * Input properties
383 */
384 int i_state;
385 int i_type;
386 int i_frame_size;
387 unsigned int i_channels;
388 unsigned int i_rate, i_frame_length, i_header_size;
389 int i_input_rate;
390 /* LOAS */
391 unsigned char b_latm_cfg;
392 latm_mux_t latm;
393 } decoder_sys_t;
394
395#endif
396 typedef struct {
397 uint8_t adts_header_present;
398 uint8_t adif_header_present;
399 uint8_t latm_header_present;
400 uint8_t sf_index;
401 uint8_t object_type;
402 uint8_t channelConfiguration;
403#ifdef ERROR_RESILIENCE
404 uint8_t aacSectionDataResilienceFlag;
405 uint8_t aacScalefactorDataResilienceFlag;
406 uint8_t aacSpectralDataResilienceFlag;
407#endif
408 uint16_t frameLength;
409 uint8_t postSeekResetFlag;
410
411 uint32_t frame;
412
413 uint8_t downMatrix;
414 uint8_t upMatrix;
415 uint8_t first_syn_ele;
416 uint8_t has_lfe;
417 /* number of channels in current frame */
418 uint8_t fr_channels;
419 /* number of elements in current frame */
420 uint8_t fr_ch_ele;
421
422 /* element_output_channels:
423 determines the number of channels the element will output
424 */
425 uint8_t element_output_channels[MAX_SYNTAX_ELEMENTS];
426 /* element_alloced:
427 determines whether the data needed for the element is allocated or not
428 */
429 uint8_t element_alloced[MAX_SYNTAX_ELEMENTS];
430 /* alloced_channels:
431 determines the number of channels where output data is allocated for
432 */
433 uint8_t alloced_channels;
434
435 /* output data buffer */
436 void *sample_buffer;
437
438 /*add for loas sub frame large than one*/
439 void *sample_buffer_all;
440
441 uint8_t window_shape_prev[MAX_CHANNELS];
442#ifdef LTP_DEC
443 uint16_t ltp_lag[MAX_CHANNELS];
444#endif
445 fb_info *fb;
446 drc_info *drc;
447
448 real_t *time_out[MAX_CHANNELS];
449 real_t *fb_intermed[MAX_CHANNELS];
450
451#ifdef SBR_DEC
452 int8_t sbr_present_flag;
453 int8_t forceUpSampling;
454 int8_t downSampledSBR;
455 /* determines whether SBR data is allocated for the gives element */
456 uint8_t sbr_alloced[MAX_SYNTAX_ELEMENTS];
457
458 sbr_info *sbr[MAX_SYNTAX_ELEMENTS];
459#endif
460#if (defined(PS_DEC) || defined(DRM_PS))
461 uint8_t ps_used[MAX_SYNTAX_ELEMENTS];
462 uint8_t ps_used_global;
463#endif
464
465#ifdef SSR_DEC
466 real_t *ssr_overlap[MAX_CHANNELS];
467 real_t *prev_fmd[MAX_CHANNELS];
468 real_t ipqf_buffer[MAX_CHANNELS][4][96 / 4];
469#endif
470
471#ifdef MAIN_DEC
472 pred_state *pred_stat[MAX_CHANNELS];
473#endif
474#ifdef LTP_DEC
475 int16_t *lt_pred_stat[MAX_CHANNELS];
476#endif
477
478#ifdef DRM
479 uint8_t error_state;
480#endif
481
482 /* RNG states */
483 uint32_t __r1;
484 uint32_t __r2;
485
486 /* Program Config Element */
487 uint8_t pce_set;
488 program_config pce;
489 uint8_t element_id[MAX_CHANNELS];
490 uint8_t internal_channel[MAX_CHANNELS];
491
492 /* Configuration data */
493 NeAACDecConfiguration config;
494
495#ifdef PROFILE
496 int64_t cycles;
497 int64_t spectral_cycles;
498 int64_t output_cycles;
499 int64_t scalefac_cycles;
500 int64_t requant_cycles;
501#endif
502 latm_header latm_config;
503 const unsigned char *cmes;
504#ifdef NEW_CODE_CHECK_LATM
505 decoder_sys_t dec_sys;
506#endif
507 int last_sf_index;
508 int last_ch_configure;
509 short dec_buffer[DEC_BUF_SIZE];
510 short output_buffer[OUT_BUF_SIZE];
511 unsigned char temp_bufer[TMP_BUF_SIZE];
512 } NeAACDecStruct;
513
514
515
516#ifdef __cplusplus
517}
518#endif
519#endif