po: Update Lithuanian translation.
[wine.git] / dlls / quartz / parser.c
blobf15f36464513069efc84f9aa61689bb3cd6b3481
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, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
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_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
407 ParserImpl *This = impl_from_IBaseFilter(iface);
408 FIXME("(%p)->(%s,%p)\n", This, debugstr_w(Id), ppPin);
410 /* FIXME: critical section */
412 return E_NOTIMPL;
415 HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
417 return BaseFilterImpl_QueryFilterInfo(iface, pInfo);
420 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
422 return BaseFilterImpl_JoinFilterGraph(iface, pGraph, pName);
425 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
427 return BaseFilterImpl_QueryVendorInfo(iface, pVendorInfo);
430 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
432 Parser_OutputPin_CheckMediaType,
433 BaseOutputPinImpl_AttemptConnection,
434 BasePinImpl_GetMediaTypeVersion,
435 Parser_OutputPin_GetMediaType
437 Parser_OutputPin_DecideBufferSize,
438 Parser_OutputPin_DecideAllocator,
439 Parser_OutputPin_BreakConnect
442 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
444 IPin ** ppOldPins;
445 HRESULT hr;
447 ppOldPins = This->ppPins;
449 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
450 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
452 hr = BaseOutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, &output_BaseOutputFuncTable, &This->filter.csFilter, This->ppPins + (This->cStreams + 1));
454 if (SUCCEEDED(hr))
456 IPin *pPin = This->ppPins[This->cStreams + 1];
457 Parser_OutputPin *pin = unsafe_impl_Parser_OutputPin_from_IPin(pPin);
458 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
459 CopyMediaType(pin->pmt, amt);
460 pin->dwSamplesProcessed = 0;
462 pin->pin.pin.pinInfo.pFilter = &This->filter.IBaseFilter_iface;
463 pin->allocProps = *props;
464 This->cStreams++;
465 BaseFilterImpl_IncrementPinVersion(&This->filter);
466 CoTaskMemFree(ppOldPins);
468 else
470 CoTaskMemFree(This->ppPins);
471 This->ppPins = ppOldPins;
472 ERR("Failed with error %x\n", hr);
475 return hr;
478 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
480 /* NOTE: should be in critical section when calling this function */
481 HRESULT hr;
482 ULONG i;
483 IPin ** ppOldPins = This->ppPins;
485 TRACE("(%p)\n", This);
487 /* reduce the pin array down to 1 (just our input pin) */
488 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
489 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
491 for (i = 0; i < This->cStreams; i++)
493 hr = ((BaseOutputPin *)ppOldPins[i + 1])->pFuncsTable->pfnBreakConnect((BaseOutputPin *)ppOldPins[i + 1]);
494 TRACE("Disconnect: %08x\n", hr);
495 IPin_Release(ppOldPins[i + 1]);
498 BaseFilterImpl_IncrementPinVersion(&This->filter);
499 This->cStreams = 0;
500 CoTaskMemFree(ppOldPins);
502 return S_OK;
505 static HRESULT WINAPI Parser_ChangeStart(IMediaSeeking *iface)
507 FIXME("(%p) filter hasn't implemented start position change!\n", iface);
508 return S_OK;
511 static HRESULT WINAPI Parser_ChangeStop(IMediaSeeking *iface)
513 FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
514 return S_OK;
517 static HRESULT WINAPI Parser_ChangeRate(IMediaSeeking *iface)
519 FIXME("(%p) filter hasn't implemented rate change!\n", iface);
520 return S_OK;
524 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
526 ParserImpl *This = impl_from_IMediaSeeking(iface);
528 return IBaseFilter_QueryInterface(&This->filter.IBaseFilter_iface, riid, ppv);
531 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
533 ParserImpl *This = impl_from_IMediaSeeking(iface);
535 return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
538 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
540 ParserImpl *This = impl_from_IMediaSeeking(iface);
542 return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
545 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
547 Parser_Seeking_QueryInterface,
548 Parser_Seeking_AddRef,
549 Parser_Seeking_Release,
550 SourceSeekingImpl_GetCapabilities,
551 SourceSeekingImpl_CheckCapabilities,
552 SourceSeekingImpl_IsFormatSupported,
553 SourceSeekingImpl_QueryPreferredFormat,
554 SourceSeekingImpl_GetTimeFormat,
555 SourceSeekingImpl_IsUsingTimeFormat,
556 SourceSeekingImpl_SetTimeFormat,
557 SourceSeekingImpl_GetDuration,
558 SourceSeekingImpl_GetStopPosition,
559 SourceSeekingImpl_GetCurrentPosition,
560 SourceSeekingImpl_ConvertTimeFormat,
561 SourceSeekingImpl_SetPositions,
562 SourceSeekingImpl_GetPositions,
563 SourceSeekingImpl_GetAvailable,
564 SourceSeekingImpl_SetRate,
565 SourceSeekingImpl_GetRate,
566 SourceSeekingImpl_GetPreroll
569 static HRESULT WINAPI Parser_OutputPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
571 Parser_OutputPin *This = (Parser_OutputPin*)iface;
572 ALLOCATOR_PROPERTIES actual;
574 if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
575 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
576 if (ppropInputRequest->cbPrefix)
577 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
578 if (ppropInputRequest->cbBuffer)
579 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
580 if (ppropInputRequest->cBuffers)
581 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
583 return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
586 static HRESULT WINAPI Parser_OutputPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
588 Parser_OutputPin *This = (Parser_OutputPin*)iface;
589 if (iPosition < 0)
590 return E_INVALIDARG;
591 if (iPosition > 0)
592 return VFW_S_NO_MORE_ITEMS;
593 CopyMediaType(pmt, This->pmt);
594 return S_OK;
597 static HRESULT WINAPI Parser_OutputPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
599 Parser_OutputPin *This = (Parser_OutputPin*)iface;
600 HRESULT hr;
602 *pAlloc = NULL;
604 if (This->alloc)
606 hr = IMemInputPin_NotifyAllocator(pPin, This->alloc, This->readonly);
607 if (SUCCEEDED(hr))
609 *pAlloc = This->alloc;
610 IMemAllocator_AddRef(*pAlloc);
613 else
614 hr = VFW_E_NO_ALLOCATOR;
616 return hr;
619 static HRESULT WINAPI Parser_OutputPin_BreakConnect(BaseOutputPin *This)
621 HRESULT hr;
623 TRACE("(%p)->()\n", This);
625 EnterCriticalSection(This->pin.pCritSec);
626 if (!This->pin.pConnectedTo || !This->pMemInputPin)
627 hr = VFW_E_NOT_CONNECTED;
628 else
630 hr = IPin_Disconnect(This->pin.pConnectedTo);
631 IPin_Disconnect(&This->pin.IPin_iface);
633 LeaveCriticalSection(This->pin.pCritSec);
635 return hr;
639 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
641 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
643 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
645 *ppv = NULL;
647 if (IsEqualIID(riid, &IID_IUnknown))
648 *ppv = iface;
649 else if (IsEqualIID(riid, &IID_IPin))
650 *ppv = iface;
651 /* The Parser filter does not support querying IMediaSeeking, return it directly */
652 else if (IsEqualIID(riid, &IID_IMediaSeeking))
653 *ppv = &impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter)->sourceSeeking;
655 if (*ppv)
657 IUnknown_AddRef((IUnknown *)(*ppv));
658 return S_OK;
661 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
663 return E_NOINTERFACE;
666 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
668 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
669 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
671 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
673 if (!refCount)
675 FreeMediaType(This->pmt);
676 CoTaskMemFree(This->pmt);
677 FreeMediaType(&This->pin.pin.mtCurrent);
678 if (This->pin.pAllocator)
679 IMemAllocator_Release(This->pin.pAllocator);
680 CoTaskMemFree(This);
681 return 0;
683 return refCount;
686 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
688 Parser_OutputPin *This = unsafe_impl_Parser_OutputPin_from_IPin(iface);
689 ParserImpl *parser = impl_from_IBaseFilter(This->pin.pin.pinInfo.pFilter);
691 /* Set the allocator to our input pin's */
692 EnterCriticalSection(This->pin.pin.pCritSec);
693 This->alloc = parser->pInputPin->pAlloc;
694 LeaveCriticalSection(This->pin.pin.pCritSec);
696 return BaseOutputPinImpl_Connect(iface, pReceivePin, pmt);
699 static HRESULT WINAPI Parser_OutputPin_CheckMediaType(BasePin *pin, const AM_MEDIA_TYPE *pmt)
701 Parser_OutputPin *This = (Parser_OutputPin *)pin;
703 dump_AM_MEDIA_TYPE(pmt);
705 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
708 static const IPinVtbl Parser_OutputPin_Vtbl =
710 Parser_OutputPin_QueryInterface,
711 BasePinImpl_AddRef,
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,
720 BasePinImpl_QueryId,
721 BasePinImpl_QueryAccept,
722 BasePinImpl_EnumMediaTypes,
723 BasePinImpl_QueryInternalConnections,
724 BaseOutputPinImpl_EndOfStream,
725 BaseOutputPinImpl_BeginFlush,
726 BaseOutputPinImpl_EndFlush,
727 BasePinImpl_NewSegment
730 static HRESULT WINAPI Parser_PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
732 PullPin *This = impl_PullPin_from_IPin(iface);
734 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
736 *ppv = NULL;
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;
746 if (*ppv)
748 IUnknown_AddRef((IUnknown *)(*ppv));
749 return S_OK;
752 return PullPin_QueryInterface(iface, riid, ppv);
755 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
757 HRESULT hr;
758 PullPin *This = impl_PullPin_from_IPin(iface);
760 TRACE("()\n");
762 EnterCriticalSection(&This->thread_lock);
763 EnterCriticalSection(This->pin.pCritSec);
765 if (This->pin.pConnectedTo)
767 FILTER_STATE state;
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));
781 else
782 hr = VFW_E_NOT_STOPPED;
784 else
785 hr = S_FALSE;
787 LeaveCriticalSection(This->pin.pCritSec);
788 LeaveCriticalSection(&This->thread_lock);
790 return hr;
793 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
795 HRESULT hr;
797 TRACE("()\n");
799 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
800 if (FAILED(hr))
802 BasePin *This = (BasePin *)iface;
804 EnterCriticalSection(This->pCritSec);
805 Parser_RemoveOutputPins(impl_from_IBaseFilter(This->pinInfo.pFilter));
806 LeaveCriticalSection(This->pCritSec);
809 return hr;
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,
824 BasePinImpl_AddRef,
825 PullPin_Release,
826 BaseInputPinImpl_Connect,
827 Parser_PullPin_ReceiveConnection,
828 Parser_PullPin_Disconnect,
829 BasePinImpl_ConnectedTo,
830 BasePinImpl_ConnectionMediaType,
831 BasePinImpl_QueryPinInfo,
832 BasePinImpl_QueryDirection,
833 BasePinImpl_QueryId,
834 PullPin_QueryAccept,
835 Parser_PullPin_EnumMediaTypes,
836 BasePinImpl_QueryInternalConnections,
837 PullPin_EndOfStream,
838 PullPin_BeginFlush,
839 PullPin_EndFlush,
840 PullPin_NewSegment