quartz: Move IMediaSeeking from the parser pin to the parser filter.
[wine.git] / dlls / quartz / parser.c
blobda664ac6db65c176edd3d772d68568a87351999d
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(IBaseFilter *iface);
47 static HRESULT Parser_ChangeStop(IBaseFilter *iface);
48 static HRESULT Parser_ChangeRate(IBaseFilter *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 ParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
54 return (ParserImpl *)((char*)iface - FIELD_OFFSET(ParserImpl, 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 MediaSeekingImpl_Init((IBaseFilter*)pParser, Parser_ChangeStop, Parser_ChangeStart, Parser_ChangeRate, &pParser->mediaSeeking);
84 pParser->mediaSeeking.lpVtbl = &Parser_Seeking_Vtbl;
86 hr = Parser_InputPin_Construct(&piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, &pParser->csFilter, (IPin **)&pParser->pInputPin);
88 if (SUCCEEDED(hr))
90 pParser->ppPins[0] = (IPin *)pParser->pInputPin;
91 pParser->pInputPin->fnPreConnect = fnPreConnect;
93 else
95 CoTaskMemFree(pParser->ppPins);
96 pParser->csFilter.DebugInfo->Spare[0] = 0;
97 DeleteCriticalSection(&pParser->csFilter);
98 CoTaskMemFree(pParser);
101 return hr;
104 static HRESULT Parser_OutputPin_Init(const PIN_INFO * pPinInfo, ALLOCATOR_PROPERTIES * props, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, const AM_MEDIA_TYPE * pmt, LPCRITICAL_SECTION pCritSec, Parser_OutputPin * pPinImpl)
106 pPinImpl->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
107 CopyMediaType(pPinImpl->pmt, pmt);
108 pPinImpl->dwSamplesProcessed = 0;
110 return OutputPin_Init(pPinInfo, props, pUserData, pQueryAccept, pCritSec, &pPinImpl->pin);
113 static HRESULT Parser_OutputPin_Construct(const PIN_INFO * pPinInfo, ALLOCATOR_PROPERTIES * props, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, const AM_MEDIA_TYPE * pmt, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
115 Parser_OutputPin * pPinImpl;
117 *ppPin = NULL;
119 assert(pPinInfo->dir == PINDIR_OUTPUT);
121 pPinImpl = CoTaskMemAlloc(sizeof(Parser_OutputPin));
123 if (!pPinImpl)
124 return E_OUTOFMEMORY;
126 if (SUCCEEDED(Parser_OutputPin_Init(pPinInfo, props, pUserData, pQueryAccept, pmt, pCritSec, pPinImpl)))
128 pPinImpl->pin.pin.lpVtbl = &Parser_OutputPin_Vtbl;
130 *ppPin = (IPin *)pPinImpl;
131 return S_OK;
134 CoTaskMemFree(pPinImpl);
135 return E_FAIL;
138 static HRESULT WINAPI Parser_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
140 ParserImpl *This = (ParserImpl *)iface;
141 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
143 *ppv = NULL;
145 if (IsEqualIID(riid, &IID_IUnknown))
146 *ppv = (LPVOID)This;
147 else if (IsEqualIID(riid, &IID_IPersist))
148 *ppv = (LPVOID)This;
149 else if (IsEqualIID(riid, &IID_IMediaFilter))
150 *ppv = (LPVOID)This;
151 else if (IsEqualIID(riid, &IID_IBaseFilter))
152 *ppv = (LPVOID)This;
153 else if (IsEqualIID(riid, &IID_IMediaSeeking))
154 *ppv = (LPVOID)&This->mediaSeeking;
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 LONGLONG duration;
294 DOUBLE speed;
296 IMediaSeeking_GetDuration((IMediaSeeking *)&This->mediaSeeking, &duration);
297 IMediaSeeking_GetRate((IMediaSeeking *)&This->mediaSeeking, &speed);
298 OutputPin_DeliverNewSegment((OutputPin *)This->ppPins[i], 0, duration, speed);
299 OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
302 /* FIXME: this is a little hacky: we have to deliver (at least?) one sample
303 * to each renderer before they will complete their transitions. We should probably
304 * seek through the stream for the first of each, rather than do it this way which is
305 * probably a bit prone to deadlocking */
306 hr = PullPin_StartProcessing(This->pInputPin);
309 /* FIXME: else pause thread */
311 if (SUCCEEDED(hr))
312 hr = PullPin_PauseProcessing(This->pInputPin);
314 return hr;
317 static HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
319 HRESULT hr = S_OK;
320 ParserImpl *This = (ParserImpl *)iface;
321 int i;
323 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
325 EnterCriticalSection(&This->csFilter);
327 if (This->state == State_Running)
329 LeaveCriticalSection(&This->csFilter);
330 return S_OK;
333 This->rtStreamStart = tStart;
335 hr = PullPin_Seek(This->pInputPin, tStart, ((LONGLONG)0x7fffffff << 32) | 0xffffffff);
337 if (SUCCEEDED(hr) && (This->state == State_Stopped))
339 hr = PullPin_InitProcessing(This->pInputPin);
341 if (SUCCEEDED(hr))
343 for (i = 1; i < (This->cStreams + 1); i++)
345 OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
350 if (SUCCEEDED(hr))
351 hr = PullPin_StartProcessing(This->pInputPin);
353 if (SUCCEEDED(hr))
354 This->state = State_Running;
356 LeaveCriticalSection(&This->csFilter);
358 return hr;
361 static HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
363 ParserImpl *This = (ParserImpl *)iface;
365 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
367 EnterCriticalSection(&This->csFilter);
369 *pState = This->state;
371 LeaveCriticalSection(&This->csFilter);
373 /* FIXME: this is a little bit unsafe, but I don't see that we can do this
374 * while in the critical section. Maybe we could copy the pointer and addref in the
375 * critical section and then release after this.
377 if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
378 return VFW_S_STATE_INTERMEDIATE;
380 return S_OK;
383 static HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
385 ParserImpl *This = (ParserImpl *)iface;
387 TRACE("(%p)\n", pClock);
389 EnterCriticalSection(&This->csFilter);
391 if (This->pClock)
392 IReferenceClock_Release(This->pClock);
393 This->pClock = pClock;
394 if (This->pClock)
395 IReferenceClock_AddRef(This->pClock);
397 LeaveCriticalSection(&This->csFilter);
399 return S_OK;
402 static HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
404 ParserImpl *This = (ParserImpl *)iface;
406 TRACE("(%p)\n", ppClock);
408 EnterCriticalSection(&This->csFilter);
410 *ppClock = This->pClock;
411 if (This->pClock)
412 IReferenceClock_AddRef(This->pClock);
414 LeaveCriticalSection(&This->csFilter);
416 return S_OK;
419 /** IBaseFilter implementation **/
421 static HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
423 ENUMPINDETAILS epd;
424 ParserImpl *This = (ParserImpl *)iface;
426 TRACE("(%p)\n", ppEnum);
428 epd.cPins = This->cStreams + 1; /* +1 for input pin */
429 epd.ppPins = This->ppPins;
430 return IEnumPinsImpl_Construct(&epd, ppEnum);
433 static HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
435 FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
437 /* FIXME: critical section */
439 return E_NOTIMPL;
442 static HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
444 ParserImpl *This = (ParserImpl *)iface;
446 TRACE("(%p)\n", pInfo);
448 strcpyW(pInfo->achName, This->filterInfo.achName);
449 pInfo->pGraph = This->filterInfo.pGraph;
451 if (pInfo->pGraph)
452 IFilterGraph_AddRef(pInfo->pGraph);
454 return S_OK;
457 static HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
459 HRESULT hr = S_OK;
460 ParserImpl *This = (ParserImpl *)iface;
462 TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
464 EnterCriticalSection(&This->csFilter);
466 if (pName)
467 strcpyW(This->filterInfo.achName, pName);
468 else
469 *This->filterInfo.achName = '\0';
470 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
472 LeaveCriticalSection(&This->csFilter);
474 return hr;
477 static HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
479 TRACE("(%p)\n", pVendorInfo);
480 return E_NOTIMPL;
483 static const IBaseFilterVtbl Parser_Vtbl =
485 Parser_QueryInterface,
486 Parser_AddRef,
487 Parser_Release,
488 Parser_GetClassID,
489 Parser_Stop,
490 Parser_Pause,
491 Parser_Run,
492 Parser_GetState,
493 Parser_SetSyncSource,
494 Parser_GetSyncSource,
495 Parser_EnumPins,
496 Parser_FindPin,
497 Parser_QueryFilterInfo,
498 Parser_JoinFilterGraph,
499 Parser_QueryVendorInfo
502 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
504 IPin ** ppOldPins;
505 HRESULT hr;
507 ppOldPins = This->ppPins;
509 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
510 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
512 hr = Parser_OutputPin_Construct(piOutput, props, NULL, Parser_OutputPin_QueryAccept, amt, &This->csFilter, This->ppPins + This->cStreams + 1);
514 if (SUCCEEDED(hr))
516 ((Parser_OutputPin *)(This->ppPins[This->cStreams + 1]))->pin.pin.pUserData = (LPVOID)This->ppPins[This->cStreams + 1];
517 This->cStreams++;
518 CoTaskMemFree(ppOldPins);
520 else
522 CoTaskMemFree(This->ppPins);
523 This->ppPins = ppOldPins;
524 ERR("Failed with error %x\n", hr);
527 return hr;
530 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
532 /* NOTE: should be in critical section when calling this function */
534 ULONG i;
535 IPin ** ppOldPins = This->ppPins;
537 /* reduce the pin array down to 1 (just our input pin) */
538 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
539 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
541 for (i = 0; i < This->cStreams; i++)
543 OutputPin_DeliverDisconnect((OutputPin *)ppOldPins[i + 1]);
544 IPin_Release(ppOldPins[i + 1]);
547 This->cStreams = 0;
548 CoTaskMemFree(ppOldPins);
550 return S_OK;
553 static HRESULT Parser_ChangeStart(IBaseFilter *iface)
555 FIXME("(%p)\n", iface);
556 return S_OK;
559 static HRESULT Parser_ChangeStop(IBaseFilter *iface)
561 FIXME("(%p)\n", iface);
562 return S_OK;
565 static HRESULT Parser_ChangeRate(IBaseFilter *iface)
567 FIXME("(%p)\n", iface);
568 return S_OK;
572 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
574 ParserImpl *This = impl_from_IMediaSeeking(iface);
576 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
579 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
581 ParserImpl *This = impl_from_IMediaSeeking(iface);
583 return IUnknown_AddRef((IUnknown *)This);
586 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
588 ParserImpl *This = impl_from_IMediaSeeking(iface);
590 return IUnknown_Release((IUnknown *)This);
593 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
595 Parser_Seeking_QueryInterface,
596 Parser_Seeking_AddRef,
597 Parser_Seeking_Release,
598 MediaSeekingImpl_GetCapabilities,
599 MediaSeekingImpl_CheckCapabilities,
600 MediaSeekingImpl_IsFormatSupported,
601 MediaSeekingImpl_QueryPreferredFormat,
602 MediaSeekingImpl_GetTimeFormat,
603 MediaSeekingImpl_IsUsingTimeFormat,
604 MediaSeekingImpl_SetTimeFormat,
605 MediaSeekingImpl_GetDuration,
606 MediaSeekingImpl_GetStopPosition,
607 MediaSeekingImpl_GetCurrentPosition,
608 MediaSeekingImpl_ConvertTimeFormat,
609 MediaSeekingImpl_SetPositions,
610 MediaSeekingImpl_GetPositions,
611 MediaSeekingImpl_GetAvailable,
612 MediaSeekingImpl_SetRate,
613 MediaSeekingImpl_GetRate,
614 MediaSeekingImpl_GetPreroll
617 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
619 Parser_OutputPin *This = (Parser_OutputPin *)iface;
621 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
623 *ppv = NULL;
625 if (IsEqualIID(riid, &IID_IUnknown))
626 *ppv = (LPVOID)iface;
627 else if (IsEqualIID(riid, &IID_IPin))
628 *ppv = (LPVOID)iface;
629 else if (IsEqualIID(riid, &IID_IMediaSeeking))
631 return IBaseFilter_QueryInterface((IBaseFilter*)&This->pin.pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
634 if (*ppv)
636 IUnknown_AddRef((IUnknown *)(*ppv));
637 return S_OK;
640 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
642 return E_NOINTERFACE;
645 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
647 Parser_OutputPin *This = (Parser_OutputPin *)iface;
648 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
650 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
652 if (!refCount)
654 FreeMediaType(This->pmt);
655 CoTaskMemFree(This->pmt);
656 FreeMediaType(&This->pin.pin.mtCurrent);
657 CoTaskMemFree(This);
658 return 0;
660 return refCount;
663 static HRESULT WINAPI Parser_OutputPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
665 ENUMMEDIADETAILS emd;
666 Parser_OutputPin *This = (Parser_OutputPin *)iface;
668 TRACE("(%p)\n", ppEnum);
670 /* override this method to allow enumeration of your types */
671 emd.cMediaTypes = 1;
672 emd.pMediaTypes = This->pmt;
674 return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
677 static HRESULT Parser_OutputPin_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
679 Parser_OutputPin *This = (Parser_OutputPin *)iface;
681 TRACE("()\n");
682 dump_AM_MEDIA_TYPE(pmt);
684 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
687 static const IPinVtbl Parser_OutputPin_Vtbl =
689 Parser_OutputPin_QueryInterface,
690 IPinImpl_AddRef,
691 Parser_OutputPin_Release,
692 OutputPin_Connect,
693 OutputPin_ReceiveConnection,
694 OutputPin_Disconnect,
695 IPinImpl_ConnectedTo,
696 IPinImpl_ConnectionMediaType,
697 IPinImpl_QueryPinInfo,
698 IPinImpl_QueryDirection,
699 IPinImpl_QueryId,
700 IPinImpl_QueryAccept,
701 Parser_OutputPin_EnumMediaTypes,
702 IPinImpl_QueryInternalConnections,
703 OutputPin_EndOfStream,
704 OutputPin_BeginFlush,
705 OutputPin_EndFlush,
706 OutputPin_NewSegment
709 static HRESULT Parser_InputPin_Construct(const PIN_INFO * pPinInfo, SAMPLEPROC pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
711 PullPin * pPinImpl;
713 *ppPin = NULL;
715 if (pPinInfo->dir != PINDIR_INPUT)
717 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
718 return E_INVALIDARG;
721 pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
723 if (!pPinImpl)
724 return E_OUTOFMEMORY;
726 if (SUCCEEDED(PullPin_Init(pPinInfo, pSampleProc, pUserData, pQueryAccept, pCritSec, pPinImpl)))
728 pPinImpl->pin.lpVtbl = &Parser_InputPin_Vtbl;
730 *ppPin = (IPin *)(&pPinImpl->pin.lpVtbl);
731 return S_OK;
734 CoTaskMemFree(pPinImpl);
735 return E_FAIL;
738 static HRESULT WINAPI Parser_InputPin_Disconnect(IPin * iface)
740 HRESULT hr;
741 IPinImpl *This = (IPinImpl *)iface;
743 TRACE("()\n");
745 EnterCriticalSection(This->pCritSec);
747 if (This->pConnectedTo)
749 FILTER_STATE state;
751 hr = IBaseFilter_GetState(This->pinInfo.pFilter, 0, &state);
753 if (SUCCEEDED(hr) && (state == State_Stopped))
755 IPin_Release(This->pConnectedTo);
756 This->pConnectedTo = NULL;
757 hr = Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
759 else
760 hr = VFW_E_NOT_STOPPED;
762 else
763 hr = S_FALSE;
765 LeaveCriticalSection(This->pCritSec);
767 return hr;
770 HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
772 HRESULT hr;
774 TRACE("()\n");
776 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
777 if (FAILED(hr))
779 IPinImpl *This = (IPinImpl *)iface;
781 EnterCriticalSection(This->pCritSec);
782 Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
783 LeaveCriticalSection(This->pCritSec);
786 return hr;
789 static const IPinVtbl Parser_InputPin_Vtbl =
791 PullPin_QueryInterface,
792 IPinImpl_AddRef,
793 PullPin_Release,
794 OutputPin_Connect,
795 Parser_PullPin_ReceiveConnection,
796 Parser_InputPin_Disconnect,
797 IPinImpl_ConnectedTo,
798 IPinImpl_ConnectionMediaType,
799 IPinImpl_QueryPinInfo,
800 IPinImpl_QueryDirection,
801 IPinImpl_QueryId,
802 IPinImpl_QueryAccept,
803 IPinImpl_EnumMediaTypes,
804 IPinImpl_QueryInternalConnections,
805 PullPin_EndOfStream,
806 PullPin_BeginFlush,
807 PullPin_EndFlush,
808 PullPin_NewSegment