Author: janderwald
Date: Wed Mar 24 14:12:34 2010
New Revision: 46396
URL:
http://svn.reactos.org/svn/reactos?rev=46396&view=rev
Log:
[KSPROXY]
- Check in IMemAllocator::GetBuffer if the allocator is commited
- Silence debug prints in IMediaSample
- Implement IBaseFilter::Stop
- Fix race conditions in IBaseFilter::Run, IBaseFilter::Run, IBaseFilter::Stop
- Check for invalid argument in IBaseFilter::Stop
- Call InitializeIOThread when pin state is set to acquired
- Grab current filter handle by obtaining IKsObject interface of the parent filter.
Required as the filter handle might be closed by using IAMDeviceRemoval interface
- CLSID_Filter is now fully functional (Windows XP SP3)
Modified:
trunk/reactos/dll/directx/ksproxy/allocator.cpp
trunk/reactos/dll/directx/ksproxy/input_pin.cpp
trunk/reactos/dll/directx/ksproxy/mediasample.cpp
trunk/reactos/dll/directx/ksproxy/output_pin.cpp
trunk/reactos/dll/directx/ksproxy/proxy.cpp
Modified: trunk/reactos/dll/directx/ksproxy/allocator.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ksproxy/alloca…
==============================================================================
--- trunk/reactos/dll/directx/ksproxy/allocator.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/ksproxy/allocator.cpp [iso-8859-1] Wed Mar 24 14:12:34 2010
@@ -340,7 +340,9 @@
DWORD dwFlags)
{
IMediaSample * Sample = NULL;
- OutputDebugStringW(L"CKsAllocator::GetBuffer\n");
+
+ if (!m_Commited)
+ return VFW_E_NOT_COMMITTED;
do
{
Modified: trunk/reactos/dll/directx/ksproxy/input_pin.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ksproxy/input_…
==============================================================================
--- trunk/reactos/dll/directx/ksproxy/input_pin.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/ksproxy/input_pin.cpp [iso-8859-1] Wed Mar 24 14:12:34 2010
@@ -170,14 +170,13 @@
HRESULT STDMETHODCALLTYPE CheckFormat(const AM_MEDIA_TYPE *pmt);
HRESULT STDMETHODCALLTYPE CreatePin(const AM_MEDIA_TYPE *pmt);
HRESULT STDMETHODCALLTYPE CreatePinHandle(PKSPIN_MEDIUM Medium, PKSPIN_INTERFACE
Interface, const AM_MEDIA_TYPE *pmt);
- CInputPin(IBaseFilter * ParentFilter, LPCWSTR PinName, HANDLE hFilter, ULONG PinId,
KSPIN_COMMUNICATION Communication);
+ CInputPin(IBaseFilter * ParentFilter, LPCWSTR PinName, ULONG PinId,
KSPIN_COMMUNICATION Communication);
virtual ~CInputPin(){};
protected:
LONG m_Ref;
IBaseFilter * m_ParentFilter;
LPCWSTR m_PinName;
- HANDLE m_hFilter;
HANDLE m_hPin;
ULONG m_PinId;
IMemAllocator * m_MemAllocator;
@@ -199,14 +198,12 @@
};
CInputPin::CInputPin(
- IBaseFilter * ParentFilter,
+ IBaseFilter * ParentFilter,
LPCWSTR PinName,
- HANDLE hFilter,
ULONG PinId,
KSPIN_COMMUNICATION Communication) : m_Ref(0),
m_ParentFilter(ParentFilter),
m_PinName(PinName),
- m_hFilter(hFilter),
m_hPin(INVALID_HANDLE_VALUE),
m_PinId(PinId),
m_MemAllocator(0),
@@ -223,8 +220,21 @@
ZeroMemory(m_FramingProp, sizeof(m_FramingProp));
ZeroMemory(m_FramingEx, sizeof(m_FramingEx));
+ HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ assert(hr == S_OK);
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+ assert(hFilter);
+
+ KsObjectParent->Release();
+
+
ZeroMemory(&m_MediaFormat, sizeof(AM_MEDIA_TYPE));
- HRESULT hr = KsGetMediaType(0, &m_MediaFormat, m_hFilter, m_PinId);
+ hr = KsGetMediaType(0, &m_MediaFormat, hFilter, m_PinId);
assert(hr == S_OK);
}
@@ -688,7 +698,22 @@
CInputPin::KsQueryMediums(
PKSMULTIPLE_ITEM* MediumList)
{
- return KsGetMultiplePinFactoryItems(m_hFilter, m_PinId, KSPROPERTY_PIN_MEDIUMS,
(PVOID*)MediumList);
+ HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
+ return KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_MEDIUMS,
(PVOID*)MediumList);
}
HRESULT
@@ -696,7 +721,22 @@
CInputPin::KsQueryInterfaces(
PKSMULTIPLE_ITEM* InterfaceList)
{
- return KsGetMultiplePinFactoryItems(m_hFilter, m_PinId, KSPROPERTY_PIN_INTERFACES,
(PVOID*)InterfaceList);
+ HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
+ return KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_INTERFACES,
(PVOID*)InterfaceList);
}
HRESULT
@@ -1159,9 +1199,23 @@
HRESULT hr;
ULONG MediaTypeCount = 0, Index;
AM_MEDIA_TYPE * MediaTypes;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
// query media type count
- hr = KsGetMediaTypeCount(m_hFilter, m_PinId, &MediaTypeCount);
+ hr = KsGetMediaTypeCount(hFilter, m_PinId, &MediaTypeCount);
if (FAILED(hr) || !MediaTypeCount)
return hr;
@@ -1179,7 +1233,7 @@
for(Index = 0; Index < MediaTypeCount; Index++)
{
// get media type
- hr = KsGetMediaType(Index, &MediaTypes[Index], m_hFilter, m_PinId);
+ hr = KsGetMediaType(Index, &MediaTypes[Index], hFilter, m_PinId);
if (FAILED(hr))
{
// failed
@@ -1237,11 +1291,25 @@
PKSMULTIPLE_ITEM MultipleItem;
PKSDATAFORMAT DataFormat;
HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
if (!pmt)
return E_POINTER;
- hr = KsGetMultiplePinFactoryItems(m_hFilter, m_PinId, KSPROPERTY_PIN_DATARANGES,
(PVOID*)&MultipleItem);
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
+
+ hr = KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_DATARANGES,
(PVOID*)&MultipleItem);
if (FAILED(hr))
return S_FALSE;
@@ -1379,6 +1447,23 @@
PKSDATAFORMAT DataFormat;
ULONG Length;
HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
+
+ if (!pmt)
+ return E_POINTER;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
if (m_hPin != INVALID_HANDLE_VALUE)
{
@@ -1427,7 +1512,7 @@
}
// create pin
- hr = KsCreatePin(m_hFilter, PinConnect, GENERIC_WRITE, &m_hPin);
+ hr = KsCreatePin(hFilter, PinConnect, GENERIC_WRITE, &m_hPin);
if (SUCCEEDED(hr))
{
@@ -1482,7 +1567,7 @@
REFIID riid,
LPVOID * ppv)
{
- CInputPin * handler = new CInputPin(ParentFilter, PinName, hFilter, PinId,
Communication);
+ CInputPin * handler = new CInputPin(ParentFilter, PinName, PinId, Communication);
if (!handler)
return E_OUTOFMEMORY;
Modified: trunk/reactos/dll/directx/ksproxy/mediasample.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ksproxy/medias…
==============================================================================
--- trunk/reactos/dll/directx/ksproxy/mediasample.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/ksproxy/mediasample.cpp [iso-8859-1] Wed Mar 24 14:12:34
2010
@@ -116,8 +116,6 @@
}
if (IsEqualGUID(refiid, IID_IMediaSample2))
{
-
- OutputDebugStringW(L"CMediaSample::QueryInterface requested IMediaSample2
interface\n");
#if 0
*Output = (IMediaSample2*)(this);
reinterpret_cast<IMediaSample2*>(*Output)->AddRef();
@@ -267,8 +265,6 @@
STDMETHODCALLTYPE
CMediaSample::GetMediaType(AM_MEDIA_TYPE **ppMediaType)
{
- OutputDebugStringW(L"CMediaSample::GetMediaType\n");
-
if (!m_MediaType)
{
*ppMediaType = NULL;
Modified: trunk/reactos/dll/directx/ksproxy/output_pin.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ksproxy/output…
==============================================================================
--- trunk/reactos/dll/directx/ksproxy/output_pin.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/ksproxy/output_pin.cpp [iso-8859-1] Wed Mar 24 14:12:34
2010
@@ -172,7 +172,6 @@
LPCWSTR m_PinName;
HANDLE m_hPin;
ULONG m_PinId;
- IKsObject * m_KsObjectParent;
IPin * m_Pin;
IKsAllocatorEx * m_KsAllocatorEx;
ULONG m_PipeAllocatorFlag;
@@ -189,8 +188,6 @@
KSPIN_INTERFACE m_Interface;
KSPIN_MEDIUM m_Medium;
AM_MEDIA_TYPE m_MediaFormat;
-
- IMediaSeeking * m_FilterMediaSeeking;
ALLOCATOR_PROPERTIES m_Properties;
IKsInterfaceHandler * m_InterfaceHandler;
@@ -201,12 +198,11 @@
BOOL m_IoThreadStarted;
KSSTATE m_State;
+ CRITICAL_SECTION m_Lock;
};
COutputPin::~COutputPin()
{
- if (m_KsObjectParent)
- m_KsObjectParent->Release();
}
COutputPin::COutputPin(
@@ -218,7 +214,6 @@
m_PinName(PinName),
m_hPin(INVALID_HANDLE_VALUE),
m_PinId(PinId),
- m_KsObjectParent(0),
m_Pin(0),
m_KsAllocatorEx(0),
m_PipeAllocatorFlag(0),
@@ -228,7 +223,6 @@
m_MemInputPin(0),
m_IoCount(0),
m_Communication(Communication),
- m_FilterMediaSeeking(0),
m_InterfaceHandler(0),
m_hStartEvent(0),
m_hBufferAvailable(0),
@@ -238,18 +232,20 @@
m_State(KSSTATE_STOP)
{
HRESULT hr;
-
- hr = m_ParentFilter->QueryInterface(IID_IKsObject,
(LPVOID*)&m_KsObjectParent);
- assert(hr == S_OK);
-
- hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&m_FilterMediaSeeking);
+ IKsObject * KsObjectParent;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
assert(hr == S_OK);
ZeroMemory(m_FramingProp, sizeof(m_FramingProp));
ZeroMemory(m_FramingEx, sizeof(m_FramingEx));
- hr = KsGetMediaType(0, &m_MediaFormat, m_KsObjectParent->KsGetObjectHandle(),
m_PinId);
+ hr = KsGetMediaType(0, &m_MediaFormat, KsObjectParent->KsGetObjectHandle(),
m_PinId);
assert(hr == S_OK);
+
+ InitializeCriticalSection(&m_Lock);
+
+ KsObjectParent->Release();
};
HRESULT
@@ -489,7 +485,17 @@
COutputPin::GetCapabilities(
DWORD *pCapabilities)
{
- return m_FilterMediaSeeking->GetCapabilities(pCapabilities);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetCapabilities(pCapabilities);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -497,7 +503,17 @@
COutputPin::CheckCapabilities(
DWORD *pCapabilities)
{
- return m_FilterMediaSeeking->CheckCapabilities(pCapabilities);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->CheckCapabilities(pCapabilities);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -505,7 +521,17 @@
COutputPin::IsFormatSupported(
const GUID *pFormat)
{
- return m_FilterMediaSeeking->IsFormatSupported(pFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->IsFormatSupported(pFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -513,7 +539,17 @@
COutputPin::QueryPreferredFormat(
GUID *pFormat)
{
- return m_FilterMediaSeeking->QueryPreferredFormat(pFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->QueryPreferredFormat(pFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -521,7 +557,17 @@
COutputPin::GetTimeFormat(
GUID *pFormat)
{
- return m_FilterMediaSeeking->GetTimeFormat(pFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetTimeFormat(pFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -529,7 +575,17 @@
COutputPin::IsUsingTimeFormat(
const GUID *pFormat)
{
- return m_FilterMediaSeeking->IsUsingTimeFormat(pFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->IsUsingTimeFormat(pFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -537,7 +593,17 @@
COutputPin::SetTimeFormat(
const GUID *pFormat)
{
- return m_FilterMediaSeeking->SetTimeFormat(pFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->SetTimeFormat(pFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -545,7 +611,17 @@
COutputPin::GetDuration(
LONGLONG *pDuration)
{
- return m_FilterMediaSeeking->GetDuration(pDuration);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetDuration(pDuration);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -553,7 +629,17 @@
COutputPin::GetStopPosition(
LONGLONG *pStop)
{
- return m_FilterMediaSeeking->GetStopPosition(pStop);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetStopPosition(pStop);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
@@ -562,7 +648,17 @@
COutputPin::GetCurrentPosition(
LONGLONG *pCurrent)
{
- return m_FilterMediaSeeking->GetCurrentPosition(pCurrent);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetCurrentPosition(pCurrent);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -573,7 +669,17 @@
LONGLONG Source,
const GUID *pSourceFormat)
{
- return m_FilterMediaSeeking->ConvertTimeFormat(pTarget, pTargetFormat, Source,
pSourceFormat);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->ConvertTimeFormat(pTarget, pTargetFormat, Source,
pSourceFormat);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -584,7 +690,17 @@
LONGLONG *pStop,
DWORD dwStopFlags)
{
- return m_FilterMediaSeeking->SetPositions(pCurrent, dwCurrentFlags, pStop,
dwStopFlags);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->SetPositions(pCurrent, dwCurrentFlags, pStop,
dwStopFlags);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -593,7 +709,17 @@
LONGLONG *pCurrent,
LONGLONG *pStop)
{
- return m_FilterMediaSeeking->GetPositions(pCurrent, pStop);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetPositions(pCurrent, pStop);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -602,7 +728,17 @@
LONGLONG *pEarliest,
LONGLONG *pLatest)
{
- return m_FilterMediaSeeking->GetAvailable(pEarliest, pLatest);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetAvailable(pEarliest, pLatest);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -610,7 +746,17 @@
COutputPin::SetRate(
double dRate)
{
- return m_FilterMediaSeeking->SetRate(dRate);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->SetRate(dRate);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -618,7 +764,17 @@
COutputPin::GetRate(
double *pdRate)
{
- return m_FilterMediaSeeking->GetRate(pdRate);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetRate(pdRate);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
HRESULT
@@ -626,7 +782,17 @@
COutputPin::GetPreroll(
LONGLONG *pllPreroll)
{
- return m_FilterMediaSeeking->GetPreroll(pllPreroll);
+ IMediaSeeking * FilterMediaSeeking;
+ HRESULT hr;
+
+ hr = m_ParentFilter->QueryInterface(IID_IMediaSeeking,
(LPVOID*)&FilterMediaSeeking);
+ if (FAILED(hr))
+ return hr;
+
+ hr = FilterMediaSeeking->GetPreroll(pllPreroll);
+
+ FilterMediaSeeking->Release();
+ return hr;
}
//-------------------------------------------------------------------
@@ -683,8 +849,24 @@
COutputPin::KsQueryMediums(
PKSMULTIPLE_ITEM* MediumList)
{
- HANDLE hFilter = m_KsObjectParent->KsGetObjectHandle();
- return KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_MEDIUMS,
(PVOID*)MediumList);
+ HRESULT hr;
+ HANDLE hFilter;
+ IKsObject * KsObjectParent;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return E_NOINTERFACE;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ if (hFilter)
+ hr = KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_MEDIUMS,
(PVOID*)MediumList);
+ else
+ hr = E_HANDLE;
+
+ KsObjectParent->Release();
+
+ return hr;
}
HRESULT
@@ -692,9 +874,24 @@
COutputPin::KsQueryInterfaces(
PKSMULTIPLE_ITEM* InterfaceList)
{
- HANDLE hFilter = m_KsObjectParent->KsGetObjectHandle();
-
- return KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_INTERFACES,
(PVOID*)InterfaceList);
+ HRESULT hr;
+ HANDLE hFilter;
+ IKsObject * KsObjectParent;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ if (hFilter)
+ hr = KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_INTERFACES,
(PVOID*)InterfaceList);
+ else
+ hr = E_HANDLE;
+
+ KsObjectParent->Release();
+
+ return hr;
}
HRESULT
@@ -1412,6 +1609,9 @@
m_MemInputPin->Release();
m_MemAllocator->Release();
+ CloseHandle(m_hPin);
+ m_hPin = INVALID_HANDLE_VALUE;
+
OutputDebugStringW(L"COutputPin::Disconnect\n");
return S_OK;
}
@@ -1491,15 +1691,17 @@
ULONG MediaTypeCount = 0, Index;
AM_MEDIA_TYPE * MediaTypes;
HANDLE hFilter;
-
- if (!m_KsObjectParent)
- {
- // no interface
- return E_NOINTERFACE;
- }
+ IKsObject * KsObjectParent;
+
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
// get parent filter handle
- hFilter = m_KsObjectParent->KsGetObjectHandle();
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ // release IKsObject
+ KsObjectParent->Release();
// query media type count
hr = KsGetMediaTypeCount(hFilter, m_PinId, &MediaTypeCount);
@@ -1582,12 +1784,26 @@
PKSMULTIPLE_ITEM MultipleItem;
PKSDATAFORMAT DataFormat;
HRESULT hr;
+ IKsObject * KsObjectParent;
+ HANDLE hFilter;
if (!pmt)
return E_POINTER;
- HANDLE hFilter = m_KsObjectParent->KsGetObjectHandle();
- assert(hFilter != NULL);
+ // get IKsObject interface
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ // get parent filter handle
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ // release IKsObject
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
+
hr = KsGetMultiplePinFactoryItems(hFilter, m_PinId, KSPROPERTY_PIN_DATARANGES,
(PVOID*)&MultipleItem);
if (FAILED(hr))
@@ -1724,6 +1940,9 @@
PKSDATAFORMAT DataFormat;
ULONG Length;
HRESULT hr;
+ HANDLE hFilter;
+ IKsObject * KsObjectParent;
+
//KSALLOCATOR_FRAMING Framing;
//KSPROPERTY Property;
//ULONG BytesReturned;
@@ -1774,8 +1993,19 @@
CopyMemory((DataFormat + 1), pmt->pbFormat, pmt->cbFormat);
}
- HANDLE hFilter = m_KsObjectParent->KsGetObjectHandle();
- assert(hFilter != NULL);
+ // get IKsObject interface
+ hr = m_ParentFilter->QueryInterface(IID_IKsObject, (LPVOID*)&KsObjectParent);
+ if (FAILED(hr))
+ return hr;
+
+ // get parent filter handle
+ hFilter = KsObjectParent->KsGetObjectHandle();
+
+ // release IKsObject
+ KsObjectParent->Release();
+
+ if (!hFilter)
+ return E_HANDLE;
// create pin
hr = KsCreatePin(hFilter, PinConnect, GENERIC_READ, &m_hPin);
@@ -1852,15 +2082,13 @@
HRESULT hr;
PKSSTREAM_SEGMENT StreamSegment;
HANDLE hEvent;
- WCHAR Buffer[100];
+ WCHAR Buffer[200];
IMediaSample * Samples[1];
// first wait for the start event to signal
WaitForSingleObject(m_hStartEvent, INFINITE);
assert(m_InterfaceHandler);
- REFERENCE_TIME Start = 0;
- REFERENCE_TIME Stop = 1;
do
{
if (m_StopInProgress)
@@ -1869,16 +2097,15 @@
break;
}
+ assert(m_State == KSSTATE_RUN);
+ assert(m_MemAllocator);
+
// get buffer
hr = m_MemAllocator->GetBuffer(&Sample, NULL, NULL, AM_GBF_NOWAIT);
if (FAILED(hr))
{
- OutputDebugStringW(L"OutOfSamples\n");
- m_Pin->BeginFlush();
WaitForSingleObject(m_hBufferAvailable, INFINITE);
- m_Pin->EndFlush();
- OutputDebugStringW(L"After Wait OutOfSamples\n");
// now retry again
continue;
}
@@ -1897,9 +2124,7 @@
{
swprintf(Buffer, L"COutputPin::IoProcessRoutine KsProcessMediaSamples
FAILED PinName %s hr %lx\n", m_PinName, hr);
OutputDebugStringW(Buffer);
- SetEvent(m_hStopEvent);
- m_IoThreadStarted = false;
- ExitThread(0);
+ break;
}
// get completion event
@@ -1916,10 +2141,7 @@
if (SUCCEEDED(hr))
{
- LONG Length = Sample->GetActualDataLength();
- Stop += Length;
- // Sample->SetMediaTime(&Start, &Stop);
- Start = Stop;
+ assert(m_MemInputPin);
// now deliver the sample
hr = m_MemInputPin->Receive(Sample);
@@ -1963,24 +2185,18 @@
if (!m_hStartEvent)
m_hStartEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- else
- ResetEvent(m_hStartEvent);
if (!m_hStartEvent)
return E_OUTOFMEMORY;
if (!m_hStopEvent)
m_hStopEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- else
- ResetEvent(m_hStopEvent);
if (!m_hStopEvent)
return E_OUTOFMEMORY;
if (!m_hBufferAvailable)
m_hBufferAvailable = CreateEventW(NULL, FALSE, FALSE, NULL);
- else
- ResetEvent(m_hBufferAvailable);
if (!m_hBufferAvailable)
return E_OUTOFMEMORY;
@@ -2008,120 +2224,172 @@
HRESULT hr = S_OK;
KSPROPERTY Property;
KSSTATE CurState;
- WCHAR Buffer[100];
+ WCHAR Buffer[200];
ULONG BytesReturned;
COutputPin * pPin = (COutputPin*)Pin;
-
Property.Set = KSPROPSETID_Connection;
Property.Id = KSPROPERTY_CONNECTION_STATE;
Property.Flags = KSPROPERTY_TYPE_SET;
-
- if (pPin->m_State < State)
+ EnterCriticalSection(&pPin->m_Lock);
+
+ if (pPin->m_State <= State)
{
if (pPin->m_State == KSSTATE_STOP)
{
+ hr = pPin->InitializeIOThread();
+ if (FAILED(hr))
+ {
+ // failed to initialize I/O thread
+ OutputDebugStringW(L"Failed to initialize I/O Thread\n");
+ LeaveCriticalSection(&pPin->m_Lock);
+ return hr;
+ }
CurState = KSSTATE_ACQUIRE;
hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_ACQUIRE
PinName %s hr %lx\n", pPin->m_PinName, hr);
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState:
KSSTATE_STOP KSSTATE_ACQUIRE PinName %s hr %lx\n", pPin->m_PinName, hr);
OutputDebugStringW(Buffer);
if (FAILED(hr))
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
pPin->m_State = CurState;
if (pPin->m_State == State)
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
}
if (pPin->m_State == KSSTATE_ACQUIRE)
{
CurState = KSSTATE_PAUSE;
hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_PAUSE
PinName %s hr %lx\n", pPin->m_PinName, hr);
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState
KSSTATE_ACQUIRE KSSTATE_PAUSE PinName %s hr %lx\n", pPin->m_PinName, hr);
OutputDebugStringW(Buffer);
if (FAILED(hr))
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
pPin->m_State = CurState;
if (pPin->m_State == State)
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
}
-
- CurState = KSSTATE_RUN;
- hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
-
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_RUN PinName %s
hr %lx\n", pPin->m_PinName, hr);
- OutputDebugStringW(Buffer);
- if (FAILED(hr))
- return hr;
-
- // signal start event
- SetEvent(pPin->m_hStartEvent);
-
-
- pPin->m_State = CurState;
+ if (State == KSSTATE_RUN && pPin->m_State == KSSTATE_PAUSE)
+ {
+ CurState = KSSTATE_RUN;
+ hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
+
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState:
KSSTATE_PAUSE KSSTATE_RUN PinName %s hr %lx\n", pPin->m_PinName, hr);
+ OutputDebugStringW(Buffer);
+
+ if (SUCCEEDED(hr))
+ {
+ pPin->m_State = CurState;
+ // signal start event
+ SetEvent(pPin->m_hStartEvent);
+ }
+ }
+
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
}
else
{
if (pPin->m_State == KSSTATE_RUN)
{
+ // setting pending stop flag
+ pPin->m_StopInProgress = true;
+
+ // release any waiting threads
+ SetEvent(pPin->m_hBufferAvailable);
+
+ // wait until i/o thread is done
+ WaitForSingleObject(pPin->m_hStopEvent, INFINITE);
+
CurState = KSSTATE_PAUSE;
hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_PAUSE
PinName %u hr %lx\n", pPin->m_PinName, hr);
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState:
KSSTATE_RUN KSSTATE_PAUSE PinName %s hr %lx\n", pPin->m_PinName, hr);
OutputDebugStringW(Buffer);
+
if (FAILED(hr))
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
pPin->m_State = CurState;
- if (pPin->m_State == State)
+ if (FAILED(hr))
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
}
if (pPin->m_State == KSSTATE_PAUSE)
{
CurState = KSSTATE_ACQUIRE;
hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_ACQUIRE
PinName %u hr %lx\n", pPin->m_PinName, hr);
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState:
KSSTATE_PAUSE KSSTATE_ACQUIRE PinName %s hr %lx\n", pPin->m_PinName, hr);
OutputDebugStringW(Buffer);
+
if (FAILED(hr))
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
pPin->m_State = CurState;
if (pPin->m_State == State)
+ {
+ LeaveCriticalSection(&pPin->m_Lock);
return hr;
+ }
}
- // setting pending stop flag
- pPin->m_StopInProgress = true;
+ CloseHandle(pPin->m_hStopEvent);
+ CloseHandle(pPin->m_hStartEvent);
+ CloseHandle(pPin->m_hBufferAvailable);
+
+ /* close event handles */
+ pPin->m_hStopEvent = NULL;
+ pPin->m_hStartEvent = NULL;
+ pPin->m_hBufferAvailable = NULL;
CurState = KSSTATE_STOP;
hr = pPin->KsProperty(&Property, sizeof(KSPROPERTY), &CurState,
sizeof(KSSTATE), &BytesReturned);
- swprintf(Buffer, L"COutputPin_SetState Setting State KSSTATE_STOP PinName %s
hr %lx\n", pPin->m_PinName, hr);
+ swprintf(Buffer, L"COutputPin_SetState Setting State CurState:
KSSTATE_ACQUIRE KSSTATE_STOP PinName %s hr %lx\n", pPin->m_PinName, hr);
OutputDebugStringW(Buffer);
- if (FAILED(hr))
- return hr;
-
- // release any waiting threads
- SetEvent(pPin->m_hBufferAvailable);
-
- // wait until i/o thread is done
- WaitForSingleObject(pPin->m_hStopEvent, INFINITE);
-
- pPin->m_State = CurState;
- return hr;
- }
-}
-
+
+ if (SUCCEEDED(hr))
+ {
+ // store state
+ pPin->m_State = CurState;
+ }
+
+ // unset pending stop flag
+ pPin->m_StopInProgress = false;
+
+ LeaveCriticalSection(&pPin->m_Lock);
+ return hr;
+ }
+}
HRESULT
WINAPI
Modified: trunk/reactos/dll/directx/ksproxy/proxy.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/ksproxy/proxy.…
==============================================================================
--- trunk/reactos/dll/directx/ksproxy/proxy.cpp [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/ksproxy/proxy.cpp [iso-8859-1] Wed Mar 24 14:12:34 2010
@@ -63,7 +63,7 @@
InterlockedDecrement(&m_Ref);
if (!m_Ref)
{
- delete this;
+ //delete this;
return 0;
}
return m_Ref;
@@ -171,7 +171,7 @@
HRESULT STDMETHODCALLTYPE GetPages(CAUUID *pPages);
- CKsProxy() : m_Ref(0), m_pGraph(0), m_ReferenceClock((IReferenceClock*)this),
m_FilterState(State_Stopped), m_hDevice(0), m_Plugins(), m_Pins(), m_DevicePath(0),
m_hClock(0) {};
+ CKsProxy();
~CKsProxy()
{
if (m_hDevice)
@@ -203,7 +203,22 @@
LPWSTR m_DevicePath;
CLSID m_DeviceInterfaceGUID;
HANDLE m_hClock;
+ CRITICAL_SECTION m_Lock;
};
+
+CKsProxy::CKsProxy() : m_Ref(0),
+ m_pGraph(0),
+ m_ReferenceClock((IReferenceClock*)this),
+ m_FilterState(State_Stopped),
+ m_hDevice(0),
+ m_Plugins(),
+ m_Pins(),
+ m_DevicePath(0),
+ m_hClock(0)
+{
+ InitializeCriticalSection(&m_Lock);
+}
+
HRESULT
STDMETHODCALLTYPE
@@ -2516,8 +2531,19 @@
STDMETHODCALLTYPE
CKsProxy::Stop()
{
- OutputDebugStringW(L"CKsProxy::Stop : NotImplemented\n");
- return E_NOTIMPL;
+ HRESULT hr;
+
+ OutputDebugStringW(L"CKsProxy::Stop\n");
+
+ EnterCriticalSection(&m_Lock);
+
+ hr = SetPinState(KSSTATE_STOP);
+ if (SUCCEEDED(hr))
+ m_FilterState = State_Stopped;
+
+ LeaveCriticalSection(&m_Lock);
+
+ return hr;
}
HRESULT
@@ -2528,15 +2554,24 @@
OutputDebugStringW(L"CKsProxy::Pause\n");
- if (m_FilterState == State_Stopped)
- {
- hr = SetPinState(KSSTATE_PAUSE);
- if (FAILED(hr))
- return hr;
-
- }
-
- m_FilterState = State_Paused;
+ EnterCriticalSection(&m_Lock);
+
+ if (m_FilterState == State_Running)
+ {
+ hr = SetPinState(KSSTATE_STOP);
+ }
+ if (SUCCEEDED(hr))
+ {
+ if (m_FilterState == State_Stopped)
+ {
+ hr = SetPinState(KSSTATE_PAUSE);
+ }
+ }
+
+ if (SUCCEEDED(hr))
+ m_FilterState = State_Paused;
+
+ LeaveCriticalSection(&m_Lock);
return hr;
}
@@ -2550,21 +2585,28 @@
OutputDebugStringW(L"CKsProxy::Run\n");
+ EnterCriticalSection(&m_Lock);
+
if (m_FilterState == State_Stopped)
{
+ LeaveCriticalSection(&m_Lock);
// setting filter state to pause
hr = Pause();
if (FAILED(hr))
return hr;
+ EnterCriticalSection(&m_Lock);
assert(m_FilterState == State_Paused);
}
hr = SetPinState(KSSTATE_RUN);
- if (FAILED(hr))
- return hr;
-
- m_FilterState = State_Running;
+
+ if (SUCCEEDED(hr))
+ {
+ m_FilterState = State_Running;
+ }
+
+ LeaveCriticalSection(&m_Lock);
return hr;
}
@@ -2647,6 +2689,9 @@
DWORD dwMilliSecsTimeout,
FILTER_STATE *State)
{
+ if (!State)
+ return E_POINTER;
+
*State = m_FilterState;
return S_OK;
}
@@ -2851,7 +2896,11 @@
IFilterGraph *pGraph,
LPCWSTR pName)
{
- OutputDebugStringW(L"CKsProxy::JoinFilterGraph\n");
+#ifdef KSPROXY_TRACE
+ WCHAR Buffer[100];
+ swprintf(Buffer, L"CKsProxy::JoinFilterGraph pName %s pGraph %p m_Ref
%u\n", pName, pGraph, m_Ref);
+ OutputDebugStringW(Buffer);
+#endif
if (pGraph)
{