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
;
255 static HRESULT
OutputPin_Init(const IPinVtbl
*OutputPin_Vtbl
, const PIN_INFO
* pPinInfo
, const ALLOCATOR_PROPERTIES
* props
, LPVOID pUserData
,
256 QUERYACCEPTPROC pQueryAccept
, LPCRITICAL_SECTION pCritSec
, OutputPin
* pPinImpl
)
260 /* Common attributes */
261 pPinImpl
->pin
.lpVtbl
= OutputPin_Vtbl
;
262 pPinImpl
->pin
.refCount
= 1;
263 pPinImpl
->pin
.pConnectedTo
= NULL
;
264 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
265 pPinImpl
->pin
.pUserData
= pUserData
;
266 pPinImpl
->pin
.pCritSec
= pCritSec
;
267 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
268 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
270 /* Output pin attributes */
271 pPinImpl
->pMemInputPin
= NULL
;
272 pPinImpl
->pConnectSpecific
= OutputPin_ConnectSpecific
;
275 pPinImpl
->allocProps
= *props
;
276 if (pPinImpl
->allocProps
.cbAlign
== 0)
277 pPinImpl
->allocProps
.cbAlign
= 1;
280 ZeroMemory(&pPinImpl
->allocProps
, sizeof(pPinImpl
->allocProps
));
285 HRESULT
InputPin_Construct(const IPinVtbl
*InputPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
291 if (pPinInfo
->dir
!= PINDIR_INPUT
)
293 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
297 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
300 return E_OUTOFMEMORY
;
302 if (SUCCEEDED(InputPin_Init(InputPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
304 *ppPin
= (IPin
*)pPinImpl
;
308 CoTaskMemFree(pPinImpl
);
312 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
)
314 OutputPin
* pPinImpl
;
318 if (pPinInfo
->dir
!= PINDIR_OUTPUT
)
320 ERR("Pin direction(%x) != PINDIR_OUTPUT\n", pPinInfo
->dir
);
324 assert(outputpin_size
>= sizeof(OutputPin
));
326 pPinImpl
= CoTaskMemAlloc(outputpin_size
);
329 return E_OUTOFMEMORY
;
331 if (SUCCEEDED(OutputPin_Init(OutputPin_Vtbl
, pPinInfo
, props
, pUserData
, pQueryAccept
, pCritSec
, pPinImpl
)))
333 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
337 CoTaskMemFree(pPinImpl
);
341 /*** Common pin functions ***/
343 ULONG WINAPI
IPinImpl_AddRef(IPin
* iface
)
345 IPinImpl
*This
= (IPinImpl
*)iface
;
346 ULONG refCount
= InterlockedIncrement(&This
->refCount
);
348 TRACE("(%p)->() AddRef from %d\n", iface
, refCount
- 1);
353 HRESULT WINAPI
IPinImpl_Disconnect(IPin
* iface
)
356 IPinImpl
*This
= (IPinImpl
*)iface
;
360 EnterCriticalSection(This
->pCritSec
);
362 if (This
->pConnectedTo
)
364 IPin_Release(This
->pConnectedTo
);
365 This
->pConnectedTo
= NULL
;
371 LeaveCriticalSection(This
->pCritSec
);
376 HRESULT WINAPI
IPinImpl_ConnectedTo(IPin
* iface
, IPin
** ppPin
)
379 IPinImpl
*This
= (IPinImpl
*)iface
;
381 TRACE("(%p)\n", ppPin
);
383 EnterCriticalSection(This
->pCritSec
);
385 if (This
->pConnectedTo
)
387 *ppPin
= This
->pConnectedTo
;
392 hr
= VFW_E_NOT_CONNECTED
;
394 LeaveCriticalSection(This
->pCritSec
);
399 HRESULT WINAPI
IPinImpl_ConnectionMediaType(IPin
* iface
, AM_MEDIA_TYPE
* pmt
)
402 IPinImpl
*This
= (IPinImpl
*)iface
;
404 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
406 EnterCriticalSection(This
->pCritSec
);
408 if (This
->pConnectedTo
)
410 CopyMediaType(pmt
, &This
->mtCurrent
);
415 ZeroMemory(pmt
, sizeof(*pmt
));
416 hr
= VFW_E_NOT_CONNECTED
;
419 LeaveCriticalSection(This
->pCritSec
);
424 HRESULT WINAPI
IPinImpl_QueryPinInfo(IPin
* iface
, PIN_INFO
* pInfo
)
426 IPinImpl
*This
= (IPinImpl
*)iface
;
428 TRACE("(%p/%p)->(%p)\n", This
, iface
, pInfo
);
430 Copy_PinInfo(pInfo
, &This
->pinInfo
);
431 IBaseFilter_AddRef(pInfo
->pFilter
);
436 HRESULT WINAPI
IPinImpl_QueryDirection(IPin
* iface
, PIN_DIRECTION
* pPinDir
)
438 IPinImpl
*This
= (IPinImpl
*)iface
;
440 TRACE("(%p/%p)->(%p)\n", This
, iface
, pPinDir
);
442 *pPinDir
= This
->pinInfo
.dir
;
447 HRESULT WINAPI
IPinImpl_QueryId(IPin
* iface
, LPWSTR
* Id
)
449 IPinImpl
*This
= (IPinImpl
*)iface
;
451 TRACE("(%p/%p)->(%p)\n", This
, iface
, Id
);
453 *Id
= CoTaskMemAlloc((strlenW(This
->pinInfo
.achName
) + 1) * sizeof(WCHAR
));
455 return E_OUTOFMEMORY
;
457 strcpyW(*Id
, This
->pinInfo
.achName
);
462 HRESULT WINAPI
IPinImpl_QueryAccept(IPin
* iface
, const AM_MEDIA_TYPE
* pmt
)
464 IPinImpl
*This
= (IPinImpl
*)iface
;
466 TRACE("(%p/%p)->(%p)\n", This
, iface
, pmt
);
468 return (This
->fnQueryAccept(This
->pUserData
, pmt
) == S_OK
? S_OK
: S_FALSE
);
471 HRESULT WINAPI
IPinImpl_EnumMediaTypes(IPin
* iface
, IEnumMediaTypes
** ppEnum
)
473 IPinImpl
*This
= (IPinImpl
*)iface
;
474 ENUMMEDIADETAILS emd
;
476 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
478 /* override this method to allow enumeration of your types */
480 emd
.pMediaTypes
= NULL
;
482 return IEnumMediaTypesImpl_Construct(&emd
, ppEnum
);
485 HRESULT WINAPI
IPinImpl_QueryInternalConnections(IPin
* iface
, IPin
** apPin
, ULONG
* cPin
)
487 IPinImpl
*This
= (IPinImpl
*)iface
;
489 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, apPin
, cPin
);
491 return E_NOTIMPL
; /* to tell caller that all input pins connected to all output pins */
494 /*** IPin implementation for an input pin ***/
496 HRESULT WINAPI
InputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
498 InputPin
*This
= (InputPin
*)iface
;
500 TRACE("(%p)->(%s, %p)\n", iface
, qzdebugstr_guid(riid
), ppv
);
504 if (IsEqualIID(riid
, &IID_IUnknown
))
505 *ppv
= (LPVOID
)iface
;
506 else if (IsEqualIID(riid
, &IID_IPin
))
507 *ppv
= (LPVOID
)iface
;
508 else if (IsEqualIID(riid
, &IID_IMemInputPin
))
509 *ppv
= (LPVOID
)&This
->lpVtblMemInput
;
510 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
512 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
517 IUnknown_AddRef((IUnknown
*)(*ppv
));
521 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
523 return E_NOINTERFACE
;
526 ULONG WINAPI
InputPin_Release(IPin
* iface
)
528 InputPin
*This
= (InputPin
*)iface
;
529 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
531 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
535 FreeMediaType(&This
->pin
.mtCurrent
);
536 if (This
->pAllocator
)
537 IMemAllocator_Release(This
->pAllocator
);
545 HRESULT WINAPI
InputPin_Connect(IPin
* iface
, IPin
* pConnector
, const AM_MEDIA_TYPE
* pmt
)
547 ERR("Outgoing connection on an input pin! (%p, %p)\n", pConnector
, pmt
);
553 HRESULT WINAPI
InputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
555 InputPin
*This
= (InputPin
*)iface
;
556 PIN_DIRECTION pindirReceive
;
559 TRACE("(%p, %p)\n", pReceivePin
, pmt
);
560 dump_AM_MEDIA_TYPE(pmt
);
562 EnterCriticalSection(This
->pin
.pCritSec
);
564 if (This
->pin
.pConnectedTo
)
565 hr
= VFW_E_ALREADY_CONNECTED
;
567 if (SUCCEEDED(hr
) && This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
)
568 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
569 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
573 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
575 if (pindirReceive
!= PINDIR_OUTPUT
)
577 ERR("Can't connect from non-output pin\n");
578 hr
= VFW_E_INVALID_DIRECTION
;
584 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
585 This
->pin
.pConnectedTo
= pReceivePin
;
586 IPin_AddRef(pReceivePin
);
589 LeaveCriticalSection(This
->pin
.pCritSec
);
594 static HRESULT
deliver_endofstream(IPin
* pin
, LPVOID unused
)
596 return IPin_EndOfStream( pin
);
599 HRESULT WINAPI
InputPin_EndOfStream(IPin
* iface
)
603 /* Should do an end of stream notification?
604 * Also, don't accept any more samples from now!
605 * TODO: Don't accept any more packets
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
)
620 /* TODO: Drop all cached packets, and don't accept any more samples! */
621 return SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
624 static HRESULT
deliver_endflush(IPin
* pin
, LPVOID unused
)
626 return IPin_EndFlush( pin
);
629 HRESULT WINAPI
InputPin_EndFlush(IPin
* iface
)
633 /* TODO: Accept any samples again */
634 return SendFurther( iface
, deliver_endflush
, NULL
, NULL
);
637 typedef struct newsegmentargs
639 REFERENCE_TIME tStart
, tStop
;
643 static HRESULT
deliver_newsegment(IPin
*pin
, LPVOID data
)
645 newsegmentargs
*args
= data
;
646 return IPin_NewSegment(pin
, args
->tStart
, args
->tStop
, args
->rate
);
649 HRESULT WINAPI
InputPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
651 InputPin
*This
= (InputPin
*)iface
;
654 TRACE("(%x%08x, %x%08x, %e)\n", (ULONG
)(tStart
>> 32), (ULONG
)tStart
, (ULONG
)(tStop
>> 32), (ULONG
)tStop
, dRate
);
656 args
.tStart
= This
->tStart
= tStart
;
657 args
.tStop
= This
->tStop
= tStop
;
658 args
.rate
= This
->dRate
= dRate
;
660 return SendFurther( iface
, deliver_newsegment
, &args
, NULL
);
663 static const IPinVtbl InputPin_Vtbl
=
665 InputPin_QueryInterface
,
669 InputPin_ReceiveConnection
,
671 IPinImpl_ConnectedTo
,
672 IPinImpl_ConnectionMediaType
,
673 IPinImpl_QueryPinInfo
,
674 IPinImpl_QueryDirection
,
676 IPinImpl_QueryAccept
,
677 IPinImpl_EnumMediaTypes
,
678 IPinImpl_QueryInternalConnections
,
679 InputPin_EndOfStream
,
685 /*** IMemInputPin implementation ***/
687 HRESULT WINAPI
MemInputPin_QueryInterface(IMemInputPin
* iface
, REFIID riid
, LPVOID
* ppv
)
689 InputPin
*This
= impl_from_IMemInputPin(iface
);
691 return IPin_QueryInterface((IPin
*)&This
->pin
, riid
, ppv
);
694 ULONG WINAPI
MemInputPin_AddRef(IMemInputPin
* iface
)
696 InputPin
*This
= impl_from_IMemInputPin(iface
);
698 return IPin_AddRef((IPin
*)&This
->pin
);
701 ULONG WINAPI
MemInputPin_Release(IMemInputPin
* iface
)
703 InputPin
*This
= impl_from_IMemInputPin(iface
);
705 return IPin_Release((IPin
*)&This
->pin
);
708 HRESULT WINAPI
MemInputPin_GetAllocator(IMemInputPin
* iface
, IMemAllocator
** ppAllocator
)
710 InputPin
*This
= impl_from_IMemInputPin(iface
);
712 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppAllocator
);
714 *ppAllocator
= This
->pAllocator
;
716 IMemAllocator_AddRef(*ppAllocator
);
718 return *ppAllocator
? S_OK
: VFW_E_NO_ALLOCATOR
;
721 HRESULT WINAPI
MemInputPin_NotifyAllocator(IMemInputPin
* iface
, IMemAllocator
* pAllocator
, BOOL bReadOnly
)
723 InputPin
*This
= impl_from_IMemInputPin(iface
);
725 TRACE("(%p/%p)->(%p, %d)\n", This
, iface
, pAllocator
, bReadOnly
);
727 if (This
->pAllocator
)
728 IMemAllocator_Release(This
->pAllocator
);
729 This
->pAllocator
= pAllocator
;
730 if (This
->pAllocator
)
731 IMemAllocator_AddRef(This
->pAllocator
);
736 HRESULT WINAPI
MemInputPin_GetAllocatorRequirements(IMemInputPin
* iface
, ALLOCATOR_PROPERTIES
* pProps
)
738 InputPin
*This
= impl_from_IMemInputPin(iface
);
740 TRACE("(%p/%p)->(%p)\n", This
, iface
, pProps
);
742 /* override this method if you have any specific requirements */
747 HRESULT WINAPI
MemInputPin_Receive(IMemInputPin
* iface
, IMediaSample
* pSample
)
749 InputPin
*This
= impl_from_IMemInputPin(iface
);
751 /* this trace commented out for performance reasons */
752 /*TRACE("(%p/%p)->(%p)\n", This, iface, pSample);*/
754 return This
->fnSampleProc(This
->pin
.pUserData
, pSample
);
757 HRESULT WINAPI
MemInputPin_ReceiveMultiple(IMemInputPin
* iface
, IMediaSample
** pSamples
, long nSamples
, long *nSamplesProcessed
)
760 InputPin
*This
= impl_from_IMemInputPin(iface
);
762 TRACE("(%p/%p)->(%p, %ld, %p)\n", This
, iface
, pSamples
, nSamples
, nSamplesProcessed
);
764 for (*nSamplesProcessed
= 0; *nSamplesProcessed
< nSamples
; (*nSamplesProcessed
)++)
766 hr
= IMemInputPin_Receive(iface
, pSamples
[*nSamplesProcessed
]);
774 HRESULT WINAPI
MemInputPin_ReceiveCanBlock(IMemInputPin
* iface
)
776 InputPin
*This
= impl_from_IMemInputPin(iface
);
778 FIXME("(%p/%p)->()\n", This
, iface
);
780 /* FIXME: we should check whether any output pins will block */
785 static const IMemInputPinVtbl MemInputPin_Vtbl
=
787 MemInputPin_QueryInterface
,
790 MemInputPin_GetAllocator
,
791 MemInputPin_NotifyAllocator
,
792 MemInputPin_GetAllocatorRequirements
,
794 MemInputPin_ReceiveMultiple
,
795 MemInputPin_ReceiveCanBlock
798 HRESULT WINAPI
OutputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
800 OutputPin
*This
= (OutputPin
*)iface
;
802 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
806 if (IsEqualIID(riid
, &IID_IUnknown
))
807 *ppv
= (LPVOID
)iface
;
808 else if (IsEqualIID(riid
, &IID_IPin
))
809 *ppv
= (LPVOID
)iface
;
810 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
812 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
817 IUnknown_AddRef((IUnknown
*)(*ppv
));
821 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
823 return E_NOINTERFACE
;
826 ULONG WINAPI
OutputPin_Release(IPin
* iface
)
828 OutputPin
*This
= (OutputPin
*)iface
;
829 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
831 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
835 FreeMediaType(&This
->pin
.mtCurrent
);
842 HRESULT WINAPI
OutputPin_Connect(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
845 OutputPin
*This
= (OutputPin
*)iface
;
847 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
848 dump_AM_MEDIA_TYPE(pmt
);
850 /* If we try to connect to ourself, we will definitely deadlock.
851 * There are other cases where we could deadlock too, but this
852 * catches the obvious case */
853 assert(pReceivePin
!= iface
);
855 EnterCriticalSection(This
->pin
.pCritSec
);
857 /* if we have been a specific type to connect with, then we can either connect
858 * with that or fail. We cannot choose different AM_MEDIA_TYPE */
859 if (pmt
&& !IsEqualGUID(&pmt
->majortype
, &GUID_NULL
) && !IsEqualGUID(&pmt
->subtype
, &GUID_NULL
))
860 hr
= This
->pConnectSpecific(iface
, pReceivePin
, pmt
);
863 /* negotiate media type */
865 IEnumMediaTypes
* pEnumCandidates
;
866 AM_MEDIA_TYPE
* pmtCandidate
; /* Candidate media type */
868 if (SUCCEEDED(hr
= IPin_EnumMediaTypes(iface
, &pEnumCandidates
)))
870 hr
= VFW_E_NO_ACCEPTABLE_TYPES
; /* Assume the worst, but set to S_OK if connected successfully */
872 /* try this filter's media types first */
873 while (S_OK
== IEnumMediaTypes_Next(pEnumCandidates
, 1, &pmtCandidate
, NULL
))
875 if (( !pmt
|| CompareMediaTypes(pmt
, pmtCandidate
, TRUE
) ) &&
876 (This
->pConnectSpecific(iface
, pReceivePin
, pmtCandidate
) == S_OK
))
879 CoTaskMemFree(pmtCandidate
);
882 CoTaskMemFree(pmtCandidate
);
884 IEnumMediaTypes_Release(pEnumCandidates
);
887 /* then try receiver filter's media types */
888 if (hr
!= S_OK
&& SUCCEEDED(hr
= IPin_EnumMediaTypes(pReceivePin
, &pEnumCandidates
))) /* if we haven't already connected successfully */
890 hr
= VFW_E_NO_ACCEPTABLE_TYPES
; /* Assume the worst, but set to S_OK if connected successfully */
892 while (S_OK
== IEnumMediaTypes_Next(pEnumCandidates
, 1, &pmtCandidate
, NULL
))
894 if (( !pmt
|| CompareMediaTypes(pmt
, pmtCandidate
, TRUE
) ) &&
895 (This
->pConnectSpecific(iface
, pReceivePin
, pmtCandidate
) == S_OK
))
898 CoTaskMemFree(pmtCandidate
);
901 CoTaskMemFree(pmtCandidate
);
903 IEnumMediaTypes_Release(pEnumCandidates
);
905 } /* if negotiate media type */
907 LeaveCriticalSection(This
->pin
.pCritSec
);
909 TRACE(" -- %x\n", hr
);
913 HRESULT WINAPI
OutputPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
915 ERR("Incoming connection on an output pin! (%p, %p)\n", pReceivePin
, pmt
);
920 HRESULT WINAPI
OutputPin_Disconnect(IPin
* iface
)
923 OutputPin
*This
= (OutputPin
*)iface
;
927 EnterCriticalSection(This
->pin
.pCritSec
);
929 if (This
->pMemInputPin
)
931 IMemInputPin_Release(This
->pMemInputPin
);
932 This
->pMemInputPin
= NULL
;
934 if (This
->pin
.pConnectedTo
)
936 IPin_Release(This
->pin
.pConnectedTo
);
937 This
->pin
.pConnectedTo
= NULL
;
943 LeaveCriticalSection(This
->pin
.pCritSec
);
948 HRESULT WINAPI
OutputPin_EndOfStream(IPin
* iface
)
952 /* not supposed to do anything in an output pin */
957 HRESULT WINAPI
OutputPin_BeginFlush(IPin
* iface
)
959 TRACE("(%p)->()\n", iface
);
961 /* not supposed to do anything in an output pin */
966 HRESULT WINAPI
OutputPin_EndFlush(IPin
* iface
)
968 TRACE("(%p)->()\n", iface
);
970 /* not supposed to do anything in an output pin */
975 HRESULT WINAPI
OutputPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
977 TRACE("(%p)->(%x%08x, %x%08x, %e)\n", iface
, (ULONG
)(tStart
>> 32), (ULONG
)tStart
, (ULONG
)(tStop
>> 32), (ULONG
)tStop
, dRate
);
979 /* not supposed to do anything in an output pin */
984 static const IPinVtbl OutputPin_Vtbl
=
986 OutputPin_QueryInterface
,
990 OutputPin_ReceiveConnection
,
991 OutputPin_Disconnect
,
992 IPinImpl_ConnectedTo
,
993 IPinImpl_ConnectionMediaType
,
994 IPinImpl_QueryPinInfo
,
995 IPinImpl_QueryDirection
,
997 IPinImpl_QueryAccept
,
998 IPinImpl_EnumMediaTypes
,
999 IPinImpl_QueryInternalConnections
,
1000 OutputPin_EndOfStream
,
1001 OutputPin_BeginFlush
,
1003 OutputPin_NewSegment
1006 HRESULT
OutputPin_GetDeliveryBuffer(OutputPin
* This
, IMediaSample
** ppSample
, REFERENCE_TIME
* tStart
, REFERENCE_TIME
* tStop
, DWORD dwFlags
)
1010 TRACE("(%p, %p, %p, %x)\n", ppSample
, tStart
, tStop
, dwFlags
);
1012 EnterCriticalSection(This
->pin
.pCritSec
);
1014 if (!This
->pin
.pConnectedTo
)
1015 hr
= VFW_E_NOT_CONNECTED
;
1018 IMemAllocator
* pAlloc
= NULL
;
1020 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1023 hr
= IMemAllocator_GetBuffer(pAlloc
, ppSample
, tStart
, tStop
, dwFlags
);
1026 hr
= IMediaSample_SetTime(*ppSample
, tStart
, tStop
);
1029 IMemAllocator_Release(pAlloc
);
1032 LeaveCriticalSection(This
->pin
.pCritSec
);
1037 HRESULT
OutputPin_SendSample(OutputPin
* This
, IMediaSample
* pSample
)
1040 IMemInputPin
* pMemConnected
= NULL
;
1043 EnterCriticalSection(This
->pin
.pCritSec
);
1045 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1046 hr
= VFW_E_NOT_CONNECTED
;
1049 /* we don't have the lock held when using This->pMemInputPin,
1050 * so we need to AddRef it to stop it being deleted while we are
1051 * using it. Same with its filter. */
1052 pMemConnected
= This
->pMemInputPin
;
1053 IMemInputPin_AddRef(pMemConnected
);
1054 hr
= IPin_QueryPinInfo(This
->pin
.pConnectedTo
, &pinInfo
);
1057 LeaveCriticalSection(This
->pin
.pCritSec
);
1061 /* NOTE: if we are in a critical section when Receive is called
1062 * then it causes some problems (most notably with the native Video
1063 * Renderer) if we are re-entered for whatever reason */
1064 hr
= IMemInputPin_Receive(pMemConnected
, pSample
);
1066 /* If the filter's destroyed, tell upstream to stop sending data */
1067 if(IBaseFilter_Release(pinInfo
.pFilter
) == 0 && SUCCEEDED(hr
))
1071 IMemInputPin_Release(pMemConnected
);
1076 HRESULT
OutputPin_DeliverNewSegment(OutputPin
* This
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1080 EnterCriticalSection(This
->pin
.pCritSec
);
1082 if (!This
->pin
.pConnectedTo
)
1083 hr
= VFW_E_NOT_CONNECTED
;
1085 hr
= IPin_NewSegment(This
->pin
.pConnectedTo
, tStart
, tStop
, dRate
);
1087 LeaveCriticalSection(This
->pin
.pCritSec
);
1092 HRESULT
OutputPin_CommitAllocator(OutputPin
* This
)
1096 TRACE("(%p)->()\n", This
);
1098 EnterCriticalSection(This
->pin
.pCritSec
);
1100 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1101 hr
= VFW_E_NOT_CONNECTED
;
1104 IMemAllocator
* pAlloc
= NULL
;
1106 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1109 hr
= IMemAllocator_Commit(pAlloc
);
1112 IMemAllocator_Release(pAlloc
);
1115 LeaveCriticalSection(This
->pin
.pCritSec
);
1120 HRESULT
OutputPin_DeliverDisconnect(OutputPin
* This
)
1124 TRACE("(%p)->()\n", This
);
1126 EnterCriticalSection(This
->pin
.pCritSec
);
1128 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
1129 hr
= VFW_E_NOT_CONNECTED
;
1132 IMemAllocator
* pAlloc
= NULL
;
1134 hr
= IMemInputPin_GetAllocator(This
->pMemInputPin
, &pAlloc
);
1137 hr
= IMemAllocator_Decommit(pAlloc
);
1140 IMemAllocator_Release(pAlloc
);
1143 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
1146 LeaveCriticalSection(This
->pin
.pCritSec
);
1152 static HRESULT
PullPin_Init(const IPinVtbl
*PullPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
,
1153 QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, PullPin
* pPinImpl
)
1155 /* Common attributes */
1156 pPinImpl
->pin
.lpVtbl
= PullPin_Vtbl
;
1157 pPinImpl
->pin
.refCount
= 1;
1158 pPinImpl
->pin
.pConnectedTo
= NULL
;
1159 pPinImpl
->pin
.fnQueryAccept
= pQueryAccept
;
1160 pPinImpl
->pin
.pUserData
= pUserData
;
1161 pPinImpl
->pin
.pCritSec
= pCritSec
;
1162 Copy_PinInfo(&pPinImpl
->pin
.pinInfo
, pPinInfo
);
1163 ZeroMemory(&pPinImpl
->pin
.mtCurrent
, sizeof(AM_MEDIA_TYPE
));
1165 /* Input pin attributes */
1166 pPinImpl
->fnSampleProc
= pSampleProc
;
1167 pPinImpl
->fnCleanProc
= pCleanUp
;
1168 pPinImpl
->fnPreConnect
= NULL
;
1169 pPinImpl
->pAlloc
= NULL
;
1170 pPinImpl
->pReader
= NULL
;
1171 pPinImpl
->hThread
= NULL
;
1172 pPinImpl
->hEventStateChanged
= CreateEventW(NULL
, TRUE
, TRUE
, NULL
);
1174 pPinImpl
->rtStart
= 0;
1175 pPinImpl
->rtCurrent
= 0;
1176 pPinImpl
->rtStop
= ((LONGLONG
)0x7fffffff << 32) | 0xffffffff;
1177 pPinImpl
->state
= State_Stopped
;
1182 HRESULT
PullPin_Construct(const IPinVtbl
*PullPin_Vtbl
, const PIN_INFO
* pPinInfo
, SAMPLEPROC pSampleProc
, LPVOID pUserData
, QUERYACCEPTPROC pQueryAccept
, CLEANUPPROC pCleanUp
, LPCRITICAL_SECTION pCritSec
, IPin
** ppPin
)
1188 if (pPinInfo
->dir
!= PINDIR_INPUT
)
1190 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo
->dir
);
1191 return E_INVALIDARG
;
1194 pPinImpl
= CoTaskMemAlloc(sizeof(*pPinImpl
));
1197 return E_OUTOFMEMORY
;
1199 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl
, pPinInfo
, pSampleProc
, pUserData
, pQueryAccept
, pCleanUp
, pCritSec
, pPinImpl
)))
1201 *ppPin
= (IPin
*)(&pPinImpl
->pin
.lpVtbl
);
1205 CoTaskMemFree(pPinImpl
);
1209 HRESULT WINAPI
PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
1211 PIN_DIRECTION pindirReceive
;
1213 PullPin
*This
= (PullPin
*)iface
;
1215 TRACE("(%p/%p)->(%p, %p)\n", This
, iface
, pReceivePin
, pmt
);
1216 dump_AM_MEDIA_TYPE(pmt
);
1218 EnterCriticalSection(This
->pin
.pCritSec
);
1220 if (This
->pin
.pConnectedTo
)
1221 hr
= VFW_E_ALREADY_CONNECTED
;
1223 if (SUCCEEDED(hr
) && (This
->pin
.fnQueryAccept(This
->pin
.pUserData
, pmt
) != S_OK
))
1224 hr
= VFW_E_TYPE_NOT_ACCEPTED
; /* FIXME: shouldn't we just map common errors onto
1225 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
1229 IPin_QueryDirection(pReceivePin
, &pindirReceive
);
1231 if (pindirReceive
!= PINDIR_OUTPUT
)
1233 ERR("Can't connect from non-output pin\n");
1234 hr
= VFW_E_INVALID_DIRECTION
;
1238 This
->pReader
= NULL
;
1239 This
->pAlloc
= NULL
;
1242 hr
= IPin_QueryInterface(pReceivePin
, &IID_IAsyncReader
, (LPVOID
*)&This
->pReader
);
1247 ALLOCATOR_PROPERTIES props
;
1249 props
.cbBuffer
= 64 * 1024; /* 64k bytes */
1252 hr
= IAsyncReader_RequestAllocator(This
->pReader
, NULL
, &props
, &This
->pAlloc
);
1255 if (SUCCEEDED(hr
) && This
->fnPreConnect
)
1257 hr
= This
->fnPreConnect(iface
, pReceivePin
);
1262 CopyMediaType(&This
->pin
.mtCurrent
, pmt
);
1263 This
->pin
.pConnectedTo
= pReceivePin
;
1264 IPin_AddRef(pReceivePin
);
1269 IAsyncReader_Release(This
->pReader
);
1270 This
->pReader
= NULL
;
1272 IMemAllocator_Release(This
->pAlloc
);
1273 This
->pAlloc
= NULL
;
1276 LeaveCriticalSection(This
->pin
.pCritSec
);
1280 HRESULT WINAPI
PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
1282 PullPin
*This
= (PullPin
*)iface
;
1284 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
1288 if (IsEqualIID(riid
, &IID_IUnknown
))
1289 *ppv
= (LPVOID
)iface
;
1290 else if (IsEqualIID(riid
, &IID_IPin
))
1291 *ppv
= (LPVOID
)iface
;
1292 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
1294 return IBaseFilter_QueryInterface(This
->pin
.pinInfo
.pFilter
, &IID_IMediaSeeking
, ppv
);
1299 IUnknown_AddRef((IUnknown
*)(*ppv
));
1303 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
1305 return E_NOINTERFACE
;
1308 ULONG WINAPI
PullPin_Release(IPin
* iface
)
1310 PullPin
*This
= (PullPin
*)iface
;
1311 ULONG refCount
= InterlockedDecrement(&This
->pin
.refCount
);
1313 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
1318 IMemAllocator_Release(This
->pAlloc
);
1320 IAsyncReader_Release(This
->pReader
);
1321 CloseHandle(This
->hEventStateChanged
);
1322 CoTaskMemFree(This
);
1328 static DWORD WINAPI
PullPin_Thread_Main(LPVOID pv
)
1331 SleepEx(INFINITE
, TRUE
);
1334 static void CALLBACK
PullPin_Thread_Process(ULONG_PTR iface
)
1336 PullPin
*This
= (PullPin
*)iface
;
1339 ALLOCATOR_PROPERTIES allocProps
;
1341 CoInitializeEx(NULL
, COINIT_MULTITHREADED
);
1343 EnterCriticalSection(This
->pin
.pCritSec
);
1344 SetEvent(This
->hEventStateChanged
);
1345 This
->state
= State_Running
;
1346 LeaveCriticalSection(This
->pin
.pCritSec
);
1348 hr
= IMemAllocator_GetProperties(This
->pAlloc
, &allocProps
);
1350 if (This
->rtCurrent
< This
->rtStart
)
1351 This
->rtCurrent
= MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This
->rtStart
), allocProps
.cbAlign
));
1355 while (This
->rtCurrent
< This
->rtStop
&& hr
== S_OK
&& !This
->stop_playback
)
1357 /* FIXME: to improve performance by quite a bit this should be changed
1358 * so that one sample is processed while one sample is fetched. However,
1359 * it is harder to debug so for the moment it will stay as it is */
1360 IMediaSample
* pSample
= NULL
;
1361 REFERENCE_TIME rtSampleStart
;
1362 REFERENCE_TIME rtSampleStop
;
1365 TRACE("Process sample\n");
1367 hr
= IMemAllocator_GetBuffer(This
->pAlloc
, &pSample
, NULL
, NULL
, 0);
1371 rtSampleStart
= This
->rtCurrent
;
1372 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetSize(pSample
));
1373 if (rtSampleStop
> This
->rtStop
)
1374 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1375 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1376 This
->rtCurrent
= rtSampleStop
;
1380 hr
= IAsyncReader_Request(This
->pReader
, pSample
, (ULONG_PTR
)0);
1383 hr
= IAsyncReader_WaitForNext(This
->pReader
, 1000, &pSample
, &dwUser
);
1387 rtSampleStop
= rtSampleStart
+ MEDIATIME_FROM_BYTES(IMediaSample_GetActualDataLength(pSample
));
1388 if (rtSampleStop
> This
->rtStop
)
1389 rtSampleStop
= MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This
->rtStop
), allocProps
.cbAlign
));
1390 hr
= IMediaSample_SetTime(pSample
, &rtSampleStart
, &rtSampleStop
);
1394 hr
= This
->fnSampleProc(This
->pin
.pUserData
, pSample
);
1396 ERR("Processing error: %x\n", hr
);
1399 IMediaSample_Release(pSample
);
1403 EnterCriticalSection(This
->pin
.pCritSec
);
1404 This
->state
= State_Paused
;
1405 LeaveCriticalSection(This
->pin
.pCritSec
);
1409 static void CALLBACK
PullPin_Thread_Pause(ULONG_PTR iface
)
1411 PullPin
*This
= (PullPin
*)iface
;
1413 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1415 EnterCriticalSection(This
->pin
.pCritSec
);
1417 This
->state
= State_Paused
;
1418 SetEvent(This
->hEventStateChanged
);
1420 LeaveCriticalSection(This
->pin
.pCritSec
);
1424 static void CALLBACK
PullPin_Thread_Stop(ULONG_PTR iface
)
1426 PullPin
*This
= (PullPin
*)iface
;
1428 TRACE("(%p/%p)->()\n", This
, (LPVOID
)iface
);
1430 EnterCriticalSection(This
->pin
.pCritSec
);
1434 CloseHandle(This
->hThread
);
1435 This
->hThread
= NULL
;
1436 if (FAILED(hr
= IMemAllocator_Decommit(This
->pAlloc
)))
1437 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr
);
1439 SetEvent(This
->hEventStateChanged
);
1440 This
->state
= State_Stopped
;
1442 LeaveCriticalSection(This
->pin
.pCritSec
);
1444 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1449 HRESULT
PullPin_InitProcessing(PullPin
* This
)
1453 TRACE("(%p)->()\n", This
);
1455 /* if we are connected */
1458 WaitForSingleObject(This
->hEventStateChanged
, INFINITE
);
1459 EnterCriticalSection(This
->pin
.pCritSec
);
1460 if (This
->state
== State_Stopped
)
1463 assert(!This
->hThread
);
1465 /* AddRef the filter to make sure it and it's pins will be around
1466 * as long as the thread */
1467 IBaseFilter_AddRef(This
->pin
.pinInfo
.pFilter
);
1469 This
->hThread
= CreateThread(NULL
, 0, PullPin_Thread_Main
, NULL
, 0, &dwThreadId
);
1472 hr
= HRESULT_FROM_WIN32(GetLastError());
1473 IBaseFilter_Release(This
->pin
.pinInfo
.pFilter
);
1478 hr
= IMemAllocator_Commit(This
->pAlloc
);
1479 This
->state
= State_Paused
;
1480 SetEvent(This
->hEventStateChanged
);
1483 else assert(This
->hThread
);
1484 LeaveCriticalSection(This
->pin
.pCritSec
);
1487 TRACE(" -- %x\n", hr
);
1492 HRESULT
PullPin_StartProcessing(PullPin
* This
)
1494 /* if we are connected */
1495 TRACE("(%p)->()\n", This
);
1498 assert(This
->hThread
);
1500 PullPin_WaitForStateChange(This
, INFINITE
);
1501 ResetEvent(This
->hEventStateChanged
);
1502 This
->stop_playback
= 0;
1504 if (!QueueUserAPC(PullPin_Thread_Process
, This
->hThread
, (ULONG_PTR
)This
))
1505 return HRESULT_FROM_WIN32(GetLastError());
1511 HRESULT
PullPin_PauseProcessing(PullPin
* This
)
1513 /* if we are connected */
1514 TRACE("(%p)->()\n", This
);
1517 assert(This
->hThread
);
1519 PullPin_WaitForStateChange(This
, INFINITE
);
1520 EnterCriticalSection(This
->pin
.pCritSec
);
1521 This
->stop_playback
= 1;
1522 LeaveCriticalSection(This
->pin
.pCritSec
);
1523 ResetEvent(This
->hEventStateChanged
);
1525 if (!QueueUserAPC(PullPin_Thread_Pause
, This
->hThread
, (ULONG_PTR
)This
))
1526 return HRESULT_FROM_WIN32(GetLastError());
1532 HRESULT
PullPin_StopProcessing(PullPin
* This
)
1534 /* if we are connected */
1535 if (This
->pAlloc
&& This
->hThread
)
1537 PullPin_WaitForStateChange(This
, INFINITE
);
1539 This
->stop_playback
= 1;
1540 ResetEvent(This
->hEventStateChanged
);
1542 if (!QueueUserAPC(PullPin_Thread_Stop
, This
->hThread
, (ULONG_PTR
)This
))
1543 return HRESULT_FROM_WIN32(GetLastError());
1549 HRESULT
PullPin_WaitForStateChange(PullPin
* This
, DWORD dwMilliseconds
)
1551 if (WaitForSingleObject(This
->hEventStateChanged
, dwMilliseconds
) == WAIT_TIMEOUT
)
1556 HRESULT WINAPI
PullPin_EndOfStream(IPin
* iface
)
1558 FIXME("(%p)->() stub\n", iface
);
1560 return SendFurther( iface
, deliver_endofstream
, NULL
, NULL
);
1563 HRESULT WINAPI
PullPin_BeginFlush(IPin
* iface
)
1565 PullPin
*This
= (PullPin
*)iface
;
1566 FIXME("(%p)->() stub\n", iface
);
1568 SendFurther( iface
, deliver_beginflush
, NULL
, NULL
);
1570 if (This
->state
== State_Running
)
1571 return PullPin_PauseProcessing(This
);
1575 HRESULT WINAPI
PullPin_EndFlush(IPin
* iface
)
1578 PullPin
*This
= (PullPin
*)iface
;
1580 FIXME("(%p)->() stub\n", iface
);
1581 SendFurther( iface
, deliver_endflush
, NULL
, NULL
);
1583 return IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
1586 HRESULT WINAPI
PullPin_NewSegment(IPin
* iface
, REFERENCE_TIME tStart
, REFERENCE_TIME tStop
, double dRate
)
1588 newsegmentargs args
;
1589 FIXME("(%p)->(%s, %s, %g) stub\n", iface
, wine_dbgstr_longlong(tStart
), wine_dbgstr_longlong(tStop
), dRate
);
1591 args
.tStart
= tStart
;
1595 return SendFurther( iface
, deliver_newsegment
, &args
, NULL
);
1598 static const IPinVtbl PullPin_Vtbl
=
1600 PullPin_QueryInterface
,
1604 PullPin_ReceiveConnection
,
1605 IPinImpl_Disconnect
,
1606 IPinImpl_ConnectedTo
,
1607 IPinImpl_ConnectionMediaType
,
1608 IPinImpl_QueryPinInfo
,
1609 IPinImpl_QueryDirection
,
1611 IPinImpl_QueryAccept
,
1612 IPinImpl_EnumMediaTypes
,
1613 IPinImpl_QueryInternalConnections
,
1614 PullPin_EndOfStream
,