2 * IPin function declarations to allow inheritance
4 * Copyright 2003 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* This function will process incoming samples to the pin.
22 * Any return value valid in IMemInputPin::Receive is allowed here
24 * Cookie is the cookie that was set when requesting the buffer, if you don't
25 * implement custom requesting, you can safely ignore this
27 typedef HRESULT (* SAMPLEPROC_PULL
)(LPVOID userdata
, IMediaSample
* pSample
, DWORD_PTR cookie
);
29 /* This function will determine whether a type is supported or not.
30 * It is allowed to return any error value (within reason), as opposed
31 * to IPin::QueryAccept which is only allowed to return S_OK or S_FALSE.
33 typedef HRESULT (* QUERYACCEPTPROC
)(LPVOID userdata
, const AM_MEDIA_TYPE
* pmt
);
35 /* This function is called prior to finalizing a connection with
36 * another pin and can be used to get things from the other pin
37 * like IMemInput interfaces.
39 * props contains some defaults, but you can safely override them to your liking
41 typedef HRESULT (* PRECONNECTPROC
)(IPin
* iface
, IPin
* pConnectPin
, ALLOCATOR_PROPERTIES
*props
);
43 /* This function is called whenever a cleanup operation has to occur,
44 * this is usually after a flush, seek, or end of stream notification.
45 * This code may even be repeated multiple times, so build your code to
46 * tolerate this behavior. Return value is ignored and should be S_OK.
48 typedef HRESULT (* CLEANUPPROC
) (LPVOID userdata
);
50 /* This function is called whenever a request for a new sample is made,
51 * If you implement it (it can be NULL for default behavior), you have to
52 * call IMemAllocator_GetBuffer and IMemAllocator_RequestBuffer
53 * This is useful if you want to request more than 1 buffer at simultaneously
55 * This will also cause the Sample Proc to be called with empty buffers to indicate
56 * failure in retrieving the sample.
58 typedef HRESULT (* REQUESTPROC
) (LPVOID userdata
);
60 /* This function is called after processing is done (for whatever reason that is caused)
61 * This is useful if you create processing threads that need to die
63 typedef HRESULT (* STOPPROCESSPROC
) (LPVOID userdata
);
65 #define ALIGNDOWN(value,boundary) ((value)/(boundary)*(boundary))
66 #define ALIGNUP(value,boundary) (ALIGNDOWN((value)+(boundary)-1, (boundary)))
68 typedef struct PullPin
70 /* inheritance C style! */
74 REFERENCE_TIME rtStart
, rtCurrent
, rtNext
, rtStop
;
75 IAsyncReader
* pReader
;
76 IMemAllocator
* pAlloc
;
77 QUERYACCEPTPROC fnQueryAccept
;
78 SAMPLEPROC_PULL fnSampleProc
;
79 PRECONNECTPROC fnPreConnect
;
80 REQUESTPROC fnCustomRequest
;
81 CLEANUPPROC fnCleanProc
;
82 STOPPROCESSPROC fnDone
;
87 /* Any code that touches the thread must hold the thread lock,
88 * lock order: thread_lock and then the filter critical section
89 * also signal thread_sleepy so the thread knows to wake up
91 CRITICAL_SECTION thread_lock
;
93 DWORD requested_state
;
94 HANDLE hEventStateChanged
, thread_sleepy
;
103 /*** Constructors ***/
104 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
);
106 /**************************/
107 /*** Pin Implementation ***/
110 HRESULT WINAPI
PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
);
111 HRESULT WINAPI
PullPin_Disconnect(IPin
* iface
);
112 HRESULT WINAPI
PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
);
113 ULONG WINAPI
PullPin_Release(IPin
* iface
);
114 HRESULT WINAPI
PullPin_EndOfStream(IPin
* iface
);
115 HRESULT WINAPI
PullPin_QueryAccept(IPin
* iface
, const AM_MEDIA_TYPE
* pmt
);
116 HRESULT WINAPI
PullPin_BeginFlush(IPin
* iface
);
117 HRESULT WINAPI
PullPin_EndFlush(IPin
* iface
);
118 HRESULT WINAPI
PullPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
);
120 /* Thread interaction functions: Hold the thread_lock before calling them */
121 HRESULT
PullPin_StartProcessing(PullPin
* This
);
122 HRESULT
PullPin_PauseProcessing(PullPin
* This
);
123 HRESULT
PullPin_WaitForStateChange(PullPin
* This
, DWORD dwMilliseconds
);