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_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
);
48 static HRESULT WINAPI
Parser_OutputPin_DecideAllocator(BaseOutputPin
*This
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
);
49 static HRESULT WINAPI
Parser_OutputPin_BreakConnect(BaseOutputPin
*This
);
51 static inline ParserImpl
*impl_from_IMediaSeeking( IMediaSeeking
*iface
)
53 return CONTAINING_RECORD(iface
, ParserImpl
, sourceSeeking
.IMediaSeeking_iface
);
56 static inline ParserImpl
*impl_from_IBaseFilter( IBaseFilter
*iface
)
58 return CONTAINING_RECORD(iface
, ParserImpl
, filter
.IBaseFilter_iface
);
61 static inline ParserImpl
*impl_from_BaseFilter( BaseFilter
*iface
)
63 return CONTAINING_RECORD(iface
, ParserImpl
, filter
);
67 static IPin
* WINAPI
Parser_GetPin(BaseFilter
*iface
, int pos
)
69 ParserImpl
*This
= impl_from_BaseFilter(iface
);
71 TRACE("%p->(%x)\n", This
, pos
);
73 /* Input pin also has a pin, hence the > and not >= */
74 if (pos
> This
->cStreams
|| pos
< 0)
77 IPin_AddRef(This
->ppPins
[pos
]);
78 return This
->ppPins
[pos
];
81 static LONG WINAPI
Parser_GetPinCount(BaseFilter
*iface
)
83 ParserImpl
*This
= impl_from_BaseFilter(iface
);
85 TRACE("%p->()\n", This
);
87 return This
->cStreams
;
90 static const BaseFilterFuncTable BaseFuncTable
= {
95 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
)
100 /* pTransformFilter is already allocated */
101 BaseFilter_Init(&pParser
->filter
, Parser_Vtbl
, pClsid
, (DWORD_PTR
)(__FILE__
": ParserImpl.csFilter"), &BaseFuncTable
);
103 pParser
->fnDisconnect
= fnDisconnect
;
105 pParser
->cStreams
= 0;
106 pParser
->ppPins
= CoTaskMemAlloc(1 * sizeof(IPin
*));
108 /* construct input pin */
109 piInput
.dir
= PINDIR_INPUT
;
110 piInput
.pFilter
= &pParser
->filter
.IBaseFilter_iface
;
111 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
114 start
= Parser_ChangeStart
;
117 stop
= Parser_ChangeStop
;
120 rate
= Parser_ChangeRate
;
122 SourceSeeking_Init(&pParser
->sourceSeeking
, &Parser_Seeking_Vtbl
, stop
, start
, rate
, &pParser
->filter
.csFilter
);
124 hr
= PullPin_Construct(&Parser_InputPin_Vtbl
, &piInput
, fnProcessSample
, (LPVOID
)pParser
, fnQueryAccept
, fnCleanup
, fnRequest
, fnDone
, &pParser
->filter
.csFilter
, (IPin
**)&pParser
->pInputPin
);
128 pParser
->ppPins
[0] = &pParser
->pInputPin
->pin
.IPin_iface
;
129 pParser
->pInputPin
->fnPreConnect
= fnPreConnect
;
133 CoTaskMemFree(pParser
->ppPins
);
134 BaseFilterImpl_Release(&pParser
->filter
.IBaseFilter_iface
);
135 CoTaskMemFree(pParser
);
141 HRESULT WINAPI
Parser_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
143 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
144 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
148 if ( IsEqualIID(riid
, &IID_IUnknown
)
149 || IsEqualIID(riid
, &IID_IPersist
)
150 || IsEqualIID(riid
, &IID_IMediaFilter
)
151 || IsEqualIID(riid
, &IID_IBaseFilter
) )
152 *ppv
= &This
->filter
.IBaseFilter_iface
;
156 IUnknown_AddRef((IUnknown
*)*ppv
);
160 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
161 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
163 return E_NOINTERFACE
;
166 ULONG WINAPI
Parser_AddRef(IBaseFilter
* iface
)
168 return BaseFilterImpl_AddRef(iface
);
171 void Parser_Destroy(ParserImpl
*This
)
173 IPin
*connected
= NULL
;
177 assert(!This
->filter
.refCount
);
178 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
180 /* Don't need to clean up output pins, freeing input pin will do that */
181 IPin_ConnectedTo(&This
->pInputPin
->pin
.IPin_iface
, &connected
);
184 hr
= IPin_Disconnect(connected
);
186 IPin_Release(connected
);
187 hr
= IPin_Disconnect(&This
->pInputPin
->pin
.IPin_iface
);
190 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
193 /* Valgrind could find this, if I kill it here */
194 ERR("pinref should be null, is %u, destroying anyway\n", pinref
);
195 assert((LONG
)pinref
> 0);
198 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
201 CoTaskMemFree(This
->ppPins
);
202 BaseFilter_Destroy(&This
->filter
);
204 TRACE("Destroying parser\n");
208 ULONG WINAPI
Parser_Release(IBaseFilter
* iface
)
210 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
211 ULONG refCount
= InterlockedDecrement(&This
->filter
.refCount
);
213 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
216 Parser_Destroy(This
);
221 /** IPersist methods **/
223 HRESULT WINAPI
Parser_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
225 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
227 TRACE("%p->(%p)\n", This
, pClsid
);
229 *pClsid
= This
->filter
.clsid
;
234 /** IMediaFilter methods **/
236 HRESULT WINAPI
Parser_Stop(IBaseFilter
* iface
)
238 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
239 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
242 TRACE("%p->()\n", This
);
244 EnterCriticalSection(&pin
->thread_lock
);
246 IAsyncReader_BeginFlush(This
->pInputPin
->pReader
);
247 EnterCriticalSection(&This
->filter
.csFilter
);
249 if (This
->filter
.state
== State_Stopped
)
251 LeaveCriticalSection(&This
->filter
.csFilter
);
252 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
253 LeaveCriticalSection(&pin
->thread_lock
);
257 This
->filter
.state
= State_Stopped
;
259 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
261 BaseOutputPinImpl_Inactive((BaseOutputPin
*)This
->ppPins
[i
]);
264 LeaveCriticalSection(&This
->filter
.csFilter
);
266 PullPin_PauseProcessing(This
->pInputPin
);
267 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
268 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
270 LeaveCriticalSection(&pin
->thread_lock
);
274 HRESULT WINAPI
Parser_Pause(IBaseFilter
* iface
)
277 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
278 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
280 TRACE("%p->()\n", This
);
282 EnterCriticalSection(&pin
->thread_lock
);
283 EnterCriticalSection(&This
->filter
.csFilter
);
285 if (This
->filter
.state
== State_Paused
)
287 LeaveCriticalSection(&This
->filter
.csFilter
);
288 LeaveCriticalSection(&pin
->thread_lock
);
292 if (This
->filter
.state
== State_Stopped
)
294 LeaveCriticalSection(&This
->filter
.csFilter
);
295 hr
= IBaseFilter_Run(iface
, -1);
296 EnterCriticalSection(&This
->filter
.csFilter
);
300 This
->filter
.state
= State_Paused
;
302 LeaveCriticalSection(&This
->filter
.csFilter
);
303 LeaveCriticalSection(&pin
->thread_lock
);
308 HRESULT WINAPI
Parser_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
311 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
312 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
316 TRACE("%p->(%s)\n", This
, wine_dbgstr_longlong(tStart
));
318 EnterCriticalSection(&pin
->thread_lock
);
319 EnterCriticalSection(&This
->filter
.csFilter
);
321 HRESULT hr_any
= VFW_E_NOT_CONNECTED
;
323 This
->filter
.rtStreamStart
= tStart
;
324 if (This
->filter
.state
== State_Running
|| This
->filter
.state
== State_Paused
)
326 This
->filter
.state
= State_Running
;
327 LeaveCriticalSection(&This
->filter
.csFilter
);
328 LeaveCriticalSection(&pin
->thread_lock
);
332 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
334 hr
= BaseOutputPinImpl_Active((BaseOutputPin
*)This
->ppPins
[i
]);
342 LeaveCriticalSection(&This
->filter
.csFilter
);
343 hr
= PullPin_StartProcessing(This
->pInputPin
);
344 EnterCriticalSection(&This
->filter
.csFilter
);
348 This
->filter
.state
= State_Running
;
350 LeaveCriticalSection(&This
->filter
.csFilter
);
351 LeaveCriticalSection(&pin
->thread_lock
);
356 HRESULT WINAPI
Parser_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
358 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
359 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
362 TRACE("%p->(%d, %p)\n", This
, dwMilliSecsTimeout
, pState
);
364 EnterCriticalSection(&pin
->thread_lock
);
365 EnterCriticalSection(&This
->filter
.csFilter
);
367 *pState
= This
->filter
.state
;
369 LeaveCriticalSection(&This
->filter
.csFilter
);
371 if (This
->pInputPin
&& (PullPin_WaitForStateChange(This
->pInputPin
, dwMilliSecsTimeout
) == S_FALSE
))
372 hr
= VFW_S_STATE_INTERMEDIATE
;
373 LeaveCriticalSection(&pin
->thread_lock
);
378 HRESULT WINAPI
Parser_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
380 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
381 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
383 TRACE("%p->(%p)\n", This
, pClock
);
385 EnterCriticalSection(&pin
->thread_lock
);
386 BaseFilterImpl_SetSyncSource(iface
,pClock
);
387 LeaveCriticalSection(&pin
->thread_lock
);
392 HRESULT WINAPI
Parser_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
394 return BaseFilterImpl_GetSyncSource(iface
, ppClock
);
397 /** IBaseFilter implementation **/
399 HRESULT WINAPI
Parser_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
401 return BaseFilterImpl_EnumPins(iface
,ppEnum
);
404 HRESULT WINAPI
Parser_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
406 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
407 FIXME("(%p)->(%s,%p)\n", This
, debugstr_w(Id
), ppPin
);
409 /* FIXME: critical section */
414 HRESULT WINAPI
Parser_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
416 return BaseFilterImpl_QueryFilterInfo(iface
, pInfo
);
419 HRESULT WINAPI
Parser_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
421 return BaseFilterImpl_JoinFilterGraph(iface
, pGraph
, pName
);
424 HRESULT WINAPI
Parser_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
426 return BaseFilterImpl_QueryVendorInfo(iface
, pVendorInfo
);
429 static const BaseOutputPinFuncTable output_BaseOutputFuncTable
= {
432 BaseOutputPinImpl_AttemptConnection
,
433 BasePinImpl_GetMediaTypeVersion
,
434 Parser_OutputPin_GetMediaType
436 Parser_OutputPin_DecideBufferSize
,
437 Parser_OutputPin_DecideAllocator
,
438 Parser_OutputPin_BreakConnect
441 HRESULT
Parser_AddPin(ParserImpl
* This
, const PIN_INFO
* piOutput
, ALLOCATOR_PROPERTIES
* props
, const AM_MEDIA_TYPE
* amt
)
446 ppOldPins
= This
->ppPins
;
448 This
->ppPins
= CoTaskMemAlloc((This
->cStreams
+ 2) * sizeof(IPin
*));
449 memcpy(This
->ppPins
, ppOldPins
, (This
->cStreams
+ 1) * sizeof(IPin
*));
451 hr
= BaseOutputPin_Construct(&Parser_OutputPin_Vtbl
, sizeof(Parser_OutputPin
), piOutput
, &output_BaseOutputFuncTable
, &This
->filter
.csFilter
, This
->ppPins
+ (This
->cStreams
+ 1));
455 IPin
*pPin
= This
->ppPins
[This
->cStreams
+ 1];
456 Parser_OutputPin
*pin
= unsafe_impl_Parser_OutputPin_from_IPin(pPin
);
457 pin
->pmt
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
458 CopyMediaType(pin
->pmt
, amt
);
459 pin
->dwSamplesProcessed
= 0;
461 pin
->pin
.pin
.pinInfo
.pFilter
= &This
->filter
.IBaseFilter_iface
;
462 pin
->allocProps
= *props
;
464 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
465 CoTaskMemFree(ppOldPins
);
469 CoTaskMemFree(This
->ppPins
);
470 This
->ppPins
= ppOldPins
;
471 ERR("Failed with error %x\n", hr
);
477 static HRESULT
Parser_RemoveOutputPins(ParserImpl
* This
)
479 /* NOTE: should be in critical section when calling this function */
482 IPin
** ppOldPins
= This
->ppPins
;
484 TRACE("(%p)\n", This
);
486 /* reduce the pin array down to 1 (just our input pin) */
487 This
->ppPins
= CoTaskMemAlloc(sizeof(IPin
*) * 1);
488 memcpy(This
->ppPins
, ppOldPins
, sizeof(IPin
*) * 1);
490 for (i
= 0; i
< This
->cStreams
; i
++)
492 hr
= ((BaseOutputPin
*)ppOldPins
[i
+ 1])->pFuncsTable
->pfnBreakConnect((BaseOutputPin
*)ppOldPins
[i
+ 1]);
493 TRACE("Disconnect: %08x\n", hr
);
494 IPin_Release(ppOldPins
[i
+ 1]);
497 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
499 CoTaskMemFree(ppOldPins
);
504 static HRESULT WINAPI
Parser_ChangeStart(IMediaSeeking
*iface
)
506 FIXME("(%p) filter hasn't implemented start position change!\n", iface
);
510 static HRESULT WINAPI
Parser_ChangeStop(IMediaSeeking
*iface
)
512 FIXME("(%p) filter hasn't implemented stop position change!\n", iface
);
516 static HRESULT WINAPI
Parser_ChangeRate(IMediaSeeking
*iface
)
518 FIXME("(%p) filter hasn't implemented rate change!\n", iface
);
523 static HRESULT WINAPI
Parser_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
525 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
527 return IBaseFilter_QueryInterface(&This
->filter
.IBaseFilter_iface
, riid
, ppv
);
530 static ULONG WINAPI
Parser_Seeking_AddRef(IMediaSeeking
* iface
)
532 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
534 return IBaseFilter_AddRef(&This
->filter
.IBaseFilter_iface
);
537 static ULONG WINAPI
Parser_Seeking_Release(IMediaSeeking
* iface
)
539 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
541 return IBaseFilter_Release(&This
->filter
.IBaseFilter_iface
);
544 static const IMediaSeekingVtbl Parser_Seeking_Vtbl
=
546 Parser_Seeking_QueryInterface
,
547 Parser_Seeking_AddRef
,
548 Parser_Seeking_Release
,
549 SourceSeekingImpl_GetCapabilities
,
550 SourceSeekingImpl_CheckCapabilities
,
551 SourceSeekingImpl_IsFormatSupported
,
552 SourceSeekingImpl_QueryPreferredFormat
,
553 SourceSeekingImpl_GetTimeFormat
,
554 SourceSeekingImpl_IsUsingTimeFormat
,
555 SourceSeekingImpl_SetTimeFormat
,
556 SourceSeekingImpl_GetDuration
,
557 SourceSeekingImpl_GetStopPosition
,
558 SourceSeekingImpl_GetCurrentPosition
,
559 SourceSeekingImpl_ConvertTimeFormat
,
560 SourceSeekingImpl_SetPositions
,
561 SourceSeekingImpl_GetPositions
,
562 SourceSeekingImpl_GetAvailable
,
563 SourceSeekingImpl_SetRate
,
564 SourceSeekingImpl_GetRate
,
565 SourceSeekingImpl_GetPreroll
568 static HRESULT WINAPI
Parser_OutputPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
)
570 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
571 ALLOCATOR_PROPERTIES actual
;
573 if (ppropInputRequest
->cbAlign
&& ppropInputRequest
->cbAlign
!= This
->allocProps
.cbAlign
)
574 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This
->allocProps
.cbAlign
, ppropInputRequest
->cbAlign
);
575 if (ppropInputRequest
->cbPrefix
)
576 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This
->allocProps
.cbPrefix
, ppropInputRequest
->cbPrefix
);
577 if (ppropInputRequest
->cbBuffer
)
578 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This
->allocProps
.cbBuffer
, ppropInputRequest
->cbBuffer
);
579 if (ppropInputRequest
->cBuffers
)
580 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This
->allocProps
.cBuffers
, ppropInputRequest
->cBuffers
);
582 return IMemAllocator_SetProperties(pAlloc
, &This
->allocProps
, &actual
);
585 static HRESULT WINAPI
Parser_OutputPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
)
587 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
591 return VFW_S_NO_MORE_ITEMS
;
592 CopyMediaType(pmt
, This
->pmt
);
596 static HRESULT WINAPI
Parser_OutputPin_DecideAllocator(BaseOutputPin
*iface
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
)
598 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
605 hr
= IMemInputPin_NotifyAllocator(pPin
, This
->alloc
, This
->readonly
);
608 *pAlloc
= This
->alloc
;
609 IMemAllocator_AddRef(*pAlloc
);
613 hr
= VFW_E_NO_ALLOCATOR
;
618 static HRESULT WINAPI
Parser_OutputPin_BreakConnect(BaseOutputPin
*This
)
622 TRACE("(%p)->()\n", This
);
624 EnterCriticalSection(This
->pin
.pCritSec
);
625 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
626 hr
= VFW_E_NOT_CONNECTED
;
629 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
630 IPin_Disconnect(&This
->pin
.IPin_iface
);
632 LeaveCriticalSection(This
->pin
.pCritSec
);
638 static HRESULT WINAPI
Parser_OutputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
640 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
642 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
646 if (IsEqualIID(riid
, &IID_IUnknown
))
648 else if (IsEqualIID(riid
, &IID_IPin
))
650 /* The Parser filter does not support querying IMediaSeeking, return it directly */
651 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
652 *ppv
= &impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
)->sourceSeeking
;
656 IUnknown_AddRef((IUnknown
*)(*ppv
));
660 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
662 return E_NOINTERFACE
;
665 static ULONG WINAPI
Parser_OutputPin_Release(IPin
* iface
)
667 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
668 ULONG refCount
= InterlockedDecrement(&This
->pin
.pin
.refCount
);
670 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
674 FreeMediaType(This
->pmt
);
675 CoTaskMemFree(This
->pmt
);
676 FreeMediaType(&This
->pin
.pin
.mtCurrent
);
677 if (This
->pin
.pAllocator
)
678 IMemAllocator_Release(This
->pin
.pAllocator
);
685 static HRESULT WINAPI
Parser_OutputPin_Connect(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
687 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
688 ParserImpl
*parser
= impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
);
690 /* Set the allocator to our input pin's */
691 EnterCriticalSection(This
->pin
.pin
.pCritSec
);
692 This
->alloc
= parser
->pInputPin
->pAlloc
;
693 LeaveCriticalSection(This
->pin
.pin
.pCritSec
);
695 return BaseOutputPinImpl_Connect(iface
, pReceivePin
, pmt
);
698 static HRESULT WINAPI
Parser_OutputPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
* pmt
)
700 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
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 Parser_OutputPin_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
,