2003-08-07 00:04:45 +02:00
|
|
|
/*
|
|
|
|
* Generic Implementation of IPin Interface
|
|
|
|
*
|
|
|
|
* Copyright 2003 Robert Shearman
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-07 00:04:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "pin.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IPinVtbl InputPin_Vtbl;
|
|
|
|
static const IPinVtbl OutputPin_Vtbl;
|
|
|
|
static const IMemInputPinVtbl MemInputPin_Vtbl;
|
|
|
|
static const IPinVtbl PullPin_Vtbl;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2007-04-07 16:05:33 +02:00
|
|
|
#define ALIGNDOWN(value,boundary) ((value)/(boundary)*(boundary))
|
|
|
|
#define ALIGNUP(value,boundary) (ALIGNDOWN((value)+(boundary)-1, (boundary)))
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-03-19 02:47:17 +01:00
|
|
|
typedef HRESULT (*SendPinFunc)( IPin *to, LPVOID arg );
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2008-03-20 02:31:45 +01:00
|
|
|
HRESULT updatehres( HRESULT original, HRESULT new )
|
2008-03-19 02:47:17 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
static HRESULT SendFurther( IPin *from, SendPinFunc fnMiddle, LPVOID arg, SendPinFunc fnEnd )
|
|
|
|
{
|
|
|
|
PIN_INFO pin_info;
|
|
|
|
ULONG amount = 0;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
HRESULT hr_return = S_OK;
|
|
|
|
IEnumPins *enumpins = NULL;
|
|
|
|
BOOL foundend = TRUE;
|
|
|
|
PIN_DIRECTION from_dir;
|
|
|
|
|
|
|
|
IPin_QueryDirection( from, &from_dir );
|
|
|
|
|
|
|
|
hr = IPin_QueryInternalConnections( from, NULL, &amount );
|
|
|
|
if (hr != E_NOTIMPL && amount)
|
|
|
|
FIXME("Use QueryInternalConnections!\n");
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
pin_info.pFilter = NULL;
|
|
|
|
hr = IPin_QueryPinInfo( from, &pin_info );
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
hr = IBaseFilter_EnumPins( pin_info.pFilter, &enumpins );
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
hr = IEnumPins_Reset( enumpins );
|
|
|
|
while (hr == S_OK) {
|
|
|
|
IPin *pin = NULL;
|
|
|
|
hr = IEnumPins_Next( enumpins, 1, &pin, NULL );
|
|
|
|
if (hr == VFW_E_ENUM_OUT_OF_SYNC)
|
|
|
|
{
|
|
|
|
hr = IEnumPins_Reset( enumpins );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pin)
|
|
|
|
{
|
|
|
|
PIN_DIRECTION dir;
|
|
|
|
|
|
|
|
IPin_QueryDirection( pin, &dir );
|
|
|
|
if (dir != from_dir)
|
|
|
|
{
|
|
|
|
IPin *connected = NULL;
|
|
|
|
|
|
|
|
foundend = FALSE;
|
|
|
|
IPin_ConnectedTo( pin, &connected );
|
|
|
|
if (connected)
|
|
|
|
{
|
|
|
|
HRESULT hr_local;
|
|
|
|
|
2008-03-20 01:41:15 +01:00
|
|
|
hr_local = fnMiddle( connected, arg );
|
2008-03-19 02:47:17 +01:00
|
|
|
hr_return = updatehres( hr_return, hr_local );
|
|
|
|
IPin_Release(connected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IPin_Release( pin );
|
|
|
|
}
|
2008-07-09 19:19:20 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = S_OK;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-08 21:24:33 +02:00
|
|
|
}
|
|
|
|
|
2008-03-19 02:47:17 +01:00
|
|
|
if (!foundend)
|
|
|
|
hr = hr_return;
|
|
|
|
else if (fnEnd) {
|
|
|
|
HRESULT hr_local;
|
|
|
|
|
|
|
|
hr_local = fnEnd( from, arg );
|
|
|
|
hr_return = updatehres( hr_return, hr_local );
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (pin_info.pFilter)
|
|
|
|
IBaseFilter_Release( pin_info.pFilter );
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-07-27 17:14:18 +02:00
|
|
|
static inline InputPin *impl_from_IMemInputPin( IMemInputPin *iface )
|
|
|
|
{
|
|
|
|
return (InputPin *)((char*)iface - FIELD_OFFSET(InputPin, lpVtblMemInput));
|
|
|
|
}
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
static void Copy_PinInfo(PIN_INFO * pDest, const PIN_INFO * pSrc)
|
|
|
|
{
|
|
|
|
/* Tempting to just do a memcpy, but the name field is
|
|
|
|
128 characters long! We will probably never exceed 10
|
|
|
|
most of the time, so we are better off copying
|
|
|
|
each field manually */
|
|
|
|
strcpyW(pDest->achName, pSrc->achName);
|
|
|
|
pDest->dir = pSrc->dir;
|
|
|
|
pDest->pFilter = pSrc->pFilter;
|
|
|
|
}
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
/* Function called as a helper to IPin_Connect */
|
2003-08-07 00:04:45 +02:00
|
|
|
/* specific AM_MEDIA_TYPE - it cannot be NULL */
|
|
|
|
/* NOTE: not part of standard interface */
|
|
|
|
static HRESULT OutputPin_ConnectSpecific(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
OutputPin *This = (OutputPin *)iface;
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IMemAllocator * pMemAlloc = NULL;
|
|
|
|
ALLOCATOR_PROPERTIES actual; /* FIXME: should we put the actual props back in to This? */
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", pReceivePin, pmt);
|
|
|
|
dump_AM_MEDIA_TYPE(pmt);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
/* FIXME: call queryacceptproc */
|
|
|
|
|
|
|
|
This->pin.pConnectedTo = pReceivePin;
|
|
|
|
IPin_AddRef(pReceivePin);
|
|
|
|
CopyMediaType(&This->pin.mtCurrent, pmt);
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
hr = IPin_ReceiveConnection(pReceivePin, iface, pmt);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
/* get the IMemInputPin interface we will use to deliver samples to the
|
|
|
|
* connected pin */
|
2003-08-07 00:04:45 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2007-03-14 14:42:37 +01:00
|
|
|
This->pMemInputPin = NULL;
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = IPin_QueryInterface(pReceivePin, &IID_IMemInputPin, (LPVOID)&This->pMemInputPin);
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr) && !This->custom_allocator)
|
2005-01-03 21:23:14 +01:00
|
|
|
{
|
2007-03-14 14:42:37 +01:00
|
|
|
hr = IMemInputPin_GetAllocator(This->pMemInputPin, &pMemAlloc);
|
2005-01-03 21:23:14 +01:00
|
|
|
|
2007-03-14 14:42:37 +01:00
|
|
|
if (hr == VFW_E_NO_ALLOCATOR)
|
|
|
|
/* Input pin provides no allocator, use standard memory allocator */
|
|
|
|
hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)&pMemAlloc);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemAllocator_SetProperties(pMemAlloc, &This->allocProps, &actual);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-07-18 02:37:51 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemInputPin_NotifyAllocator(This->pMemInputPin, pMemAlloc, This->readonly);
|
|
|
|
|
2007-03-14 14:42:37 +01:00
|
|
|
if (pMemAlloc)
|
|
|
|
IMemAllocator_Release(pMemAlloc);
|
|
|
|
}
|
2008-04-22 22:57:11 +02:00
|
|
|
else if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (This->alloc)
|
|
|
|
{
|
|
|
|
hr = IMemInputPin_NotifyAllocator(This->pMemInputPin, This->alloc, This->readonly);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = VFW_E_NO_ALLOCATOR;
|
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
/* break connection if we couldn't get the allocator */
|
|
|
|
if (FAILED(hr))
|
2007-03-14 14:42:37 +01:00
|
|
|
{
|
|
|
|
if (This->pMemInputPin)
|
|
|
|
IMemInputPin_Release(This->pMemInputPin);
|
|
|
|
This->pMemInputPin = NULL;
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
IPin_Disconnect(pReceivePin);
|
2007-03-14 14:42:37 +01:00
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IPin_Release(This->pin.pConnectedTo);
|
2003-08-07 00:04:45 +02:00
|
|
|
This->pin.pConnectedTo = NULL;
|
2005-06-05 21:18:34 +02:00
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE(" -- %x\n", hr);
|
2003-08-07 00:04:45 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static HRESULT InputPin_Init(const IPinVtbl *InputPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PUSH pSampleProc, LPVOID pUserData,
|
2008-06-10 17:57:41 +02:00
|
|
|
QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, LPCRITICAL_SECTION pCritSec, IMemAllocator *allocator, InputPin * pPinImpl)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2003-11-18 21:47:48 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
/* Common attributes */
|
|
|
|
pPinImpl->pin.refCount = 1;
|
|
|
|
pPinImpl->pin.pConnectedTo = NULL;
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->pin.fnQueryAccept = pQueryAccept;
|
2003-08-07 00:04:45 +02:00
|
|
|
pPinImpl->pin.pUserData = pUserData;
|
|
|
|
pPinImpl->pin.pCritSec = pCritSec;
|
|
|
|
Copy_PinInfo(&pPinImpl->pin.pinInfo, pPinInfo);
|
2005-06-05 21:18:34 +02:00
|
|
|
ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* Input pin attributes */
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->fnSampleProc = pSampleProc;
|
2008-04-04 23:29:21 +02:00
|
|
|
pPinImpl->fnCleanProc = pCleanUp;
|
2008-06-10 17:57:41 +02:00
|
|
|
pPinImpl->pAllocator = pPinImpl->preferred_allocator = allocator;
|
|
|
|
if (pPinImpl->preferred_allocator)
|
|
|
|
IMemAllocator_AddRef(pPinImpl->preferred_allocator);
|
2003-08-07 00:04:45 +02:00
|
|
|
pPinImpl->tStart = 0;
|
|
|
|
pPinImpl->tStop = 0;
|
2008-04-13 08:04:07 +02:00
|
|
|
pPinImpl->dRate = 1.0;
|
2008-04-04 23:29:21 +02:00
|
|
|
pPinImpl->pin.lpVtbl = InputPin_Vtbl;
|
|
|
|
pPinImpl->lpVtblMemInput = &MemInputPin_Vtbl;
|
2008-04-05 01:27:29 +02:00
|
|
|
pPinImpl->flushing = pPinImpl->end_of_stream = 0;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-04 23:29:21 +02:00
|
|
|
static HRESULT OutputPin_Init(const IPinVtbl *OutputPin_Vtbl, const PIN_INFO * pPinInfo, const ALLOCATOR_PROPERTIES * props, LPVOID pUserData,
|
|
|
|
QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, OutputPin * pPinImpl)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2003-11-18 21:47:48 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
/* Common attributes */
|
2008-04-04 23:29:21 +02:00
|
|
|
pPinImpl->pin.lpVtbl = OutputPin_Vtbl;
|
2003-08-07 00:04:45 +02:00
|
|
|
pPinImpl->pin.refCount = 1;
|
|
|
|
pPinImpl->pin.pConnectedTo = NULL;
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->pin.fnQueryAccept = pQueryAccept;
|
2003-08-07 00:04:45 +02:00
|
|
|
pPinImpl->pin.pUserData = pUserData;
|
|
|
|
pPinImpl->pin.pCritSec = pCritSec;
|
|
|
|
Copy_PinInfo(&pPinImpl->pin.pinInfo, pPinInfo);
|
2005-06-05 21:18:34 +02:00
|
|
|
ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* Output pin attributes */
|
|
|
|
pPinImpl->pMemInputPin = NULL;
|
|
|
|
pPinImpl->pConnectSpecific = OutputPin_ConnectSpecific;
|
2008-04-22 22:57:11 +02:00
|
|
|
/* If custom_allocator is set, you will need to specify an allocator
|
|
|
|
* in the alloc member of the struct before an output pin can connect
|
|
|
|
*/
|
|
|
|
pPinImpl->custom_allocator = 0;
|
|
|
|
pPinImpl->alloc = NULL;
|
|
|
|
pPinImpl->readonly = FALSE;
|
2003-09-26 01:50:06 +02:00
|
|
|
if (props)
|
|
|
|
{
|
2008-03-12 21:32:07 +01:00
|
|
|
pPinImpl->allocProps = *props;
|
2003-09-26 01:50:06 +02:00
|
|
|
if (pPinImpl->allocProps.cbAlign == 0)
|
|
|
|
pPinImpl->allocProps.cbAlign = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ZeroMemory(&pPinImpl->allocProps, sizeof(pPinImpl->allocProps));
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-10 17:57:41 +02:00
|
|
|
HRESULT InputPin_Construct(const IPinVtbl *InputPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PUSH pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, LPCRITICAL_SECTION pCritSec, IMemAllocator *allocator, IPin ** ppPin)
|
2008-04-04 23:29:21 +02:00
|
|
|
{
|
|
|
|
InputPin * pPinImpl;
|
|
|
|
|
|
|
|
*ppPin = NULL;
|
|
|
|
|
|
|
|
if (pPinInfo->dir != PINDIR_INPUT)
|
|
|
|
{
|
|
|
|
ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
|
|
|
|
|
|
|
|
if (!pPinImpl)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-06-10 17:57:41 +02:00
|
|
|
if (SUCCEEDED(InputPin_Init(InputPin_Vtbl, pPinInfo, pSampleProc, pUserData, pQueryAccept, pCleanUp, pCritSec, allocator, pPinImpl)))
|
2008-04-04 23:29:21 +02:00
|
|
|
{
|
|
|
|
*ppPin = (IPin *)pPinImpl;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoTaskMemFree(pPinImpl);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT OutputPin_Construct(const IPinVtbl *OutputPin_Vtbl, long outputpin_size, const PIN_INFO * pPinInfo, ALLOCATOR_PROPERTIES *props, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
|
|
|
OutputPin * pPinImpl;
|
|
|
|
|
|
|
|
*ppPin = NULL;
|
|
|
|
|
|
|
|
if (pPinInfo->dir != PINDIR_OUTPUT)
|
|
|
|
{
|
|
|
|
ERR("Pin direction(%x) != PINDIR_OUTPUT\n", pPinInfo->dir);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2008-04-04 23:29:21 +02:00
|
|
|
assert(outputpin_size >= sizeof(OutputPin));
|
|
|
|
|
|
|
|
pPinImpl = CoTaskMemAlloc(outputpin_size);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
if (!pPinImpl)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-04-04 23:29:21 +02:00
|
|
|
if (SUCCEEDED(OutputPin_Init(OutputPin_Vtbl, pPinInfo, props, pUserData, pQueryAccept, pCritSec, pPinImpl)))
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
|
|
|
*ppPin = (IPin *)(&pPinImpl->pin.lpVtbl);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2007-11-19 00:20:05 +01:00
|
|
|
|
|
|
|
CoTaskMemFree(pPinImpl);
|
2003-08-07 00:04:45 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** Common pin functions ***/
|
|
|
|
|
|
|
|
ULONG WINAPI IPinImpl_AddRef(IPin * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() AddRef from %d\n", iface, refCount - 1);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_Disconnect(IPin * iface)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pCritSec);
|
|
|
|
{
|
|
|
|
if (This->pConnectedTo)
|
|
|
|
{
|
|
|
|
IPin_Release(This->pConnectedTo);
|
|
|
|
This->pConnectedTo = NULL;
|
2008-07-11 19:51:25 +02:00
|
|
|
FreeMediaType(&This->mtCurrent);
|
|
|
|
ZeroMemory(&This->mtCurrent, sizeof(This->mtCurrent));
|
2003-08-07 00:04:45 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_ConnectedTo(IPin * iface, IPin ** ppPin)
|
|
|
|
{
|
2004-08-16 23:07:22 +02:00
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-03-14 04:25:58 +01:00
|
|
|
TRACE("(%p)\n", ppPin);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 23:07:22 +02:00
|
|
|
EnterCriticalSection(This->pCritSec);
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2004-08-16 23:07:22 +02:00
|
|
|
if (This->pConnectedTo)
|
|
|
|
{
|
|
|
|
*ppPin = This->pConnectedTo;
|
|
|
|
IPin_AddRef(*ppPin);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
2008-06-20 06:18:26 +02:00
|
|
|
{
|
2004-08-16 23:07:22 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
2008-06-20 06:18:26 +02:00
|
|
|
*ppPin = NULL;
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
2004-08-16 23:07:22 +02:00
|
|
|
LeaveCriticalSection(This->pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_ConnectionMediaType(IPin * iface, AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pmt);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pCritSec);
|
|
|
|
{
|
|
|
|
if (This->pConnectedTo)
|
|
|
|
{
|
|
|
|
CopyMediaType(pmt, &This->mtCurrent);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZeroMemory(pmt, sizeof(*pmt));
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_QueryPinInfo(IPin * iface, PIN_INFO * pInfo)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pInfo);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
Copy_PinInfo(pInfo, &This->pinInfo);
|
2005-05-06 16:34:44 +02:00
|
|
|
IBaseFilter_AddRef(pInfo->pFilter);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_QueryDirection(IPin * iface, PIN_DIRECTION * pPinDir)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pPinDir);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*pPinDir = This->pinInfo.dir;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_QueryId(IPin * iface, LPWSTR * Id)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, Id);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*Id = CoTaskMemAlloc((strlenW(This->pinInfo.achName) + 1) * sizeof(WCHAR));
|
2007-02-02 18:47:54 +01:00
|
|
|
if (!*Id)
|
2003-08-07 00:04:45 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
strcpyW(*Id, This->pinInfo.achName);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pmt);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
return (This->fnQueryAccept(This->pUserData, pmt) == S_OK ? S_OK : S_FALSE);
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
ENUMMEDIADETAILS emd;
|
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* override this method to allow enumeration of your types */
|
|
|
|
emd.cMediaTypes = 0;
|
|
|
|
emd.pMediaTypes = NULL;
|
|
|
|
|
|
|
|
return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI IPinImpl_QueryInternalConnections(IPin * iface, IPin ** apPin, ULONG * cPin)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IPinImpl *This = (IPinImpl *)iface;
|
2004-08-16 21:49:46 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p, %p)\n", This, iface, apPin, cPin);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL; /* to tell caller that all input pins connected to all output pins */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** IPin implementation for an input pin ***/
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IPin))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IMemInputPin))
|
|
|
|
*ppv = (LPVOID)&This->lpVtblMemInput;
|
2008-03-22 00:12:54 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMediaSeeking))
|
|
|
|
{
|
|
|
|
return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI InputPin_Release(IPin * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->pin.refCount);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2005-06-05 21:18:34 +02:00
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
2003-08-07 00:04:45 +02:00
|
|
|
if (This->pAllocator)
|
|
|
|
IMemAllocator_Release(This->pAllocator);
|
2008-06-10 17:57:41 +02:00
|
|
|
This->pAllocator = NULL;
|
|
|
|
This->pin.lpVtbl = NULL;
|
2003-08-07 00:04:45 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_Connect(IPin * iface, IPin * pConnector, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
ERR("Outgoing connection on an input pin! (%p, %p)\n", pConnector, pmt);
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
2003-09-26 01:50:06 +02:00
|
|
|
PIN_DIRECTION pindirReceive;
|
2003-08-07 00:04:45 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", pReceivePin, pmt);
|
|
|
|
dump_AM_MEDIA_TYPE(pmt);
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (This->pin.pConnectedTo)
|
|
|
|
hr = VFW_E_ALREADY_CONNECTED;
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
if (SUCCEEDED(hr) && This->pin.fnQueryAccept(This->pin.pUserData, pmt) != S_OK)
|
|
|
|
hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
|
2003-08-07 00:04:45 +02:00
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
CopyMediaType(&This->pin.mtCurrent, pmt);
|
|
|
|
This->pin.pConnectedTo = pReceivePin;
|
|
|
|
IPin_AddRef(pReceivePin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-03-19 02:47:17 +01:00
|
|
|
static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_EndOfStream( pin );
|
|
|
|
}
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
HRESULT WINAPI InputPin_EndOfStream(IPin * iface)
|
|
|
|
{
|
2008-07-09 19:19:20 +02:00
|
|
|
HRESULT hr = S_OK;
|
2008-04-05 01:27:29 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
2008-07-09 19:19:20 +02:00
|
|
|
|
2008-04-05 01:27:29 +02:00
|
|
|
TRACE("(%p)\n", This);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-07-09 19:19:20 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
if (This->flushing)
|
|
|
|
hr = S_FALSE;
|
|
|
|
else
|
|
|
|
This->end_of_stream = 1;
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-03-19 02:47:17 +01:00
|
|
|
|
2008-07-09 19:19:20 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
hr = SendFurther( iface, deliver_endofstream, NULL, NULL );
|
|
|
|
return hr;
|
2008-03-19 02:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_BeginFlush( pin );
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_BeginFlush(IPin * iface)
|
|
|
|
{
|
2008-04-05 01:27:29 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
|
|
|
HRESULT hr;
|
|
|
|
TRACE("() semi-stub\n");
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
2008-04-08 00:45:51 +02:00
|
|
|
This->flushing = 1;
|
2008-03-19 02:47:17 +01:00
|
|
|
|
2008-04-05 01:27:29 +02:00
|
|
|
if (This->fnCleanProc)
|
|
|
|
This->fnCleanProc(This->pin.pUserData);
|
|
|
|
|
|
|
|
hr = SendFurther( iface, deliver_beginflush, NULL, NULL );
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-04-08 00:45:51 +02:00
|
|
|
|
2008-04-05 01:27:29 +02:00
|
|
|
return hr;
|
2008-03-19 02:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
|
|
|
|
{
|
|
|
|
return IPin_EndFlush( pin );
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_EndFlush(IPin * iface)
|
|
|
|
{
|
2008-04-05 01:27:29 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)\n", This);
|
2008-03-19 02:47:17 +01:00
|
|
|
|
2008-04-05 01:27:29 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
2008-07-09 19:19:20 +02:00
|
|
|
This->flushing = This->end_of_stream = 0;
|
2008-04-05 01:27:29 +02:00
|
|
|
|
|
|
|
hr = SendFurther( iface, deliver_endflush, NULL, NULL );
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
2008-03-19 02:47:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI InputPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
InputPin *This = (InputPin *)iface;
|
2008-03-19 02:47:17 +01:00
|
|
|
newsegmentargs args;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%x%08x, %x%08x, %e)\n", (ULONG)(tStart >> 32), (ULONG)tStart, (ULONG)(tStop >> 32), (ULONG)tStop, dRate);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-03-19 02:47:17 +01:00
|
|
|
args.tStart = This->tStart = tStart;
|
|
|
|
args.tStop = This->tStop = tStop;
|
|
|
|
args.rate = This->dRate = dRate;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-03-19 02:47:17 +01:00
|
|
|
return SendFurther( iface, deliver_newsegment, &args, NULL );
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IPinVtbl InputPin_Vtbl =
|
|
|
|
{
|
|
|
|
InputPin_QueryInterface,
|
|
|
|
IPinImpl_AddRef,
|
|
|
|
InputPin_Release,
|
|
|
|
InputPin_Connect,
|
|
|
|
InputPin_ReceiveConnection,
|
|
|
|
IPinImpl_Disconnect,
|
|
|
|
IPinImpl_ConnectedTo,
|
|
|
|
IPinImpl_ConnectionMediaType,
|
|
|
|
IPinImpl_QueryPinInfo,
|
|
|
|
IPinImpl_QueryDirection,
|
|
|
|
IPinImpl_QueryId,
|
|
|
|
IPinImpl_QueryAccept,
|
|
|
|
IPinImpl_EnumMediaTypes,
|
|
|
|
IPinImpl_QueryInternalConnections,
|
|
|
|
InputPin_EndOfStream,
|
|
|
|
InputPin_BeginFlush,
|
|
|
|
InputPin_EndFlush,
|
|
|
|
InputPin_NewSegment
|
|
|
|
};
|
|
|
|
|
|
|
|
/*** IMemInputPin implementation ***/
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_QueryInterface(IMemInputPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return IPin_QueryInterface((IPin *)&This->pin, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI MemInputPin_AddRef(IMemInputPin * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return IPin_AddRef((IPin *)&This->pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI MemInputPin_Release(IMemInputPin * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
return IPin_Release((IPin *)&This->pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_GetAllocator(IMemInputPin * iface, IMemAllocator ** ppAllocator)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, ppAllocator);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*ppAllocator = This->pAllocator;
|
|
|
|
if (*ppAllocator)
|
|
|
|
IMemAllocator_AddRef(*ppAllocator);
|
|
|
|
|
|
|
|
return *ppAllocator ? S_OK : VFW_E_NO_ALLOCATOR;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_NotifyAllocator(IMemInputPin * iface, IMemAllocator * pAllocator, BOOL bReadOnly)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p, %d)\n", This, iface, pAllocator, bReadOnly);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (bReadOnly)
|
|
|
|
FIXME("Read only flag not handled yet!\n");
|
|
|
|
|
2008-04-25 23:14:24 +02:00
|
|
|
/* FIXME: Should we release the allocator on disconnection? */
|
|
|
|
if (!pAllocator)
|
|
|
|
{
|
|
|
|
WARN("Null allocator\n");
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
2008-06-10 17:57:41 +02:00
|
|
|
if (This->preferred_allocator && pAllocator != This->preferred_allocator)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
if (This->pAllocator)
|
|
|
|
IMemAllocator_Release(This->pAllocator);
|
|
|
|
This->pAllocator = pAllocator;
|
|
|
|
if (This->pAllocator)
|
|
|
|
IMemAllocator_AddRef(This->pAllocator);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_GetAllocatorRequirements(IMemInputPin * iface, ALLOCATOR_PROPERTIES * pProps)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2004-08-16 21:49:46 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p)\n", This, iface, pProps);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* override this method if you have any specific requirements */
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_Receive(IMemInputPin * iface, IMediaSample * pSample)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2008-04-05 01:27:29 +02:00
|
|
|
HRESULT hr;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* this trace commented out for performance reasons */
|
2004-08-16 21:49:46 +02:00
|
|
|
/*TRACE("(%p/%p)->(%p)\n", This, iface, pSample);*/
|
2008-07-05 01:59:22 +02:00
|
|
|
hr = This->fnSampleProc(This->pin.pUserData, pSample);
|
2008-04-05 01:27:29 +02:00
|
|
|
return hr;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_ReceiveMultiple(IMemInputPin * iface, IMediaSample ** pSamples, long nSamples, long *nSamplesProcessed)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2004-08-16 21:49:46 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%p, %ld, %p)\n", This, iface, pSamples, nSamples, nSamplesProcessed);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
for (*nSamplesProcessed = 0; *nSamplesProcessed < nSamples; (*nSamplesProcessed)++)
|
|
|
|
{
|
|
|
|
hr = IMemInputPin_Receive(iface, pSamples[*nSamplesProcessed]);
|
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface)
|
|
|
|
{
|
2005-07-27 17:14:18 +02:00
|
|
|
InputPin *This = impl_from_IMemInputPin(iface);
|
2004-08-16 21:49:46 +02:00
|
|
|
|
2008-06-10 17:57:41 +02:00
|
|
|
TRACE("(%p/%p)->()\n", This, iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
OutputPin *This = (OutputPin *)iface;
|
2004-08-16 21:49:46 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IPin))
|
|
|
|
*ppv = (LPVOID)iface;
|
2008-03-22 00:12:54 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMediaSeeking))
|
|
|
|
{
|
|
|
|
return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG WINAPI OutputPin_Release(IPin * iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
OutputPin *This = (OutputPin *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->pin.refCount);
|
2008-04-19 04:30:25 +02:00
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
|
2008-04-19 04:30:25 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2005-06-05 21:18:34 +02:00
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
2003-08-07 00:04:45 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
OutputPin *This = (OutputPin *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
|
2003-08-07 00:04:45 +02:00
|
|
|
dump_AM_MEDIA_TYPE(pmt);
|
|
|
|
|
|
|
|
/* If we try to connect to ourself, we will definitely deadlock.
|
|
|
|
* There are other cases where we could deadlock too, but this
|
|
|
|
* catches the obvious case */
|
|
|
|
assert(pReceivePin != iface);
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
/* 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 */
|
2003-09-26 01:50:06 +02:00
|
|
|
if (pmt && !IsEqualGUID(&pmt->majortype, &GUID_NULL) && !IsEqualGUID(&pmt->subtype, &GUID_NULL))
|
|
|
|
hr = This->pConnectSpecific(iface, pReceivePin, pmt);
|
|
|
|
else
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2003-09-26 01:50:06 +02:00
|
|
|
/* negotiate media type */
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
IEnumMediaTypes * pEnumCandidates;
|
2008-07-11 06:41:35 +02:00
|
|
|
AM_MEDIA_TYPE * pmtCandidate = NULL; /* Candidate media type */
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
if (SUCCEEDED(hr = IPin_EnumMediaTypes(iface, &pEnumCandidates)))
|
|
|
|
{
|
|
|
|
hr = VFW_E_NO_ACCEPTABLE_TYPES; /* Assume the worst, but set to S_OK if connected successfully */
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
/* try this filter's media types first */
|
|
|
|
while (S_OK == IEnumMediaTypes_Next(pEnumCandidates, 1, &pmtCandidate, NULL))
|
|
|
|
{
|
2008-07-11 06:41:35 +02:00
|
|
|
assert(pmtCandidate);
|
2008-07-18 02:37:51 +02:00
|
|
|
dump_AM_MEDIA_TYPE(pmtCandidate);
|
|
|
|
if (!IsEqualGUID(&FORMAT_None, &pmtCandidate->formattype)
|
|
|
|
&& !IsEqualGUID(&GUID_NULL, &pmtCandidate->formattype))
|
2008-07-11 06:41:35 +02:00
|
|
|
assert(pmtCandidate->pbFormat);
|
2003-09-26 01:50:06 +02:00
|
|
|
if (( !pmt || CompareMediaTypes(pmt, pmtCandidate, TRUE) ) &&
|
|
|
|
(This->pConnectSpecific(iface, pReceivePin, pmtCandidate) == S_OK))
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = S_OK;
|
2008-07-11 19:51:25 +02:00
|
|
|
DeleteMediaType(pmtCandidate);
|
2003-09-26 01:50:06 +02:00
|
|
|
break;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
2008-07-11 06:41:35 +02:00
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
pmtCandidate = NULL;
|
2003-08-07 00:04:45 +02:00
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
IEnumMediaTypes_Release(pEnumCandidates);
|
|
|
|
}
|
2003-08-07 00:04:45 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
/* then try receiver filter's media types */
|
|
|
|
if (hr != S_OK && SUCCEEDED(hr = IPin_EnumMediaTypes(pReceivePin, &pEnumCandidates))) /* if we haven't already connected successfully */
|
|
|
|
{
|
2004-08-16 21:49:46 +02:00
|
|
|
hr = VFW_E_NO_ACCEPTABLE_TYPES; /* Assume the worst, but set to S_OK if connected successfully */
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
while (S_OK == IEnumMediaTypes_Next(pEnumCandidates, 1, &pmtCandidate, NULL))
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2008-07-11 06:41:35 +02:00
|
|
|
assert(pmtCandidate);
|
2008-07-18 02:37:51 +02:00
|
|
|
dump_AM_MEDIA_TYPE(pmtCandidate);
|
|
|
|
if (!IsEqualGUID(&FORMAT_None, &pmtCandidate->formattype)
|
|
|
|
&& !IsEqualGUID(&GUID_NULL, &pmtCandidate->formattype))
|
2008-07-11 06:41:35 +02:00
|
|
|
assert(pmtCandidate->pbFormat);
|
2003-09-26 01:50:06 +02:00
|
|
|
if (( !pmt || CompareMediaTypes(pmt, pmtCandidate, TRUE) ) &&
|
|
|
|
(This->pConnectSpecific(iface, pReceivePin, pmtCandidate) == S_OK))
|
2003-08-07 00:04:45 +02:00
|
|
|
{
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = S_OK;
|
2008-07-11 19:51:25 +02:00
|
|
|
DeleteMediaType(pmtCandidate);
|
2003-09-26 01:50:06 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-07-11 06:41:35 +02:00
|
|
|
DeleteMediaType(pmtCandidate);
|
|
|
|
pmtCandidate = NULL;
|
2003-09-26 01:50:06 +02:00
|
|
|
} /* while */
|
|
|
|
IEnumMediaTypes_Release(pEnumCandidates);
|
|
|
|
} /* if not found */
|
|
|
|
} /* if negotiate media type */
|
2003-08-07 00:04:45 +02:00
|
|
|
} /* if succeeded */
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE(" -- %x\n", hr);
|
2003-08-07 00:04:45 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
ERR("Incoming connection on an output pin! (%p, %p)\n", pReceivePin, pmt);
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_Disconnect(IPin * iface)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2004-09-08 03:50:37 +02:00
|
|
|
OutputPin *This = (OutputPin *)iface;
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (This->pMemInputPin)
|
|
|
|
{
|
|
|
|
IMemInputPin_Release(This->pMemInputPin);
|
|
|
|
This->pMemInputPin = NULL;
|
|
|
|
}
|
|
|
|
if (This->pin.pConnectedTo)
|
|
|
|
{
|
|
|
|
IPin_Release(This->pin.pConnectedTo);
|
|
|
|
This->pin.pConnectedTo = NULL;
|
2008-07-11 19:51:25 +02:00
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
|
|
|
ZeroMemory(&This->pin.mtCurrent, sizeof(This->pin.mtCurrent));
|
2003-08-07 00:04:45 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-04-08 00:45:51 +02:00
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_EndOfStream(IPin * iface)
|
|
|
|
{
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_BeginFlush(IPin * iface)
|
|
|
|
{
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_EndFlush(IPin * iface)
|
|
|
|
{
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI OutputPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
|
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p)->(%x%08x, %x%08x, %e)\n", iface, (ULONG)(tStart >> 32), (ULONG)tStart, (ULONG)(tStop >> 32), (ULONG)tStop, dRate);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* not supposed to do anything in an output pin */
|
|
|
|
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IPinVtbl OutputPin_Vtbl =
|
|
|
|
{
|
|
|
|
OutputPin_QueryInterface,
|
|
|
|
IPinImpl_AddRef,
|
|
|
|
OutputPin_Release,
|
|
|
|
OutputPin_Connect,
|
|
|
|
OutputPin_ReceiveConnection,
|
|
|
|
OutputPin_Disconnect,
|
|
|
|
IPinImpl_ConnectedTo,
|
|
|
|
IPinImpl_ConnectionMediaType,
|
|
|
|
IPinImpl_QueryPinInfo,
|
|
|
|
IPinImpl_QueryDirection,
|
|
|
|
IPinImpl_QueryId,
|
|
|
|
IPinImpl_QueryAccept,
|
|
|
|
IPinImpl_EnumMediaTypes,
|
|
|
|
IPinImpl_QueryInternalConnections,
|
|
|
|
OutputPin_EndOfStream,
|
|
|
|
OutputPin_BeginFlush,
|
|
|
|
OutputPin_EndFlush,
|
|
|
|
OutputPin_NewSegment
|
|
|
|
};
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2006-11-11 12:03:30 +01:00
|
|
|
HRESULT OutputPin_GetDeliveryBuffer(OutputPin * This, IMediaSample ** ppSample, REFERENCE_TIME * tStart, REFERENCE_TIME * tStop, DWORD dwFlags)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("(%p, %p, %p, %x)\n", ppSample, tStart, tStop, dwFlags);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (!This->pin.pConnectedTo)
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMemAllocator * pAlloc = NULL;
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
hr = IMemInputPin_GetAllocator(This->pMemInputPin, &pAlloc);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2006-11-11 12:03:30 +01:00
|
|
|
hr = IMemAllocator_GetBuffer(pAlloc, ppSample, tStart, tStop, dwFlags);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
2006-11-11 12:03:30 +01:00
|
|
|
hr = IMediaSample_SetTime(*ppSample, tStart, tStop);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (pAlloc)
|
|
|
|
IMemAllocator_Release(pAlloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT OutputPin_SendSample(OutputPin * This, IMediaSample * pSample)
|
|
|
|
{
|
2004-08-19 04:33:00 +02:00
|
|
|
HRESULT hr = S_OK;
|
2003-09-26 01:50:06 +02:00
|
|
|
IMemInputPin * pMemConnected = NULL;
|
2007-03-14 14:39:58 +01:00
|
|
|
PIN_INFO pinInfo;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
2004-08-19 04:33:00 +02:00
|
|
|
if (!This->pin.pConnectedTo || !This->pMemInputPin)
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
{
|
2004-08-19 04:33:00 +02:00
|
|
|
/* we don't have the lock held when using This->pMemInputPin,
|
|
|
|
* so we need to AddRef it to stop it being deleted while we are
|
2007-03-14 14:39:58 +01:00
|
|
|
* using it. Same with its filter. */
|
2004-08-19 04:33:00 +02:00
|
|
|
pMemConnected = This->pMemInputPin;
|
|
|
|
IMemInputPin_AddRef(pMemConnected);
|
2007-03-14 14:39:58 +01:00
|
|
|
hr = IPin_QueryPinInfo(This->pin.pConnectedTo, &pinInfo);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
|
|
|
/* NOTE: if we are in a critical section when Receive is called
|
|
|
|
* then it causes some problems (most notably with the native Video
|
|
|
|
* Renderer) if we are re-entered for whatever reason */
|
|
|
|
hr = IMemInputPin_Receive(pMemConnected, pSample);
|
2007-04-03 20:04:59 +02:00
|
|
|
|
|
|
|
/* If the filter's destroyed, tell upstream to stop sending data */
|
|
|
|
if(IBaseFilter_Release(pinInfo.pFilter) == 0 && SUCCEEDED(hr))
|
|
|
|
hr = S_FALSE;
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
2007-03-14 14:39:58 +01:00
|
|
|
if (pMemConnected)
|
|
|
|
IMemInputPin_Release(pMemConnected);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT OutputPin_DeliverNewSegment(OutputPin * This, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (!This->pin.pConnectedTo)
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
hr = IPin_NewSegment(This->pin.pConnectedTo, tStart, tStop, dRate);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT OutputPin_CommitAllocator(OutputPin * This)
|
|
|
|
{
|
2008-04-22 22:57:11 +02:00
|
|
|
HRESULT hr = S_OK;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
2004-08-19 04:33:00 +02:00
|
|
|
if (!This->pin.pConnectedTo || !This->pMemInputPin)
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMemAllocator * pAlloc = NULL;
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
hr = IMemInputPin_GetAllocator(This->pMemInputPin, &pAlloc);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemAllocator_Commit(pAlloc);
|
|
|
|
|
|
|
|
if (pAlloc)
|
|
|
|
IMemAllocator_Release(pAlloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-04-22 22:57:11 +02:00
|
|
|
|
2008-04-29 01:35:53 +02:00
|
|
|
TRACE("--> %08x\n", hr);
|
2003-09-26 01:50:06 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
HRESULT OutputPin_DecommitAllocator(OutputPin * This)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (!This->pin.pConnectedTo || !This->pMemInputPin)
|
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IMemAllocator * pAlloc = NULL;
|
|
|
|
|
|
|
|
hr = IMemInputPin_GetAllocator(This->pMemInputPin, &pAlloc);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemAllocator_Decommit(pAlloc);
|
|
|
|
|
|
|
|
if (pAlloc)
|
|
|
|
IMemAllocator_Release(pAlloc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
TRACE("--> %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT OutputPin_DeliverDisconnect(OutputPin * This)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
2004-08-19 04:33:00 +02:00
|
|
|
if (!This->pin.pConnectedTo || !This->pMemInputPin)
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = VFW_E_NOT_CONNECTED;
|
2008-04-22 22:57:11 +02:00
|
|
|
else if (!This->custom_allocator)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
|
|
|
IMemAllocator * pAlloc = NULL;
|
|
|
|
|
2004-08-19 04:33:00 +02:00
|
|
|
hr = IMemInputPin_GetAllocator(This->pMemInputPin, &pAlloc);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemAllocator_Decommit(pAlloc);
|
|
|
|
|
|
|
|
if (pAlloc)
|
|
|
|
IMemAllocator_Release(pAlloc);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IPin_Disconnect(This->pin.pConnectedTo);
|
|
|
|
}
|
2008-04-22 22:57:11 +02:00
|
|
|
else /* Kill the allocator! */
|
|
|
|
{
|
2008-04-25 23:14:24 +02:00
|
|
|
hr = IPin_Disconnect(This->pin.pConnectedTo);
|
2008-04-22 22:57:11 +02:00
|
|
|
}
|
2008-04-25 23:14:24 +02:00
|
|
|
IPin_Disconnect((IPin *)This);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PULL pSampleProc, LPVOID pUserData,
|
2008-04-25 23:59:05 +02:00
|
|
|
QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone, LPCRITICAL_SECTION pCritSec, PullPin * pPinImpl)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
|
|
|
/* Common attributes */
|
2008-04-04 23:29:21 +02:00
|
|
|
pPinImpl->pin.lpVtbl = PullPin_Vtbl;
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->pin.refCount = 1;
|
|
|
|
pPinImpl->pin.pConnectedTo = NULL;
|
|
|
|
pPinImpl->pin.fnQueryAccept = pQueryAccept;
|
|
|
|
pPinImpl->pin.pUserData = pUserData;
|
|
|
|
pPinImpl->pin.pCritSec = pCritSec;
|
|
|
|
Copy_PinInfo(&pPinImpl->pin.pinInfo, pPinInfo);
|
2005-06-05 21:18:34 +02:00
|
|
|
ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
/* Input pin attributes */
|
|
|
|
pPinImpl->fnSampleProc = pSampleProc;
|
2008-04-04 23:29:21 +02:00
|
|
|
pPinImpl->fnCleanProc = pCleanUp;
|
2008-04-25 23:59:05 +02:00
|
|
|
pPinImpl->fnDone = pDone;
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->fnPreConnect = NULL;
|
|
|
|
pPinImpl->pAlloc = NULL;
|
|
|
|
pPinImpl->pReader = NULL;
|
|
|
|
pPinImpl->hThread = NULL;
|
2008-04-01 23:35:14 +02:00
|
|
|
pPinImpl->hEventStateChanged = CreateEventW(NULL, TRUE, TRUE, NULL);
|
2008-04-19 04:30:25 +02:00
|
|
|
pPinImpl->thread_sleepy = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
pPinImpl->rtStart = 0;
|
2007-03-26 00:18:49 +02:00
|
|
|
pPinImpl->rtCurrent = 0;
|
2003-09-26 01:50:06 +02:00
|
|
|
pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
|
2008-04-13 08:04:07 +02:00
|
|
|
pPinImpl->dRate = 1.0;
|
2008-04-19 04:30:25 +02:00
|
|
|
pPinImpl->state = Req_Die;
|
|
|
|
pPinImpl->fnCustomRequest = pCustomRequest;
|
|
|
|
pPinImpl->stop_playback = 1;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-08 00:45:51 +02:00
|
|
|
InitializeCriticalSection(&pPinImpl->thread_lock);
|
|
|
|
pPinImpl->thread_lock.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": PullPin.thread_lock");
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-25 23:59:05 +02:00
|
|
|
HRESULT PullPin_Construct(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PULL pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
|
2008-04-04 23:29:21 +02:00
|
|
|
{
|
|
|
|
PullPin * pPinImpl;
|
|
|
|
|
|
|
|
*ppPin = NULL;
|
|
|
|
|
|
|
|
if (pPinInfo->dir != PINDIR_INPUT)
|
|
|
|
{
|
|
|
|
ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
|
|
|
|
|
|
|
|
if (!pPinImpl)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-04-25 23:59:05 +02:00
|
|
|
if (SUCCEEDED(PullPin_Init(PullPin_Vtbl, pPinInfo, pSampleProc, pUserData, pQueryAccept, pCleanUp, pCustomRequest, pDone, pCritSec, pPinImpl)))
|
2008-04-04 23:29:21 +02:00
|
|
|
{
|
|
|
|
*ppPin = (IPin *)(&pPinImpl->pin.lpVtbl);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoTaskMemFree(pPinImpl);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
static HRESULT PullPin_InitProcessing(PullPin * This);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
PIN_DIRECTION pindirReceive;
|
|
|
|
HRESULT hr = S_OK;
|
2004-09-08 03:50:37 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
|
2003-09-26 01:50:06 +02:00
|
|
|
dump_AM_MEDIA_TYPE(pmt);
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
2008-06-22 09:57:47 +02:00
|
|
|
if (!This->pin.pConnectedTo)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-22 22:57:11 +02:00
|
|
|
ALLOCATOR_PROPERTIES props;
|
|
|
|
|
|
|
|
props.cBuffers = 3;
|
|
|
|
props.cbBuffer = 64 * 1024; /* 64k bytes */
|
|
|
|
props.cbAlign = 1;
|
|
|
|
props.cbPrefix = 0;
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
if (SUCCEEDED(hr) && (This->pin.fnQueryAccept(This->pin.pUserData, pmt) != S_OK))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-14 14:42:37 +01:00
|
|
|
This->pReader = NULL;
|
|
|
|
This->pAlloc = NULL;
|
2003-09-26 01:50:06 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
|
|
|
|
}
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr) && This->fnPreConnect)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = This->fnPreConnect(iface, pReceivePin, &props);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = IAsyncReader_RequestAllocator(This->pReader, NULL, &props, &This->pAlloc);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
CopyMediaType(&This->pin.mtCurrent, pmt);
|
|
|
|
This->pin.pConnectedTo = pReceivePin;
|
|
|
|
IPin_AddRef(pReceivePin);
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = IMemAllocator_Commit(This->pAlloc);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
2008-04-22 22:57:11 +02:00
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = PullPin_InitProcessing(This);
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (FAILED(hr))
|
2007-03-14 14:42:37 +01:00
|
|
|
{
|
|
|
|
if (This->pReader)
|
|
|
|
IAsyncReader_Release(This->pReader);
|
|
|
|
This->pReader = NULL;
|
|
|
|
if (This->pAlloc)
|
|
|
|
IMemAllocator_Release(This->pAlloc);
|
|
|
|
This->pAlloc = NULL;
|
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
2008-06-22 09:57:47 +02:00
|
|
|
else
|
|
|
|
hr = VFW_E_ALREADY_CONNECTED;
|
2003-09-26 01:50:06 +02:00
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
2004-08-16 21:49:46 +02:00
|
|
|
|
|
|
|
TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
|
|
|
*ppv = (LPVOID)iface;
|
|
|
|
else if (IsEqualIID(riid, &IID_IPin))
|
|
|
|
*ppv = (LPVOID)iface;
|
2008-03-22 00:12:54 +01:00
|
|
|
else if (IsEqualIID(riid, &IID_IMediaSeeking))
|
|
|
|
{
|
|
|
|
return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
|
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
if (*ppv)
|
|
|
|
{
|
|
|
|
IUnknown_AddRef((IUnknown *)(*ppv));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
ULONG WINAPI PullPin_Release(IPin *iface)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
2005-01-06 20:36:47 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->pin.refCount);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2007-03-05 05:46:04 +01:00
|
|
|
TRACE("(%p)->() Release from %d\n", This, refCount + 1);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2005-01-06 20:36:47 +01:00
|
|
|
if (!refCount)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-25 23:59:05 +02:00
|
|
|
WaitForSingleObject(This->hEventStateChanged, INFINITE);
|
|
|
|
assert(!This->hThread);
|
|
|
|
|
2006-06-30 13:37:19 +02:00
|
|
|
if(This->pAlloc)
|
|
|
|
IMemAllocator_Release(This->pAlloc);
|
|
|
|
if(This->pReader)
|
|
|
|
IAsyncReader_Release(This->pReader);
|
2008-04-19 04:30:25 +02:00
|
|
|
CloseHandle(This->thread_sleepy);
|
2003-09-26 01:50:06 +02:00
|
|
|
CloseHandle(This->hEventStateChanged);
|
2008-04-08 00:45:51 +02:00
|
|
|
This->thread_lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&This->thread_lock);
|
2003-09-26 01:50:06 +02:00
|
|
|
CoTaskMemFree(This);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-01-06 20:36:47 +01:00
|
|
|
return refCount;
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static void CALLBACK PullPin_Flush(PullPin *This)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-19 04:30:25 +02:00
|
|
|
IMediaSample *pSample;
|
2008-04-22 22:57:11 +02:00
|
|
|
TRACE("Flushing!\n");
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
if (This->pReader)
|
|
|
|
{
|
|
|
|
/* Flush outstanding samples */
|
|
|
|
IAsyncReader_BeginFlush(This->pReader);
|
2008-07-05 03:43:05 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD_PTR dwUser;
|
|
|
|
|
|
|
|
IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
|
|
|
|
|
|
|
|
if (!pSample)
|
|
|
|
break;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
assert(!IMediaSample_GetActualDataLength(pSample));
|
2008-05-05 18:24:22 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
IMediaSample_Release(pSample);
|
|
|
|
}
|
|
|
|
|
|
|
|
IAsyncReader_EndFlush(This->pReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
static void CALLBACK PullPin_Thread_Process(PullPin *This)
|
2008-04-19 04:30:25 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMediaSample * pSample = NULL;
|
|
|
|
ALLOCATOR_PROPERTIES allocProps;
|
2008-04-01 23:35:14 +02:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
hr = IMemAllocator_GetProperties(This->pAlloc, &allocProps);
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
This->cbAlign = allocProps.cbAlign;
|
|
|
|
|
2007-03-26 00:18:49 +02:00
|
|
|
if (This->rtCurrent < This->rtStart)
|
2008-04-19 04:30:25 +02:00
|
|
|
This->rtCurrent = MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This->rtStart), This->cbAlign));
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2005-01-03 21:23:14 +01:00
|
|
|
TRACE("Start\n");
|
|
|
|
|
2008-04-16 23:26:15 +02:00
|
|
|
if (This->rtCurrent >= This->rtStop)
|
|
|
|
{
|
2008-04-19 04:30:25 +02:00
|
|
|
IPin_EndOfStream((IPin *)This);
|
|
|
|
return;
|
2008-04-16 23:26:15 +02:00
|
|
|
}
|
2008-04-19 04:30:25 +02:00
|
|
|
|
|
|
|
/* There is no sample in our buffer */
|
2008-06-24 17:52:52 +02:00
|
|
|
hr = This->fnCustomRequest(This->pin.pUserData);
|
2008-04-19 04:30:25 +02:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Request error: %x\n", hr);
|
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
SetEvent(This->hEventStateChanged);
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-04-29 01:35:53 +02:00
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2008-04-19 04:30:25 +02:00
|
|
|
do
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
DWORD_PTR dwUser;
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2005-01-03 21:23:14 +01:00
|
|
|
TRACE("Process sample\n");
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-05-05 18:24:22 +02:00
|
|
|
/* Return an empty sample on error to the implementation in case it does custom parsing, so it knows it's gone */
|
2008-06-24 17:52:52 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2008-04-19 04:30:25 +02:00
|
|
|
{
|
2008-06-24 17:52:52 +02:00
|
|
|
hr = This->fnSampleProc(This->pin.pUserData, pSample, dwUser);
|
2008-04-19 04:30:25 +02:00
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
else
|
2008-04-19 04:30:25 +02:00
|
|
|
{
|
|
|
|
/* FIXME: This is not well handled yet! */
|
2008-05-05 18:24:22 +02:00
|
|
|
ERR("Processing error: %x\n", hr);
|
2008-04-19 04:30:25 +02:00
|
|
|
}
|
2007-03-14 14:39:58 +01:00
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
if (pSample)
|
2008-04-19 04:30:25 +02:00
|
|
|
{
|
2004-08-16 21:49:46 +02:00
|
|
|
IMediaSample_Release(pSample);
|
2008-04-19 04:30:25 +02:00
|
|
|
pSample = NULL;
|
|
|
|
}
|
2008-04-16 23:26:15 +02:00
|
|
|
} while (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback);
|
2004-12-27 18:15:58 +01:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
/* Sample was rejected, and we are asked to terminate */
|
|
|
|
if (pSample)
|
2008-04-17 22:24:51 +02:00
|
|
|
{
|
2008-04-19 04:30:25 +02:00
|
|
|
IMediaSample_Release(pSample);
|
|
|
|
}
|
2008-04-17 22:24:51 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
/* Can't reset state to Sleepy here because that might race, instead PauseProcessing will do that for us
|
|
|
|
* Flush remaining samples
|
|
|
|
*/
|
2008-04-25 23:59:05 +02:00
|
|
|
if (This->fnDone)
|
|
|
|
This->fnDone(This->pin.pUserData);
|
2008-04-01 23:35:14 +02:00
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
TRACE("End: %08x, %d\n", hr, This->stop_playback);
|
2008-04-01 23:35:14 +02:00
|
|
|
}
|
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
static void CALLBACK PullPin_Thread_Pause(PullPin *This)
|
|
|
|
{
|
2008-07-11 19:51:25 +02:00
|
|
|
PullPin_Flush(This);
|
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
This->state = Req_Sleepy;
|
|
|
|
SetEvent(This->hEventStateChanged);
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static void CALLBACK PullPin_Thread_Stop(PullPin *This)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-19 04:30:25 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
CloseHandle(This->hThread);
|
|
|
|
This->hThread = NULL;
|
2008-04-01 23:35:14 +02:00
|
|
|
SetEvent(This->hEventStateChanged);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2007-04-03 14:55:29 +02:00
|
|
|
IBaseFilter_Release(This->pin.pinInfo.pFilter);
|
|
|
|
|
2008-04-17 22:24:51 +02:00
|
|
|
CoUninitialize();
|
2003-09-26 01:50:06 +02:00
|
|
|
ExitThread(0);
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
|
|
|
|
{
|
|
|
|
PullPin *This = pv;
|
|
|
|
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
PullPin_Flush(This);
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
WaitForSingleObject(This->thread_sleepy, INFINITE);
|
|
|
|
|
|
|
|
TRACE("State: %d\n", This->state);
|
|
|
|
|
|
|
|
switch (This->state)
|
|
|
|
{
|
|
|
|
case Req_Die: PullPin_Thread_Stop(This); break;
|
2008-07-05 03:43:05 +02:00
|
|
|
case Req_Run: PullPin_Thread_Process(This); break;
|
|
|
|
case Req_Pause: PullPin_Thread_Pause(This); break;
|
2008-04-19 04:30:25 +02:00
|
|
|
case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break;
|
|
|
|
default: ERR("Unknown state request: %d\n", This->state); break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-30 12:38:57 +02:00
|
|
|
return 0;
|
2008-04-19 04:30:25 +02:00
|
|
|
}
|
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
static HRESULT PullPin_InitProcessing(PullPin * This)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
/* if we are connected */
|
|
|
|
if (This->pAlloc)
|
|
|
|
{
|
2008-04-19 04:30:25 +02:00
|
|
|
DWORD dwThreadId;
|
|
|
|
|
2008-04-01 23:35:14 +02:00
|
|
|
WaitForSingleObject(This->hEventStateChanged, INFINITE);
|
2003-09-26 01:50:06 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
2008-04-01 23:35:14 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
assert(!This->hThread);
|
|
|
|
assert(This->state == Req_Die);
|
|
|
|
assert(This->stop_playback);
|
|
|
|
assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
|
|
|
|
This->state = Req_Sleepy;
|
2007-04-03 14:55:29 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
/* AddRef the filter to make sure it and it's pins will be around
|
|
|
|
* as long as the thread */
|
|
|
|
IBaseFilter_AddRef(This->pin.pinInfo.pFilter);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
|
|
|
|
This->hThread = CreateThread(NULL, 0, PullPin_Thread_Main, This, 0, &dwThreadId);
|
|
|
|
if (!This->hThread)
|
|
|
|
{
|
|
|
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
|
|
|
IBaseFilter_Release(This->pin.pinInfo.pFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
SetEvent(This->hEventStateChanged);
|
|
|
|
/* If assert fails, that means a command was not processed before the thread previously terminated */
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
}
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE(" -- %x\n", hr);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT PullPin_StartProcessing(PullPin * This)
|
|
|
|
{
|
|
|
|
/* if we are connected */
|
2004-08-16 21:49:46 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2003-09-26 01:50:06 +02:00
|
|
|
if(This->pAlloc)
|
|
|
|
{
|
|
|
|
assert(This->hThread);
|
2008-04-01 23:35:14 +02:00
|
|
|
|
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
2007-04-03 14:55:29 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
assert(This->state == Req_Sleepy);
|
|
|
|
|
|
|
|
/* Wake up! */
|
|
|
|
assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
|
|
|
|
This->state = Req_Run;
|
|
|
|
This->stop_playback = 0;
|
|
|
|
ResetEvent(This->hEventStateChanged);
|
|
|
|
SetEvent(This->thread_sleepy);
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT PullPin_PauseProcessing(PullPin * This)
|
|
|
|
{
|
2008-04-01 23:35:14 +02:00
|
|
|
/* if we are connected */
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
if(This->pAlloc)
|
|
|
|
{
|
|
|
|
assert(This->hThread);
|
|
|
|
|
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
2008-04-19 04:30:25 +02:00
|
|
|
|
2008-04-01 23:35:14 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
2008-04-29 01:35:53 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
assert(!This->stop_playback);
|
|
|
|
assert(This->state == Req_Run|| This->state == Req_Sleepy);
|
|
|
|
|
|
|
|
assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
|
|
|
|
This->state = Req_Pause;
|
2008-04-02 19:45:32 +02:00
|
|
|
This->stop_playback = 1;
|
2008-04-01 23:35:14 +02:00
|
|
|
ResetEvent(This->hEventStateChanged);
|
2008-04-19 04:30:25 +02:00
|
|
|
SetEvent(This->thread_sleepy);
|
2008-04-01 23:35:14 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
2008-04-01 23:35:14 +02:00
|
|
|
}
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-24 17:52:52 +02:00
|
|
|
static HRESULT PullPin_StopProcessing(PullPin * This)
|
2003-09-26 01:50:06 +02:00
|
|
|
{
|
2008-04-08 00:45:51 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
2008-04-17 22:24:51 +02:00
|
|
|
/* if we are alive */
|
2008-04-19 04:30:25 +02:00
|
|
|
assert(This->hThread);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
assert(This->state == Req_Pause || This->state == Req_Sleepy);
|
|
|
|
|
|
|
|
This->stop_playback = 1;
|
|
|
|
This->state = Req_Die;
|
|
|
|
assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
|
|
|
|
ResetEvent(This->hEventStateChanged);
|
|
|
|
SetEvent(This->thread_sleepy);
|
2003-09-26 01:50:06 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds)
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject(This->hEventStateChanged, dwMilliseconds) == WAIT_TIMEOUT)
|
|
|
|
return S_FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI PullPin_EndOfStream(IPin * iface)
|
|
|
|
{
|
2008-03-20 01:43:11 +01:00
|
|
|
FIXME("(%p)->() stub\n", iface);
|
|
|
|
|
|
|
|
return SendFurther( iface, deliver_endofstream, NULL, NULL );
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
|
|
|
|
{
|
2008-04-01 23:35:14 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
2008-04-19 04:30:25 +02:00
|
|
|
TRACE("(%p)->()\n", This);
|
2008-04-08 00:45:51 +02:00
|
|
|
|
2008-05-05 18:24:22 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
SendFurther( iface, deliver_beginflush, NULL, NULL );
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2008-04-08 00:45:51 +02:00
|
|
|
EnterCriticalSection(&This->thread_lock);
|
|
|
|
{
|
2008-07-05 03:43:05 +02:00
|
|
|
if (This->pReader)
|
|
|
|
IAsyncReader_BeginFlush(This->pReader);
|
2008-04-08 00:45:51 +02:00
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
2008-04-17 22:24:51 +02:00
|
|
|
|
2008-07-05 03:43:05 +02:00
|
|
|
if (This->hThread && This->state == Req_Run)
|
2008-04-19 04:30:25 +02:00
|
|
|
{
|
|
|
|
PullPin_PauseProcessing(This);
|
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
|
|
|
}
|
2008-04-08 00:45:51 +02:00
|
|
|
}
|
2008-04-30 23:28:21 +02:00
|
|
|
LeaveCriticalSection(&This->thread_lock);
|
2008-04-01 23:35:14 +02:00
|
|
|
|
2008-05-05 18:24:22 +02:00
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
This->fnCleanProc(This->pin.pUserData);
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2008-04-01 23:35:14 +02:00
|
|
|
return S_OK;
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI PullPin_EndFlush(IPin * iface)
|
|
|
|
{
|
2008-04-01 23:35:14 +02:00
|
|
|
PullPin *This = (PullPin *)iface;
|
|
|
|
|
2008-04-08 00:45:51 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
2008-07-10 23:32:58 +02:00
|
|
|
/* Send further first: Else a race condition might terminate processing early */
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
SendFurther( iface, deliver_endflush, NULL, NULL );
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
2008-04-08 00:45:51 +02:00
|
|
|
EnterCriticalSection(&This->thread_lock);
|
|
|
|
{
|
|
|
|
FILTER_STATE state;
|
|
|
|
IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
|
|
|
|
|
2008-07-09 19:19:20 +02:00
|
|
|
if (state != State_Stopped)
|
2008-04-08 00:45:51 +02:00
|
|
|
PullPin_StartProcessing(This);
|
2008-05-05 18:24:22 +02:00
|
|
|
|
|
|
|
PullPin_WaitForStateChange(This, INFINITE);
|
2008-04-08 00:45:51 +02:00
|
|
|
}
|
|
|
|
LeaveCriticalSection(&This->thread_lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
HRESULT WINAPI PullPin_Disconnect(IPin *iface)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
PullPin *This = (PullPin *)iface;
|
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
|
|
|
EnterCriticalSection(This->pin.pCritSec);
|
|
|
|
{
|
|
|
|
if (FAILED(hr = IMemAllocator_Decommit(This->pAlloc)))
|
|
|
|
ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr);
|
|
|
|
|
|
|
|
if (This->pin.pConnectedTo)
|
|
|
|
{
|
|
|
|
IPin_Release(This->pin.pConnectedTo);
|
|
|
|
This->pin.pConnectedTo = NULL;
|
2008-06-24 17:52:52 +02:00
|
|
|
PullPin_StopProcessing(This);
|
2008-07-11 19:51:25 +02:00
|
|
|
|
|
|
|
FreeMediaType(&This->pin.mtCurrent);
|
|
|
|
ZeroMemory(&This->pin.mtCurrent, sizeof(This->pin.mtCurrent));
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
|
|
|
LeaveCriticalSection(This->pin.pCritSec);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
|
|
|
|
{
|
2008-04-01 23:35:14 +02:00
|
|
|
newsegmentargs args;
|
2008-03-20 01:43:11 +01:00
|
|
|
FIXME("(%p)->(%s, %s, %g) stub\n", iface, wine_dbgstr_longlong(tStart), wine_dbgstr_longlong(tStop), dRate);
|
|
|
|
|
2008-04-01 23:35:14 +02:00
|
|
|
args.tStart = tStart;
|
|
|
|
args.tStop = tStop;
|
|
|
|
args.rate = dRate;
|
|
|
|
|
|
|
|
return SendFurther( iface, deliver_newsegment, &args, NULL );
|
2003-09-26 01:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IPinVtbl PullPin_Vtbl =
|
|
|
|
{
|
|
|
|
PullPin_QueryInterface,
|
|
|
|
IPinImpl_AddRef,
|
|
|
|
PullPin_Release,
|
2008-04-08 00:45:51 +02:00
|
|
|
InputPin_Connect,
|
2003-09-26 01:50:06 +02:00
|
|
|
PullPin_ReceiveConnection,
|
2008-04-22 22:57:11 +02:00
|
|
|
PullPin_Disconnect,
|
2003-09-26 01:50:06 +02:00
|
|
|
IPinImpl_ConnectedTo,
|
|
|
|
IPinImpl_ConnectionMediaType,
|
|
|
|
IPinImpl_QueryPinInfo,
|
|
|
|
IPinImpl_QueryDirection,
|
|
|
|
IPinImpl_QueryId,
|
|
|
|
IPinImpl_QueryAccept,
|
|
|
|
IPinImpl_EnumMediaTypes,
|
|
|
|
IPinImpl_QueryInternalConnections,
|
|
|
|
PullPin_EndOfStream,
|
|
|
|
PullPin_BeginFlush,
|
|
|
|
PullPin_EndFlush,
|
|
|
|
PullPin_NewSegment
|
|
|
|
};
|