From 35c6d50d305654cd03ef9c677963bcd613719d78 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 25 Nov 2006 17:58:07 +0000 Subject: [PATCH] Windows updates --- audiowin.cc | 3 +- dssourcefilter.cc | 374 ++++++++++++++++++++++++---------------------- dssourcepin.cc | 20 ++- videowin.cc | 16 +- videowin.h | 4 +- 5 files changed, 226 insertions(+), 191 deletions(-) diff --git a/audiowin.cc b/audiowin.cc index 3e04813..d13127e 100644 --- a/audiowin.cc +++ b/audiowin.cc @@ -168,6 +168,7 @@ UINT AudioWin::DeliverMediaPacket(MediaPacket packet, /*First Check, if we have an audio sample*/ VideoWin *vw=(VideoWin*)Video::getInstance(); + if (!vw->isdsinited()) return 0; if (vw->InIframemode()) { samplepos=0; MILLISLEEP(10); @@ -253,7 +254,6 @@ UINT AudioWin::DeliverMediaPacket(MediaPacket packet, ms->SetTime(NULL,NULL); ms->SetMediaTime(NULL, NULL); ms->SetPreroll(FALSE); - MessageBox(0,"here I'm","Hallo",0); // ms->SetSyncPoint(TRUE); } } @@ -286,3 +286,4 @@ int AudioWin::test() #endif + diff --git a/dssourcefilter.cc b/dssourcefilter.cc index 8689b8c..ff77a0c 100644 --- a/dssourcefilter.cc +++ b/dssourcefilter.cc @@ -1,43 +1,43 @@ -/* - Copyright 2004-2006 Marten Richter - - This file is part of VOMP. - - VOMP is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - VOMP is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#include "dssourcefilter.h" - -#define AUDIOPIN_NAME L"Audio" -#define VIDEOPIN_NAME L"Video" - -class DsSFEnumPins: public IEnumPins { -public: - DsSFEnumPins(DsSourcePin* audio,DsSourcePin* video,DsSourceFilter *filt,ULONG pos=0); - virtual ~DsSFEnumPins(); +/* + Copyright 2004-2006 Marten Richter + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "dssourcefilter.h" + +#define AUDIOPIN_NAME L"Audio" +#define VIDEOPIN_NAME L"Video" + +class DsSFEnumPins: public IEnumPins { +public: + DsSFEnumPins(DsSourcePin* audio,DsSourcePin* video,DsSourceFilter *filt,ULONG pos=0); + virtual ~DsSFEnumPins(); virtual HRESULT STDMETHODCALLTYPE Next(ULONG numpin,IPin **pins,ULONG *fetched); virtual HRESULT STDMETHODCALLTYPE Skip(ULONG numpin); virtual HRESULT STDMETHODCALLTYPE Reset(); virtual HRESULT STDMETHODCALLTYPE Clone(IEnumPins **enuma); - virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void ** object); + virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void ** object); virtual ULONG STDMETHODCALLTYPE AddRef(); virtual ULONG STDMETHODCALLTYPE Release(); protected: DsSourcePin* audiopin; DsSourcePin* videopin; DsSourceFilter *filter; - ULONG curpos; + ULONG curpos; volatile long refs; }; @@ -47,11 +47,14 @@ DsSFEnumPins::DsSFEnumPins(DsSourcePin* audio,DsSourcePin* video,DsSourceFilter curpos=pos; filter=filt; filt->AddRef(); + refs=0; + } -DsSFEnumPins::~DsSFEnumPins(){ - filter->Release(); -} +DsSFEnumPins::~DsSFEnumPins(){ + filter->Release(); + +} HRESULT STDMETHODCALLTYPE DsSFEnumPins::Next(ULONG numpin,IPin **pins,ULONG *fetched) { int i; @@ -87,19 +90,19 @@ HRESULT STDMETHODCALLTYPE DsSFEnumPins::Clone(IEnumPins **enuma){ return S_OK; } -HRESULT STDMETHODCALLTYPE DsSFEnumPins::QueryInterface(REFIID id,void ** object){ - if (object==NULL) return E_POINTER; - if (id==IID_IUnknown ||id == IID_IEnumPins) { - *object=(IUnknown*)this; - ((IUnknown*)object)->AddRef(); - return NOERROR; - } else { - *object=NULL; - return E_NOINTERFACE; - } -} - - +HRESULT STDMETHODCALLTYPE DsSFEnumPins::QueryInterface(REFIID id,void ** object){ + if (object==NULL) return E_POINTER; + if (id==IID_IUnknown ||id == IID_IEnumPins) { + *object=(IUnknown*)this; + ((IUnknown*)object)->AddRef(); + return NOERROR; + } else { + *object=NULL; + return E_NOINTERFACE; + } +} + + ULONG STDMETHODCALLTYPE DsSFEnumPins::AddRef(){ InterlockedIncrement(&refs); @@ -123,63 +126,63 @@ ULONG STDMETHODCALLTYPE DsSFEnumPins::Release(){ - - - - -DsSourceFilter::DsSourceFilter() -{ - //add audio pin - HRESULT res; - audiopin=new DsSourcePin(this,&res,L"Vomp Audio Out",true); - videopin=new DsSourcePin(this,&res,L"Vomp Video Out",false); - filtergraph=NULL; - clock=NULL; - mystate=State_Stopped; - laststart=0; - refs=0; - InitializeCriticalSection(&filterlock); - -} - -DsSourceFilter::~DsSourceFilter() -{ - if (audiopin) delete audiopin; - if (videopin) delete videopin; - if (clock) { - clock->Release(); - clock=NULL; - } - DeleteCriticalSection(&filterlock); - -} - -HRESULT STDMETHODCALLTYPE DsSourceFilter::GetClassID(CLSID *clsid){ - if (clsid==NULL) return E_POINTER; - *clsid=_uuidof(this); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryInterface(REFIID id,void ** object){ - if (object==NULL) return E_POINTER; - if (id==IID_IUnknown) { - *object=(IUnknown*)this; - ((IUnknown*)object)->AddRef(); - return NOERROR; - } else if (id==IID_IBaseFilter) { - *object=(IBaseFilter*)this; - ((IBaseFilter*)object)->AddRef(); - return NOERROR; - } else if (id==IID_IMediaFilter) { - *object=(IMediaFilter*)this; - ((IMediaFilter*)object)->AddRef(); - return NOERROR; - }else { - *object=NULL; - return E_NOINTERFACE; - } -} - + + + + +DsSourceFilter::DsSourceFilter() +{ + //add audio pin + HRESULT res; + audiopin=new DsSourcePin(this,&res,L"Vomp Audio Out",true); + videopin=new DsSourcePin(this,&res,L"Vomp Video Out",false); + filtergraph=NULL; + clock=NULL; + mystate=State_Stopped; + laststart=0; + refs=0; + InitializeCriticalSection(&filterlock); + +} + +DsSourceFilter::~DsSourceFilter() +{ + if (audiopin) delete audiopin; + if (videopin) delete videopin; + if (clock) { + clock->Release(); + clock=NULL; + } + DeleteCriticalSection(&filterlock); + +} + +HRESULT STDMETHODCALLTYPE DsSourceFilter::GetClassID(CLSID *clsid){ + if (clsid==NULL) return E_POINTER; + *clsid=_uuidof(this); + return S_OK; +} + +HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryInterface(REFIID id,void ** object){ + if (object==NULL) return E_POINTER; + if (id==IID_IUnknown) { + *object=(IUnknown*)this; + AddRef(); + return NOERROR; + } else if (id==IID_IBaseFilter) { + *object=(IBaseFilter*)this; + AddRef(); + return NOERROR; + } else if (id==IID_IMediaFilter) { + *object=(IMediaFilter*)this; + AddRef(); + return NOERROR; + }else { + *object=NULL; + return E_NOINTERFACE; + } +} + ULONG STDMETHODCALLTYPE DsSourceFilter::AddRef(){ InterlockedIncrement(&refs); long tempref=refs; @@ -190,38 +193,42 @@ ULONG STDMETHODCALLTYPE DsSourceFilter::Release(){ long tempref=InterlockedDecrement(&refs); if (tempref==0) { - //refs++; + refs++; delete this; return NULL; } else { if (tempref>1) return tempref; else return 1; } -} - -/*IBaseFilter*/ -HRESULT STDMETHODCALLTYPE DsSourceFilter::EnumPins(IEnumPins **enumar){ - if (enumar==NULL) return E_POINTER; - *enumar=new DsSFEnumPins(audiopin,videopin, this); - (*enumar)->AddRef(); - return S_OK; -} - +} + +/*IBaseFilter*/ +HRESULT STDMETHODCALLTYPE DsSourceFilter::EnumPins(IEnumPins **enumar){ + if (enumar==NULL) return E_POINTER; + *enumar=new DsSFEnumPins(audiopin,videopin, this); + (*enumar)->AddRef(); + return S_OK; +} + HRESULT STDMETHODCALLTYPE DsSourceFilter::FindPin(LPCWSTR iden,IPin **pin){ if (pin==NULL) return E_POINTER; + EnterCriticalSection(&filterlock); if (wcscmp(AUDIOPIN_NAME,iden)==NULL) { *pin=(IPin*)audiopin; (*pin)->AddRef(); + LeaveCriticalSection(&filterlock); return S_OK; } if (wcscmp(VIDEOPIN_NAME,iden)==NULL) { *pin=(IPin*)videopin; (*pin)->AddRef(); + LeaveCriticalSection(&filterlock); return S_OK; } *pin=NULL; + LeaveCriticalSection(&filterlock); return VFW_E_NOT_FOUND; } HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryFilterInfo(FILTER_INFO *info){ @@ -236,7 +243,7 @@ HRESULT STDMETHODCALLTYPE DsSourceFilter::JoinFilterGraph(IFilterGraph *graph,LP //Should we lock EnterCriticalSection(&filterlock); filtergraph=graph; - filtergraph->AddRef(); + //filtergraph->AddRef(); //We ignore the name LeaveCriticalSection(&filterlock); @@ -245,17 +252,20 @@ HRESULT STDMETHODCALLTYPE DsSourceFilter::JoinFilterGraph(IFilterGraph *graph,LP HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryVendorInfo(LPWSTR *vendinf) { return E_NOTIMPL; } - - -/*IMediaFilter*/ + + +/*IMediaFilter*/ HRESULT STDMETHODCALLTYPE DsSourceFilter::GetState(DWORD timeout,FILTER_STATE *state){ if (state==NULL) return E_POINTER; + EnterCriticalSection(&filterlock); *state=mystate; + LeaveCriticalSection(&filterlock); return S_OK; } HRESULT STDMETHODCALLTYPE DsSourceFilter::SetSyncSource(IReferenceClock *uhr){ EnterCriticalSection(&filterlock); + //MessageBox(0,"Sets ync","",0); if (clock!=NULL) { clock->Release(); } @@ -330,7 +340,10 @@ HRESULT STDMETHODCALLTYPE DsSourceFilter::Run(REFERENCE_TIME start){ if (mystate==State_Stopped) { HRESULT phres=Pause(); - if (phres!=S_OK) return phres; + if (phres!=S_OK){ + LeaveCriticalSection(&filterlock); + return phres; + } } laststart=start; @@ -358,65 +371,66 @@ HRESULT STDMETHODCALLTYPE DsSourceFilter::Run(REFERENCE_TIME start){ return S_OK; } - - - -int DsSourceFilter::GetPinCount() -{ - return 2; //audio and video -} - - - -int DsSourceFilter::getCurrentAudioMediaSample(IMediaSample** ms) -{ - if (!audiopin || !IsActive()) { - return 0; - } - if (audiopin->getCurrentMediaSample(ms)!=S_OK) { - return 0; - } - return 1; -} - -int DsSourceFilter::getCurrentVideoMediaSample(IMediaSample** ms) -{ - if (!videopin || !IsActive()) { - return 0; - } - if (videopin->getCurrentMediaSample(ms)!=S_OK) { - return 0; - } - return 1; -} - -int DsSourceFilter::DeliverAudioMediaSample(IMediaSample* ms) -{ - if (!audiopin || !IsActive()) { - ms->Release(); - return 0; - } - if (audiopin->deliver(ms)!=S_OK) { - ms->Release(); - return 0; - } - ms->Release(); - return 1; - -} - -int DsSourceFilter::DeliverVideoMediaSample(IMediaSample* ms) -{ - if (!videopin || !IsActive()) { - ms->Release(); - return 0; - } - if (videopin->deliver(ms)!=S_OK) { - ms->Release(); - return 0; - } - ms->Release(); - return 1; - -} + + + +int DsSourceFilter::GetPinCount() +{ + return 2; //audio and video +} + + + +int DsSourceFilter::getCurrentAudioMediaSample(IMediaSample** ms) +{ + if (!audiopin || !IsActive()) { + return 0; + } + if (audiopin->getCurrentMediaSample(ms)!=S_OK) { + return 0; + } + return 1; +} + +int DsSourceFilter::getCurrentVideoMediaSample(IMediaSample** ms) +{ + if (!videopin || !IsActive()) { + return 0; + } + if (videopin->getCurrentMediaSample(ms)!=S_OK) { + return 0; + } + return 1; +} + +int DsSourceFilter::DeliverAudioMediaSample(IMediaSample* ms) +{ + if (!audiopin || !IsActive()) { + ms->Release(); + return 0; + } + if (audiopin->deliver(ms)!=S_OK) { + ms->Release(); + return 0; + } + ms->Release(); + return 1; + +} + +int DsSourceFilter::DeliverVideoMediaSample(IMediaSample* ms) +{ + if (!videopin || !IsActive()) { + ms->Release(); + return 0; + } + if (videopin->deliver(ms)!=S_OK) { + ms->Release(); + return 0; + } + ms->Release(); + return 1; + +} + diff --git a/dssourcepin.cc b/dssourcepin.cc index 88319a4..63812a1 100644 --- a/dssourcepin.cc +++ b/dssourcepin.cc @@ -144,6 +144,7 @@ DsSourcePin::DsSourcePin(DsSourceFilter *pFilter, DsSourcePin::~DsSourcePin() { + } @@ -185,12 +186,14 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE if (mtype!=NULL) { if (CheckMediaType(mtype)==S_OK){ + pinempf->AddRef(); if (pinempf->ReceiveConnection((IPin*)this,mtype)==S_OK) { CopyMType(&medtype,mtype); LeaveCriticalSection(&m_pFilter->filterlock); } else { LeaveCriticalSection(&m_pFilter->filterlock); CoTaskMemFree(mtype->pbFormat); + pinempf->Release(); return VFW_E_TYPE_NOT_ACCEPTED; } @@ -207,10 +210,11 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE AM_MEDIA_TYPE * emtype; emtype=&emtype_np; ULONG fetched=0; + pinempf->AddRef(); while (emt->Next(1,&emtype,&fetched)==S_OK) { if (CheckMediaType(emtype)==S_OK){ if (pinempf->ReceiveConnection((IPin*)this,emtype)==S_OK) { - + connected=pinempf; CopyMType(&medtype,emtype); CoTaskMemFree(emtype->pbFormat); gotmt=true; @@ -238,6 +242,7 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE } emt->Release(); if (gotmt==false) { + pinempf->Release(); LeaveCriticalSection(&m_pFilter->filterlock); return VFW_E_NO_ACCEPTABLE_TYPES; } @@ -246,8 +251,10 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE if (pinempf->QueryInterface(IID_IMemInputPin,(void**)&connectedinput)!=S_OK) { LeaveCriticalSection(&m_pFilter->filterlock); - connectedinput->Release(); - connectedinput=NULL; + connected->Release(); + connected=NULL; + /* connectedinput->Release(); + connectedinput=NULL;*/ return VFW_E_NO_TRANSPORT; } ALLOCATOR_PROPERTIES eigenall; @@ -277,6 +284,10 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::Connect(IPin *pinempf,const AM_MEDIA_TYPE } if (allocator!=NULL) allocator->Release(); allocator=NULL; + connected->Release(); + connected=NULL; + connectedinput->Release(); + connectedinput=NULL; LeaveCriticalSection(&m_pFilter->filterlock); return VFW_E_NO_TRANSPORT; @@ -312,7 +323,7 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::ReceiveConnection(IPin *connect, if (pin==NULL) return E_POINTER; IPin* pinn=connected; *pin=pinn; - if (connected!=NULL) { + if (pinn!=NULL) { pinn->AddRef(); return S_OK; } else { @@ -333,6 +344,7 @@ HRESULT STDMETHODCALLTYPE DsSourcePin::ReceiveConnection(IPin *connect, if (info==NULL) return E_POINTER; info->dir=PINDIR_OUTPUT; info->pFilter=(IBaseFilter*)m_pFilter; + if (m_pFilter) m_pFilter->AddRef(); if (isaudiopin) wcscpy(info->achName,L"Audio"); else wcscpy(info->achName,L"Video"); return S_OK; diff --git a/videowin.cc b/videowin.cc index ad0390f..50e19d0 100644 --- a/videowin.cc +++ b/videowin.cc @@ -31,6 +31,7 @@ void AdjustWindow(); VideoWin::VideoWin() { + dsinited=false; dsgraphbuilder=NULL; dsmediacontrol=NULL; dsvmrrenderer=NULL; @@ -227,7 +228,6 @@ int VideoWin::dsplay() 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); @@ -313,6 +313,8 @@ int VideoWin::dsplay() dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol); dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio); + dsinited=true; + MILLISLEEP(100); hresdeb=dsmediacontrol->Run(); iframemode=false;//exit iframe mode @@ -341,7 +343,6 @@ int VideoWin::EnterIframePlayback() //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); @@ -415,6 +416,8 @@ int VideoWin::EnterIframePlayback() dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol); dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio); + dsinited=true; + dsmediacontrol->Run(); ReleaseMutex(filtermutex); @@ -554,6 +557,7 @@ ULLONG VideoWin::frameNumberToTimecode(ULONG framenumber) void VideoWin::CleanupDS() { WaitForSingleObject(filtermutex,INFINITE); + dsinited=false; if (dsmediacontrol)dsmediacontrol->Stop(); if (cur_audio_media_sample) { cur_audio_media_sample->Release(); @@ -601,9 +605,9 @@ void VideoWin::CleanupDS() #ifdef DS_DEBUG RemoveFromRot(graphidentifier); #endif - dsgraphbuilder->Release(); + dsgraphbuilder->Release(); dsgraphbuilder=NULL; - sourcefilter->Release(); + sourcefilter=NULL; //The Graph Builder destroys our SourceFilter } ReleaseMutex(filtermutex); @@ -631,6 +635,7 @@ UINT VideoWin::DeliverMediaPacket(MediaPacket packet, UINT *samplepos) { /*First Check, if we have an audio sample*/ + if (!isdsinited()) return 0; #ifdef DO_VIDEO if (!videoon) { *samplepos+=packet.length; @@ -887,7 +892,7 @@ void VideoWin::displayIFrame(const UCHAR* buffer, UINT length) { if (!iframemode) EnterIframePlayback(); - + if (!isdsinited()) return ; #ifdef DO_VIDEO IMediaSample* ms=NULL; REFERENCE_TIME reftime1=0; @@ -981,3 +986,4 @@ int VideoWin::test2() #endif + diff --git a/videowin.h b/videowin.h index 7b9dd4b..2b0050c 100644 --- a/videowin.h +++ b/videowin.h @@ -107,6 +107,7 @@ class VideoWin : public Video unsigned int getPosx() {return videoposx;}; unsigned int getPosy() {return videoposy;}; bool isVideoOn() {return videoon;}; + bool isdsinited() {return dsinited;}; #ifdef DEV int test(); @@ -136,7 +137,7 @@ private: long long startoffset; long long lastrefvideotime; long long lastrefaudiotime; - + bool dsinited; bool firstsynched; bool audioon; bool videoon; @@ -154,3 +155,4 @@ private: #endif + -- 2.39.5