bool update() { tick(); adjustTime(); FramePtr newFrame = fetchFrame(); if(newFrame != 0){ // Don't free currentFrame if it is currentFrame itself that's being converted if(currentFrame == 0 || currentFrame->GetAvFrame() != newFrame->GetAvFrame()){ currentFrame = newFrame; // Save the current frame for snapshots etc. } lastFrameQueuePts = timeFromTs(newFrame->GetPts()); return true; } return false; }
FramePtr fetchFrame() { bool wasStepIntoQueue = stepIntoQueue; if(frameQueue.empty() && IsEof() && !reportedEof) { reportedEof = true; messageCallback(MEof, "eof"); } if(stepIntoQueue && !frameQueue.empty()) { stepIntoQueue = false; timeHandler->SetTime(timeFromTs(frameQueue.top()->GetPts()) + .001); audioHandler->discardQueueUntilTs(timeHandler->GetTime()); } double time = timeHandler->GetTime(); FramePtr newFrame = 0; // Throw away all old frames (timestamp older than now) except for the last // and set the pFrame pointer to that. int poppedFrames = 0; while(!frameQueue.empty() && timeFromTs(frameQueue.top()->GetPts()) < time) { newFrame = frameQueue.top(); frameQueue.pop(); poppedFrames++; } if(poppedFrames > 1){ FlogD("skipped " << poppedFrames - 1 << " frames"); } if(newFrame != 0 && (newFrame->GetPts() >= time || wasStepIntoQueue)) return newFrame; return 0; }