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
);
123 } while (hr
== S_OK
);
129 hr_local
= fnEnd( from
, arg
);
130 hr_return
= updatehres( hr_return
, hr_local
);
134 if (pin_info
.pFilter
)
135 IBaseFilter_Release( pin_info
.pFilter
);
139 static inline InputPin
*impl_from_IMemInputPin( IMemInputPin
*iface
)
141 return (InputPin
*)((char*)iface
- FIELD_OFFSET(InputPin
, lpVtblMemInput
));
145 static void Copy_PinInfo(PIN_INFO
* pDest
, const PIN_INFO
* pSrc
)
147 /* Tempting to just do a memcpy, but the name field is
148 128 characters long! We will probably never exceed 10
149 most of the time, so we are better off copying
150 each field manually */
151 strcpyW(pDest
->achName
, pSrc
->achName
);
152 pDest
->dir
= pSrc
->dir
;
153 pDest
->pFilter
= pSrc
->pFilter
;
156 /* Function called as a helper to IPin_Connect */
157 /* specific AM_MEDIA_TYPE - it cannot be NULL */
158 /* NOTE: not part of standard interface */
159 static HRESULT
OutputPin_ConnectSpecific(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
161 OutputPin
*This
= (OutputPin
*)iface
;
163 IMemAllocator
* pMemAlloc
= NULL
;
164 ALLOCATOR_PROPERTIES actual
; /* FIXME: should we put the actual props back in to This? */
166 TRACE("(%p, %p)\n", pReceivePin
, pmt
);
167 dump_AM_MEDIA_TYPE(pmt
);
169 /* FIXME: call queryacceptproc */
171 This
->pin
.pConnectedTo
= pReceivePin
;
172 IPin_AddRef(pReceivePin
);
173 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
175 hr
= IPin_ReceiveConnection(pReceivePin
, iface
, pmt
);
177 /* get the IMemInputPin interface we will use to deliver samples to the
181 This
->pMemInputPin
= NULL
;
182 hr
= IPin_QueryInterface(pReceivePin
, &IID_IMemInputPin
, (LPVOID
)&This
->pMemInputPin
);
186 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pMemAlloc
);
188 if (hr
== VFW_E_NO_ALLOCATOR
)
190 /* Input pin provides no allocator, use standard memory allocator */
191 hr
= CoCreateInstance(&CLSID_MemoryAllocator
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMemAllocator
, (LPVOID
*)&pMemAlloc
);
195 hr
= IMemInputPin_NotifyAllocator(This
->pMemInputPin
, pMemAlloc
, FALSE
);
200 hr
= IMemAllocator_SetProperties(pMemAlloc
, &This
->allocProps
, &actual
);
203 IMemAllocator_Release(pMemAlloc
);
206 /* break connection if we couldn't get the allocator */
209 if (This
->pMemInputPin
)
210 IMemInputPin_Release(This
->pMemInputPin
);
211 This
->pMemInputPin
= NULL
;
213 IPin_Disconnect(pReceivePin
);
219 IPin_Release(This
->pin
.pConnectedTo
);
220 This
->pin
.pConnectedTo
= NULL
;
221 FreeMediaType(&This
->pin
.mtCurrent
);
224 TRACE(" -- %x\n", hr
);
228 static HRESULT
InputPin_Init(const IPinVtbl
*InputPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
,
229 QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, InputPin
* pPinImpl
)
233 /* Common attributes */
234 pPinImpl
->pin
.refCount
= 1;
235 pPinImpl
->pin
.pConnectedTo
= NULL
;
236 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
237 pPinImpl
->pin
.pUserData
= pUserData
;
238 pPinImpl
->pin
.pCritSec
= pCritSec
;
239 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
240 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
242 /* Input pin attributes */
243 pPinImpl
->fnSampleProc
= pSampleProc
;
244 pPinImpl
->fnCleanProc
= pCleanUp
;
245 pPinImpl
->pAllocator
= NULL
;
246 pPinImpl
->tStart
= 0;
249 pPinImpl
->pin
.lpVtbl
= InputPin_Vtbl
;
250 pPinImpl
->lpVtblMemInput
= &MemInputPin_Vtbl
;
251 pPinImpl
->flushing
= pPinImpl
->end_of_stream
= 0;
256 static HRESULT
OutputPin_Init(const IPinVtbl
*OutputPin_Vtbl
, const PIN_INFO
* pPinInfo
, const ALLOCATOR_PROPERTIES
* props
, LPVOID pUserData
,
257 QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, OutputPin
* pPinImpl
)
261 /* Common attributes */
262 pPinImpl
->pin
.lpVtbl
= OutputPin_Vtbl
;
263 pPinImpl
->pin
.refCount
= 1;
264 pPinImpl
->pin
.pConnectedTo
= NULL
;
265 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
266 pPinImpl
->pin
.pUserData
= pUserData
;
267 pPinImpl
->pin
.pCritSec
= pCritSec
;
268 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
269 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
271 /* Output pin attributes */
272 pPinImpl
->pMemInputPin
= NULL
;
273 pPinImpl
->pConnectSpecific
= OutputPin_ConnectSpecific
;
276 pPinImpl
->allocProps
= *props
;
277 if (pPinImpl
->allocProps
.cbAlign
== 0)
278 pPinImpl
->allocProps
.cbAlign
= 1;
281 ZeroMemory(&pPinImpl
->allocProps
, sizeof(pPinImpl
->allocProps
));
286 HRESULT
InputPin_Construct(const IPinVtbl
*InputPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
292 if (pPinInfo
->dir
!= PINDIR_INPUT
)
294 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
298 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
301 return E_OUTOFMEMORY
;
303 if (SUCCEEDED(InputPin_Init(InputPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
305 *ppPin
= (IPin
*)pPinImpl
;
309 CoTaskMemFree(pPinImpl
);
313 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
)
315 OutputPin
* pPinImpl
;
319 if (pPinInfo
->dir
!= PINDIR_OUTPUT
)
321 ERR("Pin direction(%x) != PINDIR_OUTPUT\n", pPinInfo
->dir
);
325 assert(outputpin_size
>= sizeof(OutputPin
));
327 pPinImpl
= CoTaskMemAlloc(outputpin_size
);
330 return E_OUTOFMEMORY
;
332 if (SUCCEEDED(OutputPin_Init(OutputPin_Vtbl
, pPinInfo
, props
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
334 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
338 CoTaskMemFree(pPinImpl
);
342 /*** Common pin functions ***/
344 ULONG WINAPI
IPinImpl_AddRef(IPin
* iface
)
346 IPinImpl
*This
= (IPinImpl
*)iface
;
347 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
349 TRACE("(%p)->() AddRef from %d\n", iface
, refCount
- 1);
354 HRESULT WINAPI
IPinImpl_Disconnect(IPin
* iface
)
357 IPinImpl
*This
= (IPinImpl
*)iface
;
361 EnterCriticalSection(This
->pCritSec
);
363 if (This
->pConnectedTo
)
365 IPin_Release(This
->pConnectedTo
);
366 This
->pConnectedTo
= NULL
;
372 LeaveCriticalSection(This
->pCritSec
);
377 HRESULT WINAPI
IPinImpl_ConnectedTo(IPin
* iface
, IPin
** ppPin
)
380 IPinImpl
*This
= (IPinImpl
*)iface
;
382 TRACE("(%p)\n", ppPin
);
384 EnterCriticalSection(This
->pCritSec
);
386 if (This
->pConnectedTo
)
388 *ppPin
= This
->pConnectedTo
;
393 hr
= VFW_E_NOT_CONNECTED
;
395 LeaveCriticalSection(This
->pCritSec
);
400 HRESULT WINAPI
IPinImpl_ConnectionMediaType(IPin
* iface
, AM_MEDIA_TYPE
* pmt
)
403 IPinImpl
*This
= (IPinImpl
*)iface
;
405 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
407 EnterCriticalSection(This
->pCritSec
);
409 if (This
->pConnectedTo
)
411 CopyMediaType(pmt
, &This
->mtCurrent
);
416 ZeroMemory(pmt
, sizeof(*pmt
));
417 hr
= VFW_E_NOT_CONNECTED
;
420 LeaveCriticalSection(This
->pCritSec
);
425 HRESULT WINAPI
IPinImpl_QueryPinInfo(IPin
* iface
, PIN_INFO
* pInfo
)
427 IPinImpl
*This
= (IPinImpl
*)iface
;
429 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
431 Copy_PinInfo(pInfo
, &This
->pinInfo
);
432 IBaseFilter_AddRef(pInfo
->pFilter
);
437 HRESULT WINAPI
IPinImpl_QueryDirection(IPin
* iface
, PIN_DIRECTION
* pPinDir
)
439 IPinImpl
*This
= (IPinImpl
*)iface
;
441 TRACE("(%p/%p)->(%p)\n", This
, iface
, pPinDir
);
443 *pPinDir
= This
->pinInfo
.dir
;
448 HRESULT WINAPI
IPinImpl_QueryId(IPin
* iface
, LPWSTR
* Id
)
450 IPinImpl
*This
= (IPinImpl
*)iface
;
452 TRACE("(%p/%p)->(%p)\n", This
, iface
, Id
);
454 *Id
= CoTaskMemAlloc((strlenW(This
->pinInfo
.achName
) + 1) * sizeof(WCHAR
));
456 return E_OUTOFMEMORY
;
458 strcpyW(*Id
, This
->pinInfo
.achName
);
463 HRESULT WINAPI
IPinImpl_QueryAccept(IPin
* iface
, const AM_MEDIA_TYPE
* pmt
)
465 IPinImpl
*This
= (IPinImpl
*)iface
;
467 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
469 return (This
->fnQueryAccept(This
->pUserData
, pmt
) == S_OK
? S_OK
: S_FALSE
);
472 HRESULT WINAPI
IPinImpl_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
474 IPinImpl
*This
= (IPinImpl
*)iface
;
475 ENUMMEDIADETAILS emd
;
477 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
479 /* override this method to allow enumeration of your types */
481 emd
.pMediaTypes
= NULL
;
483 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
486 HRESULT WINAPI
IPinImpl_QueryInternalConnections(IPin
* iface
, IPin
** apPin
, ULONG
* cPin
)
488 IPinImpl
*This
= (IPinImpl
*)iface
;
490 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, apPin
, cPin
);
492 return E_NOTIMPL
; /* to tell caller that all input pins connected to all output pins */
495 /*** IPin implementation for an input pin ***/
497 HRESULT WINAPI
InputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
499 InputPin
*This
= (InputPin
*)iface
;
501 TRACE("(%p)->(%s, %p)\n", iface
, qzdebugstr_guid(riid
), ppv
);
505 if (IsEqualIID(riid
, &IID_IUnknown
))
506 *ppv
= (LPVOID
)iface
;
507 else if (IsEqualIID(riid
, &IID_IPin
))
508 *ppv
= (LPVOID
)iface
;
509 else if (IsEqualIID(riid
, &IID_IMemInputPin
))
510 *ppv
= (LPVOID
)&This
->lpVtblMemInput
;
511 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
513 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
518 IUnknown_AddRef((IUnknown
*)(*ppv
));
522 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
524 return E_NOINTERFACE
;
527 ULONG WINAPI
InputPin_Release(IPin
* iface
)
529 InputPin
*This
= (InputPin
*)iface
;
530 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
532 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
536 FreeMediaType(&This
->pin
.mtCurrent
);
537 if (This
->pAllocator
)
538 IMemAllocator_Release(This
->pAllocator
);
546 HRESULT WINAPI
InputPin_Connect(IPin
* iface
, IPin
* pConnector
, const AM_MEDIA_TYPE
* pmt
)
548 ERR("Outgoing connection on an input pin! (%p, %p)\n", pConnector
, pmt
);
554 HRESULT WINAPI
InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
556 InputPin
*This
= (InputPin
*)iface
;
557 PIN_DIRECTION pindirReceive
;
560 TRACE("(%p, %p)\n", pReceivePin
, pmt
);
561 dump_AM_MEDIA_TYPE(pmt
);
563 EnterCriticalSection(This
->pin
.pCritSec
);
565 if (This
->pin
.pConnectedTo
)
566 hr
= VFW_E_ALREADY_CONNECTED
;
568 if (SUCCEEDED(hr
) && This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
)
569 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
570 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
574 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
576 if (pindirReceive
!= PINDIR_OUTPUT
)
578 ERR("Can't connect from non-output pin\n");
579 hr
= VFW_E_INVALID_DIRECTION
;
585 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
586 This
->pin
.pConnectedTo
= pReceivePin
;
587 IPin_AddRef(pReceivePin
);
590 LeaveCriticalSection(This
->pin
.pCritSec
);
595 static HRESULT
deliver_endofstream(IPin
* pin
, LPVOID unused
)
597 return IPin_EndOfStream( pin
);
600 HRESULT WINAPI
InputPin_EndOfStream(IPin
* iface
)
602 InputPin
*This
= (InputPin
*)iface
;
603 TRACE("(%p)\n", This
);
605 This
->end_of_stream
= 1;
607 return SendFurther( iface
, deliver_endofstream
, NULL
, NULL
);
610 static HRESULT
deliver_beginflush(IPin
* pin
, LPVOID unused
)
612 return IPin_BeginFlush( pin
);
615 HRESULT WINAPI
InputPin_BeginFlush(IPin
* iface
)
617 InputPin
*This
= (InputPin
*)iface
;
619 TRACE("() semi-stub\n");
621 /* Assign this outside the critical section so that _Receive loops can be broken */
624 EnterCriticalSection(This
->pin
.pCritSec
);
626 if (This
->fnCleanProc
)
627 This
->fnCleanProc(This
->pin
.pUserData
);
629 hr
= SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
630 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
;
1206 HRESULT
PullPin_Construct(const IPinVtbl
*PullPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
1212 if (pPinInfo
->dir
!= PINDIR_INPUT
)
1214 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
1215 return E_INVALIDARG
;
1218 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
1221 return E_OUTOFMEMORY
;
1223 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
1225 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
1229 CoTaskMemFree(pPinImpl
);
1233 HRESULT WINAPI
PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
1235 PIN_DIRECTION pindirReceive
;
1237 PullPin
*This
= (PullPin
*)iface
;
1239 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
1240 dump_AM_MEDIA_TYPE(pmt
);
1242 EnterCriticalSection(This
->pin
.pCritSec
);
1244 if (This
->pin
.pConnectedTo
)
1245 hr
= VFW_E_ALREADY_CONNECTED
;
1247 if (SUCCEEDED(hr
) && (This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
))
1248 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
1249 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
1253 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
1255 if (pindirReceive
!= PINDIR_OUTPUT
)
1257 ERR("Can't connect from non-output pin\n");
1258 hr
= VFW_E_INVALID_DIRECTION
;
1262 This
->pReader
= NULL
;
1263 This
->pAlloc
= NULL
;
1266 hr
= IPin_QueryInterface(pReceivePin
, &IID_IAsyncReader
, (LPVOID
*)&This
->pReader
);
1271 ALLOCATOR_PROPERTIES props
;
1273 props
.cbBuffer
= 64 * 1024; /* 64k bytes */
1276 hr
= IAsyncReader_RequestAllocator(This
->pReader
, NULL
, &props
, &This
->pAlloc
);
1279 if (SUCCEEDED(hr
) && This
->fnPreConnect
)
1281 hr
= This
->fnPreConnect(iface
, pReceivePin
);
1286 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
1287 This
->pin
.pConnectedTo
= pReceivePin
;
1288 IPin_AddRef(pReceivePin
);
1293 IAsyncReader_Release(This
->pReader
);
1294 This
->pReader
= NULL
;
1296 IMemAllocator_Release(This
->pAlloc
);
1297 This
->pAlloc
= NULL
;
1300 LeaveCriticalSection(This
->pin
.pCritSec
);
1304 HRESULT WINAPI
PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
1306 PullPin
*This
= (PullPin
*)iface
;
1308 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
1312 if (IsEqualIID(riid
, &IID_IUnknown
))
1313 *ppv
= (LPVOID
)iface
;
1314 else if (IsEqualIID(riid
, &IID_IPin
))
1315 *ppv
= (LPVOID
)iface
;
1316 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1318 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
1323 IUnknown_AddRef((IUnknown
*)(*ppv
));
1327 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
1329 return E_NOINTERFACE
;
1332 ULONG WINAPI
PullPin_Release(IPin
* iface
)
1334 PullPin
*This
= (PullPin
*)iface
;
1335 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
1337 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1342 IMemAllocator_Release(This
->pAlloc
);
1344 IAsyncReader_Release(This
->pReader
);
1345 CloseHandle(This
->hEventStateChanged
);
1346 CoTaskMemFree(This
);
1352 static DWORD WINAPI
PullPin_Thread_Main(LPVOID pv
)
1355 SleepEx(INFINITE
, TRUE
);
1358 static void CALLBACK
PullPin_Thread_Process(ULONG_PTR iface
)
1360 PullPin
*This
= (PullPin
*)iface
;
1363 ALLOCATOR_PROPERTIES allocProps
;
1365 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1367 EnterCriticalSection(This
->pin
.pCritSec
);
1368 SetEvent(This
->hEventStateChanged
);
1369 This
->state
= State_Running
;
1370 LeaveCriticalSection(This
->pin
.pCritSec
);
1372 hr
= IMemAllocator_GetProperties(This
->pAlloc
, &allocProps
);
1374 if (This
->rtCurrent
< This
->rtStart
)
1375 This
->rtCurrent
= MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This
->rtStart
), allocProps
.cbAlign
));
1379 while (This
->rtCurrent
< This
->rtStop
&& hr
== S_OK
&& !This
->stop_playback
)
1381 /* FIXME: to improve performance by quite a bit this should be changed
1382 * so that one sample is processed while one sample is fetched. However,
1383 * it is harder to debug so for the moment it will stay as it is */
1384 IMediaSample
* pSample
= NULL
;
1385 REFERENCE_TIME rtSampleStart
;
1386 REFERENCE_TIME rtSampleStop
;
1389 TRACE("Process sample\n");
1391 hr
= IMemAllocator_GetBuffer(This
->pAlloc
, &pSample
, NULL
, NULL
, 0);
1395 rtSampleStart
= This
->rtCurrent
;
1396 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetSize(pSample
));
1397 if (rtSampleStop
> This
->rtStop
)
1398 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1399 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1400 This
->rtCurrent
= rtSampleStop
;
1404 hr
= IAsyncReader_Request(This
->pReader
, pSample
, (ULONG_PTR
)0);
1407 hr
= IAsyncReader_WaitForNext(This
->pReader
, 1000, &pSample
, &dwUser
);
1411 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetActualDataLength(pSample
));
1412 if (rtSampleStop
> This
->rtStop
)
1413 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1414 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1418 hr
= This
->fnSampleProc(This
->pin
.pUserData
, pSample
);
1420 ERR("Processing error: %x\n", hr
);
1423 IMediaSample_Release(pSample
);
1427 EnterCriticalSection(This
->pin
.pCritSec
);
1428 This
->state
= State_Paused
;
1429 LeaveCriticalSection(This
->pin
.pCritSec
);
1433 static void CALLBACK
PullPin_Thread_Pause(ULONG_PTR iface
)
1435 PullPin
*This
= (PullPin
*)iface
;
1437 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1439 EnterCriticalSection(This
->pin
.pCritSec
);
1441 This
->state
= State_Paused
;
1442 SetEvent(This
->hEventStateChanged
);
1444 LeaveCriticalSection(This
->pin
.pCritSec
);
1448 static void CALLBACK
PullPin_Thread_Stop(ULONG_PTR iface
)
1450 PullPin
*This
= (PullPin
*)iface
;
1452 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1454 EnterCriticalSection(This
->pin
.pCritSec
);
1458 CloseHandle(This
->hThread
);
1459 This
->hThread
= NULL
;
1460 if (FAILED(hr
= IMemAllocator_Decommit(This
->pAlloc
)))
1461 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr
);
1463 SetEvent(This
->hEventStateChanged
);
1464 This
->state
= State_Stopped
;
1466 LeaveCriticalSection(This
->pin
.pCritSec
);
1468 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1473 HRESULT
PullPin_InitProcessing(PullPin
* This
)
1477 TRACE("(%p)->()\n", This
);
1479 /* if we are connected */
1482 WaitForSingleObject(This
->hEventStateChanged
, INFINITE
);
1483 EnterCriticalSection(This
->pin
.pCritSec
);
1484 if (This
->state
== State_Stopped
)
1487 assert(!This
->hThread
);
1489 /* AddRef the filter to make sure it and it's pins will be around
1490 * as long as the thread */
1491 IBaseFilter_AddRef(This
->pin
.pinInfo
.pFilter
);
1493 This
->hThread
= CreateThread(NULL
, 0, PullPin_Thread_Main
, NULL
, 0, &dwThreadId
);
1496 hr
= HRESULT_FROM_WIN32(GetLastError());
1497 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1502 hr
= IMemAllocator_Commit(This
->pAlloc
);
1503 This
->state
= State_Paused
;
1504 SetEvent(This
->hEventStateChanged
);
1507 else assert(This
->hThread
);
1508 LeaveCriticalSection(This
->pin
.pCritSec
);
1511 TRACE(" -- %x\n", hr
);
1516 HRESULT
PullPin_StartProcessing(PullPin
* This
)
1518 /* if we are connected */
1519 TRACE("(%p)->()\n", This
);
1522 assert(This
->hThread
);
1524 PullPin_WaitForStateChange(This
, INFINITE
);
1525 ResetEvent(This
->hEventStateChanged
);
1526 This
->stop_playback
= 0;
1528 if (!QueueUserAPC(PullPin_Thread_Process
, This
->hThread
, (ULONG_PTR
)This
))
1529 return HRESULT_FROM_WIN32(GetLastError());
1535 HRESULT
PullPin_PauseProcessing(PullPin
* This
)
1537 /* if we are connected */
1538 TRACE("(%p)->()\n", This
);
1541 assert(This
->hThread
);
1543 PullPin_WaitForStateChange(This
, INFINITE
);
1544 EnterCriticalSection(This
->pin
.pCritSec
);
1545 This
->stop_playback
= 1;
1546 LeaveCriticalSection(This
->pin
.pCritSec
);
1547 ResetEvent(This
->hEventStateChanged
);
1549 if (!QueueUserAPC(PullPin_Thread_Pause
, This
->hThread
, (ULONG_PTR
)This
))
1550 return HRESULT_FROM_WIN32(GetLastError());
1556 HRESULT
PullPin_StopProcessing(PullPin
* This
)
1558 /* if we are connected */
1559 if (This
->pAlloc
&& This
->hThread
)
1561 PullPin_WaitForStateChange(This
, INFINITE
);
1563 This
->stop_playback
= 1;
1564 ResetEvent(This
->hEventStateChanged
);
1566 if (!QueueUserAPC(PullPin_Thread_Stop
, This
->hThread
, (ULONG_PTR
)This
))
1567 return HRESULT_FROM_WIN32(GetLastError());
1573 HRESULT
PullPin_WaitForStateChange(PullPin
* This
, DWORD dwMilliseconds
)
1575 if (WaitForSingleObject(This
->hEventStateChanged
, dwMilliseconds
) == WAIT_TIMEOUT
)
1580 HRESULT WINAPI
PullPin_EndOfStream(IPin
* iface
)
1582 FIXME("(%p)->() stub\n", iface
);
1584 return SendFurther( iface
, deliver_endofstream
, NULL
, NULL
);
1587 HRESULT WINAPI
PullPin_BeginFlush(IPin
* iface
)
1589 PullPin
*This
= (PullPin
*)iface
;
1590 FIXME("(%p)->() stub\n", iface
);
1592 SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
1594 if (This
->state
== State_Running
)
1595 return PullPin_PauseProcessing(This
);
1599 HRESULT WINAPI
PullPin_EndFlush(IPin
* iface
)
1602 PullPin
*This
= (PullPin
*)iface
;
1604 FIXME("(%p)->() stub\n", iface
);
1605 SendFurther( iface
, deliver_endflush
, NULL
, NULL
);
1607 return IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
1610 HRESULT WINAPI
PullPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1612 newsegmentargs args
;
1613 FIXME("(%p)->(%s, %s, %g) stub\n", iface
, wine_dbgstr_longlong(tStart
), wine_dbgstr_longlong(tStop
), dRate
);
1615 args
.tStart
= tStart
;
1619 return SendFurther( iface
, deliver_newsegment
, &args
, NULL
);
1622 static const IPinVtbl PullPin_Vtbl
=
1624 PullPin_QueryInterface
,
1628 PullPin_ReceiveConnection
,
1629 IPinImpl_Disconnect
,
1630 IPinImpl_ConnectedTo
,
1631 IPinImpl_ConnectionMediaType
,
1632 IPinImpl_QueryPinInfo
,
1633 IPinImpl_QueryDirection
,
1635 IPinImpl_QueryAccept
,
1636 IPinImpl_EnumMediaTypes
,
1637 IPinImpl_QueryInternalConnections
,
1638 PullPin_EndOfStream
,