xingri.gao | c18d447 | 2023-02-28 02:51:02 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 35 | extern "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 |
yuliang.hu | 585b720 | 2024-09-06 17:28:13 +0800 | [diff] [blame^] | 85 | void *process_buf; |
| 86 | int process_buf_size; |
| 87 | void *process_buf2; |
| 88 | int process_buf_size2; |
xingri.gao | c18d447 | 2023-02-28 02:51:02 +0000 | [diff] [blame] | 89 | } fb_info; |
| 90 | |
| 91 | typedef struct { |
| 92 | uint8_t present; |
| 93 | |
| 94 | uint8_t num_bands; |
| 95 | uint8_t pce_instance_tag; |
| 96 | uint8_t excluded_chns_present; |
| 97 | uint8_t band_top[17]; |
| 98 | uint8_t prog_ref_level; |
| 99 | uint8_t dyn_rng_sgn[17]; |
| 100 | uint8_t dyn_rng_ctl[17]; |
| 101 | uint8_t exclude_mask[MAX_CHANNELS]; |
| 102 | uint8_t additional_excluded_chns[MAX_CHANNELS]; |
| 103 | |
| 104 | real_t ctrl1; |
| 105 | real_t ctrl2; |
| 106 | } drc_info; |
| 107 | |
| 108 | typedef struct { |
| 109 | uint8_t element_instance_tag; |
| 110 | uint8_t object_type; |
| 111 | uint8_t sf_index; |
| 112 | uint8_t num_front_channel_elements; |
| 113 | uint8_t num_side_channel_elements; |
| 114 | uint8_t num_back_channel_elements; |
| 115 | uint8_t num_lfe_channel_elements; |
| 116 | uint8_t num_assoc_data_elements; |
| 117 | uint8_t num_valid_cc_elements; |
| 118 | uint8_t mono_mixdown_present; |
| 119 | uint8_t mono_mixdown_element_number; |
| 120 | uint8_t stereo_mixdown_present; |
| 121 | uint8_t stereo_mixdown_element_number; |
| 122 | uint8_t matrix_mixdown_idx_present; |
| 123 | uint8_t pseudo_surround_enable; |
| 124 | uint8_t matrix_mixdown_idx; |
| 125 | uint8_t front_element_is_cpe[16]; |
| 126 | uint8_t front_element_tag_select[16]; |
| 127 | uint8_t side_element_is_cpe[16]; |
| 128 | uint8_t side_element_tag_select[16]; |
| 129 | uint8_t back_element_is_cpe[16]; |
| 130 | uint8_t back_element_tag_select[16]; |
| 131 | uint8_t lfe_element_tag_select[16]; |
| 132 | uint8_t assoc_data_element_tag_select[16]; |
| 133 | uint8_t cc_element_is_ind_sw[16]; |
| 134 | uint8_t valid_cc_element_tag_select[16]; |
| 135 | |
| 136 | uint8_t channels; |
| 137 | |
| 138 | uint8_t comment_field_bytes; |
| 139 | uint8_t comment_field_data[257]; |
| 140 | |
| 141 | /* extra added values */ |
| 142 | uint8_t num_front_channels; |
| 143 | uint8_t num_side_channels; |
| 144 | uint8_t num_back_channels; |
| 145 | uint8_t num_lfe_channels; |
| 146 | uint8_t sce_channel[16]; |
| 147 | uint8_t cpe_channel[16]; |
| 148 | } program_config; |
| 149 | |
| 150 | typedef struct { |
| 151 | uint16_t syncword; |
| 152 | uint8_t id; |
| 153 | uint8_t layer; |
| 154 | uint8_t protection_absent; |
| 155 | uint8_t profile; |
| 156 | uint8_t sf_index; |
| 157 | uint8_t private_bit; |
| 158 | uint8_t channel_configuration; |
| 159 | uint8_t original; |
| 160 | uint8_t home; |
| 161 | uint8_t emphasis; |
| 162 | uint8_t copyright_identification_bit; |
| 163 | uint8_t copyright_identification_start; |
| 164 | uint16_t aac_frame_length; |
| 165 | uint16_t adts_buffer_fullness; |
| 166 | uint8_t no_raw_data_blocks_in_frame; |
| 167 | uint16_t crc_check; |
| 168 | |
| 169 | /* control param */ |
| 170 | uint8_t old_format; |
| 171 | } adts_header; |
| 172 | |
| 173 | typedef struct { |
| 174 | uint8_t copyright_id_present; |
| 175 | int8_t copyright_id[10]; |
| 176 | uint8_t original_copy; |
| 177 | uint8_t home; |
| 178 | uint8_t bitstream_type; |
| 179 | uint32_t bitrate; |
| 180 | uint8_t num_program_config_elements; |
| 181 | uint32_t adif_buffer_fullness; |
| 182 | |
| 183 | /* maximum of 16 PCEs */ |
| 184 | program_config pce[16]; |
| 185 | } adif_header; |
| 186 | |
| 187 | #ifdef LTP_DEC |
| 188 | typedef struct { |
| 189 | uint8_t last_band; |
| 190 | uint8_t data_present; |
| 191 | uint16_t lag; |
| 192 | uint8_t lag_update; |
| 193 | uint8_t coef; |
| 194 | uint8_t long_used[MAX_SFB]; |
| 195 | uint8_t short_used[8]; |
| 196 | uint8_t short_lag_present[8]; |
| 197 | uint8_t short_lag[8]; |
| 198 | } ltp_info; |
| 199 | #endif |
| 200 | |
| 201 | #ifdef MAIN_DEC |
| 202 | typedef struct { |
| 203 | uint8_t limit; |
| 204 | uint8_t predictor_reset; |
| 205 | uint8_t predictor_reset_group_number; |
| 206 | uint8_t prediction_used[MAX_SFB]; |
| 207 | } pred_info; |
| 208 | #endif |
| 209 | |
| 210 | typedef struct { |
| 211 | uint8_t number_pulse; |
| 212 | uint8_t pulse_start_sfb; |
| 213 | uint8_t pulse_offset[4]; |
| 214 | uint8_t pulse_amp[4]; |
| 215 | } pulse_info; |
| 216 | |
| 217 | typedef struct { |
| 218 | uint8_t n_filt[8]; |
| 219 | uint8_t coef_res[8]; |
| 220 | uint8_t length[8][4]; |
| 221 | uint8_t order[8][4]; |
| 222 | uint8_t direction[8][4]; |
| 223 | uint8_t coef_compress[8][4]; |
| 224 | uint8_t coef[8][4][32]; |
| 225 | } tns_info; |
| 226 | |
| 227 | #ifdef SSR_DEC |
| 228 | typedef struct { |
| 229 | uint8_t max_band; |
| 230 | |
| 231 | uint8_t adjust_num[4][8]; |
| 232 | uint8_t alevcode[4][8][8]; |
| 233 | uint8_t aloccode[4][8][8]; |
| 234 | } ssr_info; |
| 235 | #endif |
| 236 | |
| 237 | typedef struct { |
| 238 | uint8_t max_sfb; |
| 239 | |
| 240 | uint8_t num_swb; |
| 241 | uint8_t num_window_groups; |
| 242 | uint8_t num_windows; |
| 243 | uint8_t window_sequence; |
| 244 | uint8_t window_group_length[8]; |
| 245 | uint8_t window_shape; |
| 246 | uint8_t scale_factor_grouping; |
| 247 | uint16_t sect_sfb_offset[8][15 * 8]; |
| 248 | uint16_t swb_offset[52]; |
| 249 | uint16_t swb_offset_max; |
| 250 | |
| 251 | uint8_t sect_cb[8][15 * 8]; |
| 252 | uint16_t sect_start[8][15 * 8]; |
| 253 | uint16_t sect_end[8][15 * 8]; |
| 254 | uint8_t sfb_cb[8][8 * 15]; |
| 255 | uint8_t num_sec[8]; /* number of sections in a group */ |
| 256 | |
| 257 | uint8_t global_gain; |
| 258 | int16_t scale_factors[8][51]; /* [0..255] */ |
| 259 | |
| 260 | uint8_t ms_mask_present; |
| 261 | uint8_t ms_used[MAX_WINDOW_GROUPS][MAX_SFB]; |
| 262 | |
| 263 | uint8_t noise_used; |
| 264 | uint8_t is_used; |
| 265 | |
| 266 | uint8_t pulse_data_present; |
| 267 | uint8_t tns_data_present; |
| 268 | uint8_t gain_control_data_present; |
| 269 | uint8_t predictor_data_present; |
| 270 | |
| 271 | pulse_info pul; |
| 272 | tns_info tns; |
| 273 | #ifdef MAIN_DEC |
| 274 | pred_info pred; |
| 275 | #endif |
| 276 | #ifdef LTP_DEC |
| 277 | ltp_info ltp; |
| 278 | ltp_info ltp2; |
| 279 | #endif |
| 280 | #ifdef SSR_DEC |
| 281 | ssr_info ssr; |
| 282 | #endif |
| 283 | |
| 284 | #ifdef ERROR_RESILIENCE |
| 285 | /* ER HCR data */ |
| 286 | uint16_t length_of_reordered_spectral_data; |
| 287 | uint8_t length_of_longest_codeword; |
| 288 | /* ER RLVC data */ |
| 289 | uint8_t sf_concealment; |
| 290 | uint8_t rev_global_gain; |
| 291 | uint16_t length_of_rvlc_sf; |
| 292 | uint16_t dpcm_noise_nrg; |
| 293 | uint8_t sf_escapes_present; |
| 294 | uint8_t length_of_rvlc_escapes; |
| 295 | uint16_t dpcm_noise_last_position; |
| 296 | #endif |
| 297 | } ic_stream; /* individual channel stream */ |
| 298 | |
| 299 | typedef struct { |
| 300 | uint8_t channel; |
| 301 | int16_t paired_channel; |
| 302 | |
| 303 | uint8_t element_instance_tag; |
| 304 | uint8_t common_window; |
| 305 | |
| 306 | ic_stream ics1; |
| 307 | ic_stream ics2; |
| 308 | } element; /* syntax element (SCE, CPE, LFE) */ |
| 309 | |
| 310 | #define MAX_ASC_BYTES 64 |
| 311 | typedef struct { |
| 312 | int inited; |
| 313 | int version, versionA; |
| 314 | int framelen_type; |
| 315 | int useSameStreamMux; |
| 316 | int allStreamsSameTimeFraming; |
| 317 | int numSubFrames; |
| 318 | int numPrograms; |
| 319 | int numLayers; |
| 320 | int otherDataPresent; |
| 321 | uint32_t otherDataLenBits; |
| 322 | uint32_t frameLength; |
| 323 | uint8_t ASC[MAX_ASC_BYTES]; |
| 324 | uint32_t ASCbits; |
| 325 | } latm_header; |
| 326 | |
| 327 | #define NEW_CODE_CHECK_LATM |
| 328 | #ifdef NEW_CODE_CHECK_LATM |
| 329 | #define LOAS_HEADER_SIZE 3 |
| 330 | /**************************************************************************** |
| 331 | * LOAS helpers |
| 332 | ****************************************************************************/ |
| 333 | #define LATM_MAX_EXTRA_SIZE 64 |
| 334 | typedef struct { |
| 335 | int i_object_type; |
| 336 | int i_samplerate; |
| 337 | int i_channel; |
| 338 | int i_sbr; // 0: no sbr, 1: sbr, -1: unknown |
| 339 | int i_ps; // 0: no ps, 1: ps, -1: unknown |
| 340 | |
| 341 | struct { |
| 342 | int i_object_type; |
| 343 | int i_samplerate; |
| 344 | } extension; |
| 345 | |
| 346 | /* GASpecific */ |
| 347 | int i_frame_length; // 1024 or 960 |
| 348 | |
| 349 | } mpeg4_cfg_t; |
| 350 | typedef struct { |
| 351 | int i_program; |
| 352 | int i_layer; |
| 353 | |
| 354 | int i_frame_length_type; |
| 355 | int i_frame_length; // type 1 |
| 356 | int i_frame_length_index; // type 3 4 5 6 7 |
| 357 | |
| 358 | mpeg4_cfg_t cfg; |
| 359 | |
| 360 | /* Raw configuration */ |
| 361 | int i_extra; |
| 362 | uint8_t extra[LATM_MAX_EXTRA_SIZE]; |
| 363 | |
| 364 | } latm_stream_t; |
| 365 | |
| 366 | #define LATM_MAX_LAYER (8) |
| 367 | #define LATM_MAX_PROGRAM (16) |
| 368 | typedef struct { |
| 369 | int b_same_time_framing; |
| 370 | int i_sub_frames; |
| 371 | int i_programs; |
| 372 | |
| 373 | int pi_layers[LATM_MAX_PROGRAM]; |
| 374 | |
| 375 | int pi_stream[LATM_MAX_PROGRAM][LATM_MAX_LAYER]; |
| 376 | |
| 377 | int i_streams; |
| 378 | latm_stream_t stream[LATM_MAX_PROGRAM*LATM_MAX_LAYER]; |
| 379 | |
| 380 | int i_other_data; |
| 381 | int i_crc; /* -1 if not set */ |
| 382 | } latm_mux_t; |
| 383 | |
| 384 | typedef struct { |
| 385 | /* |
| 386 | * Input properties |
| 387 | */ |
| 388 | int i_state; |
| 389 | int i_type; |
| 390 | int i_frame_size; |
| 391 | unsigned int i_channels; |
| 392 | unsigned int i_rate, i_frame_length, i_header_size; |
| 393 | int i_input_rate; |
| 394 | /* LOAS */ |
| 395 | unsigned char b_latm_cfg; |
| 396 | latm_mux_t latm; |
| 397 | } decoder_sys_t; |
| 398 | |
| 399 | #endif |
| 400 | typedef struct { |
| 401 | uint8_t adts_header_present; |
| 402 | uint8_t adif_header_present; |
| 403 | uint8_t latm_header_present; |
| 404 | uint8_t sf_index; |
| 405 | uint8_t object_type; |
| 406 | uint8_t channelConfiguration; |
| 407 | #ifdef ERROR_RESILIENCE |
| 408 | uint8_t aacSectionDataResilienceFlag; |
| 409 | uint8_t aacScalefactorDataResilienceFlag; |
| 410 | uint8_t aacSpectralDataResilienceFlag; |
| 411 | #endif |
| 412 | uint16_t frameLength; |
| 413 | uint8_t postSeekResetFlag; |
| 414 | |
| 415 | uint32_t frame; |
| 416 | |
| 417 | uint8_t downMatrix; |
| 418 | uint8_t upMatrix; |
| 419 | uint8_t first_syn_ele; |
| 420 | uint8_t has_lfe; |
| 421 | /* number of channels in current frame */ |
| 422 | uint8_t fr_channels; |
| 423 | /* number of elements in current frame */ |
| 424 | uint8_t fr_ch_ele; |
| 425 | |
| 426 | /* element_output_channels: |
| 427 | determines the number of channels the element will output |
| 428 | */ |
| 429 | uint8_t element_output_channels[MAX_SYNTAX_ELEMENTS]; |
| 430 | /* element_alloced: |
| 431 | determines whether the data needed for the element is allocated or not |
| 432 | */ |
| 433 | uint8_t element_alloced[MAX_SYNTAX_ELEMENTS]; |
| 434 | /* alloced_channels: |
| 435 | determines the number of channels where output data is allocated for |
| 436 | */ |
| 437 | uint8_t alloced_channels; |
| 438 | |
| 439 | /* output data buffer */ |
| 440 | void *sample_buffer; |
| 441 | |
| 442 | /*add for loas sub frame large than one*/ |
| 443 | void *sample_buffer_all; |
| 444 | |
| 445 | uint8_t window_shape_prev[MAX_CHANNELS]; |
| 446 | #ifdef LTP_DEC |
| 447 | uint16_t ltp_lag[MAX_CHANNELS]; |
| 448 | #endif |
| 449 | fb_info *fb; |
| 450 | drc_info *drc; |
| 451 | |
| 452 | real_t *time_out[MAX_CHANNELS]; |
| 453 | real_t *fb_intermed[MAX_CHANNELS]; |
| 454 | |
| 455 | #ifdef SBR_DEC |
| 456 | int8_t sbr_present_flag; |
| 457 | int8_t forceUpSampling; |
| 458 | int8_t downSampledSBR; |
| 459 | /* determines whether SBR data is allocated for the gives element */ |
| 460 | uint8_t sbr_alloced[MAX_SYNTAX_ELEMENTS]; |
| 461 | |
| 462 | sbr_info *sbr[MAX_SYNTAX_ELEMENTS]; |
| 463 | #endif |
| 464 | #if (defined(PS_DEC) || defined(DRM_PS)) |
| 465 | uint8_t ps_used[MAX_SYNTAX_ELEMENTS]; |
| 466 | uint8_t ps_used_global; |
| 467 | #endif |
| 468 | |
| 469 | #ifdef SSR_DEC |
| 470 | real_t *ssr_overlap[MAX_CHANNELS]; |
| 471 | real_t *prev_fmd[MAX_CHANNELS]; |
| 472 | real_t ipqf_buffer[MAX_CHANNELS][4][96 / 4]; |
| 473 | #endif |
| 474 | |
| 475 | #ifdef MAIN_DEC |
| 476 | pred_state *pred_stat[MAX_CHANNELS]; |
| 477 | #endif |
| 478 | #ifdef LTP_DEC |
| 479 | int16_t *lt_pred_stat[MAX_CHANNELS]; |
| 480 | #endif |
| 481 | |
| 482 | #ifdef DRM |
| 483 | uint8_t error_state; |
| 484 | #endif |
| 485 | |
| 486 | /* RNG states */ |
| 487 | uint32_t __r1; |
| 488 | uint32_t __r2; |
| 489 | |
| 490 | /* Program Config Element */ |
| 491 | uint8_t pce_set; |
| 492 | program_config pce; |
| 493 | uint8_t element_id[MAX_CHANNELS]; |
| 494 | uint8_t internal_channel[MAX_CHANNELS]; |
| 495 | |
| 496 | /* Configuration data */ |
| 497 | NeAACDecConfiguration config; |
| 498 | |
| 499 | #ifdef PROFILE |
| 500 | int64_t cycles; |
| 501 | int64_t spectral_cycles; |
| 502 | int64_t output_cycles; |
| 503 | int64_t scalefac_cycles; |
| 504 | int64_t requant_cycles; |
| 505 | #endif |
| 506 | latm_header latm_config; |
| 507 | const unsigned char *cmes; |
| 508 | #ifdef NEW_CODE_CHECK_LATM |
| 509 | decoder_sys_t dec_sys; |
| 510 | #endif |
| 511 | int last_sf_index; |
| 512 | int last_ch_configure; |
| 513 | short dec_buffer[DEC_BUF_SIZE]; |
| 514 | short output_buffer[OUT_BUF_SIZE]; |
| 515 | unsigned char temp_bufer[TMP_BUF_SIZE]; |
yuliang.hu | 585b720 | 2024-09-06 17:28:13 +0800 | [diff] [blame^] | 516 | element *process_buf; |
| 517 | int process_buf_size; |
xingri.gao | c18d447 | 2023-02-28 02:51:02 +0000 | [diff] [blame] | 518 | } NeAACDecStruct; |
| 519 | |
| 520 | |
| 521 | |
| 522 | #ifdef __cplusplus |
| 523 | } |
| 524 | #endif |
| 525 | #endif |