ntoskrnl.exe: Implement NtBuildNumber.
[wine.git] / dlls / quartz / parser.c
blob49b0adf6f59ad0953ab4cc7c2e579e7f242b9d7b
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_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);
67 /* FIXME: WRONG */
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)
76 return NULL;
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 = {
92 Parser_GetPin,
93 Parser_GetPinCount
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)
98 HRESULT hr;
99 PIN_INFO piInput;
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, ARRAY_SIZE(piInput.achName));
114 if (!start)
115 start = Parser_ChangeStart;
117 if (!stop)
118 stop = Parser_ChangeStop;
120 if (!rate)
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);
127 if (SUCCEEDED(hr))
129 pParser->ppPins[0] = &pParser->pInputPin->pin.IPin_iface;
130 pParser->pInputPin->fnPreConnect = fnPreConnect;
132 else
134 CoTaskMemFree(pParser->ppPins);
135 BaseFilterImpl_Release(&pParser->filter.IBaseFilter_iface);
136 CoTaskMemFree(pParser);
139 return hr;
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);
147 *ppv = NULL;
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;
155 if (*ppv)
157 IUnknown_AddRef((IUnknown *)*ppv);
158 return S_OK;
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;
175 ULONG pinref;
176 HRESULT hr;
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);
183 if (connected)
185 hr = IPin_Disconnect(connected);
186 assert(hr == S_OK);
187 IPin_Release(connected);
188 hr = IPin_Disconnect(&This->pInputPin->pin.IPin_iface);
189 assert(hr == S_OK);
191 pinref = IPin_Release(&This->pInputPin->pin.IPin_iface);
192 if (pinref)
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);
198 while (pinref)
199 pinref = IPin_Release(&This->pInputPin->pin.IPin_iface);
202 CoTaskMemFree(This->ppPins);
203 BaseFilter_Destroy(&This->filter);
205 TRACE("Destroying parser\n");
206 CoTaskMemFree(This);
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);
216 if (!refCount)
217 Parser_Destroy(This);
219 return refCount;
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;
232 return S_OK;
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]);
241 ULONG i;
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);
255 return S_OK;
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);
272 return S_OK;
275 HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
277 HRESULT hr = S_OK;
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);
290 return S_OK;
293 if (This->filter.state == State_Stopped)
295 LeaveCriticalSection(&This->filter.csFilter);
296 hr = IBaseFilter_Run(iface, -1);
297 EnterCriticalSection(&This->filter.csFilter);
300 if (SUCCEEDED(hr))
301 This->filter.state = State_Paused;
303 LeaveCriticalSection(&This->filter.csFilter);
304 LeaveCriticalSection(&pin->thread_lock);
306 return hr;
309 HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
311 HRESULT hr = S_OK;
312 ParserImpl *This = impl_from_IBaseFilter(iface);
313 PullPin *pin = impl_PullPin_from_IPin(This->ppPins[0]);
315 ULONG i;
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);
330 return S_OK;
333 for (i = 1; i < (This->cStreams + 1); i++)
335 hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
336 if (SUCCEEDED(hr))
337 hr_any = hr;
340 hr = hr_any;
341 if (SUCCEEDED(hr))
343 LeaveCriticalSection(&This->filter.csFilter);
344 hr = PullPin_StartProcessing(This->pInputPin);
345 EnterCriticalSection(&This->filter.csFilter);
348 if (SUCCEEDED(hr))
349 This->filter.state = State_Running;
351 LeaveCriticalSection(&This->filter.csFilter);
352 LeaveCriticalSection(&pin->thread_lock);
354 return hr;
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]);
361 HRESULT hr = S_OK;
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);
376 return hr;
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);
390 return S_OK;
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_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
407 return BaseFilterImpl_QueryFilterInfo(iface, pInfo);
410 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
412 return BaseFilterImpl_JoinFilterGraph(iface, pGraph, pName);
415 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
417 return BaseFilterImpl_QueryVendorInfo(iface, pVendorInfo);
420 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
422 Parser_OutputPin_CheckMediaType,
423 BaseOutputPinImpl_AttemptConnection,
424 BasePinImpl_GetMediaTypeVersion,
425 Parser_OutputPin_GetMediaType
427 Parser_OutputPin_DecideBufferSize,
428 Parser_OutputPin_DecideAllocator,
429 Parser_OutputPin_BreakConnect
432 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
434 IPin ** ppOldPins;
435 HRESULT hr;
437 ppOldPins = This->ppPins;
439 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
440 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
442 hr = BaseOutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, &output_BaseOutputFuncTable, &This->filter.csFilter, This->ppPins + (This->cStreams + 1));
444 if (SUCCEEDED(hr))
446 IPin *pPin = This->ppPins[This->cStreams + 1];
447 Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(pPin);
448 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
449 CopyMediaType(pin->pmt, amt);
450 pin->dwSamplesProcessed = 0;
452 pin->pin.pin.pinInfo.pFilter = &This->filter.IBaseFilter_iface;
453 pin->allocProps = *props;
454 This->cStreams++;
455 BaseFilterImpl_IncrementPinVersion(&This->filter);
456 CoTaskMemFree(ppOldPins);
458 else
460 CoTaskMemFree(This->ppPins);
461 This->ppPins = ppOldPins;
462 ERR("Failed with error %x\n", hr);
465 return hr;
468 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
470 /* NOTE: should be in critical section when calling this function */
471 HRESULT hr;
472 ULONG i;
473 IPin ** ppOldPins = This->ppPins;
475 TRACE("(%p)\n", This);
477 /* reduce the pin array down to 1 (just our input pin) */
478 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
479 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
481 for (i = 0; i < This->cStreams; i++)
483 hr = ((BaseOutputPin *)ppOldPins[i + 1])->pFuncsTable->pfnBreakConnect((BaseOutputPin *)ppOldPins[i + 1]);
484 TRACE("Disconnect: %08x\n", hr);
485 IPin_Release(ppOldPins[i + 1]);
488 BaseFilterImpl_IncrementPinVersion(&This->filter);
489 This->cStreams = 0;
490 CoTaskMemFree(ppOldPins);
492 return S_OK;
495 static HRESULT WINAPI Parser_ChangeStart(IMediaSeeking *iface)
497 FIXME("(%p) filter hasn't implemented start position change!\n", iface);
498 return S_OK;
501 static HRESULT WINAPI Parser_ChangeStop(IMediaSeeking *iface)
503 FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
504 return S_OK;
507 static HRESULT WINAPI Parser_ChangeRate(IMediaSeeking *iface)
509 FIXME("(%p) filter hasn't implemented rate change!\n", iface);
510 return S_OK;
514 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
516 ParserImpl *This = impl_from_IMediaSeeking(iface);
518 return IBaseFilter_QueryInterface(&This->filter.IBaseFilter_iface, riid, ppv);
521 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
523 ParserImpl *This = impl_from_IMediaSeeking(iface);
525 return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
528 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
530 ParserImpl *This = impl_from_IMediaSeeking(iface);
532 return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
535 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
537 Parser_Seeking_QueryInterface,
538 Parser_Seeking_AddRef,
539 Parser_Seeking_Release,
540 SourceSeekingImpl_GetCapabilities,
541 SourceSeekingImpl_CheckCapabilities,
542 SourceSeekingImpl_IsFormatSupported,
543 SourceSeekingImpl_QueryPreferredFormat,
544 SourceSeekingImpl_GetTimeFormat,
545 SourceSeekingImpl_IsUsingTimeFormat,
546 SourceSeekingImpl_SetTimeFormat,
547 SourceSeekingImpl_GetDuration,
548 SourceSeekingImpl_GetStopPosition,
549 SourceSeekingImpl_GetCurrentPosition,
550 SourceSeekingImpl_ConvertTimeFormat,
551 SourceSeekingImpl_SetPositions,
552 SourceSeekingImpl_GetPositions,
553 SourceSeekingImpl_GetAvailable,
554 SourceSeekingImpl_SetRate,
555 SourceSeekingImpl_GetRate,
556 SourceSeekingImpl_GetPreroll
559 static HRESULT WINAPI Parser_OutputPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
561 Parser_OutputPin *This = (Parser_OutputPin*)iface;
562 ALLOCATOR_PROPERTIES actual;
564 if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
565 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
566 if (ppropInputRequest->cbPrefix)
567 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
568 if (ppropInputRequest->cbBuffer)
569 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
570 if (ppropInputRequest->cBuffers)
571 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
573 return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
576 static HRESULT WINAPI Parser_OutputPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
578 Parser_OutputPin *This = (Parser_OutputPin*)iface;
579 if (iPosition < 0)
580 return E_INVALIDARG;
581 if (iPosition > 0)
582 return VFW_S_NO_MORE_ITEMS;
583 CopyMediaType(pmt, This->pmt);
584 return S_OK;
587 static HRESULT WINAPI Parser_OutputPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
589 Parser_OutputPin *This = (Parser_OutputPin*)iface;
590 HRESULT hr;
592 *pAlloc = NULL;
594 if (This->alloc)
596 hr = IMemInputPin_NotifyAllocator(pPin, This->alloc, This->readonly);
597 if (SUCCEEDED(hr))
599 *pAlloc = This->alloc;
600 IMemAllocator_AddRef(*pAlloc);
603 else
604 hr = VFW_E_NO_ALLOCATOR;
606 return hr;
609 static HRESULT WINAPI Parser_OutputPin_BreakConnect(BaseOutputPin *This)
611 HRESULT hr;
613 TRACE("(%p)->()\n", This);
615 EnterCriticalSection(This->pin.pCritSec);
616 if (!This->pin.pConnectedTo || !This->pMemInputPin)
617 hr = VFW_E_NOT_CONNECTED;
618 else
620 hr = IPin_Disconnect(This->pin.pConnectedTo);
621 IPin_Disconnect(&This->pin.IPin_iface);
623 LeaveCriticalSection(This->pin.pCritSec);
625 return hr;
629 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
631 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
633 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
635 *ppv = NULL;
637 if (IsEqualIID(riid, &IID_IUnknown))
638 *ppv = iface;
639 else if (IsEqualIID(riid, &IID_IPin))
640 *ppv = iface;
641 /* The Parser filter does not support querying IMediaSeeking, return it directly */
642 else if (IsEqualIID(riid, &IID_IMediaSeeking))
643 *ppv = &impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter)->sourceSeeking;
645 if (*ppv)
647 IUnknown_AddRef((IUnknown *)(*ppv));
648 return S_OK;
651 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
653 return E_NOINTERFACE;
656 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
658 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
659 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
661 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
663 if (!refCount)
665 FreeMediaType(This->pmt);
666 CoTaskMemFree(This->pmt);
667 FreeMediaType(&This->pin.pin.mtCurrent);
668 if (This->pin.pAllocator)
669 IMemAllocator_Release(This->pin.pAllocator);
670 CoTaskMemFree(This);
671 return 0;
673 return refCount;
676 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
678 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
679 ParserImpl *parser = impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter);
681 /* Set the allocator to our input pin's */
682 EnterCriticalSection(This->pin.pin.pCritSec);
683 This->alloc = parser->pInputPin->pAlloc;
684 LeaveCriticalSection(This->pin.pin.pCritSec);
686 return BaseOutputPinImpl_Connect(iface, pReceivePin, pmt);
689 static HRESULT WINAPI Parser_OutputPin_CheckMediaType(BasePin *pin, const AM_MEDIA_TYPE *pmt)
691 Parser_OutputPin *This = (Parser_OutputPin *)pin;
693 dump_AM_MEDIA_TYPE(pmt);
695 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
698 static const IPinVtbl Parser_OutputPin_Vtbl =
700 Parser_OutputPin_QueryInterface,
701 BasePinImpl_AddRef,
702 Parser_OutputPin_Release,
703 Parser_OutputPin_Connect,
704 BaseOutputPinImpl_ReceiveConnection,
705 BaseOutputPinImpl_Disconnect,
706 BasePinImpl_ConnectedTo,
707 BasePinImpl_ConnectionMediaType,
708 BasePinImpl_QueryPinInfo,
709 BasePinImpl_QueryDirection,
710 BasePinImpl_QueryId,
711 BasePinImpl_QueryAccept,
712 BasePinImpl_EnumMediaTypes,
713 BasePinImpl_QueryInternalConnections,
714 BaseOutputPinImpl_EndOfStream,
715 BaseOutputPinImpl_BeginFlush,
716 BaseOutputPinImpl_EndFlush,
717 BasePinImpl_NewSegment
720 static HRESULT WINAPI Parser_PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
722 PullPin *This = impl_PullPin_from_IPin(iface);
724 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
726 *ppv = NULL;
729 * It is important to capture the request for the IMediaSeeking interface before it is passed
730 * on to PullPin_QueryInterface, this is necessary since the Parser filter does not support
731 * querying IMediaSeeking
733 if (IsEqualIID(riid, &IID_IMediaSeeking))
734 *ppv = &impl_from_IBaseFilter(This->pin.pinInfo.pFilter)->sourceSeeking;
736 if (*ppv)
738 IUnknown_AddRef((IUnknown *)(*ppv));
739 return S_OK;
742 return PullPin_QueryInterface(iface, riid, ppv);
745 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
747 HRESULT hr;
748 PullPin *This = impl_PullPin_from_IPin(iface);
750 TRACE("()\n");
752 EnterCriticalSection(&This->thread_lock);
753 EnterCriticalSection(This->pin.pCritSec);
755 if (This->pin.pConnectedTo)
757 FILTER_STATE state;
758 ParserImpl *Parser = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
760 LeaveCriticalSection(This->pin.pCritSec);
761 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
762 EnterCriticalSection(This->pin.pCritSec);
764 if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
766 LeaveCriticalSection(This->pin.pCritSec);
767 PullPin_Disconnect(iface);
768 EnterCriticalSection(This->pin.pCritSec);
769 hr = Parser_RemoveOutputPins(impl_from_IBaseFilter(This->pin.pinInfo.pFilter));
771 else
772 hr = VFW_E_NOT_STOPPED;
774 else
775 hr = S_FALSE;
777 LeaveCriticalSection(This->pin.pCritSec);
778 LeaveCriticalSection(&This->thread_lock);
780 return hr;
783 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
785 HRESULT hr;
787 TRACE("()\n");
789 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
790 if (FAILED(hr))
792 BasePin *This = (BasePin *)iface;
794 EnterCriticalSection(This->pCritSec);
795 Parser_RemoveOutputPins(impl_from_IBaseFilter(This->pinInfo.pFilter));
796 LeaveCriticalSection(This->pCritSec);
799 return hr;
802 static HRESULT WINAPI Parser_PullPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
804 BasePin *This = (BasePin *)iface;
806 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
808 return EnumMediaTypes_Construct(This, BasePinImpl_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
811 static const IPinVtbl Parser_InputPin_Vtbl =
813 Parser_PullPin_QueryInterface,
814 BasePinImpl_AddRef,
815 PullPin_Release,
816 BaseInputPinImpl_Connect,
817 Parser_PullPin_ReceiveConnection,
818 Parser_PullPin_Disconnect,
819 BasePinImpl_ConnectedTo,
820 BasePinImpl_ConnectionMediaType,
821 BasePinImpl_QueryPinInfo,
822 BasePinImpl_QueryDirection,
823 BasePinImpl_QueryId,
824 PullPin_QueryAccept,
825 Parser_PullPin_EnumMediaTypes,
826 BasePinImpl_QueryInternalConnections,
827 PullPin_EndOfStream,
828 PullPin_BeginFlush,
829 PullPin_EndFlush,
830 PullPin_NewSegment