//--------------------------------------------------------------------------- int ofQuickTimePlayer::getCurrentFrame(){ if( !isLoaded() ){ ofLog(OF_LOG_ERROR, "ofQuickTimePlayer: movie not loaded!"); return 0; } //-------------------------------------- #ifdef OF_VIDEO_PLAYER_QUICKTIME //-------------------------------------- int frame = 0; // zach I think this may fail on variable length frames... float pos = getPosition(); float framePosInFloat = ((float)getTotalNumFrames() * pos); int framePosInInt = (int)framePosInFloat; float floatRemainder = (framePosInFloat - framePosInInt); if (floatRemainder > 0.5f) framePosInInt = framePosInInt + 1; //frame = (int)ceil((getTotalNumFrames() * getPosition())); frame = framePosInInt; return frame; //-------------------------------------- #endif //-------------------------------------- }
//--------------------------------------------------------------------------- int ofVideoPlayer::getCurrentFrame(){ //-------------------------------------- #ifdef OF_VIDEO_PLAYER_QUICKTIME //-------------------------------------- int frame = 0; // zach I think this may fail on variable length frames... float pos = getPosition(); float framePosInFloat = ((float)getTotalNumFrames() * pos); int framePosInInt = (int)framePosInFloat; float floatRemainder = (framePosInFloat - framePosInInt); if (floatRemainder > 0.5f) framePosInInt = framePosInInt + 1; //frame = (int)ceil((getTotalNumFrames() * getPosition())); frame = framePosInInt; return frame; //-------------------------------------- #else //-------------------------------------- return gstUtils.getCurrentFrame(); //-------------------------------------- #endif //-------------------------------------- }
int ofGstVideoPlayer::getCurrentFrame(){ int frame = 0; // zach I think this may fail on variable length frames... float pos = getPosition(); if(pos == -1) return -1; float framePosInFloat = ((float)getTotalNumFrames() * pos); int framePosInInt = (int)framePosInFloat; float floatRemainder = (framePosInFloat - framePosInInt); if (floatRemainder > 0.5f) framePosInInt = framePosInInt + 1; //frame = (int)ceil((getTotalNumFrames() * getPosition())); frame = framePosInInt; return frame; }
/** * Detect frozen frames (?) * * \todo reality check */ void omPlayer::iceBreak() { //DETECT END / LOOP since Listener in ofxOMX are broken int maxFrame = getTotalNumFrames()-1; int currentFrame = getCurrentFrameNbr(); if (this->listener != NULL) { //FILE REACH THE END if ((currentFrame == maxFrame) and (lastFrame < maxFrame)) listener->onVideoEnd(); //FREEZE detection (due to wrong frame counter) if ((currentFrame == lastFrame) && (!this->isPaused())) { if (freeze++ > 50) { listener->onVideoFreeze(); ofLog(OF_LOG_ERROR, "ICE BROKEN"); freeze = 0; lastFrame = 0; } } else freeze = 0; } lastFrame = currentFrame; }
void ofxOMXPlayerEngine::Process() { while (!m_bStop) { //struct timespec starttime, endtime; /*printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r", clock.OMXMediaTime(), videoPlayer->GetDecoderBufferSize(), videoPlayer->GetDecoderFreeSpace(), audioPlayer->GetCurrentPTS() / DVD_TIME_BASE, audioPlayer->GetDelay(), videoPlayer->GetCached(), audioPlayer->GetCached());*/ if(omxReader.IsEof() && !packet) { //ofLogVerbose() << "Dumping Cache " << "Audio Cache: " << audioPlayer->GetCached() << " Video Cache: " << videoPlayer->GetCached(); bool isCacheEmpty = false; if (hasAudio) { if (!audioPlayer->GetCached() && !videoPlayer->GetCached()) { isCacheEmpty = true; } }else { if (!videoPlayer->GetCached()) { isCacheEmpty = true; } } if (isCacheEmpty) { /* The way this works is that loop_offset is a marker (actually the same as the DURATION) Once the file reader seeks to the beginning of the file again loop_offset is then added to subsequent packet's timestamps */ if (GlobalEGLContainer::getInstance().doLooping)//TODO: figure this out { ofLogVerbose(__func__) << "ABOUT TO ATTEMPT LOOP GlobalEGLContainer::getInstance().doLooping " << GlobalEGLContainer::getInstance().doLooping; omxReader.SeekTime(0 * 1000.0f, AVSEEK_FLAG_BACKWARD, &startpts); if(hasAudio) { loop_offset = audioPlayer->GetCurrentPTS(); ofLogVerbose() << "LOOP via audioPlayer [] [] [] [] [] [] [] []"; } else if(hasVideo) { loop_offset = videoPlayer->GetCurrentPTS(); ofLogVerbose() << "LOOP via videoPlayer [] [] [] [] [] [] [] []"; } loopCounter++; ofLog(OF_LOG_VERBOSE, "Loop offset : %8.02f\n", loop_offset / DVD_TIME_BASE); } else { onVideoEnd(); break; } } else { OMXClock::OMXSleep(10); continue; } } if (GlobalEGLContainer::getInstance().doLooping && OMXDecoderBase::fillBufferCounter>=getTotalNumFrames()) { OMXDecoderBase::fillBufferCounter=0; } if (hasAudio) { if(audioPlayer->Error()) { ofLogError(__func__) << "audio player error."; } } if(!packet) { packet = omxReader.Read(); if (packet && GlobalEGLContainer::getInstance().doLooping && packet->pts != DVD_NOPTS_VALUE) { packet->pts += loop_offset; packet->dts += loop_offset; } } if(hasVideo && packet && omxReader.IsActive(OMXSTREAM_VIDEO, packet->stream_index)) { if(videoPlayer->AddPacket(packet)) { packet = NULL; } else { OMXClock::OMXSleep(10); } } else if(hasAudio && packet && packet->codec_type == AVMEDIA_TYPE_AUDIO) { if(audioPlayer->AddPacket(packet)) { packet = NULL; } else { OMXClock::OMXSleep(10); } } else { if(packet) { omxReader.FreePacket(packet); packet = NULL; } } } }