From 056e0def9693bb5e45e3b31c35806ea6a6405111 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 25 Nov 2006 01:02:47 +0000 Subject: [PATCH] Windows updates --- videowin.cc | 89 +++++++++++++++++++++++++++++++++-------------------- videowin.h | 2 +- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/videowin.cc b/videowin.cc index e8b014a..ad0390f 100644 --- a/videowin.cc +++ b/videowin.cc @@ -211,9 +211,11 @@ int VideoWin::dsplay() //Build filter graph HRESULT hres; - +//So this is the real code, this prevents the feeder from calling noexisting objects! + WaitForSingleObject(filtermutex,INFINITE); if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) { + ReleaseMutex(filtermutex); return 0; } #ifdef DS_DEBUG @@ -221,22 +223,22 @@ int VideoWin::dsplay() #endif //This is just a try to see if building the graph works // dsgraphbuilder->RenderFile(L"D:\\Projekte\\VTP Client\\test.mpa" ,NULL); - //So this is the real code, this prevents the feeder from calling noexisting objects! - WaitForSingleObject(filtermutex,INFINITE); + firstsynched=false; sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data // to DirectShow + sourcefilter->AddRef(); if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!"); + ReleaseMutex(filtermutex); CleanupDS(); - ReleaseMutex(filtermutex); return 0; } //if (audioon) { - if (hres=dsgraphbuilder->Render(sourcefilter->GetPin(0)/*audio*/)!=S_OK) { + if (hres=dsgraphbuilder->Render((IPin*)sourcefilter->GetAudioPin()/*audio*/)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering audio!"); + ReleaseMutex(filtermutex); CleanupDS(); - ReleaseMutex(filtermutex); return 0; } //} @@ -246,30 +248,33 @@ int VideoWin::dsplay() if (hres=CoCreateInstance(CLSID_VideoMixingRenderer9,0, CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!"); + ReleaseMutex(filtermutex); CleanupDS(); - ReleaseMutex(filtermutex); + } /*VMR 9 stuff**/ if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) { + ReleaseMutex(filtermutex); CleanupDS(); Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!"); - ReleaseMutex(filtermutex); + return 0; } IVMRFilterConfig9* vmrfilconfig; if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) { - CleanupDS(); - Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!"); ReleaseMutex(filtermutex); + CleanupDS(); + Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!"); return 0; } vmrfilconfig->SetRenderingMode(VMR9Mode_Renderless); vmrfilconfig->Release(); if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) { - CleanupDS(); - Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!"); ReleaseMutex(filtermutex); + CleanupDS(); + Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!"); + return 0; } allocatorvmr=new DsAllocator(); @@ -283,16 +288,16 @@ int VideoWin::dsplay() IFilterGraph2*fg2=NULL; if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!"); - CleanupDS(); ReleaseMutex(filtermutex); + CleanupDS(); return 0; } - if (hres=fg2->RenderEx(sourcefilter->GetPin(1)/*video*/, + if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/, AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!"); fg2->Release(); - CleanupDS(); - ReleaseMutex(filtermutex); + ReleaseMutex(filtermutex); + CleanupDS(); return 0; } fg2->Release(); @@ -304,12 +309,12 @@ int VideoWin::dsplay() } dsgraphbuilder->QueryInterface(IID_IMediaFilter,(void **) &dsmediafilter); - dsmediafilter->SetSyncSource(dsrefclock); + HRESULT hresdeb=dsmediafilter->SetSyncSource(dsrefclock); dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol); dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio); - dsmediacontrol->Run(); + hresdeb=dsmediacontrol->Run(); iframemode=false;//exit iframe mode ReleaseMutex(filtermutex); return 1; @@ -319,25 +324,28 @@ int VideoWin::EnterIframePlayback() { if (!initted) return 0; CleanupDS(); + //So this is the real code, this prevents the feeder from calling noexisting objects! + WaitForSingleObject(filtermutex,INFINITE); iframemode=true;//enter iframe mode //Build filter graph HRESULT hres; if (hres=CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder,(void**)&dsgraphbuilder)!=S_OK) { + ReleaseMutex(filtermutex); return 0; } #ifdef DS_DEBUG AddToRot(dsgraphbuilder,&graphidentifier); #endif - //So this is the real code, this prevents the feeder from calling noexisting objects! - WaitForSingleObject(filtermutex,INFINITE); + //firstsynched=false; sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data // to DirectShow + sourcefilter->AddRef(); if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!"); + ReleaseMutex(filtermutex); CleanupDS(); - ReleaseMutex(filtermutex); return 0; } #ifdef DO_VIDEO @@ -346,31 +354,32 @@ int VideoWin::EnterIframePlayback() if (hres=CoCreateInstance(CLSID_VideoMixingRenderer9,0, CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void**) &dsvmrrenderer)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN ,"Failed creating VMR9 renderer!"); - CleanupDS(); ReleaseMutex(filtermutex); + CleanupDS(); return 0; } /*VMR 9 stuff**/ if (hres=dsgraphbuilder->AddFilter(dsvmrrenderer,L"VMR9")!=S_OK) { - CleanupDS(); Log::getInstance()->log("VideoWin", Log::WARN ,"Failed adding VMR9 renderer!"); ReleaseMutex(filtermutex); + CleanupDS(); return 0; } IVMRFilterConfig9* vmrfilconfig; if (dsvmrrenderer->QueryInterface(IID_IVMRFilterConfig9,(void**)&vmrfilconfig)!=S_OK) { - CleanupDS(); - Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!"); ReleaseMutex(filtermutex); + CleanupDS(); + Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Filterconfig interface!"); + return 0; } vmrfilconfig->SetRenderingMode(VMR9Mode_Renderless); vmrfilconfig->Release(); - if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) { - CleanupDS(); + if (dsvmrrenderer->QueryInterface(IID_IVMRSurfaceAllocatorNotify9,(void**)& dsvmrsurfnotify)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN ,"Failed getting VMR9 Surface Allocator interface!"); ReleaseMutex(filtermutex); + CleanupDS(); return 0; } allocatorvmr=new DsAllocator(); @@ -381,16 +390,16 @@ int VideoWin::EnterIframePlayback() IFilterGraph2*fg2=NULL; if (dsgraphbuilder->QueryInterface(IID_IFilterGraph2,(void**)&fg2)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed querying for FilterGraph2 Interface!"); - CleanupDS(); ReleaseMutex(filtermutex); + CleanupDS(); return 0; } - if (hres=fg2->RenderEx(sourcefilter->GetPin(1)/*video*/, + if (hres=fg2->RenderEx((IPin*)sourcefilter->GetVideoPin()/*video*/, AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL)!=S_OK) { Log::getInstance()->log("VideoWin", Log::WARN , "Failed rendering Video!"); fg2->Release(); + ReleaseMutex(filtermutex); CleanupDS(); - ReleaseMutex(filtermutex); return 0; } fg2->Release(); @@ -453,7 +462,9 @@ int VideoWin::dsreset() int VideoWin::dspause() { if (!initted) return 0; + WaitForSingleObject(filtermutex,INFINITE); if (dsmediacontrol) dsmediacontrol->Pause(); + ReleaseMutex(filtermutex); return 1; } @@ -473,7 +484,10 @@ int VideoWin::unPause() // FIXME get rid - same as play!! int VideoWin::dsunPause() // FIXME get rid - same as play!! {//No on windows this is not the same, I don't get rid of! if (!initted) return 0; + WaitForSingleObject(filtermutex,INFINITE); if (dsmediacontrol) dsmediacontrol->Run(); + ReleaseMutex(filtermutex); + return 1; } @@ -589,6 +603,7 @@ void VideoWin::CleanupDS() #endif dsgraphbuilder->Release(); dsgraphbuilder=NULL; + sourcefilter->Release(); sourcefilter=NULL; //The Graph Builder destroys our SourceFilter } ReleaseMutex(filtermutex); @@ -617,6 +632,11 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet, { /*First Check, if we have an audio sample*/ #ifdef DO_VIDEO + if (!videoon) { + *samplepos+=packet.length; + MILLISLEEP(0); //yet not implemented//bad idea + return packet.length; + } /*First Check, if we have an audio sample*/ if (iframemode) { samplepos=0; @@ -661,6 +681,7 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet, UINT ms_length; UINT ms_pos; UINT haveToCopy; + if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample samplepos=0; MILLISLEEP(10); @@ -871,6 +892,8 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length) IMediaSample* ms=NULL; REFERENCE_TIME reftime1=0; REFERENCE_TIME reftime2=0; + if (!videoon) return; + if (!getCurrentVideoMediaSample(&ms) || ms==NULL) {// get the current sample MILLISLEEP(10); return ; @@ -879,7 +902,7 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length) DWORD ms_length; ms->GetPointer(&ms_buf); ms_length=ms->GetSize(); - + /*First Check, if we have an video sample*/ DWORD read_pos = 0, write_pos = 0; DWORD pattern, packet_length; @@ -938,9 +961,9 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length) #else - *samplepos+=packet.length; + // *samplepos+=packet.length; MILLISLEEP(0); //yet not implemented//bad idea - return packet.length; + return ; #endif } diff --git a/videowin.h b/videowin.h index e4e8603..7b9dd4b 100644 --- a/videowin.h +++ b/videowin.h @@ -31,7 +31,7 @@ #include "defines.h" #include "video.h" -//#define DS_DEBUG +#define DS_DEBUG class DsSourceFilter; class DsAllocator; -- 2.39.5