2010-10-05 21:37:42 +02:00
|
|
|
/*
|
|
|
|
* Generic Implementation of IPin Interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
* Copyright 2010 Aric Stewart, CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-09 17:12:32 +02:00
|
|
|
#include "strmbase_private.h"
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
|
|
|
|
|
2010-10-05 21:38:11 +02:00
|
|
|
static const IMemInputPinVtbl MemInputPin_Vtbl;
|
|
|
|
|
|
|
|
typedef HRESULT (*SendPinFunc)( IPin *to, LPVOID arg );
|
|
|
|
|
2019-09-24 02:33:24 +02:00
|
|
|
static inline struct strmbase_pin *impl_from_IPin(IPin *iface)
|
2012-03-24 17:42:32 +01:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_pin, IPin_iface);
|
2012-03-24 17:42:32 +01:00
|
|
|
}
|
|
|
|
|
2010-10-05 21:38:11 +02:00
|
|
|
/** Helper function, there are a lot of places where the error code is inherited
|
|
|
|
* The following rules apply:
|
|
|
|
*
|
|
|
|
* Return the first received error code (E_NOTIMPL is ignored)
|
|
|
|
* If no errors occur: return the first received non-error-code that isn't S_OK
|
|
|
|
*/
|
|
|
|
static HRESULT updatehres( HRESULT original, HRESULT new )
|
|
|
|
{
|
|
|
|
if (FAILED( original ) || new == E_NOTIMPL)
|
|
|
|
return original;
|
|
|
|
|
|
|
|
if (FAILED( new ) || original == S_OK)
|
|
|
|
return new;
|
|
|
|
|
|
|
|
return original;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Sends a message from a pin further to other, similar pins
|
|
|
|
* fnMiddle is called on each pin found further on the stream.
|
|
|
|
* fnEnd (can be NULL) is called when the message can't be sent any further (this is a renderer or source)
|
|
|
|
*
|
|
|
|
* If the pin given is an input pin, the message will be sent downstream to other input pins
|
|
|
|
* If the pin given is an output pin, the message will be sent upstream to other output pins
|
|
|
|
*/
|
2019-11-23 04:14:00 +01:00
|
|
|
static HRESULT SendFurther(struct strmbase_sink *sink, SendPinFunc func, void *arg)
|
2010-10-05 21:38:11 +02:00
|
|
|
{
|
2019-11-23 04:14:00 +01:00
|
|
|
struct strmbase_pin *pin;
|
2010-10-05 21:38:11 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-11-23 04:14:00 +01:00
|
|
|
unsigned int i;
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-11-23 04:14:00 +01:00
|
|
|
for (i = 0; (pin = sink->pin.filter->ops->filter_get_pin(sink->pin.filter, i)); ++i)
|
|
|
|
{
|
|
|
|
if (pin->dir == PINDIR_OUTPUT && pin->peer)
|
|
|
|
hr = updatehres(hr, func(pin->peer, arg));
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
static BOOL CompareMediaTypes(const AM_MEDIA_TYPE * pmt1, const AM_MEDIA_TYPE * pmt2, BOOL bWildcards)
|
|
|
|
{
|
|
|
|
return (((bWildcards && (IsEqualGUID(&pmt1->majortype, &GUID_NULL) || IsEqualGUID(&pmt2->majortype, &GUID_NULL))) || IsEqualGUID(&pmt1->majortype, &pmt2->majortype)) &&
|
|
|
|
((bWildcards && (IsEqualGUID(&pmt1->subtype, &GUID_NULL) || IsEqualGUID(&pmt2->subtype, &GUID_NULL))) || IsEqualGUID(&pmt1->subtype, &pmt2->subtype)));
|
|
|
|
}
|
|
|
|
|
2019-09-25 02:10:12 +02:00
|
|
|
HRESULT strmbase_pin_get_media_type(struct strmbase_pin *iface, unsigned int index, AM_MEDIA_TYPE *mt)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
2019-09-26 05:36:23 +02:00
|
|
|
HRESULT WINAPI BasePinImpl_QueryInterface(IPin *iface, REFIID iid, void **out)
|
2019-09-26 05:36:22 +02:00
|
|
|
{
|
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
|
|
|
|
if (pin->pFuncsTable->pin_query_interface
|
2019-09-26 05:36:23 +02:00
|
|
|
&& SUCCEEDED(hr = pin->pFuncsTable->pin_query_interface(pin, iid, out)))
|
2019-09-26 05:36:22 +02:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_IPin))
|
|
|
|
*out = iface;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-06-19 03:17:34 +02:00
|
|
|
ULONG WINAPI BasePinImpl_AddRef(IPin *iface)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2019-09-06 02:02:15 +02:00
|
|
|
return IBaseFilter_AddRef(&pin->filter->IBaseFilter_iface);
|
2019-06-19 03:17:34 +02:00
|
|
|
}
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-06-19 03:17:34 +02:00
|
|
|
ULONG WINAPI BasePinImpl_Release(IPin *iface)
|
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2019-09-06 02:02:15 +02:00
|
|
|
return IBaseFilter_Release(&pin->filter->IBaseFilter_iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BasePinImpl_ConnectedTo(IPin * iface, IPin ** ppPin)
|
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *This = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppPin);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->filter->csFilter);
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (This->peer)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
*ppPin = This->peer;
|
2010-10-05 21:37:42 +02:00
|
|
|
IPin_AddRef(*ppPin);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
*ppPin = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->filter->csFilter);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BasePinImpl_ConnectionMediaType(IPin * iface, AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *This = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p)\n", This, pmt);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->filter->csFilter);
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (This->peer)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-11-19 01:51:20 +01:00
|
|
|
CopyMediaType(pmt, &This->mt);
|
2019-10-06 02:18:50 +02:00
|
|
|
strmbase_dump_media_type(pmt);
|
2010-10-05 21:37:42 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZeroMemory(pmt, sizeof(*pmt));
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->filter->csFilter);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
HRESULT WINAPI BasePinImpl_QueryPinInfo(IPin *iface, PIN_INFO *info)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
TRACE("pin %p, info %p.\n", pin, info);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
info->dir = pin->dir;
|
|
|
|
IBaseFilter_AddRef(info->pFilter = &pin->filter->IBaseFilter_iface);
|
|
|
|
lstrcpyW(info->achName, pin->name);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
HRESULT WINAPI BasePinImpl_QueryDirection(IPin *iface, PIN_DIRECTION *dir)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
TRACE("pin %p, dir %p.\n", pin, dir);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
*dir = pin->dir;
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
HRESULT WINAPI BasePinImpl_QueryId(IPin *iface, WCHAR **id)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
TRACE("pin %p, id %p.\n", pin, id);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
if (!(*id = CoTaskMemAlloc((lstrlenW(pin->name) + 1) * sizeof(WCHAR))))
|
2010-10-05 21:37:42 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2019-09-06 02:02:15 +02:00
|
|
|
lstrcpyW(*id, pin->name);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BasePinImpl_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *This = impl_from_IPin(iface);
|
2018-05-04 06:47:13 +02:00
|
|
|
|
2010-10-05 21:37:42 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, pmt);
|
2019-10-06 02:18:50 +02:00
|
|
|
strmbase_dump_media_type(pmt);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
return (This->pFuncsTable->pin_query_accept(This, pmt) == S_OK ? S_OK : S_FALSE);
|
2010-10-05 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 17:12:34 +02:00
|
|
|
HRESULT WINAPI BasePinImpl_EnumMediaTypes(IPin *iface, IEnumMediaTypes **enum_media_types)
|
2010-10-05 21:37:42 +02:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *pin = impl_from_IPin(iface);
|
2019-09-25 02:10:14 +02:00
|
|
|
AM_MEDIA_TYPE mt;
|
|
|
|
HRESULT hr;
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-05-09 17:12:34 +02:00
|
|
|
TRACE("iface %p, enum_media_types %p.\n", iface, enum_media_types);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2019-09-25 02:10:14 +02:00
|
|
|
if (FAILED(hr = pin->pFuncsTable->pin_get_media_type(pin, 0, &mt)))
|
|
|
|
return hr;
|
|
|
|
if (hr == S_OK)
|
|
|
|
FreeMediaType(&mt);
|
|
|
|
|
2019-09-24 02:33:23 +02:00
|
|
|
return enum_media_types_create(pin, enum_media_types);
|
2010-10-05 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BasePinImpl_QueryInternalConnections(IPin * iface, IPin ** apPin, ULONG * cPin)
|
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
struct strmbase_pin *This = impl_from_IPin(iface);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, apPin, cPin);
|
2010-10-05 21:37:42 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL; /* to tell caller that all input pins connected to all output pins */
|
|
|
|
}
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-11-16 18:20:14 +01:00
|
|
|
HRESULT WINAPI BasePinImpl_NewSegment(IPin * iface, REFERENCE_TIME start, REFERENCE_TIME stop, double rate)
|
2010-11-01 13:42:14 +01:00
|
|
|
{
|
2019-10-06 02:18:49 +02:00
|
|
|
TRACE("iface %p, start %s, stop %s, rate %.16e.\n",
|
2019-11-16 18:20:14 +01:00
|
|
|
iface, debugstr_time(start), debugstr_time(stop), rate);
|
2010-11-01 13:42:14 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
/*** OutputPin implementation ***/
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
static inline struct strmbase_source *impl_source_from_IPin( IPin *iface )
|
2012-03-24 17:42:32 +01:00
|
|
|
{
|
2019-09-12 21:28:25 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_source, pin.IPin_iface);
|
2012-03-24 17:42:32 +01:00
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_Connect(IPin *iface, IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2019-09-12 21:28:25 +02:00
|
|
|
struct strmbase_source *This = impl_source_from_IPin(iface);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
|
2019-10-06 02:18:50 +02:00
|
|
|
strmbase_dump_media_type(pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2013-11-26 14:34:32 +01:00
|
|
|
if (!pReceivePin)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2011-08-02 22:20:32 +02:00
|
|
|
/* If we try to connect to ourselves, we will definitely deadlock.
|
2010-10-05 21:37:56 +02:00
|
|
|
* There are other cases where we could deadlock too, but this
|
|
|
|
* catches the obvious case */
|
|
|
|
assert(pReceivePin != iface);
|
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2019-11-19 01:51:21 +01:00
|
|
|
if (This->pin.filter->state != State_Stopped)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
|
|
|
WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
|
|
|
|
return VFW_E_NOT_STOPPED;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
/* 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 */
|
|
|
|
if (pmt && !IsEqualGUID(&pmt->majortype, &GUID_NULL) && !IsEqualGUID(&pmt->subtype, &GUID_NULL))
|
2019-05-09 17:12:33 +02:00
|
|
|
hr = This->pFuncsTable->pfnAttemptConnection(This, pReceivePin, pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* negotiate media type */
|
|
|
|
|
|
|
|
IEnumMediaTypes * pEnumCandidates;
|
|
|
|
AM_MEDIA_TYPE * pmtCandidate = NULL; /* Candidate media type */
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr = IPin_EnumMediaTypes(iface, &pEnumCandidates)))
|
|
|
|
{
|
|
|
|
hr = VFW_E_NO_ACCEPTABLE_TYPES; /* Assume the worst, but set to S_OK if connected successfully */
|
|
|
|
|
|
|
|
/* try this filter's media types first */
|
|
|
|
while (S_OK == IEnumMediaTypes_Next(pEnumCandidates, 1, &pmtCandidate, NULL))
|
|
|
|
{
|
|
|
|
assert(pmtCandidate);
|
|
|
|
if (!IsEqualGUID(&FORMAT_None, &pmtCandidate->formattype)
|
|
|
|
&& !IsEqualGUID(&GUID_NULL, &pmtCandidate->formattype))
|
|
|
|
assert(pmtCandidate->pbFormat);
|
2019-05-09 17:12:33 +02:00
|
|
|
if ((!pmt || CompareMediaTypes(pmt, pmtCandidate, TRUE))
|
|
|
|
&& This->pFuncsTable->pfnAttemptConnection(This, pReceivePin, pmtCandidate) == S_OK)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
pmtCandidate = NULL;
|
|
|
|
}
|
|
|
|
IEnumMediaTypes_Release(pEnumCandidates);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then try receiver filter's media types */
|
|
|
|
if (hr != S_OK && SUCCEEDED(hr = IPin_EnumMediaTypes(pReceivePin, &pEnumCandidates))) /* if we haven't already connected successfully */
|
|
|
|
{
|
2013-11-26 14:34:32 +01:00
|
|
|
ULONG fetched;
|
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = VFW_E_NO_ACCEPTABLE_TYPES; /* Assume the worst, but set to S_OK if connected successfully */
|
|
|
|
|
2013-11-26 14:34:32 +01:00
|
|
|
while (S_OK == IEnumMediaTypes_Next(pEnumCandidates, 1, &pmtCandidate, &fetched))
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
assert(pmtCandidate);
|
2019-10-06 02:18:50 +02:00
|
|
|
strmbase_dump_media_type(pmtCandidate);
|
2019-05-09 17:12:33 +02:00
|
|
|
if ((!pmt || CompareMediaTypes(pmt, pmtCandidate, TRUE))
|
|
|
|
&& This->pFuncsTable->pfnAttemptConnection(This, pReceivePin, pmtCandidate) == S_OK)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
pmtCandidate = NULL;
|
|
|
|
} /* while */
|
|
|
|
IEnumMediaTypes_Release(pEnumCandidates);
|
|
|
|
} /* if not found */
|
|
|
|
} /* if negotiate media type */
|
|
|
|
} /* if succeeded */
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
TRACE(" -- %x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_ReceiveConnection(IPin *iface, IPin *pin, const AM_MEDIA_TYPE *pmt)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2018-05-04 06:47:14 +02:00
|
|
|
ERR("(%p)->(%p, %p) incoming connection on an output pin!\n", iface, pin, pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_Disconnect(IPin *iface)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2019-09-12 21:28:25 +02:00
|
|
|
struct strmbase_source *This = impl_source_from_IPin(iface);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2019-11-19 01:51:21 +01:00
|
|
|
if (This->pin.filter->state != State_Stopped)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
|
|
|
WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
|
|
|
|
return VFW_E_NOT_STOPPED;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
if (This->pMemInputPin)
|
|
|
|
{
|
|
|
|
IMemInputPin_Release(This->pMemInputPin);
|
|
|
|
This->pMemInputPin = NULL;
|
|
|
|
}
|
2019-09-27 04:40:53 +02:00
|
|
|
if (This->pin.peer)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
IPin_Release(This->pin.peer);
|
|
|
|
This->pin.peer = NULL;
|
2019-11-19 01:51:20 +01:00
|
|
|
FreeMediaType(&This->pin.mt);
|
|
|
|
ZeroMemory(&This->pin.mt, sizeof(This->pin.mt));
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_EndOfStream(IPin *iface)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_BeginFlush(IPin *iface)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static HRESULT WINAPI source_EndFlush(IPin *iface)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
static const IPinVtbl source_vtbl =
|
|
|
|
{
|
|
|
|
BasePinImpl_QueryInterface,
|
|
|
|
BasePinImpl_AddRef,
|
|
|
|
BasePinImpl_Release,
|
|
|
|
source_Connect,
|
|
|
|
source_ReceiveConnection,
|
|
|
|
source_Disconnect,
|
|
|
|
BasePinImpl_ConnectedTo,
|
|
|
|
BasePinImpl_ConnectionMediaType,
|
|
|
|
BasePinImpl_QueryPinInfo,
|
|
|
|
BasePinImpl_QueryDirection,
|
|
|
|
BasePinImpl_QueryId,
|
|
|
|
BasePinImpl_QueryAccept,
|
|
|
|
BasePinImpl_EnumMediaTypes,
|
|
|
|
BasePinImpl_QueryInternalConnections,
|
|
|
|
source_EndOfStream,
|
|
|
|
source_BeginFlush,
|
|
|
|
source_EndFlush,
|
|
|
|
BasePinImpl_NewSegment,
|
|
|
|
};
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_GetDeliveryBuffer(struct strmbase_source *This,
|
|
|
|
IMediaSample **ppSample, REFERENCE_TIME *tStart, REFERENCE_TIME *tStop, DWORD dwFlags)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p, %p, %p, %x)\n", This, ppSample, tStart, tStop, dwFlags);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
if (!This->pin.peer)
|
2012-05-11 20:19:38 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2013-01-15 07:43:33 +01:00
|
|
|
hr = IMemAllocator_GetBuffer(This->pAllocator, ppSample, tStart, tStop, dwFlags);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2012-05-11 20:19:38 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMediaSample_SetTime(*ppSample, tStart, tStop);
|
2010-10-05 21:37:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replaces OutputPin_CommitAllocator */
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_Active(struct strmbase_source *This)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2015-10-19 10:57:50 +02:00
|
|
|
HRESULT hr;
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (!This->pin.peer || !This->pMemInputPin)
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
2013-01-15 07:43:33 +01:00
|
|
|
hr = IMemAllocator_Commit(This->pAllocator);
|
2010-10-05 21:37:56 +02:00
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
TRACE("--> %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replaces OutputPin_DecommitAllocator */
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_Inactive(struct strmbase_source *This)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2015-10-19 10:57:50 +02:00
|
|
|
HRESULT hr;
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (!This->pin.peer || !This->pMemInputPin)
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
2013-01-15 07:43:33 +01:00
|
|
|
hr = IMemAllocator_Decommit(This->pAllocator);
|
2010-10-05 21:37:56 +02:00
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
TRACE("--> %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_InitAllocator(struct strmbase_source *This, IMemAllocator **pMemAlloc)
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
|
|
|
return CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)pMemAlloc);
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_DecideAllocator(struct strmbase_source *This,
|
|
|
|
IMemInputPin *pPin, IMemAllocator **pAlloc)
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2010-10-13 18:02:14 +02:00
|
|
|
hr = IMemInputPin_GetAllocator(pPin, pAlloc);
|
2010-10-13 17:46:27 +02:00
|
|
|
|
2010-10-13 18:02:14 +02:00
|
|
|
if (hr == VFW_E_NO_ALLOCATOR)
|
|
|
|
/* Input pin provides no allocator, use standard memory allocator */
|
|
|
|
hr = BaseOutputPinImpl_InitAllocator(This, pAlloc);
|
2010-10-13 17:46:27 +02:00
|
|
|
|
2010-10-13 18:02:14 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
2010-10-13 18:02:14 +02:00
|
|
|
ALLOCATOR_PROPERTIES rProps;
|
|
|
|
ZeroMemory(&rProps, sizeof(ALLOCATOR_PROPERTIES));
|
2010-10-13 17:46:27 +02:00
|
|
|
|
2010-10-13 18:02:14 +02:00
|
|
|
IMemInputPin_GetAllocatorRequirements(pPin, &rProps);
|
|
|
|
hr = This->pFuncsTable->pfnDecideBufferSize(This, *pAlloc, &rProps);
|
2010-10-13 17:46:27 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 18:02:14 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemInputPin_NotifyAllocator(pPin, *pAlloc, FALSE);
|
|
|
|
|
2010-10-13 17:46:27 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
/*** The Construct functions ***/
|
|
|
|
|
|
|
|
/* Function called as a helper to IPin_Connect */
|
|
|
|
/* specific AM_MEDIA_TYPE - it cannot be NULL */
|
2019-09-12 21:28:25 +02:00
|
|
|
HRESULT WINAPI BaseOutputPinImpl_AttemptConnection(struct strmbase_source *This,
|
|
|
|
IPin *pReceivePin, const AM_MEDIA_TYPE *pmt)
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMemAllocator * pMemAlloc = NULL;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
if ((hr = This->pFuncsTable->base.pin_query_accept(&This->pin, pmt)) != S_OK)
|
2018-05-04 06:47:12 +02:00
|
|
|
return hr;
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
This->pin.peer = pReceivePin;
|
2010-10-05 21:37:56 +02:00
|
|
|
IPin_AddRef(pReceivePin);
|
2019-11-19 01:51:20 +01:00
|
|
|
CopyMediaType(&This->pin.mt, pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
2019-05-09 17:12:33 +02:00
|
|
|
hr = IPin_ReceiveConnection(pReceivePin, &This->pin.IPin_iface, pmt);
|
2010-10-05 21:37:56 +02:00
|
|
|
|
|
|
|
/* get the IMemInputPin interface we will use to deliver samples to the
|
|
|
|
* connected pin */
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
This->pMemInputPin = NULL;
|
|
|
|
hr = IPin_QueryInterface(pReceivePin, &IID_IMemInputPin, (LPVOID)&This->pMemInputPin);
|
|
|
|
|
2010-10-13 17:46:27 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2010-10-05 21:37:56 +02:00
|
|
|
{
|
2010-10-13 18:02:14 +02:00
|
|
|
hr = This->pFuncsTable->pfnDecideAllocator(This, This->pMemInputPin, &pMemAlloc);
|
2013-01-15 07:43:33 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
This->pAllocator = pMemAlloc;
|
|
|
|
else if (pMemAlloc)
|
2010-10-05 21:37:56 +02:00
|
|
|
IMemAllocator_Release(pMemAlloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* break connection if we couldn't get the allocator */
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
if (This->pMemInputPin)
|
|
|
|
IMemInputPin_Release(This->pMemInputPin);
|
|
|
|
This->pMemInputPin = NULL;
|
|
|
|
|
|
|
|
IPin_Disconnect(pReceivePin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
IPin_Release(This->pin.peer);
|
|
|
|
This->pin.peer = NULL;
|
2019-11-19 01:51:20 +01:00
|
|
|
FreeMediaType(&This->pin.mt);
|
2010-10-05 21:37:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(" -- %x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-08 05:20:38 +01:00
|
|
|
void strmbase_source_init(struct strmbase_source *pin, struct strmbase_filter *filter,
|
2019-09-12 21:28:26 +02:00
|
|
|
const WCHAR *name, const struct strmbase_source_ops *func_table)
|
2019-06-13 01:58:34 +02:00
|
|
|
{
|
|
|
|
memset(pin, 0, sizeof(*pin));
|
2019-12-08 05:20:38 +01:00
|
|
|
pin->pin.IPin_iface.lpVtbl = &source_vtbl;
|
2019-09-06 02:02:15 +02:00
|
|
|
pin->pin.filter = filter;
|
|
|
|
pin->pin.dir = PINDIR_OUTPUT;
|
|
|
|
lstrcpyW(pin->pin.name, name);
|
|
|
|
pin->pin.pFuncsTable = &func_table->base;
|
2019-06-13 01:58:34 +02:00
|
|
|
pin->pFuncsTable = func_table;
|
2010-10-05 21:37:56 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
void strmbase_source_cleanup(struct strmbase_source *pin)
|
2019-06-14 01:09:20 +02:00
|
|
|
{
|
2019-11-19 01:51:20 +01:00
|
|
|
FreeMediaType(&pin->pin.mt);
|
2019-06-14 01:09:20 +02:00
|
|
|
if (pin->pAllocator)
|
|
|
|
IMemAllocator_Release(pin->pAllocator);
|
|
|
|
pin->pAllocator = NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
static struct strmbase_sink *impl_sink_from_IPin(IPin *iface)
|
2012-03-24 17:42:32 +01:00
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_sink, pin.IPin_iface);
|
2012-03-24 17:42:32 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
HRESULT WINAPI BaseInputPinImpl_Connect(IPin *iface, IPin *pin, const AM_MEDIA_TYPE *pmt)
|
2010-10-05 21:38:11 +02:00
|
|
|
{
|
2018-05-04 06:47:14 +02:00
|
|
|
ERR("(%p)->(%p, %p) outgoing connection on an input pin!\n", iface, pin, pmt);
|
2010-10-05 21:38:11 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseInputPinImpl_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_sink_from_IPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
PIN_DIRECTION pindirReceive;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->(%p, %p)\n", This, pReceivePin, pmt);
|
2019-10-06 02:18:50 +02:00
|
|
|
strmbase_dump_media_type(pmt);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-12-11 04:53:32 +01:00
|
|
|
if (!pmt)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
{
|
2019-11-19 01:51:21 +01:00
|
|
|
if (This->pin.filter->state != State_Stopped)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
|
|
|
WARN("Filter is not stopped; returning VFW_E_NOT_STOPPED.\n");
|
|
|
|
return VFW_E_NOT_STOPPED;
|
|
|
|
}
|
|
|
|
|
2019-09-27 04:40:53 +02:00
|
|
|
if (This->pin.peer)
|
2010-10-05 21:38:11 +02:00
|
|
|
hr = VFW_E_ALREADY_CONNECTED;
|
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
if (SUCCEEDED(hr) && This->pin.pFuncsTable->pin_query_accept(&This->pin, pmt) != S_OK)
|
2010-10-05 21:38:11 +02:00
|
|
|
hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
|
|
|
|
* VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
IPin_QueryDirection(pReceivePin, &pindirReceive);
|
|
|
|
|
|
|
|
if (pindirReceive != PINDIR_OUTPUT)
|
|
|
|
{
|
|
|
|
ERR("Can't connect from non-output pin\n");
|
|
|
|
hr = VFW_E_INVALID_DIRECTION;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-10 17:35:13 +01:00
|
|
|
if (SUCCEEDED(hr) && This->pFuncsTable->sink_connect)
|
|
|
|
hr = This->pFuncsTable->sink_connect(This, pReceivePin, pmt);
|
|
|
|
|
2010-10-05 21:38:11 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2019-11-19 01:51:20 +01:00
|
|
|
CopyMediaType(&This->pin.mt, pmt);
|
2019-09-27 04:40:53 +02:00
|
|
|
This->pin.peer = pReceivePin;
|
2010-10-05 21:38:11 +02:00
|
|
|
IPin_AddRef(pReceivePin);
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-10 17:35:13 +01:00
|
|
|
HRESULT WINAPI BaseInputPinImpl_Disconnect(IPin *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_sink *pin = impl_sink_from_IPin(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("pin %p.\n", pin);
|
|
|
|
|
|
|
|
EnterCriticalSection(&pin->pin.filter->csFilter);
|
|
|
|
|
|
|
|
if (pin->pin.peer)
|
|
|
|
{
|
|
|
|
if (pin->pFuncsTable->sink_disconnect)
|
|
|
|
pin->pFuncsTable->sink_disconnect(pin);
|
|
|
|
|
|
|
|
IPin_Release(pin->pin.peer);
|
|
|
|
pin->pin.peer = NULL;
|
|
|
|
FreeMediaType(&pin->pin.mt);
|
|
|
|
memset(&pin->pin.mt, 0, sizeof(AM_MEDIA_TYPE));
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&pin->pin.filter->csFilter);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:38:11 +02:00
|
|
|
static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_EndOfStream( pin );
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseInputPinImpl_EndOfStream(IPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_sink_from_IPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
if (This->flushing)
|
|
|
|
hr = S_FALSE;
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
if (hr == S_OK)
|
2019-11-23 04:14:00 +01:00
|
|
|
hr = SendFurther(This, deliver_endofstream, NULL);
|
2010-10-05 21:38:11 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_BeginFlush( pin );
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseInputPinImpl_BeginFlush(IPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_sink_from_IPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
HRESULT hr;
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p) semi-stub\n", This);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2013-11-25 22:27:35 +01:00
|
|
|
This->flushing = TRUE;
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-11-23 04:14:00 +01:00
|
|
|
hr = SendFurther(This, deliver_beginflush, NULL);
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_EndFlush( pin );
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI BaseInputPinImpl_EndFlush(IPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_sink_from_IPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
HRESULT hr;
|
2018-05-04 06:47:14 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-09-06 02:02:16 +02:00
|
|
|
EnterCriticalSection(&This->pin.filter->csFilter);
|
2019-11-27 00:39:20 +01:00
|
|
|
This->flushing = FALSE;
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-11-23 04:14:00 +01:00
|
|
|
hr = SendFurther(This, deliver_endflush, NULL);
|
2019-09-06 02:02:16 +02:00
|
|
|
LeaveCriticalSection(&This->pin.filter->csFilter);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct newsegmentargs
|
|
|
|
{
|
|
|
|
REFERENCE_TIME tStart, tStop;
|
|
|
|
double rate;
|
|
|
|
} newsegmentargs;
|
|
|
|
|
|
|
|
static HRESULT deliver_newsegment(IPin *pin, LPVOID data)
|
|
|
|
{
|
|
|
|
newsegmentargs *args = data;
|
|
|
|
return IPin_NewSegment(pin, args->tStart, args->tStop, args->rate);
|
|
|
|
}
|
|
|
|
|
2019-11-16 18:20:14 +01:00
|
|
|
HRESULT WINAPI BaseInputPinImpl_NewSegment(IPin * iface, REFERENCE_TIME start, REFERENCE_TIME stop, double rate)
|
2010-10-05 21:38:11 +02:00
|
|
|
{
|
2019-11-23 04:14:00 +01:00
|
|
|
struct strmbase_sink *pin = impl_sink_from_IPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
newsegmentargs args;
|
|
|
|
|
2019-10-06 02:18:49 +02:00
|
|
|
TRACE("iface %p, start %s, stop %s, rate %.16e.\n",
|
2019-11-16 18:20:14 +01:00
|
|
|
iface, debugstr_time(start), debugstr_time(stop), rate);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-11-16 18:20:14 +01:00
|
|
|
args.tStart = start;
|
|
|
|
args.tStop = stop;
|
|
|
|
args.rate = rate;
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2019-11-23 04:14:00 +01:00
|
|
|
return SendFurther(pin, deliver_newsegment, &args);
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*** IMemInputPin implementation ***/
|
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
static inline struct strmbase_sink *impl_from_IMemInputPin(IMemInputPin *iface)
|
2010-10-05 21:38:11 +02:00
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_sink, IMemInputPin_iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_QueryInterface(IMemInputPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2012-03-24 17:42:32 +01:00
|
|
|
return IPin_QueryInterface(&This->pin.IPin_iface, riid, ppv);
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MemInputPin_AddRef(IMemInputPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2012-03-24 17:42:32 +01:00
|
|
|
return IPin_AddRef(&This->pin.IPin_iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI MemInputPin_Release(IMemInputPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
2012-03-24 17:42:32 +01:00
|
|
|
return IPin_Release(&This->pin.IPin_iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_GetAllocator(IMemInputPin * iface, IMemAllocator ** ppAllocator)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppAllocator);
|
|
|
|
|
|
|
|
*ppAllocator = This->pAllocator;
|
|
|
|
if (*ppAllocator)
|
|
|
|
IMemAllocator_AddRef(*ppAllocator);
|
|
|
|
|
|
|
|
return *ppAllocator ? S_OK : VFW_E_NO_ALLOCATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_NotifyAllocator(IMemInputPin * iface, IMemAllocator * pAllocator, BOOL bReadOnly)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p, %d)\n", This, iface, pAllocator, bReadOnly);
|
|
|
|
|
|
|
|
if (bReadOnly)
|
|
|
|
FIXME("Read only flag not handled yet!\n");
|
|
|
|
|
|
|
|
/* FIXME: Should we release the allocator on disconnection? */
|
|
|
|
if (!pAllocator)
|
|
|
|
{
|
|
|
|
WARN("Null allocator\n");
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->preferred_allocator && pAllocator != This->preferred_allocator)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (This->pAllocator)
|
|
|
|
IMemAllocator_Release(This->pAllocator);
|
|
|
|
This->pAllocator = pAllocator;
|
|
|
|
if (This->pAllocator)
|
|
|
|
IMemAllocator_AddRef(This->pAllocator);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_GetAllocatorRequirements(IMemInputPin * iface, ALLOCATOR_PROPERTIES * pProps)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pProps);
|
|
|
|
|
|
|
|
/* override this method if you have any specific requirements */
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_Receive(IMemInputPin * iface, IMediaSample * pSample)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-13 18:02:01 +02:00
|
|
|
HRESULT hr = S_FALSE;
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
/* this trace commented out for performance reasons */
|
|
|
|
/*TRACE("(%p/%p)->(%p)\n", This, iface, pSample);*/
|
2010-10-13 18:02:01 +02:00
|
|
|
if (This->pFuncsTable->pfnReceive)
|
|
|
|
hr = This->pFuncsTable->pfnReceive(This, pSample);
|
2010-10-05 21:38:11 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_ReceiveMultiple(IMemInputPin * iface, IMediaSample ** pSamples, LONG nSamples, LONG *nSamplesProcessed)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p, %d, %p)\n", This, iface, pSamples, nSamples, nSamplesProcessed);
|
|
|
|
|
|
|
|
for (*nSamplesProcessed = 0; *nSamplesProcessed < nSamples; (*nSamplesProcessed)++)
|
|
|
|
{
|
|
|
|
hr = IMemInputPin_Receive(iface, pSamples[*nSamplesProcessed]);
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface)
|
|
|
|
{
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink *This = impl_from_IMemInputPin(iface);
|
2010-10-05 21:38:11 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->()\n", This, iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IMemInputPinVtbl MemInputPin_Vtbl =
|
|
|
|
{
|
|
|
|
MemInputPin_QueryInterface,
|
|
|
|
MemInputPin_AddRef,
|
|
|
|
MemInputPin_Release,
|
|
|
|
MemInputPin_GetAllocator,
|
|
|
|
MemInputPin_NotifyAllocator,
|
|
|
|
MemInputPin_GetAllocatorRequirements,
|
|
|
|
MemInputPin_Receive,
|
|
|
|
MemInputPin_ReceiveMultiple,
|
|
|
|
MemInputPin_ReceiveCanBlock
|
|
|
|
};
|
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
void strmbase_sink_init(struct strmbase_sink *pin, const IPinVtbl *vtbl, struct strmbase_filter *filter,
|
2019-11-20 03:18:02 +01:00
|
|
|
const WCHAR *name, const struct strmbase_sink_ops *func_table, IMemAllocator *allocator)
|
2019-06-13 01:58:34 +02:00
|
|
|
{
|
|
|
|
memset(pin, 0, sizeof(*pin));
|
2019-09-06 02:02:15 +02:00
|
|
|
pin->pin.IPin_iface.lpVtbl = vtbl;
|
|
|
|
pin->pin.filter = filter;
|
|
|
|
pin->pin.dir = PINDIR_INPUT;
|
|
|
|
lstrcpyW(pin->pin.name, name);
|
|
|
|
pin->pin.pFuncsTable = &func_table->base;
|
2019-06-13 01:58:34 +02:00
|
|
|
pin->pFuncsTable = func_table;
|
|
|
|
pin->pAllocator = pin->preferred_allocator = allocator;
|
|
|
|
if (pin->preferred_allocator)
|
|
|
|
IMemAllocator_AddRef(pin->preferred_allocator);
|
|
|
|
pin->IMemInputPin_iface.lpVtbl = &MemInputPin_Vtbl;
|
2010-10-05 21:38:11 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
void strmbase_sink_cleanup(struct strmbase_sink *pin)
|
2019-06-13 01:58:36 +02:00
|
|
|
{
|
2019-11-19 01:51:20 +01:00
|
|
|
FreeMediaType(&pin->pin.mt);
|
2019-06-13 01:58:36 +02:00
|
|
|
if (pin->pAllocator)
|
|
|
|
IMemAllocator_Release(pin->pAllocator);
|
|
|
|
pin->pAllocator = NULL;
|
|
|
|
pin->pin.IPin_iface.lpVtbl = NULL;
|
|
|
|
}
|