2 * Parser (Base for parsers and splitters)
4 * Copyright 2003 Robert Shearman
5 * Copyright 2004-2005 Christian Costa
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "quartz_private.h"
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
38 static const WCHAR wcsInputPinName
[] = {'i','n','p','u','t',' ','p','i','n',0};
39 static const IMediaSeekingVtbl Parser_Seeking_Vtbl
;
40 static const IPinVtbl Parser_OutputPin_Vtbl
;
41 static const IPinVtbl Parser_InputPin_Vtbl
;
43 static HRESULT WINAPI
Parser_ChangeStart(IMediaSeeking
*iface
);
44 static HRESULT WINAPI
Parser_ChangeStop(IMediaSeeking
*iface
);
45 static HRESULT WINAPI
Parser_ChangeRate(IMediaSeeking
*iface
);
46 static HRESULT WINAPI
Parser_OutputPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
);
47 static HRESULT WINAPI
Parser_OutputPin_CheckMediaType(BasePin
*pin
, const AM_MEDIA_TYPE
*pmt
);
48 static HRESULT WINAPI
Parser_OutputPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
);
49 static HRESULT WINAPI
Parser_OutputPin_DecideAllocator(BaseOutputPin
*This
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
);
50 static HRESULT WINAPI
Parser_OutputPin_BreakConnect(BaseOutputPin
*This
);
52 static inline ParserImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
54 return CONTAINING_RECORD(iface
, ParserImpl
, sourceSeeking
.IMediaSeeking_iface
);
57 static inline ParserImpl
*impl_from_IBaseFilter( IBaseFilter
*iface
)
59 return CONTAINING_RECORD(iface
, ParserImpl
, filter
.IBaseFilter_iface
);
62 static inline ParserImpl
*impl_from_BaseFilter( BaseFilter
*iface
)
64 return CONTAINING_RECORD(iface
, ParserImpl
, filter
);
68 static IPin
* WINAPI
Parser_GetPin(BaseFilter
*iface
, int pos
)
70 ParserImpl
*This
= impl_from_BaseFilter(iface
);
72 TRACE("%p->(%x)\n", This
, pos
);
74 /* Input pin also has a pin, hence the > and not >= */
75 if (pos
> This
->cStreams
|| pos
< 0)
78 IPin_AddRef(This
->ppPins
[pos
]);
79 return This
->ppPins
[pos
];
82 static LONG WINAPI
Parser_GetPinCount(BaseFilter
*iface
)
84 ParserImpl
*This
= impl_from_BaseFilter(iface
);
86 TRACE("%p->()\n", This
);
88 return This
->cStreams
;
91 static const BaseFilterFuncTable BaseFuncTable
= {
96 HRESULT
Parser_Create(ParserImpl
* pParser
, const IBaseFilterVtbl
*Parser_Vtbl
, const CLSID
* pClsid
, PFN_PROCESS_SAMPLE fnProcessSample
, PFN_QUERY_ACCEPT fnQueryAccept
, PFN_PRE_CONNECT fnPreConnect
, PFN_CLEANUP fnCleanup
, PFN_DISCONNECT fnDisconnect
, REQUESTPROC fnRequest
, STOPPROCESSPROC fnDone
, SourceSeeking_ChangeStop stop
, SourceSeeking_ChangeStart start
, SourceSeeking_ChangeRate rate
)
101 /* pTransformFilter is already allocated */
102 BaseFilter_Init(&pParser
->filter
, Parser_Vtbl
, pClsid
, (DWORD_PTR
)(__FILE__
": ParserImpl.csFilter"), &BaseFuncTable
);
104 pParser
->fnDisconnect
= fnDisconnect
;
106 pParser
->cStreams
= 0;
107 pParser
->ppPins
= CoTaskMemAlloc(1 * sizeof(IPin
*));
109 /* construct input pin */
110 piInput
.dir
= PINDIR_INPUT
;
111 piInput
.pFilter
= &pParser
->filter
.IBaseFilter_iface
;
112 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
115 start
= Parser_ChangeStart
;
118 stop
= Parser_ChangeStop
;
121 rate
= Parser_ChangeRate
;
123 SourceSeeking_Init(&pParser
->sourceSeeking
, &Parser_Seeking_Vtbl
, stop
, start
, rate
, &pParser
->filter
.csFilter
);
125 hr
= PullPin_Construct(&Parser_InputPin_Vtbl
, &piInput
, fnProcessSample
, (LPVOID
)pParser
, fnQueryAccept
, fnCleanup
, fnRequest
, fnDone
, &pParser
->filter
.csFilter
, (IPin
**)&pParser
->pInputPin
);
129 pParser
->ppPins
[0] = &pParser
->pInputPin
->pin
.IPin_iface
;
130 pParser
->pInputPin
->fnPreConnect
= fnPreConnect
;
134 CoTaskMemFree(pParser
->ppPins
);
135 BaseFilterImpl_Release(&pParser
->filter
.IBaseFilter_iface
);
136 CoTaskMemFree(pParser
);
142 HRESULT WINAPI
Parser_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
144 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
145 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
149 if ( IsEqualIID(riid
, &IID_IUnknown
)
150 || IsEqualIID(riid
, &IID_IPersist
)
151 || IsEqualIID(riid
, &IID_IMediaFilter
)
152 || IsEqualIID(riid
, &IID_IBaseFilter
) )
153 *ppv
= &This
->filter
.IBaseFilter_iface
;
157 IUnknown_AddRef((IUnknown
*)*ppv
);
161 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
162 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
164 return E_NOINTERFACE
;
167 ULONG WINAPI
Parser_AddRef(IBaseFilter
* iface
)
169 return BaseFilterImpl_AddRef(iface
);
172 void Parser_Destroy(ParserImpl
*This
)
174 IPin
*connected
= NULL
;
178 assert(!This
->filter
.refCount
);
179 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
181 /* Don't need to clean up output pins, freeing input pin will do that */
182 IPin_ConnectedTo(&This
->pInputPin
->pin
.IPin_iface
, &connected
);
185 hr
= IPin_Disconnect(connected
);
187 IPin_Release(connected
);
188 hr
= IPin_Disconnect(&This
->pInputPin
->pin
.IPin_iface
);
191 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
194 /* Valgrind could find this, if I kill it here */
195 ERR("pinref should be null, is %u, destroying anyway\n", pinref
);
196 assert((LONG
)pinref
> 0);
199 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
202 CoTaskMemFree(This
->ppPins
);
203 BaseFilter_Destroy(&This
->filter
);
205 TRACE("Destroying parser\n");
209 ULONG WINAPI
Parser_Release(IBaseFilter
* iface
)
211 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
212 ULONG refCount
= InterlockedDecrement(&This
->filter
.refCount
);
214 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
217 Parser_Destroy(This
);
222 /** IPersist methods **/
224 HRESULT WINAPI
Parser_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
226 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
228 TRACE("%p->(%p)\n", This
, pClsid
);
230 *pClsid
= This
->filter
.clsid
;
235 /** IMediaFilter methods **/
237 HRESULT WINAPI
Parser_Stop(IBaseFilter
* iface
)
239 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
240 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
243 TRACE("%p->()\n", This
);
245 EnterCriticalSection(&pin
->thread_lock
);
247 IAsyncReader_BeginFlush(This
->pInputPin
->pReader
);
248 EnterCriticalSection(&This
->filter
.csFilter
);
250 if (This
->filter
.state
== State_Stopped
)
252 LeaveCriticalSection(&This
->filter
.csFilter
);
253 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
254 LeaveCriticalSection(&pin
->thread_lock
);
258 This
->filter
.state
= State_Stopped
;
260 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
262 BaseOutputPinImpl_Inactive((BaseOutputPin
*)This
->ppPins
[i
]);
265 LeaveCriticalSection(&This
->filter
.csFilter
);
267 PullPin_PauseProcessing(This
->pInputPin
);
268 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
269 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
271 LeaveCriticalSection(&pin
->thread_lock
);
275 HRESULT WINAPI
Parser_Pause(IBaseFilter
* iface
)
278 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
279 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
281 TRACE("%p->()\n", This
);
283 EnterCriticalSection(&pin
->thread_lock
);
284 EnterCriticalSection(&This
->filter
.csFilter
);
286 if (This
->filter
.state
== State_Paused
)
288 LeaveCriticalSection(&This
->filter
.csFilter
);
289 LeaveCriticalSection(&pin
->thread_lock
);
293 if (This
->filter
.state
== State_Stopped
)
295 LeaveCriticalSection(&This
->filter
.csFilter
);
296 hr
= IBaseFilter_Run(iface
, -1);
297 EnterCriticalSection(&This
->filter
.csFilter
);
301 This
->filter
.state
= State_Paused
;
303 LeaveCriticalSection(&This
->filter
.csFilter
);
304 LeaveCriticalSection(&pin
->thread_lock
);
309 HRESULT WINAPI
Parser_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
312 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
313 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
317 TRACE("%p->(%s)\n", This
, wine_dbgstr_longlong(tStart
));
319 EnterCriticalSection(&pin
->thread_lock
);
320 EnterCriticalSection(&This
->filter
.csFilter
);
322 HRESULT hr_any
= VFW_E_NOT_CONNECTED
;
324 This
->filter
.rtStreamStart
= tStart
;
325 if (This
->filter
.state
== State_Running
|| This
->filter
.state
== State_Paused
)
327 This
->filter
.state
= State_Running
;
328 LeaveCriticalSection(&This
->filter
.csFilter
);
329 LeaveCriticalSection(&pin
->thread_lock
);
333 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
335 hr
= BaseOutputPinImpl_Active((BaseOutputPin
*)This
->ppPins
[i
]);
343 LeaveCriticalSection(&This
->filter
.csFilter
);
344 hr
= PullPin_StartProcessing(This
->pInputPin
);
345 EnterCriticalSection(&This
->filter
.csFilter
);
349 This
->filter
.state
= State_Running
;
351 LeaveCriticalSection(&This
->filter
.csFilter
);
352 LeaveCriticalSection(&pin
->thread_lock
);
357 HRESULT WINAPI
Parser_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
359 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
360 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
363 TRACE("%p->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
365 EnterCriticalSection(&pin
->thread_lock
);
366 EnterCriticalSection(&This
->filter
.csFilter
);
368 *pState
= This
->filter
.state
;
370 LeaveCriticalSection(&This
->filter
.csFilter
);
372 if (This
->pInputPin
&& (PullPin_WaitForStateChange(This
->pInputPin
, dwMilliSecsTimeout
) == S_FALSE
))
373 hr
= VFW_S_STATE_INTERMEDIATE
;
374 LeaveCriticalSection(&pin
->thread_lock
);
379 HRESULT WINAPI
Parser_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
381 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
382 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
384 TRACE("%p->(%p)\n", This
, pClock
);
386 EnterCriticalSection(&pin
->thread_lock
);
387 BaseFilterImpl_SetSyncSource(iface
,pClock
);
388 LeaveCriticalSection(&pin
->thread_lock
);
393 HRESULT WINAPI
Parser_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
395 return BaseFilterImpl_GetSyncSource(iface
, ppClock
);
398 /** IBaseFilter implementation **/
400 HRESULT WINAPI
Parser_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
402 return BaseFilterImpl_EnumPins(iface
,ppEnum
);
405 HRESULT WINAPI
Parser_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
407 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
408 FIXME("(%p)->(%s,%p)\n", This
, debugstr_w(Id
), ppPin
);
410 /* FIXME: critical section */
415 HRESULT WINAPI
Parser_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
417 return BaseFilterImpl_QueryFilterInfo(iface
, pInfo
);
420 HRESULT WINAPI
Parser_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
422 return BaseFilterImpl_JoinFilterGraph(iface
, pGraph
, pName
);
425 HRESULT WINAPI
Parser_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
427 return BaseFilterImpl_QueryVendorInfo(iface
, pVendorInfo
);
430 static const BaseOutputPinFuncTable output_BaseOutputFuncTable
= {
432 Parser_OutputPin_CheckMediaType
,
433 BaseOutputPinImpl_AttemptConnection
,
434 BasePinImpl_GetMediaTypeVersion
,
435 Parser_OutputPin_GetMediaType
437 Parser_OutputPin_DecideBufferSize
,
438 Parser_OutputPin_DecideAllocator
,
439 Parser_OutputPin_BreakConnect
442 HRESULT
Parser_AddPin(ParserImpl
* This
, const PIN_INFO
* piOutput
, ALLOCATOR_PROPERTIES
* props
, const AM_MEDIA_TYPE
* amt
)
447 ppOldPins
= This
->ppPins
;
449 This
->ppPins
= CoTaskMemAlloc((This
->cStreams
+ 2) * sizeof(IPin
*));
450 memcpy(This
->ppPins
, ppOldPins
, (This
->cStreams
+ 1) * sizeof(IPin
*));
452 hr
= BaseOutputPin_Construct(&Parser_OutputPin_Vtbl
, sizeof(Parser_OutputPin
), piOutput
, &output_BaseOutputFuncTable
, &This
->filter
.csFilter
, This
->ppPins
+ (This
->cStreams
+ 1));
456 IPin
*pPin
= This
->ppPins
[This
->cStreams
+ 1];
457 Parser_OutputPin
*pin
= unsafe_impl_Parser_OutputPin_from_IPin(pPin
);
458 pin
->pmt
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
459 CopyMediaType(pin
->pmt
, amt
);
460 pin
->dwSamplesProcessed
= 0;
462 pin
->pin
.pin
.pinInfo
.pFilter
= &This
->filter
.IBaseFilter_iface
;
463 pin
->allocProps
= *props
;
465 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
466 CoTaskMemFree(ppOldPins
);
470 CoTaskMemFree(This
->ppPins
);
471 This
->ppPins
= ppOldPins
;
472 ERR("Failed with error %x\n", hr
);
478 static HRESULT
Parser_RemoveOutputPins(ParserImpl
* This
)
480 /* NOTE: should be in critical section when calling this function */
483 IPin
** ppOldPins
= This
->ppPins
;
485 TRACE("(%p)\n", This
);
487 /* reduce the pin array down to 1 (just our input pin) */
488 This
->ppPins
= CoTaskMemAlloc(sizeof(IPin
*) * 1);
489 memcpy(This
->ppPins
, ppOldPins
, sizeof(IPin
*) * 1);
491 for (i
= 0; i
< This
->cStreams
; i
++)
493 hr
= ((BaseOutputPin
*)ppOldPins
[i
+ 1])->pFuncsTable
->pfnBreakConnect((BaseOutputPin
*)ppOldPins
[i
+ 1]);
494 TRACE("Disconnect: %08x\n", hr
);
495 IPin_Release(ppOldPins
[i
+ 1]);
498 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
500 CoTaskMemFree(ppOldPins
);
505 static HRESULT WINAPI
Parser_ChangeStart(IMediaSeeking
*iface
)
507 FIXME("(%p) filter hasn't implemented start position change!\n", iface
);
511 static HRESULT WINAPI
Parser_ChangeStop(IMediaSeeking
*iface
)
513 FIXME("(%p) filter hasn't implemented stop position change!\n", iface
);
517 static HRESULT WINAPI
Parser_ChangeRate(IMediaSeeking
*iface
)
519 FIXME("(%p) filter hasn't implemented rate change!\n", iface
);
524 static HRESULT WINAPI
Parser_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
526 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
528 return IBaseFilter_QueryInterface(&This
->filter
.IBaseFilter_iface
, riid
, ppv
);
531 static ULONG WINAPI
Parser_Seeking_AddRef(IMediaSeeking
* iface
)
533 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
535 return IBaseFilter_AddRef(&This
->filter
.IBaseFilter_iface
);
538 static ULONG WINAPI
Parser_Seeking_Release(IMediaSeeking
* iface
)
540 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
542 return IBaseFilter_Release(&This
->filter
.IBaseFilter_iface
);
545 static const IMediaSeekingVtbl Parser_Seeking_Vtbl
=
547 Parser_Seeking_QueryInterface
,
548 Parser_Seeking_AddRef
,
549 Parser_Seeking_Release
,
550 SourceSeekingImpl_GetCapabilities
,
551 SourceSeekingImpl_CheckCapabilities
,
552 SourceSeekingImpl_IsFormatSupported
,
553 SourceSeekingImpl_QueryPreferredFormat
,
554 SourceSeekingImpl_GetTimeFormat
,
555 SourceSeekingImpl_IsUsingTimeFormat
,
556 SourceSeekingImpl_SetTimeFormat
,
557 SourceSeekingImpl_GetDuration
,
558 SourceSeekingImpl_GetStopPosition
,
559 SourceSeekingImpl_GetCurrentPosition
,
560 SourceSeekingImpl_ConvertTimeFormat
,
561 SourceSeekingImpl_SetPositions
,
562 SourceSeekingImpl_GetPositions
,
563 SourceSeekingImpl_GetAvailable
,
564 SourceSeekingImpl_SetRate
,
565 SourceSeekingImpl_GetRate
,
566 SourceSeekingImpl_GetPreroll
569 static HRESULT WINAPI
Parser_OutputPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
)
571 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
572 ALLOCATOR_PROPERTIES actual
;
574 if (ppropInputRequest
->cbAlign
&& ppropInputRequest
->cbAlign
!= This
->allocProps
.cbAlign
)
575 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This
->allocProps
.cbAlign
, ppropInputRequest
->cbAlign
);
576 if (ppropInputRequest
->cbPrefix
)
577 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This
->allocProps
.cbPrefix
, ppropInputRequest
->cbPrefix
);
578 if (ppropInputRequest
->cbBuffer
)
579 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This
->allocProps
.cbBuffer
, ppropInputRequest
->cbBuffer
);
580 if (ppropInputRequest
->cBuffers
)
581 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This
->allocProps
.cBuffers
, ppropInputRequest
->cBuffers
);
583 return IMemAllocator_SetProperties(pAlloc
, &This
->allocProps
, &actual
);
586 static HRESULT WINAPI
Parser_OutputPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
)
588 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
592 return VFW_S_NO_MORE_ITEMS
;
593 CopyMediaType(pmt
, This
->pmt
);
597 static HRESULT WINAPI
Parser_OutputPin_DecideAllocator(BaseOutputPin
*iface
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
)
599 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
606 hr
= IMemInputPin_NotifyAllocator(pPin
, This
->alloc
, This
->readonly
);
609 *pAlloc
= This
->alloc
;
610 IMemAllocator_AddRef(*pAlloc
);
614 hr
= VFW_E_NO_ALLOCATOR
;
619 static HRESULT WINAPI
Parser_OutputPin_BreakConnect(BaseOutputPin
*This
)
623 TRACE("(%p)->()\n", This
);
625 EnterCriticalSection(This
->pin
.pCritSec
);
626 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
627 hr
= VFW_E_NOT_CONNECTED
;
630 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
631 IPin_Disconnect(&This
->pin
.IPin_iface
);
633 LeaveCriticalSection(This
->pin
.pCritSec
);
639 static HRESULT WINAPI
Parser_OutputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
641 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
643 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
647 if (IsEqualIID(riid
, &IID_IUnknown
))
649 else if (IsEqualIID(riid
, &IID_IPin
))
651 /* The Parser filter does not support querying IMediaSeeking, return it directly */
652 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
653 *ppv
= &impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
)->sourceSeeking
;
657 IUnknown_AddRef((IUnknown
*)(*ppv
));
661 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
663 return E_NOINTERFACE
;
666 static ULONG WINAPI
Parser_OutputPin_Release(IPin
* iface
)
668 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
669 ULONG refCount
= InterlockedDecrement(&This
->pin
.pin
.refCount
);
671 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
675 FreeMediaType(This
->pmt
);
676 CoTaskMemFree(This
->pmt
);
677 FreeMediaType(&This
->pin
.pin
.mtCurrent
);
678 if (This
->pin
.pAllocator
)
679 IMemAllocator_Release(This
->pin
.pAllocator
);
686 static HRESULT WINAPI
Parser_OutputPin_Connect(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
688 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
689 ParserImpl
*parser
= impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
);
691 /* Set the allocator to our input pin's */
692 EnterCriticalSection(This
->pin
.pin
.pCritSec
);
693 This
->alloc
= parser
->pInputPin
->pAlloc
;
694 LeaveCriticalSection(This
->pin
.pin
.pCritSec
);
696 return BaseOutputPinImpl_Connect(iface
, pReceivePin
, pmt
);
699 static HRESULT WINAPI
Parser_OutputPin_CheckMediaType(BasePin
*pin
, const AM_MEDIA_TYPE
*pmt
)
701 Parser_OutputPin
*This
= (Parser_OutputPin
*)pin
;
703 dump_AM_MEDIA_TYPE(pmt
);
705 return (memcmp(This
->pmt
, pmt
, sizeof(AM_MEDIA_TYPE
)) == 0);
708 static const IPinVtbl Parser_OutputPin_Vtbl
=
710 Parser_OutputPin_QueryInterface
,
712 Parser_OutputPin_Release
,
713 Parser_OutputPin_Connect
,
714 BaseOutputPinImpl_ReceiveConnection
,
715 BaseOutputPinImpl_Disconnect
,
716 BasePinImpl_ConnectedTo
,
717 BasePinImpl_ConnectionMediaType
,
718 BasePinImpl_QueryPinInfo
,
719 BasePinImpl_QueryDirection
,
721 BasePinImpl_QueryAccept
,
722 BasePinImpl_EnumMediaTypes
,
723 BasePinImpl_QueryInternalConnections
,
724 BaseOutputPinImpl_EndOfStream
,
725 BaseOutputPinImpl_BeginFlush
,
726 BaseOutputPinImpl_EndFlush
,
727 BasePinImpl_NewSegment
730 static HRESULT WINAPI
Parser_PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
732 PullPin
*This
= impl_PullPin_from_IPin(iface
);
734 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
739 * It is important to capture the request for the IMediaSeeking interface before it is passed
740 * on to PullPin_QueryInterface, this is necessary since the Parser filter does not support
741 * querying IMediaSeeking
743 if (IsEqualIID(riid
, &IID_IMediaSeeking
))
744 *ppv
= &impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
)->sourceSeeking
;
748 IUnknown_AddRef((IUnknown
*)(*ppv
));
752 return PullPin_QueryInterface(iface
, riid
, ppv
);
755 static HRESULT WINAPI
Parser_PullPin_Disconnect(IPin
* iface
)
758 PullPin
*This
= impl_PullPin_from_IPin(iface
);
762 EnterCriticalSection(&This
->thread_lock
);
763 EnterCriticalSection(This
->pin
.pCritSec
);
765 if (This
->pin
.pConnectedTo
)
768 ParserImpl
*Parser
= impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
);
770 LeaveCriticalSection(This
->pin
.pCritSec
);
771 hr
= IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
772 EnterCriticalSection(This
->pin
.pCritSec
);
774 if (SUCCEEDED(hr
) && (state
== State_Stopped
) && SUCCEEDED(Parser
->fnDisconnect(Parser
)))
776 LeaveCriticalSection(This
->pin
.pCritSec
);
777 PullPin_Disconnect(iface
);
778 EnterCriticalSection(This
->pin
.pCritSec
);
779 hr
= Parser_RemoveOutputPins(impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
));
782 hr
= VFW_E_NOT_STOPPED
;
787 LeaveCriticalSection(This
->pin
.pCritSec
);
788 LeaveCriticalSection(&This
->thread_lock
);
793 static HRESULT WINAPI
Parser_PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
799 hr
= PullPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
802 BasePin
*This
= (BasePin
*)iface
;
804 EnterCriticalSection(This
->pCritSec
);
805 Parser_RemoveOutputPins(impl_from_IBaseFilter(This
->pinInfo
.pFilter
));
806 LeaveCriticalSection(This
->pCritSec
);
812 static HRESULT WINAPI
Parser_PullPin_EnumMediaTypes(IPin
*iface
, IEnumMediaTypes
**ppEnum
)
814 BasePin
*This
= (BasePin
*)iface
;
816 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
818 return EnumMediaTypes_Construct(This
, BasePinImpl_GetMediaType
, BasePinImpl_GetMediaTypeVersion
, ppEnum
);
821 static const IPinVtbl Parser_InputPin_Vtbl
=
823 Parser_PullPin_QueryInterface
,
826 BaseInputPinImpl_Connect
,
827 Parser_PullPin_ReceiveConnection
,
828 Parser_PullPin_Disconnect
,
829 BasePinImpl_ConnectedTo
,
830 BasePinImpl_ConnectionMediaType
,
831 BasePinImpl_QueryPinInfo
,
832 BasePinImpl_QueryDirection
,
835 Parser_PullPin_EnumMediaTypes
,
836 BasePinImpl_QueryInternalConnections
,