00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "common.h"
00034 #include "structs.h"
00035
00036 #include <stdlib.h>
00037
00038 #include "bits.h"
00039 #include "mp4.h"
00040 #include "syntax.h"
00041
00042
00043 static uint8_t ObjectTypesTable[32] = {
00044 0,
00045 #ifdef MAIN_DEC
00046 1,
00047 #else
00048 0,
00049 #endif
00050 1,
00051 #ifdef SSR_DEC
00052 1,
00053 #else
00054 0,
00055 #endif
00056 #ifdef LTP_DEC
00057 1,
00058 #else
00059 0,
00060 #endif
00061 #ifdef SBR_DEC
00062 1,
00063 #else
00064 0,
00065 #endif
00066 0,
00067 0,
00068 0,
00069 0,
00070 0,
00071 0,
00072 0,
00073 0,
00074 0,
00075 0,
00076 0,
00077
00078
00079 #ifdef ERROR_RESILIENCE
00080 1,
00081 0,
00082 #ifdef LTP_DEC
00083 1,
00084 #else
00085 0,
00086 #endif
00087 0,
00088 0,
00089 0,
00090 #ifdef LD_DEC
00091 1,
00092 #else
00093 0,
00094 #endif
00095 0,
00096 0,
00097 0,
00098 0,
00099 #else
00100 0,
00101 0,
00102 0,
00103 0,
00104 0,
00105 0,
00106 0,
00107 0,
00108 0,
00109 0,
00110 0,
00111 #endif
00112 0,
00113 0,
00114 0,
00115 0
00116 };
00117
00118
00119 int8_t NEAACDECAPI NeAACDecAudioSpecificConfig(uint8_t *pBuffer,
00120 uint32_t buffer_size,
00121 mp4AudioSpecificConfig *mp4ASC)
00122 {
00123 return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL);
00124 }
00125
00126 int8_t AudioSpecificConfig2(uint8_t *pBuffer,
00127 uint32_t buffer_size,
00128 mp4AudioSpecificConfig *mp4ASC,
00129 program_config *pce)
00130 {
00131 bitfile ld;
00132 int8_t result = 0;
00133 #ifdef SBR_DEC
00134 int8_t bits_to_decode = 0;
00135 #endif
00136
00137 if (pBuffer == NULL)
00138 return -7;
00139 if (mp4ASC == NULL)
00140 return -8;
00141
00142 memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig));
00143
00144 faad_initbits(&ld, pBuffer, buffer_size);
00145 faad_byte_align(&ld);
00146
00147 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
00148 DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
00149
00150 mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
00151 DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));
00152
00153 mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4
00154 DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));
00155
00156 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
00157
00158 if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1)
00159 {
00160 faad_endbits(&ld);
00161 return -1;
00162 }
00163
00164 if (mp4ASC->samplingFrequency == 0)
00165 {
00166 faad_endbits(&ld);
00167 return -2;
00168 }
00169
00170 if (mp4ASC->channelsConfiguration > 7)
00171 {
00172 faad_endbits(&ld);
00173 return -3;
00174 }
00175
00176 #if (defined(PS_DEC) || defined(DRM_PS))
00177
00178 if (mp4ASC->channelsConfiguration == 1)
00179 {
00180
00181 mp4ASC->channelsConfiguration = 2;
00182 }
00183 #endif
00184
00185 #ifdef SBR_DEC
00186 mp4ASC->sbr_present_flag = -1;
00187 if (mp4ASC->objectTypeIndex == 5)
00188 {
00189 uint8_t tmp;
00190
00191 mp4ASC->sbr_present_flag = 1;
00192 tmp = (uint8_t)faad_getbits(&ld, 4
00193 DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
00194
00195 if (tmp == mp4ASC->samplingFrequencyIndex)
00196 mp4ASC->downSampledSBR = 1;
00197 mp4ASC->samplingFrequencyIndex = tmp;
00198 if (mp4ASC->samplingFrequencyIndex == 15)
00199 {
00200 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
00201 DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
00202 } else {
00203 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
00204 }
00205 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
00206 DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
00207 }
00208 #endif
00209
00210
00211 if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 ||
00212 mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 ||
00213 mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7)
00214 {
00215 result = GASpecificConfig(&ld, mp4ASC, pce);
00216
00217 #ifdef ERROR_RESILIENCE
00218 } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) {
00219 result = GASpecificConfig(&ld, mp4ASC, pce);
00220 mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2
00221 DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig"));
00222
00223 if (mp4ASC->epConfig != 0)
00224 result = -5;
00225 #endif
00226
00227 } else {
00228 result = -4;
00229 }
00230
00231 #ifdef SSR_DEC
00232
00233 if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag)
00234 return -6;
00235 #endif
00236
00237
00238 #ifdef SBR_DEC
00239 bits_to_decode = (int8_t)(buffer_size*8 - faad_get_processed_bits(&ld));
00240
00241 if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16))
00242 {
00243 int16_t syncExtensionType = (int16_t)faad_getbits(&ld, 11
00244 DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType"));
00245
00246 if (syncExtensionType == 0x2b7)
00247 {
00248 mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
00249 DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType"));
00250
00251 if (mp4ASC->objectTypeIndex == 5)
00252 {
00253 mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(&ld
00254 DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag"));
00255
00256 if (mp4ASC->sbr_present_flag)
00257 {
00258 uint8_t tmp;
00259 tmp = (uint8_t)faad_getbits(&ld, 4
00260 DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
00261
00262
00263 if (tmp == mp4ASC->samplingFrequencyIndex)
00264 mp4ASC->downSampledSBR = 1;
00265 mp4ASC->samplingFrequencyIndex = tmp;
00266
00267 if (mp4ASC->samplingFrequencyIndex == 15)
00268 {
00269 mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
00270 DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
00271 } else {
00272 mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
00273 }
00274 }
00275 }
00276 }
00277 }
00278
00279
00280
00281 if (mp4ASC->sbr_present_flag == -1)
00282 {
00283 if (mp4ASC->samplingFrequency <= 24000)
00284 {
00285 mp4ASC->samplingFrequency *= 2;
00286 mp4ASC->forceUpSampling = 1;
00287 } else {
00288 mp4ASC->downSampledSBR = 1;
00289 }
00290 }
00291 #endif
00292
00293 faad_endbits(&ld);
00294
00295 return result;
00296 }