-/*
- 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();
+/*\r
+ Copyright 2004-2006 Marten Richter\r
+\r
+ This file is part of VOMP.\r
+\r
+ VOMP is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation; either version 2 of the License, or\r
+ (at your option) any later version.\r
+\r
+ VOMP is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with VOMP; if not, write to the Free Software\r
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*/\r
+#include "dssourcefilter.h"\r
+\r
+#define AUDIOPIN_NAME L"Audio"\r
+#define VIDEOPIN_NAME L"Video"\r
+\r
+class DsSFEnumPins: public IEnumPins {\r
+public:\r
+ DsSFEnumPins(DsSourcePin* audio,DsSourcePin* video,DsSourceFilter *filt,ULONG pos=0);\r
+ virtual ~DsSFEnumPins();\r
virtual HRESULT STDMETHODCALLTYPE Next(ULONG numpin,IPin **pins,ULONG *fetched);\r
virtual HRESULT STDMETHODCALLTYPE Skip(ULONG numpin);\r
virtual HRESULT STDMETHODCALLTYPE Reset();\r
virtual HRESULT STDMETHODCALLTYPE Clone(IEnumPins **enuma);\r
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void ** object);
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void ** object);\r
virtual ULONG STDMETHODCALLTYPE AddRef();\r
virtual ULONG STDMETHODCALLTYPE Release();\r
protected:\r
DsSourcePin* audiopin;\r
DsSourcePin* videopin;\r
DsSourceFilter *filter;\r
- ULONG curpos;
+ ULONG curpos;\r
volatile long refs;\r
};\r
\r
curpos=pos;\r
filter=filt;\r
filt->AddRef();\r
+ refs=0;\r
+ \r
}\r
\r
-DsSFEnumPins::~DsSFEnumPins(){
- filter->Release();
-}
+DsSFEnumPins::~DsSFEnumPins(){\r
+ filter->Release();\r
+ \r
+}\r
\r
HRESULT STDMETHODCALLTYPE DsSFEnumPins::Next(ULONG numpin,IPin **pins,ULONG *fetched) {\r
int i;\r
return S_OK;\r
}\r
\r
-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){\r
+ if (object==NULL) return E_POINTER;\r
+ if (id==IID_IUnknown ||id == IID_IEnumPins) {\r
+ *object=(IUnknown*)this;\r
+ ((IUnknown*)object)->AddRef();\r
+ return NOERROR;\r
+ } else {\r
+ *object=NULL;\r
+ return E_NOINTERFACE;\r
+ }\r
+}\r
+\r
+\r
\r
ULONG STDMETHODCALLTYPE DsSFEnumPins::AddRef(){\r
InterlockedIncrement(&refs);\r
\r
\r
\r
-
-
-
-
-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;
- }
-}
-
+\r
+\r
+\r
+\r
+DsSourceFilter::DsSourceFilter()\r
+{\r
+ //add audio pin\r
+ HRESULT res;\r
+ audiopin=new DsSourcePin(this,&res,L"Vomp Audio Out",true);\r
+ videopin=new DsSourcePin(this,&res,L"Vomp Video Out",false);\r
+ filtergraph=NULL;\r
+ clock=NULL;\r
+ mystate=State_Stopped;\r
+ laststart=0;\r
+ refs=0;\r
+ InitializeCriticalSection(&filterlock);\r
+\r
+}\r
+\r
+DsSourceFilter::~DsSourceFilter()\r
+{\r
+ if (audiopin) delete audiopin;\r
+ if (videopin) delete videopin;\r
+ if (clock) {\r
+ clock->Release();\r
+ clock=NULL;\r
+ }\r
+ DeleteCriticalSection(&filterlock);\r
+ \r
+}\r
+\r
+HRESULT STDMETHODCALLTYPE DsSourceFilter::GetClassID(CLSID *clsid){\r
+ if (clsid==NULL) return E_POINTER;\r
+ *clsid=_uuidof(this);\r
+ return S_OK;\r
+}\r
+\r
+HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryInterface(REFIID id,void ** object){\r
+ if (object==NULL) return E_POINTER;\r
+ if (id==IID_IUnknown) {\r
+ *object=(IUnknown*)this;\r
+ AddRef();\r
+ return NOERROR;\r
+ } else if (id==IID_IBaseFilter) {\r
+ *object=(IBaseFilter*)this;\r
+ AddRef();\r
+ return NOERROR;\r
+ } else if (id==IID_IMediaFilter) {\r
+ *object=(IMediaFilter*)this;\r
+ AddRef();\r
+ return NOERROR;\r
+ }else {\r
+ *object=NULL;\r
+ return E_NOINTERFACE;\r
+ }\r
+}\r
+\r
ULONG STDMETHODCALLTYPE DsSourceFilter::AddRef(){\r
InterlockedIncrement(&refs);\r
long tempref=refs;\r
long tempref=InterlockedDecrement(&refs);\r
\r
if (tempref==0) {\r
- //refs++;\r
+ refs++;\r
delete this;\r
return NULL;\r
} else {\r
if (tempref>1) return tempref;\r
else return 1;\r
}\r
-}
-
-/*IBaseFilter*/
-HRESULT STDMETHODCALLTYPE DsSourceFilter::EnumPins(IEnumPins **enumar){
- if (enumar==NULL) return E_POINTER;
- *enumar=new DsSFEnumPins(audiopin,videopin, this);
- (*enumar)->AddRef();
- return S_OK;
-}
-
+}\r
+\r
+/*IBaseFilter*/\r
+HRESULT STDMETHODCALLTYPE DsSourceFilter::EnumPins(IEnumPins **enumar){\r
+ if (enumar==NULL) return E_POINTER;\r
+ *enumar=new DsSFEnumPins(audiopin,videopin, this);\r
+ (*enumar)->AddRef();\r
+ return S_OK;\r
+}\r
+\r
HRESULT STDMETHODCALLTYPE DsSourceFilter::FindPin(LPCWSTR iden,IPin **pin){\r
if (pin==NULL) return E_POINTER;\r
+ EnterCriticalSection(&filterlock);\r
\r
if (wcscmp(AUDIOPIN_NAME,iden)==NULL) {\r
*pin=(IPin*)audiopin;\r
(*pin)->AddRef();\r
+ LeaveCriticalSection(&filterlock);\r
return S_OK;\r
}\r
if (wcscmp(VIDEOPIN_NAME,iden)==NULL) {\r
*pin=(IPin*)videopin;\r
(*pin)->AddRef();\r
+ LeaveCriticalSection(&filterlock);\r
return S_OK;\r
}\r
\r
*pin=NULL;\r
+ LeaveCriticalSection(&filterlock);\r
return VFW_E_NOT_FOUND;\r
}\r
HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryFilterInfo(FILTER_INFO *info){\r
//Should we lock\r
EnterCriticalSection(&filterlock);\r
filtergraph=graph;\r
- filtergraph->AddRef();\r
+ //filtergraph->AddRef();\r
//We ignore the name\r
LeaveCriticalSection(&filterlock);\r
\r
HRESULT STDMETHODCALLTYPE DsSourceFilter::QueryVendorInfo(LPWSTR *vendinf) {\r
return E_NOTIMPL;\r
}\r
-
-
-/*IMediaFilter*/
+\r
+\r
+/*IMediaFilter*/\r
HRESULT STDMETHODCALLTYPE DsSourceFilter::GetState(DWORD timeout,FILTER_STATE *state){\r
if (state==NULL) return E_POINTER;\r
+ EnterCriticalSection(&filterlock);\r
*state=mystate;\r
+ LeaveCriticalSection(&filterlock);\r
return S_OK;\r
}\r
\r
HRESULT STDMETHODCALLTYPE DsSourceFilter::SetSyncSource(IReferenceClock *uhr){\r
EnterCriticalSection(&filterlock);\r
+ //MessageBox(0,"Sets ync","",0);\r
if (clock!=NULL) {\r
clock->Release();\r
}\r
\r
if (mystate==State_Stopped) {\r
HRESULT phres=Pause();\r
- if (phres!=S_OK) return phres;\r
+ if (phres!=S_OK){\r
+ LeaveCriticalSection(&filterlock);\r
+ return phres;\r
+ }\r
}\r
\r
laststart=start;\r
\r
return S_OK;\r
}\r
-
-
-
-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;
-
-}
+\r
+\r
+\r
+int DsSourceFilter::GetPinCount()\r
+{\r
+ return 2; //audio and video\r
+}\r
+\r
+\r
+\r
+int DsSourceFilter::getCurrentAudioMediaSample(IMediaSample** ms)\r
+{\r
+ if (!audiopin || !IsActive()) {\r
+ return 0;\r
+ }\r
+ if (audiopin->getCurrentMediaSample(ms)!=S_OK) {\r
+ return 0;\r
+ }\r
+ return 1;\r
+}\r
+\r
+int DsSourceFilter::getCurrentVideoMediaSample(IMediaSample** ms)\r
+{\r
+ if (!videopin || !IsActive()) {\r
+ return 0;\r
+ }\r
+ if (videopin->getCurrentMediaSample(ms)!=S_OK) {\r
+ return 0;\r
+ }\r
+ return 1;\r
+}\r
+\r
+int DsSourceFilter::DeliverAudioMediaSample(IMediaSample* ms)\r
+{\r
+ if (!audiopin || !IsActive()) {\r
+ ms->Release();\r
+ return 0;\r
+ }\r
+ if (audiopin->deliver(ms)!=S_OK) {\r
+ ms->Release();\r
+ return 0;\r
+ }\r
+ ms->Release();\r
+ return 1;\r
+\r
+}\r
+\r
+int DsSourceFilter::DeliverVideoMediaSample(IMediaSample* ms)\r
+{\r
+ if (!videopin || !IsActive()) {\r
+ ms->Release();\r
+ return 0;\r
+ }\r
+ if (videopin->deliver(ms)!=S_OK) {\r
+ ms->Release();\r
+ return 0;\r
+ }\r
+ ms->Release();\r
+ return 1;\r
+\r
+}\r
+\r
\r
DsSourcePin::~DsSourcePin()\r
{\r
\r
+ \r
\r
}\r
\r
\r
if (mtype!=NULL) {\r
if (CheckMediaType(mtype)==S_OK){\r
+ pinempf->AddRef();\r
if (pinempf->ReceiveConnection((IPin*)this,mtype)==S_OK) {\r
CopyMType(&medtype,mtype);\r
LeaveCriticalSection(&m_pFilter->filterlock);\r
} else {\r
LeaveCriticalSection(&m_pFilter->filterlock);\r
CoTaskMemFree(mtype->pbFormat);\r
+ pinempf->Release();\r
return VFW_E_TYPE_NOT_ACCEPTED;\r
}\r
\r
AM_MEDIA_TYPE * emtype;\r
emtype=&emtype_np;\r
ULONG fetched=0;\r
+ pinempf->AddRef();\r
while (emt->Next(1,&emtype,&fetched)==S_OK) {\r
if (CheckMediaType(emtype)==S_OK){\r
if (pinempf->ReceiveConnection((IPin*)this,emtype)==S_OK) {\r
- \r
+ connected=pinempf;\r
CopyMType(&medtype,emtype);\r
CoTaskMemFree(emtype->pbFormat);\r
gotmt=true;\r
}\r
emt->Release();\r
if (gotmt==false) {\r
+ pinempf->Release();\r
LeaveCriticalSection(&m_pFilter->filterlock);\r
return VFW_E_NO_ACCEPTABLE_TYPES;\r
}\r
\r
if (pinempf->QueryInterface(IID_IMemInputPin,(void**)&connectedinput)!=S_OK) {\r
LeaveCriticalSection(&m_pFilter->filterlock);\r
- connectedinput->Release();\r
- connectedinput=NULL;\r
+ connected->Release();\r
+ connected=NULL;\r
+ /* connectedinput->Release();\r
+ connectedinput=NULL;*/\r
return VFW_E_NO_TRANSPORT;\r
}\r
ALLOCATOR_PROPERTIES eigenall;\r
}\r
if (allocator!=NULL) allocator->Release();\r
allocator=NULL;\r
+ connected->Release();\r
+ connected=NULL;\r
+ connectedinput->Release();\r
+ connectedinput=NULL;\r
LeaveCriticalSection(&m_pFilter->filterlock);\r
return VFW_E_NO_TRANSPORT;\r
\r
if (pin==NULL) return E_POINTER;\r
IPin* pinn=connected;\r
*pin=pinn;\r
- if (connected!=NULL) {\r
+ if (pinn!=NULL) {\r
pinn->AddRef();\r
return S_OK;\r
} else {\r
if (info==NULL) return E_POINTER;\r
info->dir=PINDIR_OUTPUT;\r
info->pFilter=(IBaseFilter*)m_pFilter;\r
+ if (m_pFilter) m_pFilter->AddRef();\r
if (isaudiopin) wcscpy(info->achName,L"Audio");\r
else wcscpy(info->achName,L"Video");\r
return S_OK;\r
\r
VideoWin::VideoWin()\r
{\r
+ dsinited=false;\r
dsgraphbuilder=NULL;\r
dsmediacontrol=NULL;\r
dsvmrrenderer=NULL;\r
firstsynched=false;\r
sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data\r
// to DirectShow\r
- sourcefilter->AddRef();\r
if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {\r
Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");\r
ReleaseMutex(filtermutex);\r
\r
dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);\r
dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio); \r
+ dsinited=true;\r
+ MILLISLEEP(100);\r
\r
hresdeb=dsmediacontrol->Run();\r
iframemode=false;//exit iframe mode\r
//firstsynched=false;\r
sourcefilter=new DsSourceFilter(); //Creating our Source filter for pushing Data\r
// to DirectShow\r
- sourcefilter->AddRef();\r
if (hres=dsgraphbuilder->AddFilter(sourcefilter,L"Vomp Win Source Filter")!=S_OK) {\r
Log::getInstance()->log("VideoWin", Log::WARN , "Failed adding Vomp Source Filter!");\r
ReleaseMutex(filtermutex); \r
\r
dsgraphbuilder->QueryInterface(IID_IMediaControl,(void **) &dsmediacontrol);\r
dsgraphbuilder->QueryInterface(IID_IBasicAudio,(void **) &dsbasicaudio); \r
+ dsinited=true;\r
+ \r
\r
dsmediacontrol->Run();\r
ReleaseMutex(filtermutex);\r
void VideoWin::CleanupDS()\r
{\r
WaitForSingleObject(filtermutex,INFINITE);\r
+ dsinited=false;\r
if (dsmediacontrol)dsmediacontrol->Stop();\r
if (cur_audio_media_sample) {\r
cur_audio_media_sample->Release();\r
#ifdef DS_DEBUG\r
RemoveFromRot(graphidentifier);\r
#endif\r
- dsgraphbuilder->Release();\r
+ dsgraphbuilder->Release();\r
dsgraphbuilder=NULL;\r
- sourcefilter->Release();\r
+ \r
sourcefilter=NULL; //The Graph Builder destroys our SourceFilter\r
}\r
ReleaseMutex(filtermutex);\r
UINT *samplepos)\r
{\r
/*First Check, if we have an audio sample*/\r
+ if (!isdsinited()) return 0;\r
#ifdef DO_VIDEO\r
if (!videoon) {\r
*samplepos+=packet.length;\r
{\r
if (!iframemode) EnterIframePlayback();\r
\r
-\r
+ if (!isdsinited()) return ;\r
#ifdef DO_VIDEO\r
IMediaSample* ms=NULL;\r
REFERENCE_TIME reftime1=0;\r
#endif\r
\r
\r
+\r