mshtml: Use get_elem_attr_value helper in npplugin.c.
[wine.git] / dlls / quartz / parser.c
blobf702c62825d1dc563139469833e5d6ac19a9c9f4
1 /*
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"
23 #include "pin.h"
25 #include "vfwmsgs.h"
26 #include "amvideo.h"
28 #include "wine/unicode.h"
29 #include "wine/debug.h"
31 #include <math.h>
32 #include <assert.h>
34 #include "parser.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);
66 /* FIXME: WRONG */
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)
75 return NULL;
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 = {
89 Parser_GetPin,
90 Parser_GetPinCount
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)
95 HRESULT hr;
96 PIN_INFO piInput;
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]));
111 if (!start)
112 start = Parser_ChangeStart;
114 if (!stop)
115 stop = Parser_ChangeStop;
117 if (!rate)
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);
124 if (SUCCEEDED(hr))
126 pParser->ppPins[0] = &pParser->pInputPin->pin.IPin_iface;
127 pParser->pInputPin->fnPreConnect = fnPreConnect;
129 else
131 CoTaskMemFree(pParser->ppPins);
132 BaseFilterImpl_Release(&pParser->filter.IBaseFilter_iface);
133 CoTaskMemFree(pParser);
136 return hr;
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);
144 *ppv = NULL;
146 if ( IsEqualIID(riid, &IID_IUnknown)
147 || IsEqualIID(riid, &IID_IPersist)
148 || IsEqualIID(riid, &IID_IMediaFilter)
149 || IsEqualIID(riid, &IID_IBaseFilter) )
150 *ppv = This;
152 if (*ppv)
154 IUnknown_AddRef((IUnknown *)(*ppv));
155 return S_OK;
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;
172 ULONG pinref;
174 assert(!This->filter.refCount);
175 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
177 /* Don't need to clean up output pins, freeing input pin will do that */
178 IPin_ConnectedTo(&This->pInputPin->pin.IPin_iface, &connected);
179 if (connected)
181 assert(IPin_Disconnect(connected) == S_OK);
182 IPin_Release(connected);
183 assert(IPin_Disconnect(&This->pInputPin->pin.IPin_iface) == S_OK);
185 pinref = IPin_Release(&This->pInputPin->pin.IPin_iface);
186 if (pinref)
188 /* Valgrind could find this, if I kill it here */
189 ERR("pinref should be null, is %u, destroying anyway\n", pinref);
190 assert((LONG)pinref > 0);
192 while (pinref)
193 pinref = IPin_Release(&This->pInputPin->pin.IPin_iface);
196 CoTaskMemFree(This->ppPins);
198 TRACE("Destroying parser\n");
199 CoTaskMemFree(This);
202 ULONG WINAPI Parser_Release(IBaseFilter * iface)
204 ParserImpl *This = impl_from_IBaseFilter(iface);
205 ULONG refCount = BaseFilterImpl_Release(iface);
207 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
209 if (!refCount)
210 Parser_Destroy(This);
212 return refCount;
215 /** IPersist methods **/
217 HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
219 ParserImpl *This = impl_from_IBaseFilter(iface);
221 TRACE("(%p)\n", pClsid);
223 *pClsid = This->filter.clsid;
225 return S_OK;
228 /** IMediaFilter methods **/
230 HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
232 ParserImpl *This = impl_from_IBaseFilter(iface);
233 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
234 ULONG i;
236 TRACE("()\n");
238 EnterCriticalSection(&pin->thread_lock);
240 IAsyncReader_BeginFlush(This->pInputPin->pReader);
241 EnterCriticalSection(&This->filter.csFilter);
243 if (This->filter.state == State_Stopped)
245 LeaveCriticalSection(&This->filter.csFilter);
246 IAsyncReader_EndFlush(This->pInputPin->pReader);
247 LeaveCriticalSection(&pin->thread_lock);
248 return S_OK;
251 This->filter.state = State_Stopped;
253 for (i = 1; i < (This->cStreams + 1); i++)
255 BaseOutputPinImpl_Inactive((BaseOutputPin *)This->ppPins[i]);
258 LeaveCriticalSection(&This->filter.csFilter);
260 PullPin_PauseProcessing(This->pInputPin);
261 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
262 IAsyncReader_EndFlush(This->pInputPin->pReader);
264 LeaveCriticalSection(&pin->thread_lock);
265 return S_OK;
268 HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
270 HRESULT hr = S_OK;
271 ParserImpl *This = impl_from_IBaseFilter(iface);
272 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
274 TRACE("()\n");
276 EnterCriticalSection(&pin->thread_lock);
277 EnterCriticalSection(&This->filter.csFilter);
279 if (This->filter.state == State_Paused)
281 LeaveCriticalSection(&This->filter.csFilter);
282 LeaveCriticalSection(&pin->thread_lock);
283 return S_OK;
286 if (This->filter.state == State_Stopped)
288 LeaveCriticalSection(&This->filter.csFilter);
289 hr = IBaseFilter_Run(iface, -1);
290 EnterCriticalSection(&This->filter.csFilter);
293 if (SUCCEEDED(hr))
294 This->filter.state = State_Paused;
296 LeaveCriticalSection(&This->filter.csFilter);
297 LeaveCriticalSection(&pin->thread_lock);
299 return hr;
302 HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
304 HRESULT hr = S_OK;
305 ParserImpl *This = impl_from_IBaseFilter(iface);
306 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
308 ULONG i;
310 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
312 EnterCriticalSection(&pin->thread_lock);
313 EnterCriticalSection(&This->filter.csFilter);
315 HRESULT hr_any = VFW_E_NOT_CONNECTED;
317 This->filter.rtStreamStart = tStart;
318 if (This->filter.state == State_Running || This->filter.state == State_Paused)
320 This->filter.state = State_Running;
321 LeaveCriticalSection(&This->filter.csFilter);
322 LeaveCriticalSection(&pin->thread_lock);
323 return S_OK;
326 for (i = 1; i < (This->cStreams + 1); i++)
328 hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
329 if (SUCCEEDED(hr))
330 hr_any = hr;
333 hr = hr_any;
334 if (SUCCEEDED(hr))
336 LeaveCriticalSection(&This->filter.csFilter);
337 hr = PullPin_StartProcessing(This->pInputPin);
338 EnterCriticalSection(&This->filter.csFilter);
341 if (SUCCEEDED(hr))
342 This->filter.state = State_Running;
344 LeaveCriticalSection(&This->filter.csFilter);
345 LeaveCriticalSection(&pin->thread_lock);
347 return hr;
350 HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
352 ParserImpl *This = impl_from_IBaseFilter(iface);
353 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
354 HRESULT hr = S_OK;
356 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
358 EnterCriticalSection(&pin->thread_lock);
359 EnterCriticalSection(&This->filter.csFilter);
361 *pState = This->filter.state;
363 LeaveCriticalSection(&This->filter.csFilter);
365 if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
366 hr = VFW_S_STATE_INTERMEDIATE;
367 LeaveCriticalSection(&pin->thread_lock);
369 return hr;
372 HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
374 ParserImpl *This = impl_from_IBaseFilter(iface);
375 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
377 TRACE("(%p)\n", pClock);
379 EnterCriticalSection(&pin->thread_lock);
380 BaseFilterImpl_SetSyncSource(iface,pClock);
381 LeaveCriticalSection(&pin->thread_lock);
383 return S_OK;
386 HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
388 return BaseFilterImpl_GetSyncSource(iface, ppClock);
391 /** IBaseFilter implementation **/
393 HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
395 return BaseFilterImpl_EnumPins(iface,ppEnum);
398 HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
400 FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
402 /* FIXME: critical section */
404 return E_NOTIMPL;
407 HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
409 return BaseFilterImpl_QueryFilterInfo(iface, pInfo);
412 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
414 return BaseFilterImpl_JoinFilterGraph(iface, pGraph, pName);
417 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
419 return BaseFilterImpl_QueryVendorInfo(iface, pVendorInfo);
422 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
424 NULL,
425 BaseOutputPinImpl_AttemptConnection,
426 BasePinImpl_GetMediaTypeVersion,
427 Parser_OutputPin_GetMediaType
429 Parser_OutputPin_DecideBufferSize,
430 Parser_OutputPin_DecideAllocator,
431 Parser_OutputPin_BreakConnect
434 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
436 IPin ** ppOldPins;
437 HRESULT hr;
439 ppOldPins = This->ppPins;
441 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
442 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
444 hr = BaseOutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, &output_BaseOutputFuncTable, &This->filter.csFilter, This->ppPins + (This->cStreams + 1));
446 if (SUCCEEDED(hr))
448 IPin *pPin = This->ppPins[This->cStreams + 1];
449 Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(pPin);
450 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
451 CopyMediaType(pin->pmt, amt);
452 pin->dwSamplesProcessed = 0;
454 pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
455 pin->allocProps = *props;
456 This->cStreams++;
457 BaseFilterImpl_IncrementPinVersion(&This->filter);
458 CoTaskMemFree(ppOldPins);
460 else
462 CoTaskMemFree(This->ppPins);
463 This->ppPins = ppOldPins;
464 ERR("Failed with error %x\n", hr);
467 return hr;
470 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
472 /* NOTE: should be in critical section when calling this function */
473 HRESULT hr;
474 ULONG i;
475 IPin ** ppOldPins = This->ppPins;
477 TRACE("(%p)\n", This);
479 /* reduce the pin array down to 1 (just our input pin) */
480 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
481 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
483 for (i = 0; i < This->cStreams; i++)
485 hr = ((BaseOutputPin *)ppOldPins[i + 1])->pFuncsTable->pfnBreakConnect((BaseOutputPin *)ppOldPins[i + 1]);
486 TRACE("Disconnect: %08x\n", hr);
487 IPin_Release(ppOldPins[i + 1]);
490 BaseFilterImpl_IncrementPinVersion(&This->filter);
491 This->cStreams = 0;
492 CoTaskMemFree(ppOldPins);
494 return S_OK;
497 static HRESULT WINAPI Parser_ChangeStart(IMediaSeeking *iface)
499 FIXME("(%p) filter hasn't implemented start position change!\n", iface);
500 return S_OK;
503 static HRESULT WINAPI Parser_ChangeStop(IMediaSeeking *iface)
505 FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
506 return S_OK;
509 static HRESULT WINAPI Parser_ChangeRate(IMediaSeeking *iface)
511 FIXME("(%p) filter hasn't implemented rate change!\n", iface);
512 return S_OK;
516 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
518 ParserImpl *This = impl_from_IMediaSeeking(iface);
520 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
523 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
525 ParserImpl *This = impl_from_IMediaSeeking(iface);
527 return IUnknown_AddRef((IUnknown *)This);
530 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
532 ParserImpl *This = impl_from_IMediaSeeking(iface);
534 return IUnknown_Release((IUnknown *)This);
537 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
539 Parser_Seeking_QueryInterface,
540 Parser_Seeking_AddRef,
541 Parser_Seeking_Release,
542 SourceSeekingImpl_GetCapabilities,
543 SourceSeekingImpl_CheckCapabilities,
544 SourceSeekingImpl_IsFormatSupported,
545 SourceSeekingImpl_QueryPreferredFormat,
546 SourceSeekingImpl_GetTimeFormat,
547 SourceSeekingImpl_IsUsingTimeFormat,
548 SourceSeekingImpl_SetTimeFormat,
549 SourceSeekingImpl_GetDuration,
550 SourceSeekingImpl_GetStopPosition,
551 SourceSeekingImpl_GetCurrentPosition,
552 SourceSeekingImpl_ConvertTimeFormat,
553 SourceSeekingImpl_SetPositions,
554 SourceSeekingImpl_GetPositions,
555 SourceSeekingImpl_GetAvailable,
556 SourceSeekingImpl_SetRate,
557 SourceSeekingImpl_GetRate,
558 SourceSeekingImpl_GetPreroll
561 static HRESULT WINAPI Parser_OutputPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
563 Parser_OutputPin *This = (Parser_OutputPin*)iface;
564 ALLOCATOR_PROPERTIES actual;
566 if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
567 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
568 if (ppropInputRequest->cbPrefix)
569 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
570 if (ppropInputRequest->cbBuffer)
571 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
572 if (ppropInputRequest->cBuffers)
573 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
575 return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
578 static HRESULT WINAPI Parser_OutputPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
580 Parser_OutputPin *This = (Parser_OutputPin*)iface;
581 if (iPosition < 0)
582 return E_INVALIDARG;
583 if (iPosition > 0)
584 return VFW_S_NO_MORE_ITEMS;
585 CopyMediaType(pmt, This->pmt);
586 return S_OK;
589 static HRESULT WINAPI Parser_OutputPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
591 Parser_OutputPin *This = (Parser_OutputPin*)iface;
592 HRESULT hr;
594 *pAlloc = NULL;
596 if (This->alloc)
598 hr = IMemInputPin_NotifyAllocator(pPin, This->alloc, This->readonly);
599 if (SUCCEEDED(hr))
601 *pAlloc = This->alloc;
602 IMemAllocator_AddRef(*pAlloc);
605 else
606 hr = VFW_E_NO_ALLOCATOR;
608 return hr;
611 static HRESULT WINAPI Parser_OutputPin_BreakConnect(BaseOutputPin *This)
613 HRESULT hr;
615 TRACE("(%p)->()\n", This);
617 EnterCriticalSection(This->pin.pCritSec);
618 if (!This->pin.pConnectedTo || !This->pMemInputPin)
619 hr = VFW_E_NOT_CONNECTED;
620 else
622 hr = IPin_Disconnect(This->pin.pConnectedTo);
623 IPin_Disconnect(&This->pin.IPin_iface);
625 LeaveCriticalSection(This->pin.pCritSec);
627 return hr;
631 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
633 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
635 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
637 *ppv = NULL;
639 if (IsEqualIID(riid, &IID_IUnknown))
640 *ppv = iface;
641 else if (IsEqualIID(riid, &IID_IPin))
642 *ppv = iface;
643 /* The Parser filter does not support querying IMediaSeeking, return it directly */
644 else if (IsEqualIID(riid, &IID_IMediaSeeking))
645 *ppv = &impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter)->sourceSeeking;
647 if (*ppv)
649 IUnknown_AddRef((IUnknown *)(*ppv));
650 return S_OK;
653 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
655 return E_NOINTERFACE;
658 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
660 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
661 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
663 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
665 if (!refCount)
667 FreeMediaType(This->pmt);
668 CoTaskMemFree(This->pmt);
669 FreeMediaType(&This->pin.pin.mtCurrent);
670 if (This->pin.pAllocator)
671 IMemAllocator_Release(This->pin.pAllocator);
672 CoTaskMemFree(This);
673 return 0;
675 return refCount;
678 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
680 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
681 ParserImpl *parser = impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter);
683 /* Set the allocator to our input pin's */
684 EnterCriticalSection(This->pin.pin.pCritSec);
685 This->alloc = parser->pInputPin->pAlloc;
686 LeaveCriticalSection(This->pin.pin.pCritSec);
688 return BaseOutputPinImpl_Connect(iface, pReceivePin, pmt);
691 static HRESULT WINAPI Parser_OutputPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE * pmt)
693 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
695 TRACE("()\n");
696 dump_AM_MEDIA_TYPE(pmt);
698 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
701 static const IPinVtbl Parser_OutputPin_Vtbl =
703 Parser_OutputPin_QueryInterface,
704 BasePinImpl_AddRef,
705 Parser_OutputPin_Release,
706 Parser_OutputPin_Connect,
707 BaseOutputPinImpl_ReceiveConnection,
708 BaseOutputPinImpl_Disconnect,
709 BasePinImpl_ConnectedTo,
710 BasePinImpl_ConnectionMediaType,
711 BasePinImpl_QueryPinInfo,
712 BasePinImpl_QueryDirection,
713 BasePinImpl_QueryId,
714 Parser_OutputPin_QueryAccept,
715 BasePinImpl_EnumMediaTypes,
716 BasePinImpl_QueryInternalConnections,
717 BaseOutputPinImpl_EndOfStream,
718 BaseOutputPinImpl_BeginFlush,
719 BaseOutputPinImpl_EndFlush,
720 BasePinImpl_NewSegment
723 static HRESULT WINAPI Parser_PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
725 PullPin *This = impl_PullPin_from_IPin(iface);
727 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
729 *ppv = NULL;
732 * It is important to capture the request for the IMediaSeeking interface before it is passed
733 * on to PullPin_QueryInterface, this is necessary since the Parser filter does not support
734 * querying IMediaSeeking
736 if (IsEqualIID(riid, &IID_IMediaSeeking))
737 *ppv = &impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->sourceSeeking;
739 if (*ppv)
741 IUnknown_AddRef((IUnknown *)(*ppv));
742 return S_OK;
745 return PullPin_QueryInterface(iface, riid, ppv);
748 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
750 HRESULT hr;
751 PullPin *This = impl_PullPin_from_IPin(iface);
753 TRACE("()\n");
755 EnterCriticalSection(&This->thread_lock);
756 EnterCriticalSection(This->pin.pCritSec);
758 if (This->pin.pConnectedTo)
760 FILTER_STATE state;
761 ParserImpl *Parser = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
763 LeaveCriticalSection(This->pin.pCritSec);
764 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
765 EnterCriticalSection(This->pin.pCritSec);
767 if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
769 LeaveCriticalSection(This->pin.pCritSec);
770 PullPin_Disconnect(iface);
771 EnterCriticalSection(This->pin.pCritSec);
772 hr = Parser_RemoveOutputPins(impl_from_IBaseFilter(This->pin.pinInfo.pFilter));
774 else
775 hr = VFW_E_NOT_STOPPED;
777 else
778 hr = S_FALSE;
780 LeaveCriticalSection(This->pin.pCritSec);
781 LeaveCriticalSection(&This->thread_lock);
783 return hr;
786 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
788 HRESULT hr;
790 TRACE("()\n");
792 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
793 if (FAILED(hr))
795 BasePin *This = (BasePin *)iface;
797 EnterCriticalSection(This->pCritSec);
798 Parser_RemoveOutputPins(impl_from_IBaseFilter(This->pinInfo.pFilter));
799 LeaveCriticalSection(This->pCritSec);
802 return hr;
805 static HRESULT WINAPI Parser_PullPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
807 BasePin *This = (BasePin *)iface;
809 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
811 return EnumMediaTypes_Construct(This, BasePinImpl_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
814 static const IPinVtbl Parser_InputPin_Vtbl =
816 Parser_PullPin_QueryInterface,
817 BasePinImpl_AddRef,
818 PullPin_Release,
819 BaseInputPinImpl_Connect,
820 Parser_PullPin_ReceiveConnection,
821 Parser_PullPin_Disconnect,
822 BasePinImpl_ConnectedTo,
823 BasePinImpl_ConnectionMediaType,
824 BasePinImpl_QueryPinInfo,
825 BasePinImpl_QueryDirection,
826 BasePinImpl_QueryId,
827 PullPin_QueryAccept,
828 Parser_PullPin_EnumMediaTypes,
829 BasePinImpl_QueryInternalConnections,
830 PullPin_EndOfStream,
831 PullPin_BeginFlush,
832 PullPin_EndFlush,
833 PullPin_NewSegment