ex
Fork of mbed-os-example-mbed5-blinky by
Embed:
(wiki syntax)
Show/hide line numbers
rda_mp4.h
00001 #ifndef RDA_MP4_H 00002 #define RDA_MP4_H 00003 00004 #ifdef __cplusplus 00005 extern "C" { 00006 #endif /* __cplusplus */ 00007 00008 #include "mp4ff_int_types.h" 00009 #include <stdlib.h> 00010 #include "rda_log.h" 00011 00012 #define INLINE __inline 00013 //#define NULL ((void *) 0) 00014 00015 #define SBR_DEC 00016 //#define PS_DEC 00017 00018 #define MAIN 1 00019 #define LC 2 00020 #define SSR 3 00021 #define LTP 4 00022 #define HE_AAC 5 00023 #define LD 23 00024 #define ER_LC 17 00025 #define ER_LTP 19 00026 #define DRM_ER_LC 27 /* special object type for DRM */ 00027 00028 /* header types */ 00029 #define RAW 0 00030 #define ADIF 1 00031 #define ADTS 2 00032 #define LATM 3 00033 00034 /* SBR signalling */ 00035 #define NO_SBR 0 00036 #define SBR_UPSAMPLED 1 00037 #define SBR_DOWNSAMPLED 2 00038 #define NO_SBR_UPSAMPLED 3 00039 00040 /* First object type that has ER */ 00041 #define ER_OBJECT_START 17 00042 00043 typedef struct _bitfile 00044 { 00045 /* bit input */ 00046 uint32_t bufa; 00047 uint32_t bufb; 00048 uint32_t bits_left; 00049 uint32_t buffer_size; /* size of the buffer in bytes */ 00050 uint32_t bytes_left; 00051 uint8_t error; 00052 uint32_t *tail; 00053 uint32_t *start; 00054 const void *buffer; 00055 } bitfile; 00056 00057 typedef struct mp4AudioSpecificConfig 00058 { 00059 /* Audio Specific Info */ 00060 unsigned char objectTypeIndex; 00061 unsigned char samplingFrequencyIndex; 00062 unsigned long samplingFrequency; 00063 unsigned char channelsConfiguration; 00064 00065 /* GA Specific Info */ 00066 unsigned char frameLengthFlag; 00067 unsigned char dependsOnCoreCoder; 00068 unsigned short coreCoderDelay; 00069 unsigned char extensionFlag; 00070 unsigned char aacSectionDataResilienceFlag; 00071 unsigned char aacScalefactorDataResilienceFlag; 00072 unsigned char aacSpectralDataResilienceFlag; 00073 unsigned char epConfig; 00074 00075 char sbr_present_flag; 00076 char ps_present_flag; 00077 char forceUpSampling; 00078 char downSampledSBR; 00079 } mp4AudioSpecificConfig; 00080 00081 /* circumvent memory alignment errors on ARM */ 00082 static INLINE uint32_t getdword(void *mem) 00083 { 00084 uint32_t tmp; 00085 #ifndef ARCH_IS_BIG_ENDIAN 00086 ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[3]; 00087 ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[2]; 00088 ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[1]; 00089 ((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[0]; 00090 #else 00091 ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0]; 00092 ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1]; 00093 ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2]; 00094 ((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[3]; 00095 #endif 00096 00097 return tmp; 00098 } 00099 00100 /* reads only n bytes from the stream instead of the standard 4 */ 00101 static /*INLINE*/ uint32_t getdword_n(void *mem, int n) 00102 { 00103 uint32_t tmp = 0; 00104 #ifndef ARCH_IS_BIG_ENDIAN 00105 switch (n) 00106 { 00107 case 3: 00108 ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[2]; 00109 case 2: 00110 ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[1]; 00111 case 1: 00112 ((uint8_t*)&tmp)[3] = ((uint8_t*)mem)[0]; 00113 default: 00114 break; 00115 } 00116 #else 00117 switch (n) 00118 { 00119 case 3: 00120 ((uint8_t*)&tmp)[2] = ((uint8_t*)mem)[2]; 00121 case 2: 00122 ((uint8_t*)&tmp)[1] = ((uint8_t*)mem)[1]; 00123 case 1: 00124 ((uint8_t*)&tmp)[0] = ((uint8_t*)mem)[0]; 00125 default: 00126 break; 00127 } 00128 #endif 00129 00130 return tmp; 00131 } 00132 00133 static INLINE uint32_t faad_showbits(bitfile *ld, uint32_t bits) 00134 { 00135 if (bits <= ld->bits_left) 00136 { 00137 //return (ld->bufa >> (ld->bits_left - bits)) & bitmask[bits]; 00138 return (ld->bufa << (32 - ld->bits_left)) >> (32 - bits); 00139 } 00140 00141 bits -= ld->bits_left; 00142 //return ((ld->bufa & bitmask[ld->bits_left]) << bits) | (ld->bufb >> (32 - bits)); 00143 return ((ld->bufa & ((1<<ld->bits_left)-1)) << bits) | (ld->bufb >> (32 - bits)); 00144 } 00145 00146 static /*INLINE*/ void faad_flushbits_ex(bitfile *ld, uint32_t bits) 00147 { 00148 uint32_t tmp; 00149 00150 ld->bufa = ld->bufb; 00151 if (ld->bytes_left >= 4) 00152 { 00153 tmp = getdword(ld->tail); 00154 ld->bytes_left -= 4; 00155 } else { 00156 tmp = getdword_n(ld->tail, ld->bytes_left); 00157 ld->bytes_left = 0; 00158 } 00159 ld->bufb = tmp; 00160 ld->tail++; 00161 ld->bits_left += (32 - bits); 00162 } 00163 00164 static INLINE void faad_flushbits(bitfile *ld, uint32_t bits) 00165 { 00166 /* do nothing if error */ 00167 if (ld->error != 0) 00168 return; 00169 00170 if (bits < ld->bits_left) 00171 { 00172 ld->bits_left -= bits; 00173 } else { 00174 faad_flushbits_ex(ld, bits); 00175 } 00176 } 00177 00178 /* return next n bits (right adjusted) */ 00179 static /*INLINE*/ uint32_t faad_getbits(bitfile *ld, uint32_t n) 00180 { 00181 uint32_t ret; 00182 00183 if (n == 0) 00184 return 0; 00185 00186 ret = faad_showbits(ld, n); 00187 faad_flushbits(ld, n); 00188 00189 return ret; 00190 } 00191 00192 static INLINE uint8_t faad_get1bit(bitfile *ld) 00193 { 00194 uint8_t r; 00195 00196 if (ld->bits_left > 0) 00197 { 00198 ld->bits_left--; 00199 r = (uint8_t)((ld->bufa >> ld->bits_left) & 1); 00200 return r; 00201 } 00202 00203 /* bits_left == 0 */ 00204 #if 0 00205 r = (uint8_t)(ld->bufb >> 31); 00206 faad_flushbits_ex(ld, 1); 00207 #else 00208 r = (uint8_t)faad_getbits(ld, 1); 00209 #endif 00210 return r; 00211 } 00212 00213 void faad_initbits(bitfile *ld, const void *_buffer, const uint32_t buffer_size); 00214 uint8_t faad_byte_align(bitfile *ld); 00215 void faad_endbits(bitfile *ld); 00216 uint32_t faad_get_processed_bits(bitfile *ld); 00217 uint32_t get_sample_rate(const uint8_t sr_index); 00218 int8_t rda_GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC); 00219 int8_t rda_AudioSpecificConfigFromBitfile(bitfile *ld, mp4AudioSpecificConfig *mp4ASC, uint32_t buffer_size, uint8_t short_form); 00220 int8_t rda_AudioSpecificConfig2(uint8_t *pBuffer, uint32_t buffer_size, mp4AudioSpecificConfig *mp4ASC, uint8_t short_form); 00221 int32_t rda_MakeAdtsHeader(unsigned char *data, int size, mp4AudioSpecificConfig *mp4ASC); 00222 uint32_t read_callback(void *user_data, void *buffer, uint32_t length); 00223 uint32_t seek_callback(void *user_data, uint64_t position); 00224 00225 #ifdef __cplusplus 00226 } 00227 #endif /* __cplusplus */ 00228 00229 #endif 00230
Generated on Tue Jul 12 2022 16:28:53 by
1.7.2
