2003-08-07 00:04:45 +02:00
|
|
|
/*
|
|
|
|
* IPin function declarations to allow inheritance
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
|
|
|
/* This function will process incoming samples to the pin.
|
|
|
|
* Any return value valid in IMemInputPin::Receive is allowed here
|
2008-04-19 04:30:25 +02:00
|
|
|
*
|
|
|
|
* Cookie is the cookie that was set when requesting the buffer, if you don't
|
|
|
|
* implement custom requesting, you can safely ignore this
|
2003-08-07 00:04:45 +02:00
|
|
|
*/
|
2008-04-19 04:30:25 +02:00
|
|
|
typedef HRESULT (* SAMPLEPROC_PUSH)(LPVOID userdata, IMediaSample * pSample);
|
|
|
|
typedef HRESULT (* SAMPLEPROC_PULL)(LPVOID userdata, IMediaSample * pSample, DWORD_PTR cookie);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/* This function will determine whether a type is supported or not.
|
|
|
|
* It is allowed to return any error value (within reason), as opposed
|
|
|
|
* to IPin::QueryAccept which is only allowed to return S_OK or S_FALSE.
|
|
|
|
*/
|
|
|
|
typedef HRESULT (* QUERYACCEPTPROC)(LPVOID userdata, const AM_MEDIA_TYPE * pmt);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
/* This function is called prior to finalizing a connection with
|
|
|
|
* another pin and can be used to get things from the other pin
|
|
|
|
* like IMemInput interfaces.
|
2008-04-22 22:57:11 +02:00
|
|
|
*
|
|
|
|
* props contains some defaults, but you can safely override them to your liking
|
2003-09-26 01:50:06 +02:00
|
|
|
*/
|
2008-04-22 22:57:11 +02:00
|
|
|
typedef HRESULT (* PRECONNECTPROC)(IPin * iface, IPin * pConnectPin, ALLOCATOR_PROPERTIES *props);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
2008-04-04 23:29:21 +02:00
|
|
|
/* This function is called whenever a cleanup operation has to occur,
|
|
|
|
* this is usually after a flush, seek, or end of stream notification.
|
|
|
|
* This code may even be repeated multiple times, so build your code to
|
|
|
|
* tolerate this behavior. Return value is ignored and should be S_OK.
|
|
|
|
*/
|
|
|
|
typedef HRESULT (* CLEANUPPROC) (LPVOID userdata);
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
/* This function is called whenever a request for a new sample is made,
|
|
|
|
* If you implement it (it can be NULL for default behavior), you have to
|
|
|
|
* call IMemAllocator_GetBuffer and IMemAllocator_RequestBuffer
|
2008-05-06 20:01:59 +02:00
|
|
|
* This is useful if you want to request more than 1 buffer at simultaneously
|
2008-04-19 04:30:25 +02:00
|
|
|
*
|
|
|
|
* This will also cause the Sample Proc to be called with empty buffers to indicate
|
|
|
|
* failure in retrieving the sample.
|
|
|
|
*/
|
|
|
|
typedef HRESULT (* REQUESTPROC) (LPVOID userdata);
|
|
|
|
|
2008-04-25 23:59:05 +02:00
|
|
|
/* This function is called after processing is done (for whatever reason that is caused)
|
|
|
|
* This is useful if you create processing threads that need to die
|
|
|
|
*/
|
|
|
|
typedef HRESULT (* STOPPROCESSPROC) (LPVOID userdata);
|
|
|
|
|
2008-04-22 22:57:11 +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
|
|
|
typedef struct IPinImpl
|
|
|
|
{
|
|
|
|
const struct IPinVtbl * lpVtbl;
|
2005-07-13 13:59:15 +02:00
|
|
|
LONG refCount;
|
2003-08-07 00:04:45 +02:00
|
|
|
LPCRITICAL_SECTION pCritSec;
|
|
|
|
PIN_INFO pinInfo;
|
|
|
|
IPin * pConnectedTo;
|
|
|
|
AM_MEDIA_TYPE mtCurrent;
|
|
|
|
ENUMMEDIADETAILS enumMediaDetails;
|
2003-09-26 01:50:06 +02:00
|
|
|
QUERYACCEPTPROC fnQueryAccept;
|
2003-08-07 00:04:45 +02:00
|
|
|
LPVOID pUserData;
|
|
|
|
} IPinImpl;
|
|
|
|
|
|
|
|
typedef struct InputPin
|
|
|
|
{
|
|
|
|
/* inheritance C style! */
|
|
|
|
IPinImpl pin;
|
|
|
|
|
|
|
|
const IMemInputPinVtbl * lpVtblMemInput;
|
|
|
|
IMemAllocator * pAllocator;
|
2008-04-19 04:30:25 +02:00
|
|
|
SAMPLEPROC_PUSH fnSampleProc;
|
2008-04-04 23:29:21 +02:00
|
|
|
CLEANUPPROC fnCleanProc;
|
2003-08-07 00:04:45 +02:00
|
|
|
REFERENCE_TIME tStart;
|
|
|
|
REFERENCE_TIME tStop;
|
|
|
|
double dRate;
|
2008-04-05 01:27:29 +02:00
|
|
|
BOOL flushing, end_of_stream;
|
2008-06-10 17:57:41 +02:00
|
|
|
IMemAllocator *preferred_allocator;
|
2003-08-07 00:04:45 +02:00
|
|
|
} InputPin;
|
|
|
|
|
|
|
|
typedef struct OutputPin
|
|
|
|
{
|
|
|
|
/* inheritance C style! */
|
|
|
|
IPinImpl pin;
|
|
|
|
|
|
|
|
IMemInputPin * pMemInputPin;
|
|
|
|
HRESULT (* pConnectSpecific)(IPin * iface, IPin * pReceiver, const AM_MEDIA_TYPE * pmt);
|
2008-04-22 22:57:11 +02:00
|
|
|
BOOL custom_allocator;
|
|
|
|
IMemAllocator *alloc;
|
|
|
|
BOOL readonly;
|
2003-09-26 01:50:06 +02:00
|
|
|
ALLOCATOR_PROPERTIES allocProps;
|
2003-08-07 00:04:45 +02:00
|
|
|
} OutputPin;
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
typedef struct PullPin
|
|
|
|
{
|
|
|
|
/* inheritance C style! */
|
|
|
|
IPinImpl pin;
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
REFERENCE_TIME rtStart, rtCurrent, rtNext, rtStop;
|
2003-09-26 01:50:06 +02:00
|
|
|
IAsyncReader * pReader;
|
|
|
|
IMemAllocator * pAlloc;
|
2008-04-19 04:30:25 +02:00
|
|
|
SAMPLEPROC_PULL fnSampleProc;
|
2003-09-26 01:50:06 +02:00
|
|
|
PRECONNECTPROC fnPreConnect;
|
2008-04-19 04:30:25 +02:00
|
|
|
REQUESTPROC fnCustomRequest;
|
2008-04-04 23:29:21 +02:00
|
|
|
CLEANUPPROC fnCleanProc;
|
2008-04-25 23:59:05 +02:00
|
|
|
STOPPROCESSPROC fnDone;
|
2008-04-04 23:29:21 +02:00
|
|
|
double dRate;
|
2008-04-01 23:35:14 +02:00
|
|
|
BOOL stop_playback;
|
2008-04-19 04:30:25 +02:00
|
|
|
DWORD cbAlign;
|
2008-04-08 00:45:51 +02:00
|
|
|
|
|
|
|
/* Any code that touches the thread must hold the thread lock,
|
|
|
|
* lock order: thread_lock and then the filter critical section
|
2008-04-19 04:30:25 +02:00
|
|
|
* also signal thread_sleepy so the thread knows to wake up
|
2008-04-08 00:45:51 +02:00
|
|
|
*/
|
|
|
|
CRITICAL_SECTION thread_lock;
|
2008-04-19 04:30:25 +02:00
|
|
|
HANDLE hThread;
|
|
|
|
DWORD requested_state;
|
|
|
|
HANDLE hEventStateChanged, thread_sleepy;
|
|
|
|
DWORD state;
|
2003-09-26 01:50:06 +02:00
|
|
|
} PullPin;
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
#define Req_Sleepy 0
|
|
|
|
#define Req_Die 1
|
|
|
|
#define Req_Run 2
|
|
|
|
#define Req_Pause 3
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
/*** Constructors ***/
|
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 *, IPin ** ppPin);
|
2008-04-04 23:29:21 +02:00
|
|
|
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);
|
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, STOPPROCESSPROC, REQUESTPROC pCustomRequest, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
|
2003-08-07 00:04:45 +02:00
|
|
|
|
|
|
|
/**************************/
|
|
|
|
/*** Pin Implementation ***/
|
|
|
|
|
|
|
|
/* Common */
|
|
|
|
ULONG WINAPI IPinImpl_AddRef(IPin * iface);
|
|
|
|
HRESULT WINAPI IPinImpl_Disconnect(IPin * iface);
|
|
|
|
HRESULT WINAPI IPinImpl_ConnectedTo(IPin * iface, IPin ** ppPin);
|
|
|
|
HRESULT WINAPI IPinImpl_ConnectionMediaType(IPin * iface, AM_MEDIA_TYPE * pmt);
|
|
|
|
HRESULT WINAPI IPinImpl_QueryPinInfo(IPin * iface, PIN_INFO * pInfo);
|
|
|
|
HRESULT WINAPI IPinImpl_QueryDirection(IPin * iface, PIN_DIRECTION * pPinDir);
|
|
|
|
HRESULT WINAPI IPinImpl_QueryId(IPin * iface, LPWSTR * Id);
|
|
|
|
HRESULT WINAPI IPinImpl_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt);
|
|
|
|
HRESULT WINAPI IPinImpl_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum);
|
|
|
|
HRESULT WINAPI IPinImpl_QueryInternalConnections(IPin * iface, IPin ** apPin, ULONG * cPin);
|
|
|
|
|
|
|
|
/* Input Pin */
|
|
|
|
HRESULT WINAPI InputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv);
|
|
|
|
ULONG WINAPI InputPin_Release(IPin * iface);
|
|
|
|
HRESULT WINAPI InputPin_Connect(IPin * iface, IPin * pConnector, const AM_MEDIA_TYPE * pmt);
|
|
|
|
HRESULT WINAPI InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt);
|
|
|
|
HRESULT WINAPI InputPin_EndOfStream(IPin * iface);
|
|
|
|
HRESULT WINAPI InputPin_BeginFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI InputPin_EndFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI InputPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
|
|
|
|
|
|
|
|
/* Output Pin */
|
|
|
|
HRESULT WINAPI OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv);
|
|
|
|
ULONG WINAPI OutputPin_Release(IPin * iface);
|
|
|
|
HRESULT WINAPI OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt);
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT WINAPI OutputPin_Disconnect(IPin * iface);
|
2003-08-07 00:04:45 +02:00
|
|
|
HRESULT WINAPI OutputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt);
|
|
|
|
HRESULT WINAPI OutputPin_EndOfStream(IPin * iface);
|
|
|
|
HRESULT WINAPI OutputPin_BeginFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI OutputPin_EndFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI OutputPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
|
|
|
|
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT OutputPin_CommitAllocator(OutputPin * This);
|
2008-07-05 03:43:05 +02:00
|
|
|
HRESULT OutputPin_DecommitAllocator(OutputPin * This);
|
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 OutputPin_SendSample(OutputPin * This, IMediaSample * pSample);
|
|
|
|
HRESULT OutputPin_DeliverDisconnect(OutputPin * This);
|
|
|
|
HRESULT OutputPin_DeliverNewSegment(OutputPin * This, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
|
|
|
|
|
2003-08-07 00:04:45 +02:00
|
|
|
/**********************************/
|
|
|
|
/*** MemInputPin Implementation ***/
|
|
|
|
|
|
|
|
HRESULT WINAPI MemInputPin_QueryInterface(IMemInputPin * iface, REFIID riid, LPVOID * ppv);
|
|
|
|
ULONG WINAPI MemInputPin_AddRef(IMemInputPin * iface);
|
|
|
|
ULONG WINAPI MemInputPin_Release(IMemInputPin * iface);
|
|
|
|
HRESULT WINAPI MemInputPin_GetAllocator(IMemInputPin * iface, IMemAllocator ** ppAllocator);
|
|
|
|
HRESULT WINAPI MemInputPin_NotifyAllocator(IMemInputPin * iface, IMemAllocator * pAllocator, BOOL bReadOnly);
|
|
|
|
HRESULT WINAPI MemInputPin_GetAllocatorRequirements(IMemInputPin * iface, ALLOCATOR_PROPERTIES * pProps);
|
|
|
|
HRESULT WINAPI MemInputPin_Receive(IMemInputPin * iface, IMediaSample * pSample);
|
|
|
|
HRESULT WINAPI MemInputPin_ReceiveMultiple(IMemInputPin * iface, IMediaSample ** pSamples, long nSamples, long *nSamplesProcessed);
|
|
|
|
HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface);
|
2003-09-26 01:50:06 +02:00
|
|
|
|
|
|
|
/* Pull Pin */
|
|
|
|
HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt);
|
2008-06-24 17:52:52 +02:00
|
|
|
HRESULT WINAPI PullPin_Disconnect(IPin * iface);
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv);
|
|
|
|
ULONG WINAPI PullPin_Release(IPin * iface);
|
|
|
|
HRESULT WINAPI PullPin_EndOfStream(IPin * iface);
|
|
|
|
HRESULT WINAPI PullPin_BeginFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI PullPin_EndFlush(IPin * iface);
|
|
|
|
HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
|
2008-04-08 00:45:51 +02:00
|
|
|
|
|
|
|
/* Thread interaction functions: Hold the thread_lock before calling them */
|
|
|
|
HRESULT PullPin_StartProcessing(PullPin * This);
|
|
|
|
HRESULT PullPin_PauseProcessing(PullPin * This);
|
2003-09-26 01:50:06 +02:00
|
|
|
HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds);
|