int bg_avdec_read_video(void * priv, gavl_video_frame_t * frame, int stream) { avdec_priv * avdec = priv; return bgav_read_video(avdec->dec, frame, stream); }
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; }