comparison libfaad2/decoder.c @ 25836:bc425ba00960

added code to check and handle the presence of LATM streams in the init() and decode() functions
author nicodvb
date Sat, 26 Jan 2008 18:45:11 +0000
parents 645cbba10a57
children e83eef58b30a
comparison
equal deleted inserted replaced
25835:645cbba10a57 25836:bc425ba00960
193 } 193 }
194 194
195 return 0; 195 return 0;
196 } 196 }
197 197
198 static int latmCheck(latm_header *latm, bitfile *ld)
199 {
200 uint32_t good=0, bad=0, bits, m;
201
202 while(!ld->error && !ld->no_more_reading)
203 {
204 bits = faad_latm_frame(latm, ld);
205 if(bits==-1U)
206 bad++;
207 else
208 {
209 good++;
210 while(bits>0)
211 {
212 m = min(bits, 8);
213 faad_getbits(ld, m);
214 bits -= m;
215 }
216 }
217 }
218
219 return (good>0);
220 }
221
222
198 int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer, 223 int32_t NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder, uint8_t *buffer,
199 uint32_t buffer_size, 224 uint32_t buffer_size,
200 uint32_t *samplerate, uint8_t *channels) 225 uint32_t *samplerate, uint8_t *channels)
201 { 226 {
202 uint32_t bits = 0; 227 uint32_t bits = 0;
212 *samplerate = get_sample_rate(hDecoder->sf_index); 237 *samplerate = get_sample_rate(hDecoder->sf_index);
213 *channels = 1; 238 *channels = 1;
214 239
215 if (buffer != NULL) 240 if (buffer != NULL)
216 { 241 {
242 int is_latm;
243 latm_header *l = &hDecoder->latm_config;
217 faad_initbits(&ld, buffer, buffer_size); 244 faad_initbits(&ld, buffer, buffer_size);
218 245
246 memset(l, 0, sizeof(latm_header));
247 is_latm = latmCheck(l, &ld);
248 l->inited = 0;
249 l->frameLength = 0;
250 faad_rewindbits(&ld);
251 if(is_latm && l->ASCbits>0)
252 {
253 int32_t x;
254 hDecoder->latm_header_present = 1;
255 x = NeAACDecInit2(hDecoder, &l->ASC, (l->ASCbits+7)/8, samplerate, channels);
256 if(x!=0)
257 hDecoder->latm_header_present = 0;
258 return x;
259 }
260 else
219 /* Check if an ADIF header is present */ 261 /* Check if an ADIF header is present */
220 if ((buffer[0] == 'A') && (buffer[1] == 'D') && 262 if ((buffer[0] == 'A') && (buffer[1] == 'D') &&
221 (buffer[2] == 'I') && (buffer[3] == 'F')) 263 (buffer[2] == 'I') && (buffer[3] == 'F'))
222 { 264 {
223 hDecoder->adif_header_present = 1; 265 hDecoder->adif_header_present = 1;
731 uint8_t output_channels = 0; 773 uint8_t output_channels = 0;
732 bitfile ld; 774 bitfile ld;
733 uint32_t bitsconsumed; 775 uint32_t bitsconsumed;
734 uint16_t frame_len; 776 uint16_t frame_len;
735 void *sample_buffer; 777 void *sample_buffer;
778 uint32_t startbit=0, endbit=0, payload_bits=0;
736 779
737 #ifdef PROFILE 780 #ifdef PROFILE
738 int64_t count = faad_get_ts(); 781 int64_t count = faad_get_ts();
739 #endif 782 #endif
740 783
773 faad_endbits(&ld); 816 faad_endbits(&ld);
774 faad_initbits(&ld, buffer, buffer_size); 817 faad_initbits(&ld, buffer, buffer_size);
775 } 818 }
776 #endif 819 #endif
777 820
821 if(hDecoder->latm_header_present)
822 {
823 payload_bits = faad_latm_frame(&hDecoder->latm_config, &ld);
824 startbit = faad_get_processed_bits(&ld);
825 if(payload_bits == -1U)
826 {
827 hInfo->error = 1;
828 goto error;
829 }
830 }
831
778 #ifdef DRM 832 #ifdef DRM
779 if (hDecoder->object_type == DRM_ER_LC) 833 if (hDecoder->object_type == DRM_ER_LC)
780 { 834 {
781 /* We do not support stereo right now */ 835 /* We do not support stereo right now */
782 if (0) //(hDecoder->channelConfiguration == 2) 836 if (0) //(hDecoder->channelConfiguration == 2)
818 raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc); 872 raw_data_block(hDecoder, hInfo, &ld, &hDecoder->pce, hDecoder->drc);
819 #ifdef SCALABLE_DEC 873 #ifdef SCALABLE_DEC
820 } 874 }
821 #endif 875 #endif
822 876
877 if(hDecoder->latm_header_present)
878 {
879 endbit = faad_get_processed_bits(&ld);
880 if(endbit-startbit > payload_bits)
881 fprintf(stderr, "\r\nERROR, too many payload bits read: %u > %d. Please. report with a link to a sample\n",
882 endbit-startbit, payload_bits);
883 if(hDecoder->latm_config.otherDataLenBits > 0)
884 faad_getbits(&ld, hDecoder->latm_config.otherDataLenBits);
885 faad_byte_align(&ld);
886 }
887
823 channels = hDecoder->fr_channels; 888 channels = hDecoder->fr_channels;
824 889
825 if (hInfo->error > 0) 890 if (hInfo->error > 0)
826 goto error; 891 goto error;
827 892
842 goto error; 907 goto error;
843 } 908 }
844 faad_endbits(&ld); 909 faad_endbits(&ld);
845 910
846 911
847 if (!hDecoder->adts_header_present && !hDecoder->adif_header_present) 912 if (!hDecoder->adts_header_present && !hDecoder->adif_header_present && !hDecoder->latm_header_present)
848 { 913 {
849 if (hDecoder->channelConfiguration == 0) 914 if (hDecoder->channelConfiguration == 0)
850 hDecoder->channelConfiguration = channels; 915 hDecoder->channelConfiguration = channels;
851 916
852 if (channels == 8) /* 7.1 */ 917 if (channels == 8) /* 7.1 */
891 hInfo->header_type = RAW; 956 hInfo->header_type = RAW;
892 if (hDecoder->adif_header_present) 957 if (hDecoder->adif_header_present)
893 hInfo->header_type = ADIF; 958 hInfo->header_type = ADIF;
894 if (hDecoder->adts_header_present) 959 if (hDecoder->adts_header_present)
895 hInfo->header_type = ADTS; 960 hInfo->header_type = ADTS;
961 if (hDecoder->latm_header_present)
962 hInfo->header_type = LATM;
896 #if (defined(PS_DEC) || defined(DRM_PS)) 963 #if (defined(PS_DEC) || defined(DRM_PS))
897 hInfo->ps = hDecoder->ps_used_global; 964 hInfo->ps = hDecoder->ps_used_global;
898 #endif 965 #endif
899 966
900 /* check if frame has channel elements */ 967 /* check if frame has channel elements */