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("Asking for pos %x\n", 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 return This
->cStreams
;
88 static const BaseFilterFuncTable BaseFuncTable
= {
93 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
)
98 /* pTransformFilter is already allocated */
99 BaseFilter_Init(&pParser
->filter
, Parser_Vtbl
, pClsid
, (DWORD_PTR
)(__FILE__
": ParserImpl.csFilter"), &BaseFuncTable
);
101 pParser
->fnDisconnect
= fnDisconnect
;
103 pParser
->cStreams
= 0;
104 pParser
->ppPins
= CoTaskMemAlloc(1 * sizeof(IPin
*));
106 /* construct input pin */
107 piInput
.dir
= PINDIR_INPUT
;
108 piInput
.pFilter
= &pParser
->filter
.IBaseFilter_iface
;
109 lstrcpynW(piInput
.achName
, wcsInputPinName
, sizeof(piInput
.achName
) / sizeof(piInput
.achName
[0]));
112 start
= Parser_ChangeStart
;
115 stop
= Parser_ChangeStop
;
118 rate
= Parser_ChangeRate
;
120 SourceSeeking_Init(&pParser
->sourceSeeking
, &Parser_Seeking_Vtbl
, stop
, start
, rate
, &pParser
->filter
.csFilter
);
122 hr
= PullPin_Construct(&Parser_InputPin_Vtbl
, &piInput
, fnProcessSample
, (LPVOID
)pParser
, fnQueryAccept
, fnCleanup
, fnRequest
, fnDone
, &pParser
->filter
.csFilter
, (IPin
**)&pParser
->pInputPin
);
126 pParser
->ppPins
[0] = &pParser
->pInputPin
->pin
.IPin_iface
;
127 pParser
->pInputPin
->fnPreConnect
= fnPreConnect
;
131 CoTaskMemFree(pParser
->ppPins
);
132 BaseFilterImpl_Release(&pParser
->filter
.IBaseFilter_iface
);
133 CoTaskMemFree(pParser
);
139 HRESULT WINAPI
Parser_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
141 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
142 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
146 if ( IsEqualIID(riid
, &IID_IUnknown
)
147 || IsEqualIID(riid
, &IID_IPersist
)
148 || IsEqualIID(riid
, &IID_IMediaFilter
)
149 || IsEqualIID(riid
, &IID_IBaseFilter
) )
154 IUnknown_AddRef((IUnknown
*)(*ppv
));
158 if (!IsEqualIID(riid
, &IID_IPin
) && !IsEqualIID(riid
, &IID_IVideoWindow
))
159 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
161 return E_NOINTERFACE
;
164 ULONG WINAPI
Parser_AddRef(IBaseFilter
* iface
)
166 return BaseFilterImpl_AddRef(iface
);
169 void Parser_Destroy(ParserImpl
*This
)
171 IPin
*connected
= NULL
;
175 assert(!This
->filter
.refCount
);
176 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
178 /* Don't need to clean up output pins, freeing input pin will do that */
179 IPin_ConnectedTo(&This
->pInputPin
->pin
.IPin_iface
, &connected
);
182 hr
= IPin_Disconnect(connected
);
184 IPin_Release(connected
);
185 hr
= IPin_Disconnect(&This
->pInputPin
->pin
.IPin_iface
);
188 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
191 /* Valgrind could find this, if I kill it here */
192 ERR("pinref should be null, is %u, destroying anyway\n", pinref
);
193 assert((LONG
)pinref
> 0);
196 pinref
= IPin_Release(&This
->pInputPin
->pin
.IPin_iface
);
199 CoTaskMemFree(This
->ppPins
);
200 BaseFilter_Destroy(&This
->filter
);
202 TRACE("Destroying parser\n");
206 ULONG WINAPI
Parser_Release(IBaseFilter
* iface
)
208 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
209 ULONG refCount
= InterlockedDecrement(&This
->filter
.refCount
);
211 TRACE("(%p)->() Release from %d\n", This
, refCount
+ 1);
214 Parser_Destroy(This
);
219 /** IPersist methods **/
221 HRESULT WINAPI
Parser_GetClassID(IBaseFilter
* iface
, CLSID
* pClsid
)
223 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
225 TRACE("(%p)\n", pClsid
);
227 *pClsid
= This
->filter
.clsid
;
232 /** IMediaFilter methods **/
234 HRESULT WINAPI
Parser_Stop(IBaseFilter
* iface
)
236 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
237 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
242 EnterCriticalSection(&pin
->thread_lock
);
244 IAsyncReader_BeginFlush(This
->pInputPin
->pReader
);
245 EnterCriticalSection(&This
->filter
.csFilter
);
247 if (This
->filter
.state
== State_Stopped
)
249 LeaveCriticalSection(&This
->filter
.csFilter
);
250 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
251 LeaveCriticalSection(&pin
->thread_lock
);
255 This
->filter
.state
= State_Stopped
;
257 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
259 BaseOutputPinImpl_Inactive((BaseOutputPin
*)This
->ppPins
[i
]);
262 LeaveCriticalSection(&This
->filter
.csFilter
);
264 PullPin_PauseProcessing(This
->pInputPin
);
265 PullPin_WaitForStateChange(This
->pInputPin
, INFINITE
);
266 IAsyncReader_EndFlush(This
->pInputPin
->pReader
);
268 LeaveCriticalSection(&pin
->thread_lock
);
272 HRESULT WINAPI
Parser_Pause(IBaseFilter
* iface
)
275 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
276 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
280 EnterCriticalSection(&pin
->thread_lock
);
281 EnterCriticalSection(&This
->filter
.csFilter
);
283 if (This
->filter
.state
== State_Paused
)
285 LeaveCriticalSection(&This
->filter
.csFilter
);
286 LeaveCriticalSection(&pin
->thread_lock
);
290 if (This
->filter
.state
== State_Stopped
)
292 LeaveCriticalSection(&This
->filter
.csFilter
);
293 hr
= IBaseFilter_Run(iface
, -1);
294 EnterCriticalSection(&This
->filter
.csFilter
);
298 This
->filter
.state
= State_Paused
;
300 LeaveCriticalSection(&This
->filter
.csFilter
);
301 LeaveCriticalSection(&pin
->thread_lock
);
306 HRESULT WINAPI
Parser_Run(IBaseFilter
* iface
, REFERENCE_TIME tStart
)
309 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
310 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
314 TRACE("(%s)\n", wine_dbgstr_longlong(tStart
));
316 EnterCriticalSection(&pin
->thread_lock
);
317 EnterCriticalSection(&This
->filter
.csFilter
);
319 HRESULT hr_any
= VFW_E_NOT_CONNECTED
;
321 This
->filter
.rtStreamStart
= tStart
;
322 if (This
->filter
.state
== State_Running
|| This
->filter
.state
== State_Paused
)
324 This
->filter
.state
= State_Running
;
325 LeaveCriticalSection(&This
->filter
.csFilter
);
326 LeaveCriticalSection(&pin
->thread_lock
);
330 for (i
= 1; i
< (This
->cStreams
+ 1); i
++)
332 hr
= BaseOutputPinImpl_Active((BaseOutputPin
*)This
->ppPins
[i
]);
340 LeaveCriticalSection(&This
->filter
.csFilter
);
341 hr
= PullPin_StartProcessing(This
->pInputPin
);
342 EnterCriticalSection(&This
->filter
.csFilter
);
346 This
->filter
.state
= State_Running
;
348 LeaveCriticalSection(&This
->filter
.csFilter
);
349 LeaveCriticalSection(&pin
->thread_lock
);
354 HRESULT WINAPI
Parser_GetState(IBaseFilter
* iface
, DWORD dwMilliSecsTimeout
, FILTER_STATE
*pState
)
356 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
357 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
360 TRACE("(%d, %p)\n", dwMilliSecsTimeout
, pState
);
362 EnterCriticalSection(&pin
->thread_lock
);
363 EnterCriticalSection(&This
->filter
.csFilter
);
365 *pState
= This
->filter
.state
;
367 LeaveCriticalSection(&This
->filter
.csFilter
);
369 if (This
->pInputPin
&& (PullPin_WaitForStateChange(This
->pInputPin
, dwMilliSecsTimeout
) == S_FALSE
))
370 hr
= VFW_S_STATE_INTERMEDIATE
;
371 LeaveCriticalSection(&pin
->thread_lock
);
376 HRESULT WINAPI
Parser_SetSyncSource(IBaseFilter
* iface
, IReferenceClock
*pClock
)
378 ParserImpl
*This
= impl_from_IBaseFilter(iface
);
379 PullPin
*pin
= impl_PullPin_from_IPin(This
->ppPins
[0]);
381 TRACE("(%p)\n", pClock
);
383 EnterCriticalSection(&pin
->thread_lock
);
384 BaseFilterImpl_SetSyncSource(iface
,pClock
);
385 LeaveCriticalSection(&pin
->thread_lock
);
390 HRESULT WINAPI
Parser_GetSyncSource(IBaseFilter
* iface
, IReferenceClock
**ppClock
)
392 return BaseFilterImpl_GetSyncSource(iface
, ppClock
);
395 /** IBaseFilter implementation **/
397 HRESULT WINAPI
Parser_EnumPins(IBaseFilter
* iface
, IEnumPins
**ppEnum
)
399 return BaseFilterImpl_EnumPins(iface
,ppEnum
);
402 HRESULT WINAPI
Parser_FindPin(IBaseFilter
* iface
, LPCWSTR Id
, IPin
**ppPin
)
404 FIXME("(%p)->(%s,%p)\n", iface
, debugstr_w(Id
), ppPin
);
406 /* FIXME: critical section */
411 HRESULT WINAPI
Parser_QueryFilterInfo(IBaseFilter
* iface
, FILTER_INFO
*pInfo
)
413 return BaseFilterImpl_QueryFilterInfo(iface
, pInfo
);
416 HRESULT WINAPI
Parser_JoinFilterGraph(IBaseFilter
* iface
, IFilterGraph
*pGraph
, LPCWSTR pName
)
418 return BaseFilterImpl_JoinFilterGraph(iface
, pGraph
, pName
);
421 HRESULT WINAPI
Parser_QueryVendorInfo(IBaseFilter
* iface
, LPWSTR
*pVendorInfo
)
423 return BaseFilterImpl_QueryVendorInfo(iface
, pVendorInfo
);
426 static const BaseOutputPinFuncTable output_BaseOutputFuncTable
= {
429 BaseOutputPinImpl_AttemptConnection
,
430 BasePinImpl_GetMediaTypeVersion
,
431 Parser_OutputPin_GetMediaType
433 Parser_OutputPin_DecideBufferSize
,
434 Parser_OutputPin_DecideAllocator
,
435 Parser_OutputPin_BreakConnect
438 HRESULT
Parser_AddPin(ParserImpl
* This
, const PIN_INFO
* piOutput
, ALLOCATOR_PROPERTIES
* props
, const AM_MEDIA_TYPE
* amt
)
443 ppOldPins
= This
->ppPins
;
445 This
->ppPins
= CoTaskMemAlloc((This
->cStreams
+ 2) * sizeof(IPin
*));
446 memcpy(This
->ppPins
, ppOldPins
, (This
->cStreams
+ 1) * sizeof(IPin
*));
448 hr
= BaseOutputPin_Construct(&Parser_OutputPin_Vtbl
, sizeof(Parser_OutputPin
), piOutput
, &output_BaseOutputFuncTable
, &This
->filter
.csFilter
, This
->ppPins
+ (This
->cStreams
+ 1));
452 IPin
*pPin
= This
->ppPins
[This
->cStreams
+ 1];
453 Parser_OutputPin
*pin
= unsafe_impl_Parser_OutputPin_from_IPin(pPin
);
454 pin
->pmt
= CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE
));
455 CopyMediaType(pin
->pmt
, amt
);
456 pin
->dwSamplesProcessed
= 0;
458 pin
->pin
.pin
.pinInfo
.pFilter
= (LPVOID
)This
;
459 pin
->allocProps
= *props
;
461 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
462 CoTaskMemFree(ppOldPins
);
466 CoTaskMemFree(This
->ppPins
);
467 This
->ppPins
= ppOldPins
;
468 ERR("Failed with error %x\n", hr
);
474 static HRESULT
Parser_RemoveOutputPins(ParserImpl
* This
)
476 /* NOTE: should be in critical section when calling this function */
479 IPin
** ppOldPins
= This
->ppPins
;
481 TRACE("(%p)\n", This
);
483 /* reduce the pin array down to 1 (just our input pin) */
484 This
->ppPins
= CoTaskMemAlloc(sizeof(IPin
*) * 1);
485 memcpy(This
->ppPins
, ppOldPins
, sizeof(IPin
*) * 1);
487 for (i
= 0; i
< This
->cStreams
; i
++)
489 hr
= ((BaseOutputPin
*)ppOldPins
[i
+ 1])->pFuncsTable
->pfnBreakConnect((BaseOutputPin
*)ppOldPins
[i
+ 1]);
490 TRACE("Disconnect: %08x\n", hr
);
491 IPin_Release(ppOldPins
[i
+ 1]);
494 BaseFilterImpl_IncrementPinVersion(&This
->filter
);
496 CoTaskMemFree(ppOldPins
);
501 static HRESULT WINAPI
Parser_ChangeStart(IMediaSeeking
*iface
)
503 FIXME("(%p) filter hasn't implemented start position change!\n", iface
);
507 static HRESULT WINAPI
Parser_ChangeStop(IMediaSeeking
*iface
)
509 FIXME("(%p) filter hasn't implemented stop position change!\n", iface
);
513 static HRESULT WINAPI
Parser_ChangeRate(IMediaSeeking
*iface
)
515 FIXME("(%p) filter hasn't implemented rate change!\n", iface
);
520 static HRESULT WINAPI
Parser_Seeking_QueryInterface(IMediaSeeking
* iface
, REFIID riid
, LPVOID
* ppv
)
522 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
524 return IUnknown_QueryInterface((IUnknown
*)This
, riid
, ppv
);
527 static ULONG WINAPI
Parser_Seeking_AddRef(IMediaSeeking
* iface
)
529 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
531 return IUnknown_AddRef((IUnknown
*)This
);
534 static ULONG WINAPI
Parser_Seeking_Release(IMediaSeeking
* iface
)
536 ParserImpl
*This
= impl_from_IMediaSeeking(iface
);
538 return IUnknown_Release((IUnknown
*)This
);
541 static const IMediaSeekingVtbl Parser_Seeking_Vtbl
=
543 Parser_Seeking_QueryInterface
,
544 Parser_Seeking_AddRef
,
545 Parser_Seeking_Release
,
546 SourceSeekingImpl_GetCapabilities
,
547 SourceSeekingImpl_CheckCapabilities
,
548 SourceSeekingImpl_IsFormatSupported
,
549 SourceSeekingImpl_QueryPreferredFormat
,
550 SourceSeekingImpl_GetTimeFormat
,
551 SourceSeekingImpl_IsUsingTimeFormat
,
552 SourceSeekingImpl_SetTimeFormat
,
553 SourceSeekingImpl_GetDuration
,
554 SourceSeekingImpl_GetStopPosition
,
555 SourceSeekingImpl_GetCurrentPosition
,
556 SourceSeekingImpl_ConvertTimeFormat
,
557 SourceSeekingImpl_SetPositions
,
558 SourceSeekingImpl_GetPositions
,
559 SourceSeekingImpl_GetAvailable
,
560 SourceSeekingImpl_SetRate
,
561 SourceSeekingImpl_GetRate
,
562 SourceSeekingImpl_GetPreroll
565 static HRESULT WINAPI
Parser_OutputPin_DecideBufferSize(BaseOutputPin
*iface
, IMemAllocator
*pAlloc
, ALLOCATOR_PROPERTIES
*ppropInputRequest
)
567 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
568 ALLOCATOR_PROPERTIES actual
;
570 if (ppropInputRequest
->cbAlign
&& ppropInputRequest
->cbAlign
!= This
->allocProps
.cbAlign
)
571 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This
->allocProps
.cbAlign
, ppropInputRequest
->cbAlign
);
572 if (ppropInputRequest
->cbPrefix
)
573 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This
->allocProps
.cbPrefix
, ppropInputRequest
->cbPrefix
);
574 if (ppropInputRequest
->cbBuffer
)
575 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This
->allocProps
.cbBuffer
, ppropInputRequest
->cbBuffer
);
576 if (ppropInputRequest
->cBuffers
)
577 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This
->allocProps
.cBuffers
, ppropInputRequest
->cBuffers
);
579 return IMemAllocator_SetProperties(pAlloc
, &This
->allocProps
, &actual
);
582 static HRESULT WINAPI
Parser_OutputPin_GetMediaType(BasePin
*iface
, int iPosition
, AM_MEDIA_TYPE
*pmt
)
584 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
588 return VFW_S_NO_MORE_ITEMS
;
589 CopyMediaType(pmt
, This
->pmt
);
593 static HRESULT WINAPI
Parser_OutputPin_DecideAllocator(BaseOutputPin
*iface
, IMemInputPin
*pPin
, IMemAllocator
**pAlloc
)
595 Parser_OutputPin
*This
= (Parser_OutputPin
*)iface
;
602 hr
= IMemInputPin_NotifyAllocator(pPin
, This
->alloc
, This
->readonly
);
605 *pAlloc
= This
->alloc
;
606 IMemAllocator_AddRef(*pAlloc
);
610 hr
= VFW_E_NO_ALLOCATOR
;
615 static HRESULT WINAPI
Parser_OutputPin_BreakConnect(BaseOutputPin
*This
)
619 TRACE("(%p)->()\n", This
);
621 EnterCriticalSection(This
->pin
.pCritSec
);
622 if (!This
->pin
.pConnectedTo
|| !This
->pMemInputPin
)
623 hr
= VFW_E_NOT_CONNECTED
;
626 hr
= IPin_Disconnect(This
->pin
.pConnectedTo
);
627 IPin_Disconnect(&This
->pin
.IPin_iface
);
629 LeaveCriticalSection(This
->pin
.pCritSec
);
635 static HRESULT WINAPI
Parser_OutputPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
637 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
639 TRACE("(%s, %p)\n", qzdebugstr_guid(riid
), ppv
);
643 if (IsEqualIID(riid
, &IID_IUnknown
))
645 else if (IsEqualIID(riid
, &IID_IPin
))
647 /* The Parser filter does not support querying IMediaSeeking, return it directly */
648 else if (IsEqualIID(riid
, &IID_IMediaSeeking
))
649 *ppv
= &impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
)->sourceSeeking
;
653 IUnknown_AddRef((IUnknown
*)(*ppv
));
657 FIXME("No interface for %s!\n", qzdebugstr_guid(riid
));
659 return E_NOINTERFACE
;
662 static ULONG WINAPI
Parser_OutputPin_Release(IPin
* iface
)
664 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
665 ULONG refCount
= InterlockedDecrement(&This
->pin
.pin
.refCount
);
667 TRACE("(%p)->() Release from %d\n", iface
, refCount
+ 1);
671 FreeMediaType(This
->pmt
);
672 CoTaskMemFree(This
->pmt
);
673 FreeMediaType(&This
->pin
.pin
.mtCurrent
);
674 if (This
->pin
.pAllocator
)
675 IMemAllocator_Release(This
->pin
.pAllocator
);
682 static HRESULT WINAPI
Parser_OutputPin_Connect(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
684 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
685 ParserImpl
*parser
= impl_from_IBaseFilter(This
->pin
.pin
.pinInfo
.pFilter
);
687 /* Set the allocator to our input pin's */
688 EnterCriticalSection(This
->pin
.pin
.pCritSec
);
689 This
->alloc
= parser
->pInputPin
->pAlloc
;
690 LeaveCriticalSection(This
->pin
.pin
.pCritSec
);
692 return BaseOutputPinImpl_Connect(iface
, pReceivePin
, pmt
);
695 static HRESULT WINAPI
Parser_OutputPin_QueryAccept(IPin
*iface
, const AM_MEDIA_TYPE
* pmt
)
697 Parser_OutputPin
*This
= unsafe_impl_Parser_OutputPin_from_IPin(iface
);
700 dump_AM_MEDIA_TYPE(pmt
);
702 return (memcmp(This
->pmt
, pmt
, sizeof(AM_MEDIA_TYPE
)) == 0);
705 static const IPinVtbl Parser_OutputPin_Vtbl
=
707 Parser_OutputPin_QueryInterface
,
709 Parser_OutputPin_Release
,
710 Parser_OutputPin_Connect
,
711 BaseOutputPinImpl_ReceiveConnection
,
712 BaseOutputPinImpl_Disconnect
,
713 BasePinImpl_ConnectedTo
,
714 BasePinImpl_ConnectionMediaType
,
715 BasePinImpl_QueryPinInfo
,
716 BasePinImpl_QueryDirection
,
718 Parser_OutputPin_QueryAccept
,
719 BasePinImpl_EnumMediaTypes
,
720 BasePinImpl_QueryInternalConnections
,
721 BaseOutputPinImpl_EndOfStream
,
722 BaseOutputPinImpl_BeginFlush
,
723 BaseOutputPinImpl_EndFlush
,
724 BasePinImpl_NewSegment
727 static HRESULT WINAPI
Parser_PullPin_QueryInterface(IPin
* iface
, REFIID riid
, LPVOID
* ppv
)
729 PullPin
*This
= impl_PullPin_from_IPin(iface
);
731 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
736 * It is important to capture the request for the IMediaSeeking interface before it is passed
737 * on to PullPin_QueryInterface, this is necessary since the Parser filter does not support
738 * querying IMediaSeeking
740 if (IsEqualIID(riid
, &IID_IMediaSeeking
))
741 *ppv
= &impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
)->sourceSeeking
;
745 IUnknown_AddRef((IUnknown
*)(*ppv
));
749 return PullPin_QueryInterface(iface
, riid
, ppv
);
752 static HRESULT WINAPI
Parser_PullPin_Disconnect(IPin
* iface
)
755 PullPin
*This
= impl_PullPin_from_IPin(iface
);
759 EnterCriticalSection(&This
->thread_lock
);
760 EnterCriticalSection(This
->pin
.pCritSec
);
762 if (This
->pin
.pConnectedTo
)
765 ParserImpl
*Parser
= impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
);
767 LeaveCriticalSection(This
->pin
.pCritSec
);
768 hr
= IBaseFilter_GetState(This
->pin
.pinInfo
.pFilter
, INFINITE
, &state
);
769 EnterCriticalSection(This
->pin
.pCritSec
);
771 if (SUCCEEDED(hr
) && (state
== State_Stopped
) && SUCCEEDED(Parser
->fnDisconnect(Parser
)))
773 LeaveCriticalSection(This
->pin
.pCritSec
);
774 PullPin_Disconnect(iface
);
775 EnterCriticalSection(This
->pin
.pCritSec
);
776 hr
= Parser_RemoveOutputPins(impl_from_IBaseFilter(This
->pin
.pinInfo
.pFilter
));
779 hr
= VFW_E_NOT_STOPPED
;
784 LeaveCriticalSection(This
->pin
.pCritSec
);
785 LeaveCriticalSection(&This
->thread_lock
);
790 static HRESULT WINAPI
Parser_PullPin_ReceiveConnection(IPin
* iface
, IPin
* pReceivePin
, const AM_MEDIA_TYPE
* pmt
)
796 hr
= PullPin_ReceiveConnection(iface
, pReceivePin
, pmt
);
799 BasePin
*This
= (BasePin
*)iface
;
801 EnterCriticalSection(This
->pCritSec
);
802 Parser_RemoveOutputPins(impl_from_IBaseFilter(This
->pinInfo
.pFilter
));
803 LeaveCriticalSection(This
->pCritSec
);
809 static HRESULT WINAPI
Parser_PullPin_EnumMediaTypes(IPin
*iface
, IEnumMediaTypes
**ppEnum
)
811 BasePin
*This
= (BasePin
*)iface
;
813 TRACE("(%p/%p)->(%p)\n", This
, iface
, ppEnum
);
815 return EnumMediaTypes_Construct(This
, BasePinImpl_GetMediaType
, BasePinImpl_GetMediaTypeVersion
, ppEnum
);
818 static const IPinVtbl Parser_InputPin_Vtbl
=
820 Parser_PullPin_QueryInterface
,
823 BaseInputPinImpl_Connect
,
824 Parser_PullPin_ReceiveConnection
,
825 Parser_PullPin_Disconnect
,
826 BasePinImpl_ConnectedTo
,
827 BasePinImpl_ConnectionMediaType
,
828 BasePinImpl_QueryPinInfo
,
829 BasePinImpl_QueryDirection
,
832 Parser_PullPin_EnumMediaTypes
,
833 BasePinImpl_QueryInternalConnections
,