1 /* Copyright (c) MediaArea.net SARL. All Rights Reserved. 2 * 3 * Use of this source code is governed by a BSD-style license that can 4 * be found in the License.html file in the root of the source tree. 5 */ 6 7 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 // 9 // Information about AAC files 10 // 11 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 12 13 //--------------------------------------------------------------------------- 14 #ifndef MediaInfo_File_AacH 15 #define MediaInfo_File_AacH 16 //--------------------------------------------------------------------------- 17 18 //--------------------------------------------------------------------------- 19 #ifdef MEDIAINFO_MPEG4_YES 20 #include "MediaInfo/Multiple/File_Mpeg4_Descriptors.h" 21 #endif 22 #include "MediaInfo/Tag/File__Tags.h" 23 #include "MediaInfo/Audio/File_Usac.h" 24 //--------------------------------------------------------------------------- 25 26 namespace MediaInfoLib 27 { 28 29 //--------------------------------------------------------------------------- 30 enum Aac_OutputChannel 31 { 32 //USAC 33 CH_M_L030, 34 CH_M_R030, 35 CH_M_000, 36 CH_LFE, 37 CH_M_L110, 38 CH_M_R110, 39 CH_M_L022, 40 CH_M_R022, 41 CH_M_L135, 42 CH_M_R135, 43 CH_M_180, 44 CH_M_LSD, 45 CH_M_RSD, 46 CH_M_L090, 47 CH_M_R090, 48 CH_M_L060, 49 CH_M_R060, 50 CH_U_L030, 51 CH_U_R030, 52 CH_U_000, 53 CH_U_L135, 54 CH_U_R135, 55 CH_U_180, 56 CH_U_L090, 57 CH_U_R090, 58 CH_T_000, 59 CH_LFE2, 60 CH_L_L045, 61 CH_L_R045, 62 CH_L_000, 63 CH_U_L110, 64 CH_U_R110, 65 //MPEG-H 3D Audio 66 CH_U_L045, 67 CH_U_R045, 68 CH_M_L045, 69 CH_M_R045, 70 CH_LFE3, 71 CH_M_LSCR, 72 CH_M_RSCR, 73 CH_M_LSCH, 74 CH_M_RSCH, 75 CH_M_L150, 76 CH_M_R150, 77 CH_MAX 78 }; 79 80 //*************************************************************************** 81 // Class File_Aac 82 //*************************************************************************** 83 84 struct sbr_handler 85 { 86 //sbr_header 87 int8u bs_amp_res[2]; 88 int8u bs_amp_res_FromHeader; 89 int8u bs_start_freq; 90 int8u bs_stop_freq; 91 int8u bs_xover_band; 92 int8u bs_freq_scale; 93 int8u bs_alter_scale; 94 int8u bs_noise_bands; 95 96 //sbr_grid 97 int8u bs_num_env[2]; 98 bool bs_freq_res[2][8]; 99 int8u bs_num_noise[2]; 100 101 //sbr_dtdf 102 int8u bs_df_env[2][4]; 103 int8u bs_df_noise[2][2]; 104 105 //Computed values 106 int8u num_noise_bands; 107 int8u num_env_bands[2]; 108 }; 109 110 struct ps_handler 111 { 112 bool enable_iid; 113 bool enable_icc; 114 bool enable_ext; 115 int8u iid_mode; 116 int8u icc_mode; 117 }; 118 119 typedef const int8s (*sbr_huffman)[2]; 120 121 class File_Aac : public File_Usac, public File__Tags_Helper 122 { 123 public : 124 //In 125 int64u Frame_Count_Valid; 126 bool FrameIsAlwaysComplete; 127 enum mode 128 { 129 Mode_Unknown, 130 Mode_AudioSpecificConfig, 131 Mode_raw_data_block, 132 Mode_ADIF, 133 Mode_ADTS, 134 Mode_LATM, 135 }; 136 mode Mode; 137 void AudioSpecificConfig_OutOfBand(int64s sampling_frequency, int8u audioObjectType=(int8u)-1, bool sbrData=false, bool psData=false, bool sbrPresentFlag=false, bool psPresentFlag=false); 138 139 //Constructor/Destructor 140 File_Aac(); 141 ~File_Aac(); 142 143 protected : 144 //Streams management 145 void Streams_Accept(); 146 void Streams_Fill(); 147 void Streams_Update(); 148 void Streams_Finish(); 149 150 //Buffer - File header 151 bool FileHeader_Begin(); 152 void FileHeader_Parse(); 153 void FileHeader_Parse_ADIF(); 154 void FileHeader_Parse_ADTS(); 155 156 //Buffer - Global 157 void Read_Buffer_Continue (); 158 void Read_Buffer_Continue_AudioSpecificConfig(); 159 void Read_Buffer_Continue_raw_data_block(); 160 161 //Buffer - Synchro 162 bool Synchronize(); 163 bool Synchronize_ADTS(); 164 bool Synchronize_LATM(); 165 bool Synched_Test(); 166 bool Synched_Test_ADTS(); 167 bool Synched_Test_LATM(); 168 169 //Buffer - Demux 170 #if MEDIAINFO_DEMUX 171 bool Demux_UnpacketizeContainer_Test(); 172 bool Demux_UnpacketizeContainer_Test_ADTS(); 173 bool Demux_UnpacketizeContainer_Test_LATM(); 174 #endif //MEDIAINFO_DEMUX 175 176 //Buffer - Per element 177 bool Header_Begin(); 178 bool Header_Begin_ADTS(); 179 bool Header_Begin_LATM(); 180 void Header_Parse(); 181 void Header_Parse_ADTS(); 182 void Header_Parse_LATM(); 183 void Data_Parse(); 184 void Data_Parse_ADTS(); 185 void Data_Parse_LATM(); 186 187 //*********************************************************************** 188 // Elements - Main 189 //*********************************************************************** 190 191 //Elements - Interface to MPEG-4 container 192 void AudioSpecificConfig (size_t End=(size_t)-1); 193 void GetAudioObjectType (int8u &ObjectType, const char* Name); 194 195 //Elements - Multiplex layer 196 void EPMuxElement (); 197 void AudioMuxElement (); 198 void StreamMuxConfig (); 199 int32u LatmGetValue (); 200 void PayloadLengthInfo (); 201 void PayloadMux (); 202 bool muxConfigPresent; 203 204 //Elements - Error protection 205 void ErrorProtectionSpecificConfig (); 206 207 //Elements - MPEG-2 AAC Audio_Data_Interchange_Format, ADIF 208 void adif_header (); 209 210 //Elements - Audio_Data_Transport_Stream frame, ADTS 211 void adts_frame (); 212 void adts_fixed_header (); 213 void adts_variable_header (); 214 215 //Temp 216 int8u numSubFrames; 217 int8u numProgram; 218 int8u numLayer; 219 int8u numChunk; 220 bool audioMuxVersionA; 221 int8u streamID[16][8]; 222 int8u progSIndx[128]; 223 int8u laySIndx[128]; 224 int8u progCIndx[128]; 225 int8u layCIndx[128]; 226 int8u frameLengthType[128]; 227 int16u frameLength[128]; 228 int32u MuxSlotLengthBytes[128]; 229 int32u otherDataLenBits; 230 bool allStreamsSameTimeFraming; 231 int8u audioObjectType; 232 int8u extensionAudioObjectType; 233 int16u frame_length; 234 int32u extension_sampling_frequency; 235 bool aacScalefactorDataResilienceFlag; 236 bool aacSectionDataResilienceFlag; 237 bool aacSpectralDataResilienceFlag; 238 int8u num_raw_data_blocks; 239 bool protection_absent; 240 int64u FrameSize_Min; 241 int64u FrameSize_Max; 242 bool adts_buffer_fullness_Is7FF; 243 #if MEDIAINFO_ADVANCED 244 int64u aac_frame_length_Total; 245 #endif //MEDIAINFO_ADVANCED 246 247 //*********************************************************************** 248 // Elements - Speech coding (HVXC) 249 //*********************************************************************** 250 251 void HvxcSpecificConfig (); 252 void HVXCconfig (); 253 void ErrorResilientHvxcSpecificConfig (); 254 void ErHVXCconfig (); 255 256 //*********************************************************************** 257 // Elements - Speech Coding (CELP) 258 //*********************************************************************** 259 260 void CelpSpecificConfig (); 261 void CelpHeader (); 262 void ErrorResilientCelpSpecificConfig (); 263 void ER_SC_CelpHeader (); 264 265 //*********************************************************************** 266 // Elements - General Audio (GA) 267 //*********************************************************************** 268 269 //Elements - Decoder configuration 270 void GASpecificConfig (); 271 void program_config_element (); 272 273 //Elements - GA bitstream 274 void raw_data_block (); 275 void single_channel_element (); 276 void channel_pair_element (); 277 void ics_info (); 278 void pulse_data (); 279 void coupling_channel_element (); 280 void lfe_channel_element (); 281 void data_stream_element (); 282 void fill_element (int8u old_id); 283 void gain_control_data (); 284 285 //Elements - Subsidiary 286 void individual_channel_stream (bool common_window, bool scale_flag); 287 void section_data (); 288 void scale_factor_data (); 289 void tns_data (); 290 void ltp_data (); 291 void spectral_data (); 292 void extension_payload (size_t End, int8u id_aac); 293 void dynamic_range_info (); 294 void sac_extension_data (size_t End); 295 296 //Elements - SBR 297 void sbr_extension_data (size_t End, int8u id_aac, bool crc_flag); 298 void sbr_header (); 299 void sbr_data (int8u id_aac); 300 void sbr_single_channel_element (); 301 void sbr_channel_pair_element (); 302 void sbr_grid (bool ch); 303 void sbr_dtdf (bool ch); 304 void sbr_invf (bool ch); 305 void sbr_envelope (bool ch, bool bs_coupling); 306 void sbr_noise (bool ch, bool bs_coupling); 307 void sbr_sinusoidal_coding (bool ch); 308 int16u sbr_huff_dec (const sbr_huffman& Table, const char* Name); 309 310 //Elements - SBR - PS 311 void ps_data (size_t End); 312 313 //Elements - Perceptual noise substitution (PNS) 314 bool is_noise (size_t group, size_t sfb); 315 int is_intensity (size_t group, size_t sfb); 316 317 //Elements - Enhanced Low Delay Codec 318 void ELDSpecificConfig (); 319 void ld_sbr_header (); 320 321 //Helpers 322 void hcod (int8u sect_cb, const char* Name); 323 void hcod_sf (const char* Name); 324 void hcod_binary (int8u CodeBook, int8s* Values, int8u Values_Count); 325 void hcod_2step (int8u CodeBook, int8s* Values, int8u Values_Count); 326 327 //Temp - channel_pair_element 328 bool common_window; 329 330 //Temp - ics_info 331 int8u window_sequence; 332 int8u max_sfb; 333 int8u scale_factor_grouping; 334 int8u num_windows; 335 int8u num_window_groups; 336 int8u window_group_length [8]; 337 int16u sect_sfb_offset [8][1024]; 338 int16u swb_offset [64]; 339 int8u sfb_cb [8][64]; 340 int8u num_swb; 341 342 //Temp - section_data 343 int8u num_sec [8]; 344 int8u sect_cb [8][64]; 345 int16u sect_start [8][64]; 346 int16u sect_end [8][64]; 347 348 //Temp - ltp_data 349 int16u ltp_lag; 350 351 //Temp - SBR 352 vector<sbr_handler*> sbrs; 353 sbr_handler* sbr; 354 355 //Temp - PS 356 vector<ps_handler*> pss; 357 ps_handler* ps; 358 359 //Temp - Position 360 size_t raw_data_block_Pos; 361 362 //*********************************************************************** 363 // Elements - Structured Audio (SA) 364 //*********************************************************************** 365 366 void StructuredAudioSpecificConfig (); 367 368 //*********************************************************************** 369 // Elements - Text to Speech Interface (TTSI) 370 //*********************************************************************** 371 372 void TTSSpecificConfig (); 373 374 //*********************************************************************** 375 // Elements - Parametric Audio (HILN) 376 //*********************************************************************** 377 378 void HILNconfig (); 379 void HILNenexConfig (); 380 void ParametricSpecificConfig (); 381 void PARAconfig (); 382 383 //*********************************************************************** 384 // Elements - Technical description of parametric coding for high quality audio 385 //*********************************************************************** 386 387 void SSCSpecificConfig (); 388 389 //*********************************************************************** 390 // Elements - MPEG-1/2 Audio 391 //*********************************************************************** 392 393 void MPEG_1_2_SpecificConfig (); 394 395 //*********************************************************************** 396 // Elements - Technical description of lossless coding of oversampled audio 397 //*********************************************************************** 398 399 void DSTSpecificConfig (); 400 //*********************************************************************** 401 // Elements - Audio Lossless 402 //*********************************************************************** 403 404 void ALSSpecificConfig (); 405 406 //*********************************************************************** 407 // Elements - Scalable lossless 408 //*********************************************************************** 409 410 void SLSSpecificConfig (); 411 412 //*********************************************************************** 413 // Temp 414 //*********************************************************************** 415 416 std::map<std::string, Ztring> Infos_General; 417 std::map<std::string, Ztring> Infos; 418 std::map<std::string, Ztring> Infos_AudioSpecificConfig; 419 bool CanFill; 420 421 private : 422 void FillInfosHEAACv2(const Ztring& Format_Settings); 423 }; 424 425 } //NameSpace 426 427 #endif 428 429