msxml3: Suppress IID_IRunnableObject FIXME since its not supported.
[wine.git] / dlls / quartz / parser.c
blob94eb614842d603c71ceba800f0ba605ed10e2889
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 "control_private.h"
24 #include "pin.h"
26 #include "vfwmsgs.h"
27 #include "amvideo.h"
29 #include "wine/unicode.h"
30 #include "wine/debug.h"
32 #include <math.h>
33 #include <assert.h>
35 #include "parser.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
39 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
40 static const IBaseFilterVtbl Parser_Vtbl;
41 static const IMediaSeekingVtbl Parser_Seeking_Vtbl;
42 static const IPinVtbl Parser_OutputPin_Vtbl;
43 static const IPinVtbl Parser_InputPin_Vtbl;
45 static HRESULT Parser_OutputPin_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt);
46 static HRESULT Parser_ChangeStart(LPVOID iface);
47 static HRESULT Parser_ChangeStop(LPVOID iface);
48 static HRESULT Parser_ChangeRate(LPVOID iface);
50 static HRESULT Parser_InputPin_Construct(const PIN_INFO * pPinInfo, SAMPLEPROC pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, IPin ** ppPin);
52 static inline Parser_OutputPin *impl_from_IMediaSeeking( IMediaSeeking *iface )
54 return (Parser_OutputPin *)((char*)iface - FIELD_OFFSET(Parser_OutputPin, mediaSeeking.lpVtbl));
58 HRESULT Parser_Create(ParserImpl* pParser, const CLSID* pClsid, PFN_PROCESS_SAMPLE fnProcessSample, PFN_QUERY_ACCEPT fnQueryAccept, PFN_PRE_CONNECT fnPreConnect, PFN_CLEANUP fnCleanup)
60 HRESULT hr;
61 PIN_INFO piInput;
63 /* pTransformFilter is already allocated */
64 pParser->clsid = *pClsid;
66 pParser->lpVtbl = &Parser_Vtbl;
67 pParser->refCount = 1;
68 InitializeCriticalSection(&pParser->csFilter);
69 pParser->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ParserImpl.csFilter");
70 pParser->state = State_Stopped;
71 pParser->pClock = NULL;
72 pParser->fnCleanup = fnCleanup;
73 ZeroMemory(&pParser->filterInfo, sizeof(FILTER_INFO));
75 pParser->cStreams = 0;
76 pParser->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
78 /* construct input pin */
79 piInput.dir = PINDIR_INPUT;
80 piInput.pFilter = (IBaseFilter *)pParser;
81 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
83 hr = Parser_InputPin_Construct(&piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, &pParser->csFilter, (IPin **)&pParser->pInputPin);
85 if (SUCCEEDED(hr))
87 pParser->ppPins[0] = (IPin *)pParser->pInputPin;
88 pParser->pInputPin->fnPreConnect = fnPreConnect;
90 else
92 CoTaskMemFree(pParser->ppPins);
93 pParser->csFilter.DebugInfo->Spare[0] = 0;
94 DeleteCriticalSection(&pParser->csFilter);
95 CoTaskMemFree(pParser);
98 return hr;
101 static HRESULT Parser_OutputPin_Init(const PIN_INFO * pPinInfo, ALLOCATOR_PROPERTIES * props, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, const AM_MEDIA_TYPE * pmt, float fSamplesPerSec, LPCRITICAL_SECTION pCritSec, Parser_OutputPin * pPinImpl)
103 pPinImpl->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
104 CopyMediaType(pPinImpl->pmt, pmt);
105 pPinImpl->dwSamplesProcessed = 0;
106 pPinImpl->dwSampleSize = 0;
107 pPinImpl->fSamplesPerSec = fSamplesPerSec;
109 MediaSeekingImpl_Init((LPVOID)pPinInfo->pFilter, Parser_ChangeStop, Parser_ChangeStart, Parser_ChangeRate, &pPinImpl->mediaSeeking);
110 pPinImpl->mediaSeeking.lpVtbl = &Parser_Seeking_Vtbl;
112 return OutputPin_Init(pPinInfo, props, pUserData, pQueryAccept, pCritSec, &pPinImpl->pin);
115 static HRESULT Parser_OutputPin_Construct(const PIN_INFO * pPinInfo, ALLOCATOR_PROPERTIES * props, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, const AM_MEDIA_TYPE * pmt, float fSamplesPerSec, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
117 Parser_OutputPin * pPinImpl;
119 *ppPin = NULL;
121 assert(pPinInfo->dir == PINDIR_OUTPUT);
123 pPinImpl = CoTaskMemAlloc(sizeof(Parser_OutputPin));
125 if (!pPinImpl)
126 return E_OUTOFMEMORY;
128 if (SUCCEEDED(Parser_OutputPin_Init(pPinInfo, props, pUserData, pQueryAccept, pmt, fSamplesPerSec, pCritSec, pPinImpl)))
130 pPinImpl->pin.pin.lpVtbl = &Parser_OutputPin_Vtbl;
132 *ppPin = (IPin *)pPinImpl;
133 return S_OK;
136 CoTaskMemFree(pPinImpl);
137 return E_FAIL;
140 static HRESULT WINAPI Parser_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
142 ParserImpl *This = (ParserImpl *)iface;
143 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
145 *ppv = NULL;
147 if (IsEqualIID(riid, &IID_IUnknown))
148 *ppv = (LPVOID)This;
149 else if (IsEqualIID(riid, &IID_IPersist))
150 *ppv = (LPVOID)This;
151 else if (IsEqualIID(riid, &IID_IMediaFilter))
152 *ppv = (LPVOID)This;
153 else if (IsEqualIID(riid, &IID_IBaseFilter))
154 *ppv = (LPVOID)This;
156 if (*ppv)
158 IUnknown_AddRef((IUnknown *)(*ppv));
159 return S_OK;
162 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
164 return E_NOINTERFACE;
167 static ULONG WINAPI Parser_AddRef(IBaseFilter * iface)
169 ParserImpl *This = (ParserImpl *)iface;
170 ULONG refCount = InterlockedIncrement(&This->refCount);
172 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
174 return refCount;
177 static ULONG WINAPI Parser_Release(IBaseFilter * iface)
179 ParserImpl *This = (ParserImpl *)iface;
180 ULONG refCount = InterlockedDecrement(&This->refCount);
182 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
184 if (!refCount)
186 ULONG i;
188 if (This->fnCleanup)
189 This->fnCleanup(This);
191 if (This->pClock)
192 IReferenceClock_Release(This->pClock);
194 for (i = 0; i < This->cStreams + 1; i++)
196 IPin *pConnectedTo;
198 if (SUCCEEDED(IPin_ConnectedTo(This->ppPins[i], &pConnectedTo)))
200 IPin_Disconnect(pConnectedTo);
201 IPin_Release(pConnectedTo);
203 IPin_Disconnect(This->ppPins[i]);
205 IPin_Release(This->ppPins[i]);
208 CoTaskMemFree(This->ppPins);
209 This->lpVtbl = NULL;
211 This->csFilter.DebugInfo->Spare[0] = 0;
212 DeleteCriticalSection(&This->csFilter);
214 TRACE("Destroying parser\n");
215 CoTaskMemFree(This);
217 return 0;
219 else
220 return refCount;
223 /** IPersist methods **/
225 static HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
227 ParserImpl *This = (ParserImpl *)iface;
229 TRACE("(%p)\n", pClsid);
231 *pClsid = This->clsid;
233 return S_OK;
236 /** IMediaFilter methods **/
238 static HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
240 HRESULT hr;
241 ParserImpl *This = (ParserImpl *)iface;
243 TRACE("()\n");
245 EnterCriticalSection(&This->csFilter);
247 if (This->state == State_Stopped)
249 LeaveCriticalSection(&This->csFilter);
250 return S_OK;
252 hr = PullPin_StopProcessing(This->pInputPin);
253 This->state = State_Stopped;
255 LeaveCriticalSection(&This->csFilter);
257 return hr;
260 static HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
262 HRESULT hr = S_OK;
263 BOOL bInit;
264 ParserImpl *This = (ParserImpl *)iface;
266 TRACE("()\n");
268 EnterCriticalSection(&This->csFilter);
270 if (This->state == State_Paused)
272 LeaveCriticalSection(&This->csFilter);
273 return S_OK;
275 bInit = (This->state == State_Stopped);
276 This->state = State_Paused;
278 LeaveCriticalSection(&This->csFilter);
280 if (bInit)
282 unsigned int i;
284 hr = PullPin_Seek(This->pInputPin, 0, ((LONGLONG)0x7fffffff << 32) | 0xffffffff);
286 if (SUCCEEDED(hr))
287 hr = PullPin_InitProcessing(This->pInputPin);
289 if (SUCCEEDED(hr))
291 for (i = 1; i < This->cStreams + 1; i++)
293 Parser_OutputPin* StreamPin = (Parser_OutputPin *)This->ppPins[i];
294 OutputPin_DeliverNewSegment((OutputPin *)This->ppPins[i], 0, (LONGLONG)ceil(10000000.0 * (float)StreamPin->dwLength / StreamPin->fSamplesPerSec), 1.0);
295 StreamPin->mediaSeeking.llDuration = (LONGLONG)ceil(10000000.0 * (float)StreamPin->dwLength / StreamPin->fSamplesPerSec);
296 StreamPin->mediaSeeking.llStop = (LONGLONG)ceil(10000000.0 * (float)StreamPin->dwLength / StreamPin->fSamplesPerSec);
297 OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
300 /* FIXME: this is a little hacky: we have to deliver (at least?) one sample
301 * to each renderer before they will complete their transitions. We should probably
302 * seek through the stream for the first of each, rather than do it this way which is
303 * probably a bit prone to deadlocking */
304 hr = PullPin_StartProcessing(This->pInputPin);
307 /* FIXME: else pause thread */
309 if (SUCCEEDED(hr))
310 hr = PullPin_PauseProcessing(This->pInputPin);
312 return hr;
315 static HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
317 HRESULT hr = S_OK;
318 ParserImpl *This = (ParserImpl *)iface;
319 int i;
321 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
323 EnterCriticalSection(&This->csFilter);
325 if (This->state == State_Running)
327 LeaveCriticalSection(&This->csFilter);
328 return S_OK;
331 This->rtStreamStart = tStart;
333 hr = PullPin_Seek(This->pInputPin, tStart, ((LONGLONG)0x7fffffff << 32) | 0xffffffff);
335 if (SUCCEEDED(hr) && (This->state == State_Stopped))
337 hr = PullPin_InitProcessing(This->pInputPin);
339 if (SUCCEEDED(hr))
341 for (i = 1; i < (This->cStreams + 1); i++)
343 OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
348 if (SUCCEEDED(hr))
349 hr = PullPin_StartProcessing(This->pInputPin);
351 if (SUCCEEDED(hr))
352 This->state = State_Running;
354 LeaveCriticalSection(&This->csFilter);
356 return hr;
359 static HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
361 ParserImpl *This = (ParserImpl *)iface;
363 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
365 EnterCriticalSection(&This->csFilter);
367 *pState = This->state;
369 LeaveCriticalSection(&This->csFilter);
371 /* FIXME: this is a little bit unsafe, but I don't see that we can do this
372 * while in the critical section. Maybe we could copy the pointer and addref in the
373 * critical section and then release after this.
375 if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
376 return VFW_S_STATE_INTERMEDIATE;
378 return S_OK;
381 static HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
383 ParserImpl *This = (ParserImpl *)iface;
385 TRACE("(%p)\n", pClock);
387 EnterCriticalSection(&This->csFilter);
389 if (This->pClock)
390 IReferenceClock_Release(This->pClock);
391 This->pClock = pClock;
392 if (This->pClock)
393 IReferenceClock_AddRef(This->pClock);
395 LeaveCriticalSection(&This->csFilter);
397 return S_OK;
400 static HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
402 ParserImpl *This = (ParserImpl *)iface;
404 TRACE("(%p)\n", ppClock);
406 EnterCriticalSection(&This->csFilter);
408 *ppClock = This->pClock;
409 if (This->pClock)
410 IReferenceClock_AddRef(This->pClock);
412 LeaveCriticalSection(&This->csFilter);
414 return S_OK;
417 /** IBaseFilter implementation **/
419 static HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
421 ENUMPINDETAILS epd;
422 ParserImpl *This = (ParserImpl *)iface;
424 TRACE("(%p)\n", ppEnum);
426 epd.cPins = This->cStreams + 1; /* +1 for input pin */
427 epd.ppPins = This->ppPins;
428 return IEnumPinsImpl_Construct(&epd, ppEnum);
431 static HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
433 FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
435 /* FIXME: critical section */
437 return E_NOTIMPL;
440 static HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
442 ParserImpl *This = (ParserImpl *)iface;
444 TRACE("(%p)\n", pInfo);
446 strcpyW(pInfo->achName, This->filterInfo.achName);
447 pInfo->pGraph = This->filterInfo.pGraph;
449 if (pInfo->pGraph)
450 IFilterGraph_AddRef(pInfo->pGraph);
452 return S_OK;
455 static HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
457 HRESULT hr = S_OK;
458 ParserImpl *This = (ParserImpl *)iface;
460 TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
462 EnterCriticalSection(&This->csFilter);
464 if (pName)
465 strcpyW(This->filterInfo.achName, pName);
466 else
467 *This->filterInfo.achName = '\0';
468 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
470 LeaveCriticalSection(&This->csFilter);
472 return hr;
475 static HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
477 TRACE("(%p)\n", pVendorInfo);
478 return E_NOTIMPL;
481 static const IBaseFilterVtbl Parser_Vtbl =
483 Parser_QueryInterface,
484 Parser_AddRef,
485 Parser_Release,
486 Parser_GetClassID,
487 Parser_Stop,
488 Parser_Pause,
489 Parser_Run,
490 Parser_GetState,
491 Parser_SetSyncSource,
492 Parser_GetSyncSource,
493 Parser_EnumPins,
494 Parser_FindPin,
495 Parser_QueryFilterInfo,
496 Parser_JoinFilterGraph,
497 Parser_QueryVendorInfo
500 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props,
501 const AM_MEDIA_TYPE * amt, float fSamplesPerSec, DWORD dwSampleSize, DWORD dwLength)
503 IPin ** ppOldPins;
504 HRESULT hr;
506 ppOldPins = This->ppPins;
508 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
509 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
511 hr = Parser_OutputPin_Construct(piOutput, props, NULL, Parser_OutputPin_QueryAccept, amt, fSamplesPerSec, &This->csFilter, This->ppPins + This->cStreams + 1);
513 if (SUCCEEDED(hr))
515 ((Parser_OutputPin *)(This->ppPins[This->cStreams + 1]))->dwSampleSize = dwSampleSize;
516 ((Parser_OutputPin *)(This->ppPins[This->cStreams + 1]))->dwLength = dwLength;
517 ((Parser_OutputPin *)(This->ppPins[This->cStreams + 1]))->pin.pin.pUserData = (LPVOID)This->ppPins[This->cStreams + 1];
518 This->cStreams++;
519 CoTaskMemFree(ppOldPins);
521 else
523 CoTaskMemFree(This->ppPins);
524 This->ppPins = ppOldPins;
525 ERR("Failed with error %x\n", hr);
528 return hr;
531 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
533 /* NOTE: should be in critical section when calling this function */
535 ULONG i;
536 IPin ** ppOldPins = This->ppPins;
538 /* reduce the pin array down to 1 (just our input pin) */
539 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
540 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
542 for (i = 0; i < This->cStreams; i++)
544 OutputPin_DeliverDisconnect((OutputPin *)ppOldPins[i + 1]);
545 IPin_Release(ppOldPins[i + 1]);
548 This->cStreams = 0;
549 CoTaskMemFree(ppOldPins);
551 return S_OK;
554 static HRESULT Parser_ChangeStart(LPVOID iface)
556 FIXME("(%p)\n", iface);
557 return S_OK;
560 static HRESULT Parser_ChangeStop(LPVOID iface)
562 FIXME("(%p)\n", iface);
563 return S_OK;
566 static HRESULT Parser_ChangeRate(LPVOID iface)
568 FIXME("(%p)\n", iface);
569 return S_OK;
573 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
575 Parser_OutputPin *This = impl_from_IMediaSeeking(iface);
577 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
580 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
582 Parser_OutputPin *This = impl_from_IMediaSeeking(iface);
584 return IUnknown_AddRef((IUnknown *)This);
587 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
589 Parser_OutputPin *This = impl_from_IMediaSeeking(iface);
591 return IUnknown_Release((IUnknown *)This);
594 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
596 Parser_Seeking_QueryInterface,
597 Parser_Seeking_AddRef,
598 Parser_Seeking_Release,
599 MediaSeekingImpl_GetCapabilities,
600 MediaSeekingImpl_CheckCapabilities,
601 MediaSeekingImpl_IsFormatSupported,
602 MediaSeekingImpl_QueryPreferredFormat,
603 MediaSeekingImpl_GetTimeFormat,
604 MediaSeekingImpl_IsUsingTimeFormat,
605 MediaSeekingImpl_SetTimeFormat,
606 MediaSeekingImpl_GetDuration,
607 MediaSeekingImpl_GetStopPosition,
608 MediaSeekingImpl_GetCurrentPosition,
609 MediaSeekingImpl_ConvertTimeFormat,
610 MediaSeekingImpl_SetPositions,
611 MediaSeekingImpl_GetPositions,
612 MediaSeekingImpl_GetAvailable,
613 MediaSeekingImpl_SetRate,
614 MediaSeekingImpl_GetRate,
615 MediaSeekingImpl_GetPreroll
618 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
620 Parser_OutputPin *This = (Parser_OutputPin *)iface;
622 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
624 *ppv = NULL;
626 if (IsEqualIID(riid, &IID_IUnknown))
627 *ppv = (LPVOID)iface;
628 else if (IsEqualIID(riid, &IID_IPin))
629 *ppv = (LPVOID)iface;
630 else if (IsEqualIID(riid, &IID_IMediaSeeking))
631 *ppv = (LPVOID)&This->mediaSeeking;
633 if (*ppv)
635 IUnknown_AddRef((IUnknown *)(*ppv));
636 return S_OK;
639 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
641 return E_NOINTERFACE;
644 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
646 Parser_OutputPin *This = (Parser_OutputPin *)iface;
647 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
649 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
651 if (!refCount)
653 FreeMediaType(This->pmt);
654 CoTaskMemFree(This->pmt);
655 FreeMediaType(&This->pin.pin.mtCurrent);
656 CoTaskMemFree(This);
657 return 0;
659 return refCount;
662 static HRESULT WINAPI Parser_OutputPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
664 ENUMMEDIADETAILS emd;
665 Parser_OutputPin *This = (Parser_OutputPin *)iface;
667 TRACE("(%p)\n", ppEnum);
669 /* override this method to allow enumeration of your types */
670 emd.cMediaTypes = 1;
671 emd.pMediaTypes = This->pmt;
673 return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
676 static HRESULT Parser_OutputPin_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
678 Parser_OutputPin *This = (Parser_OutputPin *)iface;
680 TRACE("()\n");
681 dump_AM_MEDIA_TYPE(pmt);
683 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
686 static const IPinVtbl Parser_OutputPin_Vtbl =
688 Parser_OutputPin_QueryInterface,
689 IPinImpl_AddRef,
690 Parser_OutputPin_Release,
691 OutputPin_Connect,
692 OutputPin_ReceiveConnection,
693 OutputPin_Disconnect,
694 IPinImpl_ConnectedTo,
695 IPinImpl_ConnectionMediaType,
696 IPinImpl_QueryPinInfo,
697 IPinImpl_QueryDirection,
698 IPinImpl_QueryId,
699 IPinImpl_QueryAccept,
700 Parser_OutputPin_EnumMediaTypes,
701 IPinImpl_QueryInternalConnections,
702 OutputPin_EndOfStream,
703 OutputPin_BeginFlush,
704 OutputPin_EndFlush,
705 OutputPin_NewSegment
708 static HRESULT Parser_InputPin_Construct(const PIN_INFO * pPinInfo, SAMPLEPROC pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
710 PullPin * pPinImpl;
712 *ppPin = NULL;
714 if (pPinInfo->dir != PINDIR_INPUT)
716 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
717 return E_INVALIDARG;
720 pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
722 if (!pPinImpl)
723 return E_OUTOFMEMORY;
725 if (SUCCEEDED(PullPin_Init(pPinInfo, pSampleProc, pUserData, pQueryAccept, pCritSec, pPinImpl)))
727 pPinImpl->pin.lpVtbl = &Parser_InputPin_Vtbl;
729 *ppPin = (IPin *)(&pPinImpl->pin.lpVtbl);
730 return S_OK;
733 CoTaskMemFree(pPinImpl);
734 return E_FAIL;
737 static HRESULT WINAPI Parser_InputPin_Disconnect(IPin * iface)
739 HRESULT hr;
740 IPinImpl *This = (IPinImpl *)iface;
742 TRACE("()\n");
744 EnterCriticalSection(This->pCritSec);
746 if (This->pConnectedTo)
748 FILTER_STATE state;
750 hr = IBaseFilter_GetState(This->pinInfo.pFilter, 0, &state);
752 if (SUCCEEDED(hr) && (state == State_Stopped))
754 IPin_Release(This->pConnectedTo);
755 This->pConnectedTo = NULL;
756 hr = Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
758 else
759 hr = VFW_E_NOT_STOPPED;
761 else
762 hr = S_FALSE;
764 LeaveCriticalSection(This->pCritSec);
766 return hr;
769 HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
771 HRESULT hr;
773 TRACE("()\n");
775 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
776 if (FAILED(hr))
778 IPinImpl *This = (IPinImpl *)iface;
780 EnterCriticalSection(This->pCritSec);
781 Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
782 LeaveCriticalSection(This->pCritSec);
785 return hr;
788 static const IPinVtbl Parser_InputPin_Vtbl =
790 PullPin_QueryInterface,
791 IPinImpl_AddRef,
792 PullPin_Release,
793 OutputPin_Connect,
794 Parser_PullPin_ReceiveConnection,
795 Parser_InputPin_Disconnect,
796 IPinImpl_ConnectedTo,
797 IPinImpl_ConnectionMediaType,
798 IPinImpl_QueryPinInfo,
799 IPinImpl_QueryDirection,
800 IPinImpl_QueryId,
801 IPinImpl_QueryAccept,
802 IPinImpl_EnumMediaTypes,
803 IPinImpl_QueryInternalConnections,
804 PullPin_EndOfStream,
805 PullPin_BeginFlush,
806 PullPin_EndFlush,
807 PullPin_NewSegment