@@ -212,90 +212,94 @@ void ADTSAudioFifoSource::doReadFromFile() {
212212#else
213213 if (read (fileno (fFid ), headers, sizeof headers) < (signed ) sizeof headers) {
214214#endif
215- // The input source has ended:
216- handleClosure ();
217- return ;
218- }
215+ fFrameSize = 0 ;
216+ fNumTruncatedBytes = 0 ;
217+ // // The input source has ended:
218+ // handleClosure();
219+ // return;
220+ } else {
219221
220- // Extract important fields from the headers:
221- Boolean protection_absent = headers[1 ]&0x01 ;
222- u_int16_t frame_length
223- = ((headers[3 ]&0x03 )<<11 ) | (headers[4 ]<<3 ) | ((headers[5 ]&0xE0 )>>5 );
224- u_int16_t syncword = (headers[0 ]<<4 ) | (headers[1 ]>>4 );
225- if (debug & 4 ) fprintf (stderr, " Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n " , syncword, protection_absent, frame_length);
226- if (syncword != 0xFFF ) {
227- fprintf (stderr, " WARNING: Bad syncword! Try to recover sync.\n " );
228- // Resync
229- while (1 ) {
222+ // Extract important fields from the headers:
223+ Boolean protection_absent = headers[1 ]&0x01 ;
224+ u_int16_t frame_length
225+ = ((headers[3 ]&0x03 )<<11 ) | (headers[4 ]<<3 ) | ((headers[5 ]&0xE0 )>>5 );
226+ u_int16_t syncword = (headers[0 ]<<4 ) | (headers[1 ]>>4 );
227+ if (debug & 4 ) fprintf (stderr, " Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n " , syncword, protection_absent, frame_length);
228+ if (syncword != 0xFFF ) {
229+ fprintf (stderr, " WARNING: Bad syncword! Try to recover sync.\n " );
230+ // Resync
231+ while (1 ) {
230232#ifdef READ_FROM_FILES_SYNCHRONOUSLY
231- fread (headers, 1 , 1 , fFid );
233+ fread (headers, 1 , 1 , fFid );
232234#else
233- read (fileno (fFid ), headers, 1 );
235+ read (fileno (fFid ), headers, 1 );
234236#endif
235- if (headers[0 ] == 0xFF ) {
237+ if (headers[0 ] == 0xFF ) {
236238#ifdef READ_FROM_FILES_SYNCHRONOUSLY
237- fread (&headers[1 ], 1 , 1 , fFid );
239+ fread (&headers[1 ], 1 , 1 , fFid );
238240#else
239- read (fileno (fFid ), &headers[1 ], 1 );
241+ read (fileno (fFid ), &headers[1 ], 1 );
240242#endif
241- // Check the 'syncword':
242- if ((headers[1 ]&0xF0 ) == 0xF0 ) {
243+ // Check the 'syncword':
244+ if ((headers[1 ]&0xF0 ) == 0xF0 ) {
243245#ifdef READ_FROM_FILES_SYNCHRONOUSLY
244- fread (&headers[2 ], 1 , sizeof (headers) - 2 , fFid );
246+ fread (&headers[2 ], 1 , sizeof (headers) - 2 , fFid );
245247#else
246- read (fileno (fFid ), &headers[2 ], sizeof (headers) - 2 );
248+ read (fileno (fFid ), &headers[2 ], sizeof (headers) - 2 );
247249#endif
248- break ;
250+ break ;
251+ }
249252 }
253+ usleep (1000 );
250254 }
251- usleep (10000 );
252255 }
253- }
254- unsigned numBytesToRead
255- = frame_length > sizeof headers ? frame_length - sizeof headers : 0 ;
256+ unsigned numBytesToRead
257+ = frame_length > sizeof headers ? frame_length - sizeof headers : 0 ;
256258
257- // If there's a 'crc_check' field, skip it:
258- if (!protection_absent) {
259- unsigned char null[2 ];
259+ // If there's a 'crc_check' field, skip it:
260+ if (!protection_absent) {
261+ unsigned char null[2 ];
260262#ifdef READ_FROM_FILES_SYNCHRONOUSLY
261- fread (null, 1 , 2 , fFid );
263+ fread (null, 1 , 2 , fFid );
262264#else
263- read (fileno (fFid ), null, 2 );
265+ read (fileno (fFid ), null, 2 );
264266#endif
265- numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0 ;
266- }
267+ numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0 ;
268+ }
267269
268- // Next, read the raw frame data into the buffer provided:
269- if (numBytesToRead > fMaxSize ) {
270- fNumTruncatedBytes = numBytesToRead - fMaxSize ;
271- numBytesToRead = fMaxSize ;
272- }
270+ // Next, read the raw frame data into the buffer provided:
271+ if (numBytesToRead > fMaxSize ) {
272+ fNumTruncatedBytes = numBytesToRead - fMaxSize ;
273+ numBytesToRead = fMaxSize ;
274+ }
273275#ifdef READ_FROM_FILES_SYNCHRONOUSLY
274- int numBytesRead = fread (fTo , 1 , numBytesToRead, fFid );
276+ int numBytesRead = fread (fTo , 1 , numBytesToRead, fFid );
275277#else
276- int numBytesRead = read (fileno (fFid ), fTo , numBytesToRead);
278+ int numBytesRead = read (fileno (fFid ), fTo , numBytesToRead);
277279#endif
278- if (numBytesRead < 0 ) numBytesRead = 0 ;
279- fFrameSize = numBytesRead;
280- fNumTruncatedBytes += numBytesToRead - numBytesRead;
281-
282- // Set the 'presentation time':
283- if (fPresentationTime .tv_sec == 0 && fPresentationTime .tv_usec == 0 ) {
284- // This is the first frame, so use the current time:
285- gettimeofday (&fPresentationTime , NULL );
286- } else {
280+ if (numBytesRead < 0 ) numBytesRead = 0 ;
281+ fFrameSize = numBytesRead;
282+ fNumTruncatedBytes += numBytesToRead - numBytesRead;
283+
284+ // Set the 'presentation time':
285+ if (fPresentationTime .tv_sec == 0 && fPresentationTime .tv_usec == 0 ) {
286+ // This is the first frame, so use the current time:
287+ gettimeofday (&fPresentationTime , NULL );
288+ } else {
287289#ifndef PRES_TIME_CLOCK
288- // Increment by the play time of the previous frame:
289- unsigned uSeconds = fPresentationTime .tv_usec + fuSecsPerFrame;
290- fPresentationTime .tv_sec += uSeconds/1000000 ;
291- fPresentationTime .tv_usec = uSeconds%1000000 ;
290+ // Increment by the play time of the previous frame:
291+ unsigned uSeconds = fPresentationTime .tv_usec + fuSecsPerFrame;
292+ fPresentationTime .tv_sec += uSeconds/1000000 ;
293+ fPresentationTime .tv_usec = uSeconds%1000000 ;
292294#else
293- // Use system clock to set presentation time
294- gettimeofday (&fPresentationTime , NULL );
295+ // Use system clock to set presentation time
296+ gettimeofday (&fPresentationTime , NULL );
295297#endif
296- }
298+ }
299+ if (debug & 4 ) fprintf (stderr, " AAC frame - fPresentationTime, sec = %ld, usec = %ld\n " , fPresentationTime .tv_sec , fPresentationTime .tv_usec );
297300
298- fDurationInMicroseconds = fuSecsPerFrame;
301+ fDurationInMicroseconds = fuSecsPerFrame;
302+ }
299303
300304 // Switch to another task, and inform the reader that he has data:
301305#ifdef READ_FROM_FILES_SYNCHRONOUSLY
0 commit comments