void *the_videofifo_filler( void * xp) { ReadMedia *rm = (ReadMedia *)xp; int ret = 0; int first = true; int doaudio = rm->getAudioStreamCount(); int64_t seekto =SEEK_NOTHING; int can_seek = bgav_can_seek ( rm->getFile() ); int can_seek_sample = bgav_can_seek_sample ( rm->getFile() ); int timescale = rm->getVideoTimescale(); while (!rm->quitAVThreads() ) { while ( rm->getVideoFifo() !=NULL && rm->getVideoFifo()->FreeSpace() && !rm->getVEOF() ) { if (rm->quitAVThreads() ) pthread_exit(NULL);//return NULL; rm->lockAV(); // check to see if we need to seek // if this is set, we already know we can seek on this file // and don't need to check with bgav_can_seek if (can_seek) { seekto = rm->frameSeek(); if ( seekto >= 0 ) { if (doaudio && rm->getAudioFifo() ) rm->getAudioFifo()->Flush(); rm->getVideoFifo()->Flush(); bgav_seek_scaled(rm->getFile(), &seekto, timescale); } else if (seekto == SEEK_REWIND && !doaudio) { // rewind is a special case for Video. rm->getVideoFifo()->Flush(); seekto =0; bgav_seek_scaled(rm->getFile(), &seekto, timescale); } } ret = bgav_read_video(rm->getFile(), rm->getVideoFrame(), 0 ); if ( !ret ) { // only loop from video if there is no audio // audio controls loop timing if ( rm->getLoop() ){ if ( can_seek ) { if (doaudio && can_seek_sample) { // seek on video stream only if we have audio // audio and video seeking are separate in sample accurate // seeking. If no sample accurate seeking, then let audio // handle seeking bgav_seek_video(rm->getFile(), 0,0); } else if (!doaudio) { // if we don't have audio...just seek to 0 seekto=0; bgav_seek_scaled(rm->getFile(), &seekto, timescale); } } else { // if (can_seek) printf ("We want to loop video, but we cannot seek on this video stream,setting VEOF\n"); rm->setVEOF(true); } } else { rm->setVEOF(true); } rm->unlockAV(); break; } rm->unlockAV(); if( !rm->getVideoFifo()->Append( rm->getVideoFrame() )) printf("problem with appending VideoFrame\n"); } // on the first time 'round we will call the open callback // if there is no video in the file, the audio will handle it. if (first) { rm->setState( STATE_READY ); rm->callOpenCallback(); first = false; } if (rm->quitAVThreads() ) pthread_exit(NULL); //return NULL; rm->waitV(); } pthread_exit(NULL); //return NULL; }
void bg_avdec_seek(void * priv, int64_t * t, int scale) { avdec_priv * avdec = priv; bgav_seek_scaled(avdec->dec, t, scale); }
void *the_audiofifo_filler( void * xp) { int samples_returned=0; ReadMedia *rm = (ReadMedia *)xp; int first = true; int dovideo = rm->getVideoStreamCount(); int spf = rm->getSamplesPerFrame(); int samplerate = rm->getAudioSamplerate(); int64_t seekto = SEEK_NOTHING; int can_seek = bgav_can_seek ( rm->getFile() ); int can_seek_sample = bgav_can_seek_sample ( rm->getFile() ); while ( !rm->quitAVThreads() ) { //while ( rm->getAudioFifo() != NULL && rm->getAudioFifo()->FreeSpace() && !rm->getAEOF() ) { while ( rm->getAudioFifo()->FreeSpace() && !rm->getAEOF() ) { if (rm->quitAVThreads() ) pthread_exit(NULL) ; //return NULL; rm->lockAV(); // check to see if we need to seek // if this is set, we already know we can seek on this file // and don't need to check with bgav_can_seek if ( can_seek ) { seekto = rm->pcmSeek(); if ( seekto != SEEK_NOTHING ) { if ( seekto == SEEK_REWIND) { // bgav_seek_audio ONLY seeks on the audio stream seekto = 0; // bgav_seek_scaled(rm->getFile(), &seekto, samplerate); } //else { bgav_seek_scaled(rm->getFile(), &seekto, samplerate); //} rm->getAudioFifo()->Flush(); if (dovideo && rm->getVideoFifo() ) { rm->getVideoFifo()->Flush(); rm->signalV(); } } } samples_returned = bgav_read_audio(rm->getFile(), rm->getAudioFrame(), 0, spf ); //rm->unlockAV(); if (samples_returned == 0 ) { if( rm->getLoop() ) { if ( can_seek ) { // Now, rewind the file, don't flush the fifo's if (can_seek_sample) { // only seek on audio stream bgav_seek_audio(rm->getFile(), 0, 0); } else { seekto =0; bgav_seek_scaled(rm->getFile(), &seekto, samplerate); if (dovideo && rm->getVideoFifo() ) { rm->setVEOF(false); rm->signalV(); } } // SAVE THIS FOR ANOTHER TIME, OVERLAPPED SMOOTH LOOPING //if ( rm->getLoop() > 1 && bgav_read_audio(rm->getFile(), rm->getAudioFrame(), 0, spf ) ) { // add to the fifo, overlapping // rm->getAudioFifo()->AppendOverlap( rm->getAudioFrame(), 5 ); // } } else { // this file is not seekable, what do we do? printf("cannot seek on file, but we want to loop. setting end of file.\n"); rm->setAEOF(true); } } else { rm->setAEOF(true); } rm->unlockAV(); break; } rm->unlockAV(); if( !rm->getAudioFifo()->Append( rm->getAudioFrame() )) printf("problem with appending Audio Frame\n"); } if (first && !dovideo) { rm->setState( STATE_READY ); rm->callOpenCallback(); first = false; } if (rm->quitAVThreads() ) pthread_exit(NULL); //return NULL; rm->waitA(); } pthread_exit(NULL);//return NULL; }