Esempio n. 1
0
void FramePlaybackControl::DoRender(HANDLE& handle, bool bPureCG) 
{
	//Get next CG-frame if we have a CGProducer
	FramePtr pCGFrame;
	if(pCGProducer_) {
		pCGFrame = pCGProducer_->GetFrameBuffer().front();
		FrameBufferFetchResult fetchResult = pCGProducer_->GetFrameBuffer().pop_front();
		if(pCGFrame != 0) {
			pLastCGFrame_ = pCGFrame;
		}
		else if(fetchResult != FetchEOF) {
			pCGFrame = pLastCGFrame_;
		}
		else {
			pCGProducer_.reset();
			LOG << LogLevel::Debug << TEXT("Frameplayback: Cleared CGProducer");
			OnCGEmpty();
			pLastCGFrame_.reset();
		}
	}

	//Get next video frame unless we're in PureCG-mode
	FramePtr pVideoFrame;
	if(!bPureCG || activeClip_.bStopped_) {
		if(frameQueue_.size() > 0) {
			pVideoFrame = frameQueue_.front();
			frameQueue_.pop();

			if(pVideoFrame != 0) {
				pLastVideoFrame_ = pVideoFrame;
			}
		}
		else {
			pVideoFrame = pLastVideoFrame_;
		}

		if(activeClip_.bStopped_ && !frameQueue_.empty())
			eventRender_.Set();
	}
	else {
		pVideoFrame = pLastVideoFrame_;
	}

	//combine and send to consumer
	FramePtr pResultFrame;
	if(pCGFrame) {
		if(pVideoFrame && this->activeClip_.pFP_ != this->emptyProducer_) {
			pResultFrame = pStrategy_->GetReservedFrame();
			if(pResultFrame) {
				utils::image::PreOver(pResultFrame->GetDataPtr(), pVideoFrame->GetDataPtr(), pCGFrame->GetDataPtr(), pResultFrame->GetDataSize());
				pResultFrame->GetAudioData().insert(pResultFrame->GetAudioData().end(), pVideoFrame->GetAudioData().begin(), pVideoFrame->GetAudioData().end());
				pResultFrame->GetAudioData().insert(pResultFrame->GetAudioData().end(), pCGFrame->GetAudioData().begin(), pCGFrame->GetAudioData().end());
			}
		}
		else
			pResultFrame = pCGFrame;
	}
	else
		pResultFrame = pVideoFrame;

	if(pResultFrame)
		pStrategy_->DisplayFrame(pResultFrame.get());
	else if(bPureCG) {
		pResultFrame = pStrategy_->GetReservedFrame();
		if(pResultFrame) {
			utils::image::Clear(pResultFrame->GetDataPtr(), pResultFrame->GetDataSize());
			pStrategy_->DisplayFrame(pResultFrame.get());
		}
	}
}