2 * Generic Implementation of IPin Interface
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 #include "quartz_private.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
32 static const IPinVtbl InputPin_Vtbl
;
33 static const IPinVtbl OutputPin_Vtbl
;
34 static const IMemInputPinVtbl MemInputPin_Vtbl
;
35 static const IPinVtbl PullPin_Vtbl
;
37 #define ALIGNDOWN(value,boundary) ((value)/(boundary)*(boundary))
38 #define ALIGNUP(value,boundary) (ALIGNDOWN((value)+(boundary)-1, (boundary)))
40 typedef HRESULT (*SendPinFunc
)( IPin
*to
, LPVOID arg
);
42 /** Helper function, there are a lot of places where the error code is inherited
43 * The following rules apply:
45 * Return the first received error code (E_NOTIMPL is ignored)
46 * If no errors occur: return the first received non-error-code that isn't S_OK
48 HRESULT
updatehres( HRESULT original
, HRESULT
new )
50 if (FAILED( original
) || new == E_NOTIMPL
)
53 if (FAILED( new ) || original
== S_OK
)
59 /** Sends a message from a pin further to other, similar pins
60 * fnMiddle is called on each pin found further on the stream.
61 * fnEnd (can be NULL) is called when the message can't be sent any further (this is a renderer or source)
63 * If the pin given is an input pin, the message will be sent downstream to other input pins
64 * If the pin given is an output pin, the message will be sent upstream to other output pins
66 static HRESULT
SendFurther( IPin
*from
, SendPinFunc fnMiddle
, LPVOID arg
, SendPinFunc fnEnd
)
71 HRESULT hr_return
= S_OK
;
72 IEnumPins
*enumpins
= NULL
;
74 PIN_DIRECTION from_dir
;
76 IPin_QueryDirection( from
, &from_dir
);
78 hr
= IPin_QueryInternalConnections( from
, NULL
, &amount
);
79 if (hr
!= E_NOTIMPL
&& amount
)
80 FIXME("Use QueryInternalConnections!\n");
83 pin_info
.pFilter
= NULL
;
84 hr
= IPin_QueryPinInfo( from
, &pin_info
);
88 hr
= IBaseFilter_EnumPins( pin_info
.pFilter
, &enumpins
);
92 hr
= IEnumPins_Reset( enumpins
);
95 hr
= IEnumPins_Next( enumpins
, 1, &pin
, NULL
);
96 if (hr
== VFW_E_ENUM_OUT_OF_SYNC
)
98 hr
= IEnumPins_Reset( enumpins
);
105 IPin_QueryDirection( pin
, &dir
);
108 IPin
*connected
= NULL
;
111 IPin_ConnectedTo( pin
, &connected
);
116 hr_local
= fnMiddle( connected
, arg
);
117 hr_return
= updatehres( hr_return
, hr_local
);
118 IPin_Release(connected
);
130 hr_local
= fnEnd( from
, arg
);
131 hr_return
= updatehres( hr_return
, hr_local
);
135 if (pin_info
.pFilter
)
136 IBaseFilter_Release( pin_info
.pFilter
);
140 static inline InputPin
*impl_from_IMemInputPin( IMemInputPin
*iface
)
142 return (InputPin
*)((char*)iface
- FIELD_OFFSET(InputPin
, lpVtblMemInput
));
146 static void Copy_PinInfo(PIN_INFO
* pDest
, const PIN_INFO
* pSrc
)
148 /* Tempting to just do a memcpy, but the name field is
149 128 characters long! We will probably never exceed 10
150 most of the time, so we are better off copying
151 each field manually */
152 strcpyW(pDest
->achName
, pSrc
->achName
);
153 pDest
->dir
= pSrc
->dir
;
154 pDest
->pFilter
= pSrc
->pFilter
;
157 /* Function called as a helper to IPin_Connect */
158 /* specific AM_MEDIA_TYPE - it cannot be NULL */
159 /* NOTE: not part of standard interface */
160 static HRESULT
OutputPin_ConnectSpecific(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
162 OutputPin
*This
= (OutputPin
*)iface
;
164 IMemAllocator
* pMemAlloc
= NULL
;
165 ALLOCATOR_PROPERTIES actual
; /* FIXME: should we put the actual props back in to This? */
167 TRACE("(%p, %p)\n", pReceivePin
, pmt
);
168 dump_AM_MEDIA_TYPE(pmt
);
170 /* FIXME: call queryacceptproc */
172 This
->pin
.pConnectedTo
= pReceivePin
;
173 IPin_AddRef(pReceivePin
);
174 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
176 hr
= IPin_ReceiveConnection(pReceivePin
, iface
, pmt
);
178 /* get the IMemInputPin interface we will use to deliver samples to the
182 This
->pMemInputPin
= NULL
;
183 hr
= IPin_QueryInterface(pReceivePin
, &IID_IMemInputPin
, (LPVOID
)&This
->pMemInputPin
);
187 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pMemAlloc
);
189 if (hr
== VFW_E_NO_ALLOCATOR
)
191 /* Input pin provides no allocator, use standard memory allocator */
192 hr
= CoCreateInstance(&CLSID_MemoryAllocator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMemAllocator
, (LPVOID
*)&pMemAlloc
);
196 hr
= IMemInputPin_NotifyAllocator(This
->pMemInputPin
, pMemAlloc
, FALSE
);
201 hr
= IMemAllocator_SetProperties(pMemAlloc
, &This
->allocProps
, &actual
);
204 IMemAllocator_Release(pMemAlloc
);
207 /* break connection if we couldn't get the allocator */
210 if (This
->pMemInputPin
)
211 IMemInputPin_Release(This
->pMemInputPin
);
212 This
->pMemInputPin
= NULL
;
214 IPin_Disconnect(pReceivePin
);
220 IPin_Release(This
->pin
.pConnectedTo
);
221 This
->pin
.pConnectedTo
= NULL
;
222 FreeMediaType(&This
->pin
.mtCurrent
);
225 TRACE(" -- %x\n", hr
);
229 static HRESULT
InputPin_Init(const IPinVtbl
*InputPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
,
230 QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, InputPin
* pPinImpl
)
234 /* Common attributes */
235 pPinImpl
->pin
.refCount
= 1;
236 pPinImpl
->pin
.pConnectedTo
= NULL
;
237 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
238 pPinImpl
->pin
.pUserData
= pUserData
;
239 pPinImpl
->pin
.pCritSec
= pCritSec
;
240 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
241 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
243 /* Input pin attributes */
244 pPinImpl
->fnSampleProc
= pSampleProc
;
245 pPinImpl
->fnCleanProc
= pCleanUp
;
246 pPinImpl
->pAllocator
= NULL
;
247 pPinImpl
->tStart
= 0;
250 pPinImpl
->pin
.lpVtbl
= InputPin_Vtbl
;
251 pPinImpl
->lpVtblMemInput
= &MemInputPin_Vtbl
;
252 pPinImpl
->flushing
= pPinImpl
->end_of_stream
= 0;
257 static HRESULT
OutputPin_Init(const IPinVtbl
*OutputPin_Vtbl
, const PIN_INFO
* pPinInfo
, const ALLOCATOR_PROPERTIES
* props
, LPVOID pUserData
,
258 QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, OutputPin
* pPinImpl
)
262 /* Common attributes */
263 pPinImpl
->pin
.lpVtbl
= OutputPin_Vtbl
;
264 pPinImpl
->pin
.refCount
= 1;
265 pPinImpl
->pin
.pConnectedTo
= NULL
;
266 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
267 pPinImpl
->pin
.pUserData
= pUserData
;
268 pPinImpl
->pin
.pCritSec
= pCritSec
;
269 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
270 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
272 /* Output pin attributes */
273 pPinImpl
->pMemInputPin
= NULL
;
274 pPinImpl
->pConnectSpecific
= OutputPin_ConnectSpecific
;
277 pPinImpl
->allocProps
= *props
;
278 if (pPinImpl
->allocProps
.cbAlign
== 0)
279 pPinImpl
->allocProps
.cbAlign
= 1;
282 ZeroMemory(&pPinImpl
->allocProps
, sizeof(pPinImpl
->allocProps
));
287 HRESULT
InputPin_Construct(const IPinVtbl
*InputPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
293 if (pPinInfo
->dir
!= PINDIR_INPUT
)
295 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
299 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
302 return E_OUTOFMEMORY
;
304 if (SUCCEEDED(InputPin_Init(InputPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
306 *ppPin
= (IPin
*)pPinImpl
;
310 CoTaskMemFree(pPinImpl
);
314 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
)
316 OutputPin
* pPinImpl
;
320 if (pPinInfo
->dir
!= PINDIR_OUTPUT
)
322 ERR("Pin direction(%x) != PINDIR_OUTPUT\n", pPinInfo
->dir
);
326 assert(outputpin_size
>= sizeof(OutputPin
));
328 pPinImpl
= CoTaskMemAlloc(outputpin_size
);
331 return E_OUTOFMEMORY
;
333 if (SUCCEEDED(OutputPin_Init(OutputPin_Vtbl
, pPinInfo
, props
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
335 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
339 CoTaskMemFree(pPinImpl
);
343 /*** Common pin functions ***/
345 ULONG WINAPI
IPinImpl_AddRef(IPin
* iface
)
347 IPinImpl
*This
= (IPinImpl
*)iface
;
348 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
350 TRACE("(%p)->() AddRef from %d\n", iface
, refCount
- 1);
355 HRESULT WINAPI
IPinImpl_Disconnect(IPin
* iface
)
358 IPinImpl
*This
= (IPinImpl
*)iface
;
362 EnterCriticalSection(This
->pCritSec
);
364 if (This
->pConnectedTo
)
366 IPin_Release(This
->pConnectedTo
);
367 This
->pConnectedTo
= NULL
;
373 LeaveCriticalSection(This
->pCritSec
);
378 HRESULT WINAPI
IPinImpl_ConnectedTo(IPin
* iface
, IPin
** ppPin
)
381 IPinImpl
*This
= (IPinImpl
*)iface
;
383 TRACE("(%p)\n", ppPin
);
385 EnterCriticalSection(This
->pCritSec
);
387 if (This
->pConnectedTo
)
389 *ppPin
= This
->pConnectedTo
;
394 hr
= VFW_E_NOT_CONNECTED
;
396 LeaveCriticalSection(This
->pCritSec
);
401 HRESULT WINAPI
IPinImpl_ConnectionMediaType(IPin
* iface
, AM_MEDIA_TYPE
* pmt
)
404 IPinImpl
*This
= (IPinImpl
*)iface
;
406 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
408 EnterCriticalSection(This
->pCritSec
);
410 if (This
->pConnectedTo
)
412 CopyMediaType(pmt
, &This
->mtCurrent
);
417 ZeroMemory(pmt
, sizeof(*pmt
));
418 hr
= VFW_E_NOT_CONNECTED
;
421 LeaveCriticalSection(This
->pCritSec
);
426 HRESULT WINAPI
IPinImpl_QueryPinInfo(IPin
* iface
, PIN_INFO
* pInfo
)
428 IPinImpl
*This
= (IPinImpl
*)iface
;
430 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
432 Copy_PinInfo(pInfo
, &This
->pinInfo
);
433 IBaseFilter_AddRef(pInfo
->pFilter
);
438 HRESULT WINAPI
IPinImpl_QueryDirection(IPin
* iface
, PIN_DIRECTION
* pPinDir
)
440 IPinImpl
*This
= (IPinImpl
*)iface
;
442 TRACE("(%p/%p)->(%p)\n", This
, iface
, pPinDir
);
444 *pPinDir
= This
->pinInfo
.dir
;
449 HRESULT WINAPI
IPinImpl_QueryId(IPin
* iface
, LPWSTR
* Id
)
451 IPinImpl
*This
= (IPinImpl
*)iface
;
453 TRACE("(%p/%p)->(%p)\n", This
, iface
, Id
);
455 *Id
= CoTaskMemAlloc((strlenW(This
->pinInfo
.achName
) + 1) * sizeof(WCHAR
));
457 return E_OUTOFMEMORY
;
459 strcpyW(*Id
, This
->pinInfo
.achName
);
464 HRESULT WINAPI
IPinImpl_QueryAccept(IPin
* iface
, const AM_MEDIA_TYPE
* pmt
)
466 IPinImpl
*This
= (IPinImpl
*)iface
;
468 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
470 return (This
->fnQueryAccept(This
->pUserData
, pmt
) == S_OK
? S_OK
: S_FALSE
);
473 HRESULT WINAPI
IPinImpl_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
475 IPinImpl
*This
= (IPinImpl
*)iface
;
476 ENUMMEDIADETAILS emd
;
478 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
480 /* override this method to allow enumeration of your types */
482 emd
.pMediaTypes
= NULL
;
484 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
487 HRESULT WINAPI
IPinImpl_QueryInternalConnections(IPin
* iface
, IPin
** apPin
, ULONG
* cPin
)
489 IPinImpl
*This
= (IPinImpl
*)iface
;
491 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, apPin
, cPin
);
493 return E_NOTIMPL
; /* to tell caller that all input pins connected to all output pins */
496 /*** IPin implementation for an input pin ***/
498 HRESULT WINAPI
InputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
500 InputPin
*This
= (InputPin
*)iface
;
502 TRACE("(%p)->(%s, %p)\n", iface
, qzdebugstr_guid(riid
), ppv
);
506 if (IsEqualIID(riid
, &IID_IUnknown
))
507 *ppv
= (LPVOID
)iface
;
508 else if (IsEqualIID(riid
, &IID_IPin
))
509 *ppv
= (LPVOID
)iface
;
510 else if (IsEqualIID(riid
, &IID_IMemInputPin
))
511 *ppv
= (LPVOID
)&This
->lpVtblMemInput
;
512 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
514 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
519 IUnknown_AddRef((IUnknown
*)(*ppv
));
523 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
525 return E_NOINTERFACE
;
528 ULONG WINAPI
InputPin_Release(IPin
* iface
)
530 InputPin
*This
= (InputPin
*)iface
;
531 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
533 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
537 FreeMediaType(&This
->pin
.mtCurrent
);
538 if (This
->pAllocator
)
539 IMemAllocator_Release(This
->pAllocator
);
547 HRESULT WINAPI
InputPin_Connect(IPin
* iface
, IPin
* pConnector
, const AM_MEDIA_TYPE
* pmt
)
549 ERR("Outgoing connection on an input pin! (%p, %p)\n", pConnector
, pmt
);
555 HRESULT WINAPI
InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
557 InputPin
*This
= (InputPin
*)iface
;
558 PIN_DIRECTION pindirReceive
;
561 TRACE("(%p, %p)\n", pReceivePin
, pmt
);
562 dump_AM_MEDIA_TYPE(pmt
);
564 EnterCriticalSection(This
->pin
.pCritSec
);
566 if (This
->pin
.pConnectedTo
)
567 hr
= VFW_E_ALREADY_CONNECTED
;
569 if (SUCCEEDED(hr
) && This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
)
570 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
571 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
575 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
577 if (pindirReceive
!= PINDIR_OUTPUT
)
579 ERR("Can't connect from non-output pin\n");
580 hr
= VFW_E_INVALID_DIRECTION
;
586 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
587 This
->pin
.pConnectedTo
= pReceivePin
;
588 IPin_AddRef(pReceivePin
);
591 LeaveCriticalSection(This
->pin
.pCritSec
);
596 static HRESULT
deliver_endofstream(IPin
* pin
, LPVOID unused
)
598 return IPin_EndOfStream( pin
);
601 HRESULT WINAPI
InputPin_EndOfStream(IPin
* iface
)
603 InputPin
*This
= (InputPin
*)iface
;
604 TRACE("(%p)\n", This
);
606 This
->end_of_stream
= 1;
608 return SendFurther( iface
, deliver_endofstream
, NULL
, NULL
);
611 static HRESULT
deliver_beginflush(IPin
* pin
, LPVOID unused
)
613 return IPin_BeginFlush( pin
);
616 HRESULT WINAPI
InputPin_BeginFlush(IPin
* iface
)
618 InputPin
*This
= (InputPin
*)iface
;
620 TRACE("() semi-stub\n");
622 EnterCriticalSection(This
->pin
.pCritSec
);
625 if (This
->fnCleanProc
)
626 This
->fnCleanProc(This
->pin
.pUserData
);
628 hr
= SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
629 LeaveCriticalSection(This
->pin
.pCritSec
);
634 static HRESULT
deliver_endflush(IPin
* pin
, LPVOID unused
)
636 return IPin_EndFlush( pin
);
639 HRESULT WINAPI
InputPin_EndFlush(IPin
* iface
)
641 InputPin
*This
= (InputPin
*)iface
;
643 TRACE("(%p)\n", This
);
645 EnterCriticalSection(This
->pin
.pCritSec
);
648 hr
= SendFurther( iface
, deliver_endflush
, NULL
, NULL
);
649 LeaveCriticalSection(This
->pin
.pCritSec
);
654 typedef struct newsegmentargs
656 REFERENCE_TIME tStart
, tStop
;
660 static HRESULT
deliver_newsegment(IPin
*pin
, LPVOID data
)
662 newsegmentargs
*args
= data
;
663 return IPin_NewSegment(pin
, args
->tStart
, args
->tStop
, args
->rate
);
666 HRESULT WINAPI
InputPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
668 InputPin
*This
= (InputPin
*)iface
;
671 TRACE("(%x%08x, %x%08x, %e)\n", (ULONG
)(tStart
>> 32), (ULONG
)tStart
, (ULONG
)(tStop
>> 32), (ULONG
)tStop
, dRate
);
673 args
.tStart
= This
->tStart
= tStart
;
674 args
.tStop
= This
->tStop
= tStop
;
675 args
.rate
= This
->dRate
= dRate
;
677 return SendFurther( iface
, deliver_newsegment
, &args
, NULL
);
680 static const IPinVtbl InputPin_Vtbl
=
682 InputPin_QueryInterface
,
686 InputPin_ReceiveConnection
,
688 IPinImpl_ConnectedTo
,
689 IPinImpl_ConnectionMediaType
,
690 IPinImpl_QueryPinInfo
,
691 IPinImpl_QueryDirection
,
693 IPinImpl_QueryAccept
,
694 IPinImpl_EnumMediaTypes
,
695 IPinImpl_QueryInternalConnections
,
696 InputPin_EndOfStream
,
702 /*** IMemInputPin implementation ***/
704 HRESULT WINAPI
MemInputPin_QueryInterface(IMemInputPin
* iface
, REFIID riid
, LPVOID
* ppv
)
706 InputPin
*This
= impl_from_IMemInputPin(iface
);
708 return IPin_QueryInterface((IPin
*)&This
->pin
, riid
, ppv
);
711 ULONG WINAPI
MemInputPin_AddRef(IMemInputPin
* iface
)
713 InputPin
*This
= impl_from_IMemInputPin(iface
);
715 return IPin_AddRef((IPin
*)&This
->pin
);
718 ULONG WINAPI
MemInputPin_Release(IMemInputPin
* iface
)
720 InputPin
*This
= impl_from_IMemInputPin(iface
);
722 return IPin_Release((IPin
*)&This
->pin
);
725 HRESULT WINAPI
MemInputPin_GetAllocator(IMemInputPin
* iface
, IMemAllocator
** ppAllocator
)
727 InputPin
*This
= impl_from_IMemInputPin(iface
);
729 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppAllocator
);
731 *ppAllocator
= This
->pAllocator
;
733 IMemAllocator_AddRef(*ppAllocator
);
735 return *ppAllocator
? S_OK
: VFW_E_NO_ALLOCATOR
;
738 HRESULT WINAPI
MemInputPin_NotifyAllocator(IMemInputPin
* iface
, IMemAllocator
* pAllocator
, BOOL bReadOnly
)
740 InputPin
*This
= impl_from_IMemInputPin(iface
);
742 TRACE("(%p/%p)->(%p, %d)\n", This
, iface
, pAllocator
, bReadOnly
);
744 if (This
->pAllocator
)
745 IMemAllocator_Release(This
->pAllocator
);
746 This
->pAllocator
= pAllocator
;
747 if (This
->pAllocator
)
748 IMemAllocator_AddRef(This
->pAllocator
);
753 HRESULT WINAPI
MemInputPin_GetAllocatorRequirements(IMemInputPin
* iface
, ALLOCATOR_PROPERTIES
* pProps
)
755 InputPin
*This
= impl_from_IMemInputPin(iface
);
757 TRACE("(%p/%p)->(%p)\n", This
, iface
, pProps
);
759 /* override this method if you have any specific requirements */
764 HRESULT WINAPI
MemInputPin_Receive(IMemInputPin
* iface
, IMediaSample
* pSample
)
766 InputPin
*This
= impl_from_IMemInputPin(iface
);
769 /* this trace commented out for performance reasons */
770 /*TRACE("(%p/%p)->(%p)\n", This, iface, pSample);*/
772 EnterCriticalSection(This
->pin
.pCritSec
);
773 if (!This
->end_of_stream
&& !This
->flushing
&& !This
->end_of_stream
)
774 hr
= This
->fnSampleProc(This
->pin
.pUserData
, pSample
);
777 LeaveCriticalSection(This
->pin
.pCritSec
);
781 HRESULT WINAPI
MemInputPin_ReceiveMultiple(IMemInputPin
* iface
, IMediaSample
** pSamples
, long nSamples
, long *nSamplesProcessed
)
784 InputPin
*This
= impl_from_IMemInputPin(iface
);
786 TRACE("(%p/%p)->(%p, %ld, %p)\n", This
, iface
, pSamples
, nSamples
, nSamplesProcessed
);
788 for (*nSamplesProcessed
= 0; *nSamplesProcessed
< nSamples
; (*nSamplesProcessed
)++)
790 hr
= IMemInputPin_Receive(iface
, pSamples
[*nSamplesProcessed
]);
798 HRESULT WINAPI
MemInputPin_ReceiveCanBlock(IMemInputPin
* iface
)
800 InputPin
*This
= impl_from_IMemInputPin(iface
);
802 FIXME("(%p/%p)->()\n", This
, iface
);
804 /* FIXME: we should check whether any output pins will block */
809 static const IMemInputPinVtbl MemInputPin_Vtbl
=
811 MemInputPin_QueryInterface
,
814 MemInputPin_GetAllocator
,
815 MemInputPin_NotifyAllocator
,
816 MemInputPin_GetAllocatorRequirements
,
818 MemInputPin_ReceiveMultiple
,
819 MemInputPin_ReceiveCanBlock
822 HRESULT WINAPI
OutputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
824 OutputPin
*This
= (OutputPin
*)iface
;
826 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
830 if (IsEqualIID(riid
, &IID_IUnknown
))
831 *ppv
= (LPVOID
)iface
;
832 else if (IsEqualIID(riid
, &IID_IPin
))
833 *ppv
= (LPVOID
)iface
;
834 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
836 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
841 IUnknown_AddRef((IUnknown
*)(*ppv
));
845 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
847 return E_NOINTERFACE
;
850 ULONG WINAPI
OutputPin_Release(IPin
* iface
)
852 OutputPin
*This
= (OutputPin
*)iface
;
853 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
855 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
859 FreeMediaType(&This
->pin
.mtCurrent
);
866 HRESULT WINAPI
OutputPin_Connect(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
869 OutputPin
*This
= (OutputPin
*)iface
;
871 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
872 dump_AM_MEDIA_TYPE(pmt
);
874 /* If we try to connect to ourself, we will definitely deadlock.
875 * There are other cases where we could deadlock too, but this
876 * catches the obvious case */
877 assert(pReceivePin
!= iface
);
879 EnterCriticalSection(This
->pin
.pCritSec
);
881 /* if we have been a specific type to connect with, then we can either connect
882 * with that or fail. We cannot choose different AM_MEDIA_TYPE */
883 if (pmt
&& !IsEqualGUID(&pmt
->majortype
, &GUID_NULL
) && !IsEqualGUID(&pmt
->subtype
, &GUID_NULL
))
884 hr
= This
->pConnectSpecific(iface
, pReceivePin
, pmt
);
887 /* negotiate media type */
889 IEnumMediaTypes
* pEnumCandidates
;
890 AM_MEDIA_TYPE
* pmtCandidate
; /* Candidate media type */
892 if (SUCCEEDED(hr
= IPin_EnumMediaTypes(iface
, &pEnumCandidates
)))
894 hr
= VFW_E_NO_ACCEPTABLE_TYPES
; /* Assume the worst, but set to S_OK if connected successfully */
896 /* try this filter's media types first */
897 while (S_OK
== IEnumMediaTypes_Next(pEnumCandidates
, 1, &pmtCandidate
, NULL
))
899 if (( !pmt
|| CompareMediaTypes(pmt
, pmtCandidate
, TRUE
) ) &&
900 (This
->pConnectSpecific(iface
, pReceivePin
, pmtCandidate
) == S_OK
))
903 CoTaskMemFree(pmtCandidate
);
906 CoTaskMemFree(pmtCandidate
);
908 IEnumMediaTypes_Release(pEnumCandidates
);
911 /* then try receiver filter's media types */
912 if (hr
!= S_OK
&& SUCCEEDED(hr
= IPin_EnumMediaTypes(pReceivePin
, &pEnumCandidates
))) /* if we haven't already connected successfully */
914 hr
= VFW_E_NO_ACCEPTABLE_TYPES
; /* Assume the worst, but set to S_OK if connected successfully */
916 while (S_OK
== IEnumMediaTypes_Next(pEnumCandidates
, 1, &pmtCandidate
, NULL
))
918 if (( !pmt
|| CompareMediaTypes(pmt
, pmtCandidate
, TRUE
) ) &&
919 (This
->pConnectSpecific(iface
, pReceivePin
, pmtCandidate
) == S_OK
))
922 CoTaskMemFree(pmtCandidate
);
925 CoTaskMemFree(pmtCandidate
);
927 IEnumMediaTypes_Release(pEnumCandidates
);
929 } /* if negotiate media type */
931 LeaveCriticalSection(This
->pin
.pCritSec
);
933 TRACE(" -- %x\n", hr
);
937 HRESULT WINAPI
OutputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
939 ERR("Incoming connection on an output pin! (%p, %p)\n", pReceivePin
, pmt
);
944 HRESULT WINAPI
OutputPin_Disconnect(IPin
* iface
)
947 OutputPin
*This
= (OutputPin
*)iface
;
951 EnterCriticalSection(This
->pin
.pCritSec
);
953 if (This
->pMemInputPin
)
955 IMemInputPin_Release(This
->pMemInputPin
);
956 This
->pMemInputPin
= NULL
;
958 if (This
->pin
.pConnectedTo
)
960 IPin_Release(This
->pin
.pConnectedTo
);
961 This
->pin
.pConnectedTo
= NULL
;
967 LeaveCriticalSection(This
->pin
.pCritSec
);
972 HRESULT WINAPI
OutputPin_EndOfStream(IPin
* iface
)
976 /* not supposed to do anything in an output pin */
981 HRESULT WINAPI
OutputPin_BeginFlush(IPin
* iface
)
983 TRACE("(%p)->()\n", iface
);
985 /* not supposed to do anything in an output pin */
990 HRESULT WINAPI
OutputPin_EndFlush(IPin
* iface
)
992 TRACE("(%p)->()\n", iface
);
994 /* not supposed to do anything in an output pin */
999 HRESULT WINAPI
OutputPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1001 TRACE("(%p)->(%x%08x, %x%08x, %e)\n", iface
, (ULONG
)(tStart
>> 32), (ULONG
)tStart
, (ULONG
)(tStop
>> 32), (ULONG
)tStop
, dRate
);
1003 /* not supposed to do anything in an output pin */
1005 return E_UNEXPECTED
;
1008 static const IPinVtbl OutputPin_Vtbl
=
1010 OutputPin_QueryInterface
,
1014 OutputPin_ReceiveConnection
,
1015 OutputPin_Disconnect
,
1016 IPinImpl_ConnectedTo
,
1017 IPinImpl_ConnectionMediaType
,
1018 IPinImpl_QueryPinInfo
,
1019 IPinImpl_QueryDirection
,
1021 IPinImpl_QueryAccept
,
1022 IPinImpl_EnumMediaTypes
,
1023 IPinImpl_QueryInternalConnections
,
1024 OutputPin_EndOfStream
,
1025 OutputPin_BeginFlush
,
1027 OutputPin_NewSegment
1030 HRESULT
OutputPin_GetDeliveryBuffer(OutputPin
* This
, IMediaSample
** ppSample
, REFERENCE_TIME
* tStart
, REFERENCE_TIME
* tStop
, DWORD dwFlags
)
1034 TRACE("(%p, %p, %p, %x)\n", ppSample
, tStart
, tStop
, dwFlags
);
1036 EnterCriticalSection(This
->pin
.pCritSec
);
1038 if (!This
->pin
.pConnectedTo
)
1039 hr
= VFW_E_NOT_CONNECTED
;
1042 IMemAllocator
* pAlloc
= NULL
;
1044 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1047 hr
= IMemAllocator_GetBuffer(pAlloc
, ppSample
, tStart
, tStop
, dwFlags
);
1050 hr
= IMediaSample_SetTime(*ppSample
, tStart
, tStop
);
1053 IMemAllocator_Release(pAlloc
);
1056 LeaveCriticalSection(This
->pin
.pCritSec
);
1061 HRESULT
OutputPin_SendSample(OutputPin
* This
, IMediaSample
* pSample
)
1064 IMemInputPin
* pMemConnected
= NULL
;
1067 EnterCriticalSection(This
->pin
.pCritSec
);
1069 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1070 hr
= VFW_E_NOT_CONNECTED
;
1073 /* we don't have the lock held when using This->pMemInputPin,
1074 * so we need to AddRef it to stop it being deleted while we are
1075 * using it. Same with its filter. */
1076 pMemConnected
= This
->pMemInputPin
;
1077 IMemInputPin_AddRef(pMemConnected
);
1078 hr
= IPin_QueryPinInfo(This
->pin
.pConnectedTo
, &pinInfo
);
1081 LeaveCriticalSection(This
->pin
.pCritSec
);
1085 /* NOTE: if we are in a critical section when Receive is called
1086 * then it causes some problems (most notably with the native Video
1087 * Renderer) if we are re-entered for whatever reason */
1088 hr
= IMemInputPin_Receive(pMemConnected
, pSample
);
1090 /* If the filter's destroyed, tell upstream to stop sending data */
1091 if(IBaseFilter_Release(pinInfo
.pFilter
) == 0 && SUCCEEDED(hr
))
1095 IMemInputPin_Release(pMemConnected
);
1100 HRESULT
OutputPin_DeliverNewSegment(OutputPin
* This
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1104 EnterCriticalSection(This
->pin
.pCritSec
);
1106 if (!This
->pin
.pConnectedTo
)
1107 hr
= VFW_E_NOT_CONNECTED
;
1109 hr
= IPin_NewSegment(This
->pin
.pConnectedTo
, tStart
, tStop
, dRate
);
1111 LeaveCriticalSection(This
->pin
.pCritSec
);
1116 HRESULT
OutputPin_CommitAllocator(OutputPin
* This
)
1120 TRACE("(%p)->()\n", This
);
1122 EnterCriticalSection(This
->pin
.pCritSec
);
1124 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1125 hr
= VFW_E_NOT_CONNECTED
;
1128 IMemAllocator
* pAlloc
= NULL
;
1130 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1133 hr
= IMemAllocator_Commit(pAlloc
);
1136 IMemAllocator_Release(pAlloc
);
1139 LeaveCriticalSection(This
->pin
.pCritSec
);
1144 HRESULT
OutputPin_DeliverDisconnect(OutputPin
* This
)
1148 TRACE("(%p)->()\n", This
);
1150 EnterCriticalSection(This
->pin
.pCritSec
);
1152 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1153 hr
= VFW_E_NOT_CONNECTED
;
1156 IMemAllocator
* pAlloc
= NULL
;
1158 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1161 hr
= IMemAllocator_Decommit(pAlloc
);
1164 IMemAllocator_Release(pAlloc
);
1167 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
1170 LeaveCriticalSection(This
->pin
.pCritSec
);
1176 static HRESULT
PullPin_Init(const IPinVtbl
*PullPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
,
1177 QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, PullPin
* pPinImpl
)
1179 /* Common attributes */
1180 pPinImpl
->pin
.lpVtbl
= PullPin_Vtbl
;
1181 pPinImpl
->pin
.refCount
= 1;
1182 pPinImpl
->pin
.pConnectedTo
= NULL
;
1183 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
1184 pPinImpl
->pin
.pUserData
= pUserData
;
1185 pPinImpl
->pin
.pCritSec
= pCritSec
;
1186 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
1187 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
1189 /* Input pin attributes */
1190 pPinImpl
->fnSampleProc
= pSampleProc
;
1191 pPinImpl
->fnCleanProc
= pCleanUp
;
1192 pPinImpl
->fnPreConnect
= NULL
;
1193 pPinImpl
->pAlloc
= NULL
;
1194 pPinImpl
->pReader
= NULL
;
1195 pPinImpl
->hThread
= NULL
;
1196 pPinImpl
->hEventStateChanged
= CreateEventW(NULL
, TRUE
, TRUE
, NULL
);
1198 pPinImpl
->rtStart
= 0;
1199 pPinImpl
->rtCurrent
= 0;
1200 pPinImpl
->rtStop
= ((LONGLONG
)0x7fffffff << 32) | 0xffffffff;
1201 pPinImpl
->state
= State_Stopped
;
1203 InitializeCriticalSection(&pPinImpl
->thread_lock
);
1204 pPinImpl
->thread_lock
.DebugInfo
->Spare
[0] = (DWORD_PTR
)( __FILE__
": PullPin.thread_lock");
1209 HRESULT
PullPin_Construct(const IPinVtbl
*PullPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
1215 if (pPinInfo
->dir
!= PINDIR_INPUT
)
1217 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
1218 return E_INVALIDARG
;
1221 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
1224 return E_OUTOFMEMORY
;
1226 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
1228 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
1232 CoTaskMemFree(pPinImpl
);
1236 HRESULT WINAPI
PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
1238 PIN_DIRECTION pindirReceive
;
1240 PullPin
*This
= (PullPin
*)iface
;
1242 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
1243 dump_AM_MEDIA_TYPE(pmt
);
1245 EnterCriticalSection(This
->pin
.pCritSec
);
1247 if (This
->pin
.pConnectedTo
)
1248 hr
= VFW_E_ALREADY_CONNECTED
;
1250 if (SUCCEEDED(hr
) && (This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
))
1251 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
1252 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
1256 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
1258 if (pindirReceive
!= PINDIR_OUTPUT
)
1260 ERR("Can't connect from non-output pin\n");
1261 hr
= VFW_E_INVALID_DIRECTION
;
1265 This
->pReader
= NULL
;
1266 This
->pAlloc
= NULL
;
1269 hr
= IPin_QueryInterface(pReceivePin
, &IID_IAsyncReader
, (LPVOID
*)&This
->pReader
);
1274 ALLOCATOR_PROPERTIES props
;
1276 props
.cbBuffer
= 64 * 1024; /* 64k bytes */
1279 hr
= IAsyncReader_RequestAllocator(This
->pReader
, NULL
, &props
, &This
->pAlloc
);
1282 if (SUCCEEDED(hr
) && This
->fnPreConnect
)
1284 hr
= This
->fnPreConnect(iface
, pReceivePin
);
1289 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
1290 This
->pin
.pConnectedTo
= pReceivePin
;
1291 IPin_AddRef(pReceivePin
);
1296 IAsyncReader_Release(This
->pReader
);
1297 This
->pReader
= NULL
;
1299 IMemAllocator_Release(This
->pAlloc
);
1300 This
->pAlloc
= NULL
;
1303 LeaveCriticalSection(This
->pin
.pCritSec
);
1307 HRESULT WINAPI
PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
1309 PullPin
*This
= (PullPin
*)iface
;
1311 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
1315 if (IsEqualIID(riid
, &IID_IUnknown
))
1316 *ppv
= (LPVOID
)iface
;
1317 else if (IsEqualIID(riid
, &IID_IPin
))
1318 *ppv
= (LPVOID
)iface
;
1319 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1321 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
1326 IUnknown_AddRef((IUnknown
*)(*ppv
));
1330 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
1332 return E_NOINTERFACE
;
1335 ULONG WINAPI
PullPin_Release(IPin
* iface
)
1337 PullPin
*This
= (PullPin
*)iface
;
1338 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
1340 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1345 IMemAllocator_Release(This
->pAlloc
);
1347 IAsyncReader_Release(This
->pReader
);
1348 CloseHandle(This
->hEventStateChanged
);
1349 This
->thread_lock
.DebugInfo
->Spare
[0] = 0;
1350 DeleteCriticalSection(&This
->thread_lock
);
1351 CoTaskMemFree(This
);
1357 static DWORD WINAPI
PullPin_Thread_Main(LPVOID pv
)
1360 SleepEx(INFINITE
, TRUE
);
1363 static void CALLBACK
PullPin_Thread_Process(ULONG_PTR iface
)
1365 PullPin
*This
= (PullPin
*)iface
;
1368 ALLOCATOR_PROPERTIES allocProps
;
1370 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1372 EnterCriticalSection(This
->pin
.pCritSec
);
1373 SetEvent(This
->hEventStateChanged
);
1374 This
->state
= State_Running
;
1375 LeaveCriticalSection(This
->pin
.pCritSec
);
1377 hr
= IMemAllocator_GetProperties(This
->pAlloc
, &allocProps
);
1379 if (This
->rtCurrent
< This
->rtStart
)
1380 This
->rtCurrent
= MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This
->rtStart
), allocProps
.cbAlign
));
1384 while (This
->rtCurrent
< This
->rtStop
&& hr
== S_OK
&& !This
->stop_playback
)
1386 /* FIXME: to improve performance by quite a bit this should be changed
1387 * so that one sample is processed while one sample is fetched. However,
1388 * it is harder to debug so for the moment it will stay as it is */
1389 IMediaSample
* pSample
= NULL
;
1390 REFERENCE_TIME rtSampleStart
;
1391 REFERENCE_TIME rtSampleStop
;
1394 TRACE("Process sample\n");
1396 hr
= IMemAllocator_GetBuffer(This
->pAlloc
, &pSample
, NULL
, NULL
, 0);
1400 rtSampleStart
= This
->rtCurrent
;
1401 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetSize(pSample
));
1402 if (rtSampleStop
> This
->rtStop
)
1403 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1404 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1405 This
->rtCurrent
= rtSampleStop
;
1409 hr
= IAsyncReader_Request(This
->pReader
, pSample
, (ULONG_PTR
)0);
1412 hr
= IAsyncReader_WaitForNext(This
->pReader
, 1000, &pSample
, &dwUser
);
1416 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetActualDataLength(pSample
));
1417 if (rtSampleStop
> This
->rtStop
)
1418 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1419 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1423 hr
= This
->fnSampleProc(This
->pin
.pUserData
, pSample
);
1425 ERR("Processing error: %x\n", hr
);
1428 IMediaSample_Release(pSample
);
1432 EnterCriticalSection(This
->pin
.pCritSec
);
1433 This
->state
= State_Paused
;
1434 LeaveCriticalSection(This
->pin
.pCritSec
);
1438 static void CALLBACK
PullPin_Thread_Pause(ULONG_PTR iface
)
1440 PullPin
*This
= (PullPin
*)iface
;
1442 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1444 EnterCriticalSection(This
->pin
.pCritSec
);
1446 This
->state
= State_Paused
;
1447 SetEvent(This
->hEventStateChanged
);
1449 LeaveCriticalSection(This
->pin
.pCritSec
);
1453 static void CALLBACK
PullPin_Thread_Stop(ULONG_PTR iface
)
1455 PullPin
*This
= (PullPin
*)iface
;
1457 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1459 EnterCriticalSection(This
->pin
.pCritSec
);
1463 CloseHandle(This
->hThread
);
1464 This
->hThread
= NULL
;
1465 if (FAILED(hr
= IMemAllocator_Decommit(This
->pAlloc
)))
1466 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr
);
1468 SetEvent(This
->hEventStateChanged
);
1469 This
->state
= State_Stopped
;
1471 LeaveCriticalSection(This
->pin
.pCritSec
);
1473 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1478 HRESULT
PullPin_InitProcessing(PullPin
* This
)
1482 TRACE("(%p)->()\n", This
);
1484 /* if we are connected */
1487 WaitForSingleObject(This
->hEventStateChanged
, INFINITE
);
1488 EnterCriticalSection(This
->pin
.pCritSec
);
1489 if (This
->state
== State_Stopped
)
1492 assert(!This
->hThread
);
1494 /* AddRef the filter to make sure it and it's pins will be around
1495 * as long as the thread */
1496 IBaseFilter_AddRef(This
->pin
.pinInfo
.pFilter
);
1498 This
->hThread
= CreateThread(NULL
, 0, PullPin_Thread_Main
, NULL
, 0, &dwThreadId
);
1501 hr
= HRESULT_FROM_WIN32(GetLastError());
1502 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1507 hr
= IMemAllocator_Commit(This
->pAlloc
);
1508 This
->state
= State_Paused
;
1509 SetEvent(This
->hEventStateChanged
);
1512 else assert(This
->hThread
);
1513 LeaveCriticalSection(This
->pin
.pCritSec
);
1516 TRACE(" -- %x\n", hr
);
1521 HRESULT
PullPin_StartProcessing(PullPin
* This
)
1523 /* if we are connected */
1524 TRACE("(%p)->()\n", This
);
1527 assert(This
->hThread
);
1529 PullPin_WaitForStateChange(This
, INFINITE
);
1530 ResetEvent(This
->hEventStateChanged
);
1531 This
->stop_playback
= 0;
1533 if (!QueueUserAPC(PullPin_Thread_Process
, This
->hThread
, (ULONG_PTR
)This
))
1534 return HRESULT_FROM_WIN32(GetLastError());
1540 HRESULT
PullPin_PauseProcessing(PullPin
* This
)
1542 /* if we are connected */
1543 TRACE("(%p)->()\n", This
);
1546 assert(This
->hThread
);
1548 PullPin_WaitForStateChange(This
, INFINITE
);
1549 EnterCriticalSection(This
->pin
.pCritSec
);
1550 This
->stop_playback
= 1;
1551 LeaveCriticalSection(This
->pin
.pCritSec
);
1552 ResetEvent(This
->hEventStateChanged
);
1554 if (!QueueUserAPC(PullPin_Thread_Pause
, This
->hThread
, (ULONG_PTR
)This
))
1555 return HRESULT_FROM_WIN32(GetLastError());
1561 HRESULT
PullPin_StopProcessing(PullPin
* This
)
1563 TRACE("(%p)->()\n", This
);
1565 /* if we are connected */
1566 if (This
->pAlloc
&& This
->hThread
)
1568 PullPin_WaitForStateChange(This
, INFINITE
);
1570 This
->stop_playback
= 1;
1571 ResetEvent(This
->hEventStateChanged
);
1573 if (!QueueUserAPC(PullPin_Thread_Stop
, This
->hThread
, (ULONG_PTR
)This
))
1574 return HRESULT_FROM_WIN32(GetLastError());
1580 HRESULT
PullPin_WaitForStateChange(PullPin
* This
, DWORD dwMilliseconds
)
1582 if (WaitForSingleObject(This
->hEventStateChanged
, dwMilliseconds
) == WAIT_TIMEOUT
)
1587 HRESULT WINAPI
PullPin_EndOfStream(IPin
* iface
)
1589 FIXME("(%p)->() stub\n", iface
);
1591 return SendFurther( iface
, deliver_endofstream
, NULL
, NULL
);
1594 HRESULT WINAPI
PullPin_BeginFlush(IPin
* iface
)
1596 PullPin
*This
= (PullPin
*)iface
;
1597 TRACE("(%p)->()\n", iface
);
1599 EnterCriticalSection(This
->pin
.pCritSec
);
1601 SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
1603 LeaveCriticalSection(This
->pin
.pCritSec
);
1605 EnterCriticalSection(&This
->thread_lock
);
1607 if (This
->state
== State_Running
)
1608 PullPin_PauseProcessing(This
);
1610 PullPin_WaitForStateChange(This
, INFINITE
);
1612 LeaveCriticalSection(&This
->thread_lock
);
1614 EnterCriticalSection(This
->pin
.pCritSec
);
1616 This
->fnCleanProc(This
->pin
.pUserData
);
1618 LeaveCriticalSection(This
->pin
.pCritSec
);
1623 HRESULT WINAPI
PullPin_EndFlush(IPin
* iface
)
1625 PullPin
*This
= (PullPin
*)iface
;
1627 TRACE("(%p)->()\n", iface
);
1629 EnterCriticalSection(&This
->thread_lock
);
1632 IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
1634 if (state
== State_Running
&& This
->state
== State_Paused
)
1635 PullPin_StartProcessing(This
);
1637 PullPin_WaitForStateChange(This
, INFINITE
);
1639 LeaveCriticalSection(&This
->thread_lock
);
1641 EnterCriticalSection(This
->pin
.pCritSec
);
1642 SendFurther( iface
, deliver_endflush
, NULL
, NULL
);
1643 LeaveCriticalSection(This
->pin
.pCritSec
);
1648 HRESULT WINAPI
PullPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1650 newsegmentargs args
;
1651 FIXME("(%p)->(%s, %s, %g) stub\n", iface
, wine_dbgstr_longlong(tStart
), wine_dbgstr_longlong(tStop
), dRate
);
1653 args
.tStart
= tStart
;
1657 return SendFurther( iface
, deliver_newsegment
, &args
, NULL
);
1660 static const IPinVtbl PullPin_Vtbl
=
1662 PullPin_QueryInterface
,
1666 PullPin_ReceiveConnection
,
1667 IPinImpl_Disconnect
,
1668 IPinImpl_ConnectedTo
,
1669 IPinImpl_ConnectionMediaType
,
1670 IPinImpl_QueryPinInfo
,
1671 IPinImpl_QueryDirection
,
1673 IPinImpl_QueryAccept
,
1674 IPinImpl_EnumMediaTypes
,
1675 IPinImpl_QueryInternalConnections
,
1676 PullPin_EndOfStream
,