quartz/tests: COM cleanup for the IPin iface.

This commit is contained in:
Michael Stefaniuc 2011-06-19 14:21:26 +02:00 committed by Alexandre Julliard
parent 89a094569b
commit 6009ed4b6f
1 changed files with 31 additions and 26 deletions

View File

@ -22,6 +22,7 @@
#include <assert.h> #include <assert.h>
#define COBJMACROS #define COBJMACROS
#define CONST_VTABLE
#include "wine/test.h" #include "wine/test.h"
#include "dshow.h" #include "dshow.h"
@ -526,15 +527,20 @@ static void Copy_PinInfo(PIN_INFO * pDest, const PIN_INFO * pSrc)
typedef struct ITestPinImpl typedef struct ITestPinImpl
{ {
const struct IPinVtbl * lpVtbl; IPin IPin_iface;
LONG refCount; LONG refCount;
LPCRITICAL_SECTION pCritSec; LPCRITICAL_SECTION pCritSec;
PIN_INFO pinInfo; PIN_INFO pinInfo;
IPin * pConnectedTo; IPin * pConnectedTo;
AM_MEDIA_TYPE mtCurrent; AM_MEDIA_TYPE mtCurrent;
LPVOID pUserData; LPVOID pUserData;
} ITestPinImpl; } ITestPinImpl;
static inline ITestPinImpl *impl_from_IPin(IPin *iface)
{
return CONTAINING_RECORD(iface, ITestPinImpl, IPin_iface);
}
static HRESULT WINAPI TestFilter_Pin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv) static HRESULT WINAPI TestFilter_Pin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
{ {
*ppv = NULL; *ppv = NULL;
@ -555,20 +561,19 @@ static HRESULT WINAPI TestFilter_Pin_QueryInterface(IPin * iface, REFIID riid,
static ULONG WINAPI TestFilter_Pin_AddRef(IPin * iface) static ULONG WINAPI TestFilter_Pin_AddRef(IPin * iface)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
ULONG refCount = InterlockedIncrement(&This->refCount); ULONG refCount = InterlockedIncrement(&This->refCount);
return refCount; return refCount;
} }
static ULONG WINAPI TestFilter_Pin_Release(IPin * iface) static ULONG WINAPI TestFilter_Pin_Release(IPin * iface)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
ULONG refCount = InterlockedDecrement(&This->refCount); ULONG refCount = InterlockedDecrement(&This->refCount);
if (!refCount) if (!refCount)
{ {
FreeMediaType(&This->mtCurrent); FreeMediaType(&This->mtCurrent);
This->lpVtbl = NULL;
CoTaskMemFree(This); CoTaskMemFree(This);
return 0; return 0;
} }
@ -583,7 +588,7 @@ static HRESULT WINAPI TestFilter_InputPin_Connect(IPin * iface, IPin * pConnecto
static HRESULT WINAPI TestFilter_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt) static HRESULT WINAPI TestFilter_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
PIN_DIRECTION pindirReceive; PIN_DIRECTION pindirReceive;
HRESULT hr = S_OK; HRESULT hr = S_OK;
@ -621,7 +626,7 @@ static HRESULT WINAPI TestFilter_InputPin_ReceiveConnection(IPin * iface, IPin *
static HRESULT WINAPI TestFilter_Pin_Disconnect(IPin * iface) static HRESULT WINAPI TestFilter_Pin_Disconnect(IPin * iface)
{ {
HRESULT hr; HRESULT hr;
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
EnterCriticalSection(This->pCritSec); EnterCriticalSection(This->pCritSec);
{ {
@ -642,7 +647,7 @@ static HRESULT WINAPI TestFilter_Pin_Disconnect(IPin * iface)
static HRESULT WINAPI TestFilter_Pin_ConnectedTo(IPin * iface, IPin ** ppPin) static HRESULT WINAPI TestFilter_Pin_ConnectedTo(IPin * iface, IPin ** ppPin)
{ {
HRESULT hr; HRESULT hr;
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
EnterCriticalSection(This->pCritSec); EnterCriticalSection(This->pCritSec);
{ {
@ -666,7 +671,7 @@ static HRESULT WINAPI TestFilter_Pin_ConnectedTo(IPin * iface, IPin ** ppPin)
static HRESULT WINAPI TestFilter_Pin_ConnectionMediaType(IPin * iface, AM_MEDIA_TYPE * pmt) static HRESULT WINAPI TestFilter_Pin_ConnectionMediaType(IPin * iface, AM_MEDIA_TYPE * pmt)
{ {
HRESULT hr; HRESULT hr;
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
EnterCriticalSection(This->pCritSec); EnterCriticalSection(This->pCritSec);
{ {
@ -688,7 +693,7 @@ static HRESULT WINAPI TestFilter_Pin_ConnectionMediaType(IPin * iface, AM_MEDIA_
static HRESULT WINAPI TestFilter_Pin_QueryPinInfo(IPin * iface, PIN_INFO * pInfo) static HRESULT WINAPI TestFilter_Pin_QueryPinInfo(IPin * iface, PIN_INFO * pInfo)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
Copy_PinInfo(pInfo, &This->pinInfo); Copy_PinInfo(pInfo, &This->pinInfo);
IBaseFilter_AddRef(pInfo->pFilter); IBaseFilter_AddRef(pInfo->pFilter);
@ -698,7 +703,7 @@ static HRESULT WINAPI TestFilter_Pin_QueryPinInfo(IPin * iface, PIN_INFO * pInfo
static HRESULT WINAPI TestFilter_Pin_QueryDirection(IPin * iface, PIN_DIRECTION * pPinDir) static HRESULT WINAPI TestFilter_Pin_QueryDirection(IPin * iface, PIN_DIRECTION * pPinDir)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
*pPinDir = This->pinInfo.dir; *pPinDir = This->pinInfo.dir;
@ -712,7 +717,7 @@ static HRESULT WINAPI TestFilter_Pin_QueryId(IPin * iface, LPWSTR * Id)
static HRESULT WINAPI TestFilter_Pin_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt) static HRESULT WINAPI TestFilter_Pin_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
if (IsEqualIID(&pmt->majortype, &This->mtCurrent.majortype) && (IsEqualIID(&pmt->subtype, &This->mtCurrent.subtype) || if (IsEqualIID(&pmt->majortype, &This->mtCurrent.majortype) && (IsEqualIID(&pmt->subtype, &This->mtCurrent.subtype) ||
IsEqualIID(&GUID_NULL, &This->mtCurrent.subtype))) IsEqualIID(&GUID_NULL, &This->mtCurrent.subtype)))
@ -723,7 +728,7 @@ static HRESULT WINAPI TestFilter_Pin_QueryAccept(IPin * iface, const AM_MEDIA_TY
static HRESULT WINAPI TestFilter_Pin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum) static HRESULT WINAPI TestFilter_Pin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
return IEnumMediaTypesImpl_Construct(&This->mtCurrent, 1, ppEnum); return IEnumMediaTypesImpl_Construct(&This->mtCurrent, 1, ppEnum);
} }
@ -781,15 +786,15 @@ static HRESULT WINAPI TestFilter_OutputPin_ReceiveConnection(IPin * iface, IPin
} }
/* Private helper function */ /* Private helper function */
static HRESULT TestFilter_OutputPin_ConnectSpecific(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt) static HRESULT TestFilter_OutputPin_ConnectSpecific(ITestPinImpl * This, IPin * pReceivePin,
const AM_MEDIA_TYPE * pmt)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface;
HRESULT hr; HRESULT hr;
This->pConnectedTo = pReceivePin; This->pConnectedTo = pReceivePin;
IPin_AddRef(pReceivePin); IPin_AddRef(pReceivePin);
hr = IPin_ReceiveConnection(pReceivePin, iface, pmt); hr = IPin_ReceiveConnection(pReceivePin, &This->IPin_iface, pmt);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -802,7 +807,7 @@ static HRESULT TestFilter_OutputPin_ConnectSpecific(IPin * iface, IPin * pReceiv
static HRESULT WINAPI TestFilter_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt) static HRESULT WINAPI TestFilter_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
{ {
ITestPinImpl *This = (ITestPinImpl *)iface; ITestPinImpl *This = impl_from_IPin(iface);
HRESULT hr; HRESULT hr;
EnterCriticalSection(This->pCritSec); EnterCriticalSection(This->pCritSec);
@ -810,11 +815,11 @@ static HRESULT WINAPI TestFilter_OutputPin_Connect(IPin * iface, IPin * pReceive
/* if we have been a specific type to connect with, then we can either connect /* if we have been a specific type to connect with, then we can either connect
* with that or fail. We cannot choose different AM_MEDIA_TYPE */ * with that or fail. We cannot choose different AM_MEDIA_TYPE */
if (pmt && !IsEqualGUID(&pmt->majortype, &GUID_NULL) && !IsEqualGUID(&pmt->subtype, &GUID_NULL)) if (pmt && !IsEqualGUID(&pmt->majortype, &GUID_NULL) && !IsEqualGUID(&pmt->subtype, &GUID_NULL))
hr = TestFilter_OutputPin_ConnectSpecific(iface, pReceivePin, pmt); hr = TestFilter_OutputPin_ConnectSpecific(This, pReceivePin, pmt);
else else
{ {
if (( !pmt || CompareMediaTypes(pmt, &This->mtCurrent, TRUE) ) && if (( !pmt || CompareMediaTypes(pmt, &This->mtCurrent, TRUE) ) &&
(TestFilter_OutputPin_ConnectSpecific(iface, pReceivePin, &This->mtCurrent) == S_OK)) (TestFilter_OutputPin_ConnectSpecific(This, pReceivePin, &This->mtCurrent) == S_OK))
hr = S_OK; hr = S_OK;
else hr = VFW_E_NO_ACCEPTABLE_TYPES; else hr = VFW_E_NO_ACCEPTABLE_TYPES;
} /* if negotiate media type */ } /* if negotiate media type */
@ -864,9 +869,9 @@ static HRESULT TestFilter_Pin_Construct(const IPinVtbl *Pin_Vtbl, const PIN_INFO
Copy_PinInfo(&pPinImpl->pinInfo, pPinInfo); Copy_PinInfo(&pPinImpl->pinInfo, pPinInfo);
pPinImpl->mtCurrent = *pinmt; pPinImpl->mtCurrent = *pinmt;
pPinImpl->lpVtbl = Pin_Vtbl; pPinImpl->IPin_iface.lpVtbl = Pin_Vtbl;
*ppPin = (IPin *)pPinImpl; *ppPin = &pPinImpl->IPin_iface;
return S_OK; return S_OK;
} }