1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010-2014 L-SMASH project
6 * Authors: Takashi Hirata <silverfilain@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
23 #include "common/internal.h" /* must be placed first */
29 #include "description.h"
35 /***************************************************************************
36 implementation of part of ISO/IEC 14496-3 (ISO/IEC 14496-1 relevant)
37 ***************************************************************************/
39 /* ISO/IEC 14496-3 samplingFrequencyIndex */
40 /* ISO/IEC 14496-3 Sampling frequency mapping */
41 const uint32_t mp4a_sampling_frequency_table
[13][5] = {
42 /* threshold, exact, idx_for_ga, idx_for_sbr, idx */
43 { 92017, 96000, 0x0, 0xF, 0x0 }, /* SBR is not allowed */
44 { 75132, 88200, 0x1, 0xF, 0x1 }, /* SBR is not allowed */
45 { 55426, 64000, 0x2, 0xF, 0x2 }, /* SBR is not allowed */
46 { 46009, 48000, 0x3, 0x0, 0x3 },
47 { 37566, 44100, 0x4, 0x1, 0x4 },
48 { 27713, 32000, 0x5, 0x2, 0x5 },
49 { 23004, 24000, 0x6, 0x3, 0x6 },
50 { 18783, 22050, 0x7, 0x4, 0x7 },
51 { 13856, 16000, 0x8, 0x5, 0x8 },
52 { 11502, 12000, 0x9, 0x6, 0x9 },
53 { 9391, 11025, 0xA, 0x7, 0xA },
54 { 8000, 8000, 0xB, 0x8, 0xB },
55 { 0, 7350, 0xB, 0xF, 0xC } /* samplingFrequencyIndex for GASpecificConfig is 0xB (same as 8000Hz). */
58 /* ISO/IEC 14496-3 Interface to ISO/IEC 14496-1 (MPEG-4 Systems), Syntax of AudioSpecificConfig(). */
59 /* This structure is represent of regularized AudioSpecificConfig. */
60 /* for actual definition, see Syntax of GetAudioObjectType() for audioObjectType and extensionAudioObjectType. */
63 lsmash_mp4a_aac_sbr_mode sbr_mode
; /* L-SMASH's original, including sbrPresent flag. */
64 lsmash_mp4a_AudioObjectType audioObjectType
;
65 unsigned samplingFrequencyIndex
: 4;
66 unsigned samplingFrequency
: 24;
67 unsigned channelConfiguration
: 4;
68 lsmash_mp4a_AudioObjectType extensionAudioObjectType
;
69 unsigned extensionSamplingFrequencyIndex
: 4;
70 unsigned extensionSamplingFrequency
: 24;
71 unsigned extensionChannelConfiguration
: 4;
72 /* if( audioObjectType in
73 #[ 1, 2, 3, 4, 6, 7, *17, *19, *20, *21, *22, *23 ] // GASpecificConfig, AAC relatives and TwinVQ, BSAC
74 [ 8 ] // CelpSpecificConfig, not supported
75 [ 9 ] // HvxcSpecificConfig, not supported
76 [ 12 ] // TTSSpecificConfig, not supported
77 [ 13, 14, 15, 16 ] // StructuredAudioSpecificConfig, notsupported
78 [ 24 ] // ErrorResilientCelpSpecificConfig, notsupported
79 [ 25 ] // ErrorResilientHvxcSpecificConfig, notsupported
80 [ 26, 27 ] // ParametricSpecificConfig, notsupported
81 [ 28 ] // SSCSpecificConfig, notsupported
82 #[ 32, 33, 34 ] // MPEG_1_2_SpecificConfig
83 [ 35 ] // DSTSpecificConfig, notsupported
85 void *deepAudioSpecificConfig
; // L-SMASH's original name, reperesents such as GASpecificConfig. */
88 // error resilient stuff, not supported
89 if( audioObjectType in [17, 19, 20, 21, 22, 23, 24, 25, 26, 27] ){
90 uint8_t epConfig // 2bit
91 if( epConfig == 2 || epConfig == 3 ){
92 ErrorProtectionSpecificConfig();
95 uint8_t directMapping; // 1bit, currently always 1.
102 } mp4a_AudioSpecificConfig_t
;
104 /* ISO/IEC 14496-3 Decoder configuration (GASpecificConfig), Syntax of GASpecificConfig() */
105 /* ISO/IEC 14496-3 GASpecificConfig(), Sampling frequency mapping */
108 unsigned frameLengthFlag
: 1; /* FIXME: AAC_SSR: shall be 0, Others: depends, but noramally 0. */
109 unsigned dependsOnCoreCoder
: 1; /* FIXME: used if scalable AAC. */
110 unsigned coreCoderDelay
: 14;
111 unsigned extensionFlag
: 1; /* 1bit, 1 if ErrorResilience */
112 /* if( !channelConfiguration ){ */
113 void* program_config_element
; /* currently not supported. */
116 // we do not support AAC_scalable
117 if( (audioObjectType == MP4A_AUDIO_OBJECT_TYPE_AAC_scalable) || (audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable) ){
118 uint8_t layerNr; // 3bits
122 // we do not support special AACs
124 if( audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_BSAC ){
125 uint8_t numOfSubFrame; // 5bits
126 uint8_t layer_length; // 11bits
128 if( audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC || audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
129 || audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable || audioObjectType == MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
131 uint8_t aacSectionDataResilienceFlag; // 1bit
132 uint8_t aacScalefactorDataResilienceFlag; // 1bit
133 uint8_t aacSpectralDataResilienceFlag; // 1bit
135 uint8_t extensionFlag3; // 1bit
136 if( extensionFlag3 ){
141 } mp4a_GASpecificConfig_t
;
143 /* ISO/IEC 14496-3 MPEG_1_2_SpecificConfig */
146 uint8_t extension
; /* shall be 0. */
147 } mp4a_MPEG_1_2_SpecificConfig_t
;
149 /* ISO/IEC 14496-3 ALSSpecificConfig */
158 unsigned file_type
: 3;
159 unsigned resolution
: 3;
160 unsigned floating
: 1;
161 unsigned msb_first
: 1;
162 uint16_t frame_length
;
163 uint8_t random_access
;
164 unsigned ra_flag
: 2;
165 unsigned adapt_order
: 1;
166 unsigned coef_table
: 2;
167 unsigned long_term_prediction
: 1;
168 unsigned max_order
: 10;
169 unsigned block_switching
: 2;
170 unsigned bgmc_mode
: 1;
171 unsigned sb_part
: 1;
172 unsigned joint_stereo
: 1;
173 unsigned mc_coding
: 1;
174 unsigned chan_config
: 1;
175 unsigned chan_sort
: 1;
176 unsigned crc_enabled
: 1;
178 unsigned reserved
: 5;
179 unsigned aux_data_enabled
: 1;
180 } mp4a_ALSSpecificConfig_t
;
182 static inline void mp4a_remove_GASpecificConfig( mp4a_GASpecificConfig_t
* gasc
)
186 lsmash_free( gasc
->program_config_element
);
190 static inline void mp4a_remove_MPEG_1_2_SpecificConfig( mp4a_MPEG_1_2_SpecificConfig_t
* mpeg_1_2_sc
)
192 lsmash_free( mpeg_1_2_sc
);
195 void mp4a_remove_AudioSpecificConfig( mp4a_AudioSpecificConfig_t
* asc
)
199 switch( asc
->audioObjectType
){
200 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
201 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
202 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
203 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
204 case MP4A_AUDIO_OBJECT_TYPE_SBR
:
205 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
206 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
:
207 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
208 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
209 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
210 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
211 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
212 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
213 mp4a_remove_GASpecificConfig( (mp4a_GASpecificConfig_t
*)asc
->deepAudioSpecificConfig
);
215 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
216 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
217 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
218 mp4a_remove_MPEG_1_2_SpecificConfig( (mp4a_MPEG_1_2_SpecificConfig_t
*)asc
->deepAudioSpecificConfig
);
221 lsmash_free( asc
->deepAudioSpecificConfig
);
227 /* ADIF/PCE(program config element) style GASpecificConfig is not not supported. */
228 /* channelConfig/samplingFrequencyIndex will be used when we support ADIF/PCE style GASpecificConfig. */
229 static mp4a_GASpecificConfig_t
* mp4a_create_GASpecificConfig( uint8_t samplingFrequencyIndex
, uint8_t channelConfig
, lsmash_mp4a_AudioObjectType aot
)
231 debug_if( aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_LC
232 && aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
233 && aot
!= MP4A_AUDIO_OBJECT_TYPE_TwinVQ
)
235 if( samplingFrequencyIndex
> 0xB || channelConfig
== 0 || channelConfig
== 7 )
237 mp4a_GASpecificConfig_t
*gasc
= (mp4a_GASpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_GASpecificConfig_t
) );
240 gasc
->frameLengthFlag
= 0; /* FIXME: AAC_SSR: shall be 0, Others: depends, but noramally 0. */
241 gasc
->dependsOnCoreCoder
= 0; /* FIXME: used if scalable AAC. */
243 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
244 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
245 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
246 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
247 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
248 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
:
249 gasc
->extensionFlag
= 0;
251 #if 0 /* intentional dead code */
252 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
253 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
254 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
255 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
256 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
257 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
258 gasc
->extensionFlag
= 1;
262 gasc
->extensionFlag
= 0;
268 static mp4a_MPEG_1_2_SpecificConfig_t
* mp4a_create_MPEG_1_2_SpecificConfig()
270 mp4a_MPEG_1_2_SpecificConfig_t
*mpeg_1_2_sc
= (mp4a_MPEG_1_2_SpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_MPEG_1_2_SpecificConfig_t
) );
273 mpeg_1_2_sc
->extension
= 0; /* shall be 0. */
277 static mp4a_ALSSpecificConfig_t
*mp4a_create_ALSSpecificConfig( uint8_t *exdata
, uint32_t exdata_length
)
279 mp4a_ALSSpecificConfig_t
*alssc
= (mp4a_ALSSpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_ALSSpecificConfig_t
) );
282 alssc
->data
= lsmash_memdup( exdata
, exdata_length
);
285 lsmash_free( alssc
);
288 alssc
->size
= exdata_length
;
292 /* Currently, only normal AAC, MPEG_1_2 are supported.
293 For AAC, other than normal AAC, such as AAC_scalable, ER_AAC_xxx, are not supported.
294 ADIF/PCE(program config element) style AudioSpecificConfig is not supported.
295 aot shall not be MP4A_AUDIO_OBJECT_TYPE_SBR even if you wish to signal SBR explicitly, use sbr_mode instead.
296 Frequency/channels shall be base AAC's one, even if SBR/PS.
297 If other than AAC with SBR, sbr_mode shall be MP4A_AAC_SBR_NOT_SPECIFIED. */
298 mp4a_AudioSpecificConfig_t
*mp4a_create_AudioSpecificConfig(
299 lsmash_mp4a_AudioObjectType aot
,
302 lsmash_mp4a_aac_sbr_mode sbr_mode
,
304 uint32_t exdata_length
307 if( aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_LC
308 && aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
309 && aot
!= MP4A_AUDIO_OBJECT_TYPE_TwinVQ
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_Layer_1
310 && aot
!= MP4A_AUDIO_OBJECT_TYPE_Layer_2
&& aot
!= MP4A_AUDIO_OBJECT_TYPE_Layer_3
311 && aot
!= MP4A_AUDIO_OBJECT_TYPE_ALS
)
316 uint8_t channelConfig
;
324 channelConfig
= channels
;
333 mp4a_AudioSpecificConfig_t
*asc
= (mp4a_AudioSpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_AudioSpecificConfig_t
) );
337 asc
->sbr_mode
= sbr_mode
;
338 asc
->audioObjectType
= aot
;
339 asc
->channelConfiguration
= channelConfig
;
341 uint8_t samplingFrequencyIndex
= 0xF;
343 if( sbr_mode
!= MP4A_AAC_SBR_NOT_SPECIFIED
344 || aot
== MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
345 || aot
== MP4A_AUDIO_OBJECT_TYPE_AAC_LC
346 || aot
== MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
347 || aot
== MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
348 || aot
== MP4A_AUDIO_OBJECT_TYPE_SBR
)
350 while( frequency
< mp4a_sampling_frequency_table
[i
][0] )
352 asc
->samplingFrequencyIndex
= frequency
== mp4a_sampling_frequency_table
[i
][1] ? i
: 0xF;
353 asc
->samplingFrequency
= frequency
;
354 samplingFrequencyIndex
= mp4a_sampling_frequency_table
[i
][2];
356 if( sbr_mode
!= MP4A_AAC_SBR_NOT_SPECIFIED
)
359 /* see ISO/IEC 14496-3 Levels within the profiles / Levels for the High Efficiency AAC Profile */
365 asc
->extensionAudioObjectType
= MP4A_AUDIO_OBJECT_TYPE_SBR
;
368 asc
->extensionAudioObjectType
= MP4A_AUDIO_OBJECT_TYPE_NULL
;
370 if( sbr_mode
== MP4A_AAC_SBR_BACKWARD_COMPATIBLE
|| sbr_mode
== MP4A_AAC_SBR_HIERARCHICAL
)
372 asc
->extensionSamplingFrequency
= frequency
* 2;
373 asc
->extensionSamplingFrequencyIndex
= i
== 0xC ? 0xF : mp4a_sampling_frequency_table
[i
][3];
377 asc
->extensionSamplingFrequencyIndex
= asc
->samplingFrequencyIndex
;
378 asc
->extensionSamplingFrequency
= asc
->samplingFrequency
;
383 while( i
< 0xD && frequency
!= mp4a_sampling_frequency_table
[i
][1] )
385 asc
->samplingFrequencyIndex
= i
!= 0xD ? i
: 0xF;
386 asc
->samplingFrequency
= frequency
;
387 asc
->extensionAudioObjectType
= MP4A_AUDIO_OBJECT_TYPE_NULL
;
388 asc
->extensionSamplingFrequencyIndex
= asc
->samplingFrequencyIndex
;
389 asc
->extensionSamplingFrequency
= asc
->samplingFrequency
;
394 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
395 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
396 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
397 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
398 case MP4A_AUDIO_OBJECT_TYPE_SBR
:
399 #if 0 /* FIXME: here, stop currently unsupported codecs. */
400 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
401 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
: /* NOTE: I think we already have a support for TwinVQ, but how to test this? */
402 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
403 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
404 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
405 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
406 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
407 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
409 asc
->deepAudioSpecificConfig
= mp4a_create_GASpecificConfig( samplingFrequencyIndex
, channelConfig
, aot
);
411 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
412 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
413 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
414 asc
->deepAudioSpecificConfig
= mp4a_create_MPEG_1_2_SpecificConfig();
416 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
417 asc
->deepAudioSpecificConfig
= mp4a_create_ALSSpecificConfig( exdata
, exdata_length
);
420 break; /* this case is trapped below. */
422 if( !asc
->deepAudioSpecificConfig
)
430 /* ADIF/PCE(program config element) style GASpecificConfig is not supported. */
431 static void mp4a_put_GASpecificConfig( lsmash_bits_t
* bits
, mp4a_GASpecificConfig_t
* gasc
)
433 debug_if( !bits
|| !gasc
)
435 lsmash_bits_put( bits
, 1, gasc
->frameLengthFlag
);
436 lsmash_bits_put( bits
, 1, gasc
->dependsOnCoreCoder
);
437 lsmash_bits_put( bits
, 1, gasc
->extensionFlag
);
440 static void mp4a_put_MPEG_1_2_SpecificConfig( lsmash_bits_t
* bits
, mp4a_MPEG_1_2_SpecificConfig_t
* mpeg_1_2_sc
)
442 debug_if( !bits
|| !mpeg_1_2_sc
)
444 lsmash_bits_put( bits
, 1, mpeg_1_2_sc
->extension
); /* shall be 0 */
447 static void mp4a_put_ALSSpecificConfig( lsmash_bits_t
*bits
, mp4a_ALSSpecificConfig_t
*alssc
)
449 debug_if( !bits
|| !alssc
)
451 lsmash_bits_import_data( bits
, alssc
->data
, alssc
->size
);
454 static inline void mp4a_put_AudioObjectType( lsmash_bits_t
* bits
, lsmash_mp4a_AudioObjectType aot
)
456 if( aot
> MP4A_AUDIO_OBJECT_TYPE_ESCAPE
)
458 lsmash_bits_put( bits
, 5, MP4A_AUDIO_OBJECT_TYPE_ESCAPE
);
459 lsmash_bits_put( bits
, 6, aot
- MP4A_AUDIO_OBJECT_TYPE_ESCAPE
- 1 );
462 lsmash_bits_put( bits
, 5, aot
);
465 static inline void mp4a_put_SamplingFrequencyIndex( lsmash_bits_t
* bits
, uint8_t samplingFrequencyIndex
, uint32_t samplingFrequency
)
467 lsmash_bits_put( bits
, 4, samplingFrequencyIndex
);
468 if( samplingFrequencyIndex
== 0xF )
469 lsmash_bits_put( bits
, 24, samplingFrequency
);
472 /* Currently, only normal AAC, MPEG_1_2 are supported.
473 For AAC, other than normal AAC, such as AAC_scalable, ER_AAC_xxx, are not supported.
474 ADIF/PCE(program config element) style AudioSpecificConfig is not supported either. */
475 void mp4a_put_AudioSpecificConfig( lsmash_bs_t
* bs
, mp4a_AudioSpecificConfig_t
* asc
)
477 debug_if( !bs
|| !asc
)
480 lsmash_bits_init( &bits
, bs
);
482 if( asc
->sbr_mode
== MP4A_AAC_SBR_HIERARCHICAL
)
483 mp4a_put_AudioObjectType( &bits
, asc
->extensionAudioObjectType
); /* puts MP4A_AUDIO_OBJECT_TYPE_SBR */
485 mp4a_put_AudioObjectType( &bits
, asc
->audioObjectType
);
486 mp4a_put_SamplingFrequencyIndex( &bits
, asc
->samplingFrequencyIndex
, asc
->samplingFrequency
);
487 lsmash_bits_put( &bits
, 4, asc
->channelConfiguration
);
488 if( asc
->sbr_mode
== MP4A_AAC_SBR_HIERARCHICAL
)
490 mp4a_put_SamplingFrequencyIndex( &bits
, asc
->extensionSamplingFrequencyIndex
, asc
->extensionSamplingFrequency
);
491 mp4a_put_AudioObjectType( &bits
, asc
->audioObjectType
);
493 switch( asc
->audioObjectType
){
494 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
495 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
496 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
497 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
498 case MP4A_AUDIO_OBJECT_TYPE_SBR
:
499 #if 0 /* FIXME: here, stop currently unsupported codecs */
500 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
501 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
: /* NOTE: I think we already have a support for TwinVQ, but how to test this? */
502 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
503 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
504 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
505 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
506 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
507 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
509 mp4a_put_GASpecificConfig( &bits
, (mp4a_GASpecificConfig_t
*)asc
->deepAudioSpecificConfig
);
511 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
512 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
513 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
514 mp4a_put_MPEG_1_2_SpecificConfig( &bits
, (mp4a_MPEG_1_2_SpecificConfig_t
*)asc
->deepAudioSpecificConfig
);
516 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
517 lsmash_bits_put( &bits
, 5, 0 ); /* fillBits for byte alignment */
518 mp4a_put_ALSSpecificConfig( &bits
, (mp4a_ALSSpecificConfig_t
*)asc
->deepAudioSpecificConfig
);
521 break; /* FIXME: do we have to return error? */
524 /* FIXME: Error Resiliant stuff omitted here. */
526 if( asc
->sbr_mode
== MP4A_AAC_SBR_BACKWARD_COMPATIBLE
|| asc
->sbr_mode
== MP4A_AAC_SBR_NONE
)
528 lsmash_bits_put( &bits
, 11, 0x2b7 );
529 mp4a_put_AudioObjectType( &bits
, asc
->extensionAudioObjectType
); /* puts MP4A_AUDIO_OBJECT_TYPE_SBR */
530 if( asc
->extensionAudioObjectType
== MP4A_AUDIO_OBJECT_TYPE_SBR
) /* this is always true, due to current spec */
533 if( asc
->sbr_mode
== MP4A_AAC_SBR_NONE
)
534 lsmash_bits_put( &bits
, 1, 0x0 );
537 lsmash_bits_put( &bits
, 1, 0x1 );
538 mp4a_put_SamplingFrequencyIndex( &bits
, asc
->extensionSamplingFrequencyIndex
, asc
->extensionSamplingFrequency
);
542 lsmash_bits_put_align( &bits
);
545 static int mp4a_get_GASpecificConfig( lsmash_bits_t
*bits
, mp4a_AudioSpecificConfig_t
*asc
)
547 mp4a_GASpecificConfig_t
*gasc
= (mp4a_GASpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_GASpecificConfig_t
) );
549 return LSMASH_ERR_MEMORY_ALLOC
;
550 asc
->deepAudioSpecificConfig
= gasc
;
551 gasc
->frameLengthFlag
= lsmash_bits_get( bits
, 1 );
552 gasc
->dependsOnCoreCoder
= lsmash_bits_get( bits
, 1 );
553 if( gasc
->dependsOnCoreCoder
)
554 gasc
->coreCoderDelay
= lsmash_bits_get( bits
, 14 );
555 gasc
->extensionFlag
= lsmash_bits_get( bits
, 1 );
559 static int mp4a_get_MPEG_1_2_SpecificConfig( lsmash_bits_t
*bits
, mp4a_AudioSpecificConfig_t
*asc
)
561 mp4a_MPEG_1_2_SpecificConfig_t
*mpeg_1_2_sc
= (mp4a_MPEG_1_2_SpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_MPEG_1_2_SpecificConfig_t
) );
563 return LSMASH_ERR_MEMORY_ALLOC
;
564 asc
->deepAudioSpecificConfig
= mpeg_1_2_sc
;
565 mpeg_1_2_sc
->extension
= lsmash_bits_get( bits
, 1 );
569 static int mp4a_get_ALSSpecificConfig( lsmash_bits_t
*bits
, mp4a_AudioSpecificConfig_t
*asc
)
571 mp4a_ALSSpecificConfig_t
*alssc
= (mp4a_ALSSpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_ALSSpecificConfig_t
) );
573 return LSMASH_ERR_MEMORY_ALLOC
;
574 asc
->deepAudioSpecificConfig
= alssc
;
575 alssc
->als_id
= lsmash_bits_get( bits
, 32 );
576 alssc
->samp_freq
= lsmash_bits_get( bits
, 32 );
577 alssc
->samples
= lsmash_bits_get( bits
, 32 );
578 alssc
->channels
= lsmash_bits_get( bits
, 16 );
579 alssc
->file_type
= lsmash_bits_get( bits
, 3 );
580 alssc
->resolution
= lsmash_bits_get( bits
, 3 );
581 alssc
->floating
= lsmash_bits_get( bits
, 1 );
582 alssc
->msb_first
= lsmash_bits_get( bits
, 1 );
583 alssc
->frame_length
= lsmash_bits_get( bits
, 16 );
584 alssc
->random_access
= lsmash_bits_get( bits
, 8 );
585 alssc
->ra_flag
= lsmash_bits_get( bits
, 2 );
586 alssc
->adapt_order
= lsmash_bits_get( bits
, 1 );
587 alssc
->coef_table
= lsmash_bits_get( bits
, 2 );
588 alssc
->long_term_prediction
= lsmash_bits_get( bits
, 1 );
589 alssc
->max_order
= lsmash_bits_get( bits
, 10 );
590 alssc
->block_switching
= lsmash_bits_get( bits
, 2 );
591 alssc
->bgmc_mode
= lsmash_bits_get( bits
, 1 );
592 alssc
->sb_part
= lsmash_bits_get( bits
, 1 );
593 alssc
->joint_stereo
= lsmash_bits_get( bits
, 1 );
594 alssc
->mc_coding
= lsmash_bits_get( bits
, 1 );
595 alssc
->chan_config
= lsmash_bits_get( bits
, 1 );
596 alssc
->chan_sort
= lsmash_bits_get( bits
, 1 );
597 alssc
->crc_enabled
= lsmash_bits_get( bits
, 1 );
598 alssc
->RLSLMS
= lsmash_bits_get( bits
, 1 );
599 alssc
->reserved
= lsmash_bits_get( bits
, 5 );
600 alssc
->aux_data_enabled
= lsmash_bits_get( bits
, 1 );
604 static mp4a_AudioSpecificConfig_t
*mp4a_get_AudioSpecificConfig( uint8_t *dsi_payload
, uint32_t dsi_payload_length
)
606 lsmash_bits_t
*bits
= lsmash_bits_adhoc_create();
609 if( lsmash_bits_import_data( bits
, dsi_payload
, dsi_payload_length
) < 0 )
611 lsmash_bits_adhoc_cleanup( bits
);
614 mp4a_AudioSpecificConfig_t
*asc
= (mp4a_AudioSpecificConfig_t
*)lsmash_malloc_zero( sizeof(mp4a_AudioSpecificConfig_t
) );
617 asc
->audioObjectType
= lsmash_bits_get( bits
, 5 );
618 if( asc
->audioObjectType
== 31 )
619 asc
->extensionAudioObjectType
= asc
->audioObjectType
+= 1 + lsmash_bits_get( bits
, 6 );
620 asc
->samplingFrequencyIndex
= lsmash_bits_get( bits
, 4 );
621 if( asc
->samplingFrequencyIndex
== 0xf )
622 asc
->samplingFrequency
= lsmash_bits_get( bits
, 24 );
623 asc
->channelConfiguration
= lsmash_bits_get( bits
, 4 );
625 switch( asc
->audioObjectType
)
627 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
628 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
629 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
630 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
631 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
632 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
:
633 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
634 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
635 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
636 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
637 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
638 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
639 ret
= mp4a_get_GASpecificConfig( bits
, asc
);
641 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
642 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
643 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
644 ret
= mp4a_get_MPEG_1_2_SpecificConfig( bits
, asc
);
646 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
647 lsmash_bits_get( bits
, 5 );
648 ret
= mp4a_get_ALSSpecificConfig( bits
, asc
);
655 lsmash_bits_adhoc_cleanup( bits
);
658 lsmash_bits_adhoc_cleanup( bits
);
663 int mp4a_setup_summary_from_AudioSpecificConfig( lsmash_audio_summary_t
*summary
, uint8_t *dsi_payload
, uint32_t dsi_payload_length
)
665 mp4a_AudioSpecificConfig_t
*asc
= mp4a_get_AudioSpecificConfig( dsi_payload
, dsi_payload_length
);
667 return LSMASH_ERR_NAMELESS
;
668 summary
->summary_type
= LSMASH_SUMMARY_TYPE_AUDIO
;
669 summary
->sample_type
= ISOM_CODEC_TYPE_MP4A_AUDIO
;
670 summary
->aot
= asc
->audioObjectType
;
671 switch( asc
->audioObjectType
)
673 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
674 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
675 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
676 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
677 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
678 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
:
679 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
680 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
681 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
682 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
683 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
684 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
685 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
686 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
687 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
688 if( asc
->samplingFrequencyIndex
== 0xf )
689 summary
->frequency
= asc
->samplingFrequency
;
695 if( mp4a_sampling_frequency_table
[i
][2] == asc
->samplingFrequencyIndex
)
697 summary
->frequency
= mp4a_sampling_frequency_table
[i
][1];
704 mp4a_remove_AudioSpecificConfig( asc
);
705 return LSMASH_ERR_INVALID_DATA
;
708 if( asc
->channelConfiguration
< 8 )
709 summary
->channels
= asc
->channelConfiguration
!= 7 ? asc
->channelConfiguration
: 8;
711 summary
->channels
= 0; /* reserved */
712 summary
->sample_size
= 16;
713 switch( asc
->audioObjectType
)
715 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
716 summary
->samples_in_frame
= 1024;
718 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
719 summary
->samples_in_frame
= 384;
721 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
722 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
723 summary
->samples_in_frame
= 1152;
726 summary
->samples_in_frame
= !((mp4a_GASpecificConfig_t
*)asc
->deepAudioSpecificConfig
)->frameLengthFlag
? 1024 : 960;
730 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
732 mp4a_ALSSpecificConfig_t
*alssc
= (mp4a_ALSSpecificConfig_t
*)asc
->deepAudioSpecificConfig
;
733 summary
->frequency
= alssc
->samp_freq
;
734 summary
->channels
= alssc
->channels
+ 1;
735 summary
->sample_size
= (alssc
->resolution
+ 1) * 8;
736 summary
->samples_in_frame
= alssc
->frame_length
+ 1;
742 mp4a_remove_AudioSpecificConfig( asc
);
746 /* This function is very ad-hoc. */
747 uint8_t *mp4a_export_AudioSpecificConfig( lsmash_mp4a_AudioObjectType aot
,
750 lsmash_mp4a_aac_sbr_mode sbr_mode
,
752 uint32_t exdata_length
,
753 uint32_t *data_length
)
755 lsmash_bs_t
*bs
= lsmash_bs_create();
758 mp4a_AudioSpecificConfig_t
*asc
= mp4a_create_AudioSpecificConfig( aot
, frequency
, channels
, sbr_mode
, exdata
, exdata_length
);
761 lsmash_bs_cleanup( bs
);
764 mp4a_put_AudioSpecificConfig( bs
, asc
);
765 uint8_t *data
= lsmash_bs_export_data( bs
, data_length
);
766 mp4a_remove_AudioSpecificConfig( asc
);
767 lsmash_bs_cleanup( bs
);
773 #ifdef LSMASH_DEMUXER_ENABLED
774 static void mp4a_print_GASpecificConfig( FILE *fp
, mp4a_AudioSpecificConfig_t
*asc
, int indent
)
776 mp4a_GASpecificConfig_t
*gasc
= (mp4a_GASpecificConfig_t
*)asc
->deepAudioSpecificConfig
;
777 lsmash_ifprintf( fp
, indent
++, "[GASpecificConfig]\n" );
778 lsmash_ifprintf( fp
, indent
, "frameLengthFlag = %"PRIu8
"\n", gasc
->frameLengthFlag
);
779 lsmash_ifprintf( fp
, indent
, "dependsOnCoreCoder = %"PRIu8
"\n", gasc
->dependsOnCoreCoder
);
780 if( gasc
->dependsOnCoreCoder
)
781 lsmash_ifprintf( fp
, indent
, "coreCoderDelay = %"PRIu16
"\n", gasc
->coreCoderDelay
);
782 lsmash_ifprintf( fp
, indent
, "extensionFlag = %"PRIu8
"\n", gasc
->extensionFlag
);
783 if( !asc
->channelConfiguration
)
784 lsmash_ifprintf( fp
, indent
, "program_config_element()\n" );
787 static void mp4a_print_MPEG_1_2_SpecificConfig( FILE *fp
, mp4a_AudioSpecificConfig_t
*asc
, int indent
)
789 mp4a_MPEG_1_2_SpecificConfig_t
*mpeg_1_2_sc
= (mp4a_MPEG_1_2_SpecificConfig_t
*)asc
->deepAudioSpecificConfig
;
790 lsmash_ifprintf( fp
, indent
++, "[MPEG_1_2_SpecificConfig]\n" );
791 lsmash_ifprintf( fp
, indent
, "extension = %"PRIu8
"\n", mpeg_1_2_sc
->extension
);
794 static void mp4a_print_ALSSpecificConfig( FILE *fp
, mp4a_AudioSpecificConfig_t
*asc
, int indent
)
796 mp4a_ALSSpecificConfig_t
*alssc
= (mp4a_ALSSpecificConfig_t
*)asc
->deepAudioSpecificConfig
;
797 const char *file_type
[4] = { "raw", "wave", "aiff", "bwf" };
798 const char *floating
[2] = { "integer", "IEEE 32-bit floating-point" };
799 const char *endian
[2] = { "little", "big" };
800 const char *ra_flag
[4] = { "not stored", "stored at the beginning of frame_data()", "stored at the end of ALSSpecificConfig", "?" };
801 lsmash_ifprintf( fp
, indent
++, "[ALSSpecificConfig]\n" );
802 lsmash_ifprintf( fp
, indent
, "als_id = 0x%"PRIx32
"\n", alssc
->als_id
);
803 lsmash_ifprintf( fp
, indent
, "samp_freq = %"PRIu32
" Hz\n", alssc
->samp_freq
);
804 lsmash_ifprintf( fp
, indent
, "samples = %"PRIu32
"\n", alssc
->samples
);
805 lsmash_ifprintf( fp
, indent
, "channels = %"PRIu16
"\n", alssc
->channels
);
806 if( alssc
->file_type
<= 3 )
807 lsmash_ifprintf( fp
, indent
, "file_type = %"PRIu8
" (%s file)\n", alssc
->file_type
, file_type
[ alssc
->file_type
] );
809 lsmash_ifprintf( fp
, indent
, "file_type = %"PRIu8
"\n", alssc
->file_type
);
810 if( alssc
->resolution
<= 3 )
811 lsmash_ifprintf( fp
, indent
, "resolution = %"PRIu8
" (%d-bit)\n", alssc
->resolution
, 8 * (1 + alssc
->resolution
) );
813 lsmash_ifprintf( fp
, indent
, "resolution = %"PRIu8
"\n", alssc
->resolution
);
814 lsmash_ifprintf( fp
, indent
, "floating = %"PRIu8
" (%s)\n", alssc
->floating
, floating
[ alssc
->floating
] );
815 if( alssc
->resolution
)
816 lsmash_ifprintf( fp
, indent
, "msb_first = %"PRIu8
" (%s-endian)\n", alssc
->msb_first
, endian
[ alssc
->msb_first
] );
818 lsmash_ifprintf( fp
, indent
, "msb_first = %"PRIu8
" (%ssigned data)\n", alssc
->msb_first
, ((const char *[2]){ "un", "" })[ alssc
->msb_first
] );
819 lsmash_ifprintf( fp
, indent
, "frame_length = %"PRIu16
"\n", alssc
->frame_length
);
820 lsmash_ifprintf( fp
, indent
, "random_access = %"PRIu8
"\n", alssc
->random_access
);
821 lsmash_ifprintf( fp
, indent
, "ra_flag = %"PRIu8
" (ra_unit_size is %s)\n", alssc
->ra_flag
, ra_flag
[ alssc
->ra_flag
] );
822 lsmash_ifprintf( fp
, indent
, "adapt_order = %"PRIu8
"\n", alssc
->adapt_order
);
823 lsmash_ifprintf( fp
, indent
, "coef_table = %"PRIu8
"\n", alssc
->coef_table
);
824 lsmash_ifprintf( fp
, indent
, "long_term_prediction = %"PRIu8
"\n", alssc
->long_term_prediction
);
825 lsmash_ifprintf( fp
, indent
, "max_order = %"PRIu8
"\n", alssc
->max_order
);
826 lsmash_ifprintf( fp
, indent
, "block_switching = %"PRIu8
"\n", alssc
->block_switching
);
827 lsmash_ifprintf( fp
, indent
, "bgmc_mode = %"PRIu8
"\n", alssc
->bgmc_mode
);
828 lsmash_ifprintf( fp
, indent
, "sb_part = %"PRIu8
"\n", alssc
->sb_part
);
829 lsmash_ifprintf( fp
, indent
, "joint_stereo = %"PRIu8
"\n", alssc
->joint_stereo
);
830 lsmash_ifprintf( fp
, indent
, "mc_coding = %"PRIu8
"\n", alssc
->mc_coding
);
831 lsmash_ifprintf( fp
, indent
, "chan_config = %"PRIu8
"\n", alssc
->chan_config
);
832 lsmash_ifprintf( fp
, indent
, "chan_sort = %"PRIu8
"\n", alssc
->chan_sort
);
833 lsmash_ifprintf( fp
, indent
, "crc_enabled = %"PRIu8
"\n", alssc
->crc_enabled
);
834 lsmash_ifprintf( fp
, indent
, "RLSLMS = %"PRIu8
"\n", alssc
->RLSLMS
);
835 lsmash_ifprintf( fp
, indent
, "reserved = %"PRIu8
"\n", alssc
->reserved
);
836 lsmash_ifprintf( fp
, indent
, "aux_data_enabled = %"PRIu8
"\n", alssc
->aux_data_enabled
);
839 void mp4a_print_AudioSpecificConfig( FILE *fp
, uint8_t *dsi_payload
, uint32_t dsi_payload_length
, int indent
)
841 assert( fp
&& dsi_payload
&& dsi_payload_length
);
842 mp4a_AudioSpecificConfig_t
*asc
= mp4a_get_AudioSpecificConfig( dsi_payload
, dsi_payload_length
);
845 const char *audio_object_type
[] =
849 "AAC LC (Low Complexity)",
850 "AAC SSR (Scalable Sample Rate)",
851 "AAC LTP (Long Term Prediction)",
852 "SBR (Spectral Band Replication)",
855 "CELP (Code Excited Linear Prediction)",
856 "HVXC (Harmonic Vector Excitation Coding)",
859 "TTSI (Text-To-Speech Interface)",
861 "Wavetable synthesis",
863 "Algorithmic Synthesis and Audio FX",
869 "ER BSAC (Bit-Sliced Arithmetic Coding)",
873 "ER HILN (Harmonic and Individual Lines plus Noise)",
875 "SSC (SinuSoidal Coding)",
876 "PS (Parametric Stereo)",
882 "DST (Direct Stream Transfer)",
883 "ALS (Audio Lossless Coding)",
884 "SLS (Scalable Lossless Coding)",
889 "USAC (Unified Speech and Audio Coding)",
894 lsmash_ifprintf( fp
, indent
++, "[AudioSpecificConfig]\n" );
895 if( asc
->audioObjectType
< sizeof(audio_object_type
) / sizeof(audio_object_type
[0]) )
896 lsmash_ifprintf( fp
, indent
, "audioObjectType = %d (%s)\n", asc
->audioObjectType
, audio_object_type
[ asc
->audioObjectType
] );
898 lsmash_ifprintf( fp
, indent
, "audioObjectType = %d\n", asc
->audioObjectType
);
899 lsmash_ifprintf( fp
, indent
, "samplingFrequencyIndex = %"PRIu8
"\n", asc
->samplingFrequencyIndex
);
900 if( asc
->samplingFrequencyIndex
== 0xf )
901 lsmash_ifprintf( fp
, indent
, "samplingFrequency = %"PRIu32
"\n", asc
->samplingFrequency
);
902 lsmash_ifprintf( fp
, indent
, "channelConfiguration = %"PRIu8
"\n", asc
->channelConfiguration
);
903 if( asc
->extensionAudioObjectType
== 5 )
905 lsmash_ifprintf( fp
, indent
, "extensionSamplingFrequencyIndex = %"PRIu8
"\n", asc
->extensionSamplingFrequencyIndex
);
906 if( asc
->extensionSamplingFrequencyIndex
== 0xf )
907 lsmash_ifprintf( fp
, indent
, "extensionSamplingFrequency = %"PRIu32
"\n", asc
->extensionSamplingFrequency
);
908 if( asc
->audioObjectType
== 22 )
909 lsmash_ifprintf( fp
, indent
, "extensionChannelConfiguration = %"PRIu8
"\n", asc
->extensionChannelConfiguration
);
911 if( asc
->deepAudioSpecificConfig
)
912 switch( asc
->audioObjectType
)
914 case MP4A_AUDIO_OBJECT_TYPE_AAC_MAIN
:
915 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
916 case MP4A_AUDIO_OBJECT_TYPE_AAC_SSR
:
917 case MP4A_AUDIO_OBJECT_TYPE_AAC_LTP
:
918 case MP4A_AUDIO_OBJECT_TYPE_AAC_scalable
:
919 case MP4A_AUDIO_OBJECT_TYPE_TwinVQ
:
920 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LC
:
921 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LTP
:
922 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_scalable
:
923 case MP4A_AUDIO_OBJECT_TYPE_ER_Twin_VQ
:
924 case MP4A_AUDIO_OBJECT_TYPE_ER_BSAC
:
925 case MP4A_AUDIO_OBJECT_TYPE_ER_AAC_LD
:
926 mp4a_print_GASpecificConfig( fp
, asc
, indent
);
928 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
929 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
930 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
931 mp4a_print_MPEG_1_2_SpecificConfig( fp
, asc
, indent
);
933 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
934 mp4a_print_ALSSpecificConfig( fp
, asc
, indent
);
939 mp4a_remove_AudioSpecificConfig( asc
);
941 #endif /* LSMASH_DEMUXER_ENABLED */
943 /***************************************************************************
944 audioProfileLevelIndication
945 ***************************************************************************/
946 /* NOTE: This function is not strictly preferable, but accurate.
947 The spec of audioProfileLevelIndication is too much complicated. */
948 mp4a_audioProfileLevelIndication
mp4a_get_audioProfileLevelIndication( lsmash_audio_summary_t
*summary
)
950 if( !summary
|| summary
->summary_type
!= LSMASH_SUMMARY_TYPE_AUDIO
)
951 return MP4A_AUDIO_PLI_NONE_REQUIRED
; /* means error. */
952 if( lsmash_mp4sys_get_object_type_indication( (lsmash_summary_t
*)summary
) != MP4SYS_OBJECT_TYPE_Audio_ISO_14496_3
)
953 return MP4A_AUDIO_PLI_NOT_SPECIFIED
; /* This is of audio stream, but not described in ISO/IEC 14496-3. */
954 if( summary
->channels
== 0 || summary
->frequency
== 0 )
955 return MP4A_AUDIO_PLI_NONE_REQUIRED
; /* means error. */
956 mp4a_audioProfileLevelIndication pli
= MP4A_AUDIO_PLI_NOT_SPECIFIED
;
957 switch( summary
->aot
)
959 case MP4A_AUDIO_OBJECT_TYPE_AAC_LC
:
960 if( summary
->sbr_mode
== MP4A_AAC_SBR_HIERARCHICAL
)
962 /* NOTE: This is not strictly preferable, but accurate; just possibly over-estimated.
963 We do not expect to use MP4A_AAC_SBR_HIERARCHICAL mode without SBR, nor downsampled mode with SBR. */
964 if( summary
->channels
<= 2 && summary
->frequency
<= 24000 )
965 pli
= MP4A_AUDIO_PLI_HE_AAC_L2
;
966 else if( summary
->channels
<= 5 && summary
->frequency
<= 48000 )
967 pli
= MP4A_AUDIO_PLI_HE_AAC_L5
;
969 pli
= MP4A_AUDIO_PLI_NOT_SPECIFIED
;
972 /* pretending plain AAC-LC, if actually HE-AAC. */
973 static const uint32_t mp4sys_aac_pli_table
[5][3] = {
974 /* channels, frequency, audioProfileLevelIndication */
975 { 6, 96000, MP4A_AUDIO_PLI_AAC_L5
}, /* FIXME: 6ch is not strictly correct, but works in many case. */
976 { 6, 48000, MP4A_AUDIO_PLI_AAC_L4
}, /* FIXME: 6ch is not strictly correct, but works in many case. */
977 { 2, 48000, MP4A_AUDIO_PLI_AAC_L2
},
978 { 2, 24000, MP4A_AUDIO_PLI_AAC_L1
},
979 { 0, 0, MP4A_AUDIO_PLI_NOT_SPECIFIED
}
981 for( int i
= 0; summary
->channels
<= mp4sys_aac_pli_table
[i
][0] && summary
->frequency
<= mp4sys_aac_pli_table
[i
][1] ; i
++ )
982 pli
= mp4sys_aac_pli_table
[i
][2];
984 case MP4A_AUDIO_OBJECT_TYPE_ALS
:
985 /* FIXME: this is not stricly. Summary shall carry max_order, block_switching, bgmc_mode and RLSLMS. */
986 if( summary
->channels
<= 2 && summary
->frequency
<= 48000 && summary
->sample_size
<= 16 && summary
->samples_in_frame
<= 4096 )
987 pli
= MP4A_AUDIO_PLI_ALS_Simple_L1
;
989 pli
= MP4A_AUDIO_PLI_NOT_SPECIFIED
;
991 case MP4A_AUDIO_OBJECT_TYPE_Layer_1
:
992 case MP4A_AUDIO_OBJECT_TYPE_Layer_2
:
993 case MP4A_AUDIO_OBJECT_TYPE_Layer_3
:
994 pli
= MP4A_AUDIO_PLI_NOT_SPECIFIED
; /* 14496-3, Audio profiles and levels, does not allow any pli. */
997 pli
= MP4A_AUDIO_PLI_NOT_SPECIFIED
; /* something we don't know/support, or what the spec never covers. */
1003 static int mp4sys_is_same_profile( mp4a_audioProfileLevelIndication a
, mp4a_audioProfileLevelIndication b
)
1007 case MP4A_AUDIO_PLI_Main_L1
:
1008 case MP4A_AUDIO_PLI_Main_L2
:
1009 case MP4A_AUDIO_PLI_Main_L3
:
1010 case MP4A_AUDIO_PLI_Main_L4
:
1011 if( MP4A_AUDIO_PLI_Main_L1
<= b
&& b
<= MP4A_AUDIO_PLI_Main_L4
)
1015 case MP4A_AUDIO_PLI_Scalable_L1
:
1016 case MP4A_AUDIO_PLI_Scalable_L2
:
1017 case MP4A_AUDIO_PLI_Scalable_L3
:
1018 case MP4A_AUDIO_PLI_Scalable_L4
:
1019 if( MP4A_AUDIO_PLI_Scalable_L1
<= b
&& b
<= MP4A_AUDIO_PLI_Scalable_L4
)
1023 case MP4A_AUDIO_PLI_Speech_L1
:
1024 case MP4A_AUDIO_PLI_Speech_L2
:
1025 if( MP4A_AUDIO_PLI_Speech_L1
<= b
&& b
<= MP4A_AUDIO_PLI_Speech_L2
)
1029 case MP4A_AUDIO_PLI_Synthetic_L1
:
1030 case MP4A_AUDIO_PLI_Synthetic_L2
:
1031 case MP4A_AUDIO_PLI_Synthetic_L3
:
1032 if( MP4A_AUDIO_PLI_Synthetic_L1
<= b
&& b
<= MP4A_AUDIO_PLI_Synthetic_L3
)
1036 case MP4A_AUDIO_PLI_HighQuality_L1
:
1037 case MP4A_AUDIO_PLI_HighQuality_L2
:
1038 case MP4A_AUDIO_PLI_HighQuality_L3
:
1039 case MP4A_AUDIO_PLI_HighQuality_L4
:
1040 case MP4A_AUDIO_PLI_HighQuality_L5
:
1041 case MP4A_AUDIO_PLI_HighQuality_L6
:
1042 case MP4A_AUDIO_PLI_HighQuality_L7
:
1043 case MP4A_AUDIO_PLI_HighQuality_L8
:
1044 if( MP4A_AUDIO_PLI_HighQuality_L1
<= b
&& b
<= MP4A_AUDIO_PLI_HighQuality_L8
)
1048 case MP4A_AUDIO_PLI_LowDelay_L1
:
1049 case MP4A_AUDIO_PLI_LowDelay_L2
:
1050 case MP4A_AUDIO_PLI_LowDelay_L3
:
1051 case MP4A_AUDIO_PLI_LowDelay_L4
:
1052 case MP4A_AUDIO_PLI_LowDelay_L5
:
1053 case MP4A_AUDIO_PLI_LowDelay_L6
:
1054 case MP4A_AUDIO_PLI_LowDelay_L7
:
1055 case MP4A_AUDIO_PLI_LowDelay_L8
:
1056 if( MP4A_AUDIO_PLI_LowDelay_L1
<= b
&& b
<= MP4A_AUDIO_PLI_LowDelay_L8
)
1060 case MP4A_AUDIO_PLI_Natural_L1
:
1061 case MP4A_AUDIO_PLI_Natural_L2
:
1062 case MP4A_AUDIO_PLI_Natural_L3
:
1063 case MP4A_AUDIO_PLI_Natural_L4
:
1064 if( MP4A_AUDIO_PLI_Natural_L1
<= b
&& b
<= MP4A_AUDIO_PLI_Natural_L4
)
1068 case MP4A_AUDIO_PLI_MobileInternetworking_L1
:
1069 case MP4A_AUDIO_PLI_MobileInternetworking_L2
:
1070 case MP4A_AUDIO_PLI_MobileInternetworking_L3
:
1071 case MP4A_AUDIO_PLI_MobileInternetworking_L4
:
1072 case MP4A_AUDIO_PLI_MobileInternetworking_L5
:
1073 case MP4A_AUDIO_PLI_MobileInternetworking_L6
:
1074 if( MP4A_AUDIO_PLI_MobileInternetworking_L1
<= b
&& b
<= MP4A_AUDIO_PLI_MobileInternetworking_L6
)
1078 case MP4A_AUDIO_PLI_AAC_L1
:
1079 case MP4A_AUDIO_PLI_AAC_L2
:
1080 case MP4A_AUDIO_PLI_AAC_L4
:
1081 case MP4A_AUDIO_PLI_AAC_L5
:
1082 if( MP4A_AUDIO_PLI_AAC_L1
<= b
&& b
<= MP4A_AUDIO_PLI_AAC_L5
)
1086 case MP4A_AUDIO_PLI_HE_AAC_L2
:
1087 case MP4A_AUDIO_PLI_HE_AAC_L3
:
1088 case MP4A_AUDIO_PLI_HE_AAC_L4
:
1089 case MP4A_AUDIO_PLI_HE_AAC_L5
:
1090 if( MP4A_AUDIO_PLI_HE_AAC_L2
<= b
&& b
<= MP4A_AUDIO_PLI_HE_AAC_L5
)
1100 /* NOTE: This function is not strictly preferable, but accurate.
1101 The spec of audioProfileLevelIndication is too much complicated. */
1102 mp4a_audioProfileLevelIndication
mp4a_max_audioProfileLevelIndication( mp4a_audioProfileLevelIndication a
, mp4a_audioProfileLevelIndication b
)
1104 /* NONE_REQUIRED is minimal priotity, and NOT_SPECIFIED is max priority. */
1105 if( a
== MP4A_AUDIO_PLI_NOT_SPECIFIED
|| b
== MP4A_AUDIO_PLI_NONE_REQUIRED
)
1107 if( a
== MP4A_AUDIO_PLI_NONE_REQUIRED
|| b
== MP4A_AUDIO_PLI_NOT_SPECIFIED
)
1109 mp4a_audioProfileLevelIndication c
, d
;
1120 /* AAC-LC and SBR specific; If mixtured there, use correspond HE_AAC profile. */
1121 if( MP4A_AUDIO_PLI_AAC_L1
<= c
&& c
<= MP4A_AUDIO_PLI_AAC_L5
1122 && MP4A_AUDIO_PLI_HE_AAC_L2
<= d
&& d
<= MP4A_AUDIO_PLI_HE_AAC_L5
)
1124 if( c
<= MP4A_AUDIO_PLI_AAC_L2
)
1126 c
+= 4; /* upgrade to HE-AAC */
1127 return c
> d
? c
: d
;
1130 if( mp4sys_is_same_profile( c
, d
) )
1132 return MP4A_AUDIO_PLI_NOT_SPECIFIED
;