From 46a5dab5ac45c92862ca75328dd3b53bfb311996 Mon Sep 17 00:00:00 2001 From: Marten Richter Date: Sun, 3 Nov 2013 12:59:02 +0100 Subject: [PATCH] Some fixes for windows 8 --- dsallocator.cc | 42 ++++++++++++++++++++++++++++++++++++------ dsallocator.h | 3 +++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dsallocator.cc b/dsallocator.cc index 9c719a3..841cc5a 100644 --- a/dsallocator.cc +++ b/dsallocator.cc @@ -43,6 +43,7 @@ DsAllocator::DsAllocator() { mfclock=NULL; mfmediatype=NULL; endofstream=false; + start_get_evr_samples=false; ResetSyncOffsets(); @@ -75,6 +76,7 @@ void DsAllocator::CleanupSurfaces() { if (surfaces[i]!=NULL) surfaces[i]->Release(); surfaces[i]=NULL; } + start_get_evr_samples=false; Unlock(); } @@ -87,6 +89,7 @@ HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9All HRESULT hres= surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0)); vheight=allocinf->dwHeight; vwidth=allocinf->dwWidth; + start_get_evr_samples=false; Unlock(); /* char buffer[1024]; sprintf(buffer,"%d * %d",allocinf->dwWidth,allocinf->dwHeight); @@ -137,11 +140,13 @@ HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){ //MessageBox(0,"drive me","drive me",0); ((OsdWin*)Osd::getInstance())->setExternalDriving(this,vwidth,vheight); + start_get_evr_samples=false; return S_OK; } HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){ ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL,0,0); + start_get_evr_samples=false; return S_OK; } @@ -360,6 +365,21 @@ void DsAllocator::GetEVRSamples() mfclock->GetCorrelatedTime(0,&endtime,&dummy); LONGLONG delay=endtime-starttime; mediasink->Notify( EC_PROCESSING_LATENCY,(LONG_PTR)&delay,0); + + //Check if presentation is soon + MFTIME systime=0; + LONGLONG currenttime=0; + hres=outdatabuffer.pSample->GetSampleTime(&prestime); + if (hres==S_OK) + { + if (mfclock) mfclock->GetCorrelatedTime(0,¤ttime,&systime); + } + LONGLONG delta=prestime-currenttime; + if (delta<0) { + break; //break if presentation is soon + } + + } } else break; @@ -372,15 +392,20 @@ HRESULT STDMETHODCALLTYPE DsAllocator::ProcessMessage(MFVP_MESSAGE_TYPE mess,ULO switch (mess) { case MFVP_MESSAGE_FLUSH:{ //Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_FLUSH received"); - FlushEVRSamples(); }break; + FlushEVRSamples(); + start_get_evr_samples=false; + }break; case MFVP_MESSAGE_INVALIDATEMEDIATYPE: { Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_INVALIDATEMEDIATYPE received"); if (mfmediatype) mfmediatype->Release(); mfmediatype=NULL; + start_get_evr_samples=false; RenegotiateEVRMediaType();}break; case MFVP_MESSAGE_PROCESSINPUTNOTIFY: { - //Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_PROCESSINPUTNOTIFY received"); - GetEVRSamples(); } break; + Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_PROCESSINPUTNOTIFY received"); + if (!start_get_evr_samples) GetEVRSamples(); + start_get_evr_samples=true; + } break; case MFVP_MESSAGE_BEGINSTREAMING:{ Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_BEGINSTREAMING received"); ResetSyncOffsets(); @@ -392,6 +417,7 @@ HRESULT STDMETHODCALLTYPE DsAllocator::ProcessMessage(MFVP_MESSAGE_TYPE mess,ULO Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_ENDSTREAMING received"); ((OsdWin*)Osd::getInstance())->SetEVRStatus(OsdWin::EVR_pres_off); ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL,vwidth,vheight); + start_get_evr_samples=false; //FlushEVRSamples(); //if (mfmediatype) mfmediatype->Release(); //mfmediatype=NULL; @@ -400,6 +426,7 @@ HRESULT STDMETHODCALLTYPE DsAllocator::ProcessMessage(MFVP_MESSAGE_TYPE mess,ULO Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_ENDOFSTREAM received"); MessageBox(0,"endofstream","endofstream",0); endofstream=true; + start_get_evr_samples=false; } break; case MFVP_MESSAGE_STEP: { Log::getInstance()->log("DsAllocator", Log::DEBUG , "EVR Message MFVP_MESSAGE_STEP received"); @@ -427,7 +454,7 @@ HRESULT STDMETHODCALLTYPE DsAllocator::OnClockStart(MFTIME systime,LONGLONG star ((OsdWin*)Osd::getInstance())->setExternalDriving(this,vwidth,vheight); Log::getInstance()->log("DsAllocator", Log::DEBUG , "OnClockStart"); ((OsdWin*)Osd::getInstance())->SetEVRStatus(OsdWin::EVR_pres_started); - GetEVRSamples(); + //GetEVRSamples(); return S_OK; } @@ -637,8 +664,11 @@ void DsAllocator::GetNextSurface(LPDIRECT3DSURFACE9* surf,DWORD *waittime) *surf=NULL; *waittime=10; - if (fullevrsamples.size()==0) GetEVRSamples(); Lock(); + if (fullevrsamples.size()==0) { + *waittime=1; + if (start_get_evr_samples) GetEVRSamples(); + } //Log::getInstance()->log("DsAllocator", Log::DEBUG , "Enter Get Next Surface"); while (fullevrsamples.size()>0) @@ -721,7 +751,7 @@ void DsAllocator::GetNextSurface(LPDIRECT3DSURFACE9* surf,DWORD *waittime) void DsAllocator::DiscardSurfaceandgetWait(DWORD *waittime) { //Log::getInstance()->log("DsAllocator", Log::DEBUG , "Discard surface and get Wait"); - GetEVRSamples(); + if (start_get_evr_samples) GetEVRSamples(); //Log::getInstance()->log("DsAllocator", Log::DEBUG , "Discard surface and get Wait2"); Lock(); if (fullevrsamples.size()==0) { diff --git a/dsallocator.h b/dsallocator.h index 5134c2c..645c3fb 100644 --- a/dsallocator.h +++ b/dsallocator.h @@ -110,6 +110,7 @@ protected: DWORD vwidth; bool inevrmode; bool endofstream; + bool start_get_evr_samples; IMFTransform* mftransform; IMediaEventSink* mediasink; @@ -129,6 +130,8 @@ protected: int avgfps; LONGLONG lastdelframe; + + }; -- 2.39.2