d3dxof: Do not expect a separator when there is no element.
[wine/multimedia.git] / dlls / quartz / parser.c
blobda5e9d3d6ceb6219dbaaf79a5447123665b4d3e9
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 IMediaSeekingVtbl Parser_Seeking_Vtbl;
41 static const IPinVtbl Parser_OutputPin_Vtbl;
42 static const IPinVtbl Parser_InputPin_Vtbl;
44 static HRESULT Parser_OutputPin_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt);
45 static HRESULT Parser_ChangeCurrent(IBaseFilter *iface);
46 static HRESULT Parser_ChangeStop(IBaseFilter *iface);
47 static HRESULT Parser_ChangeRate(IBaseFilter *iface);
49 static inline ParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
51 return (ParserImpl *)((char*)iface - FIELD_OFFSET(ParserImpl, mediaSeeking.lpVtbl));
55 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, CHANGEPROC stop, CHANGEPROC current, CHANGEPROC rate)
57 HRESULT hr;
58 PIN_INFO piInput;
60 /* pTransformFilter is already allocated */
61 pParser->clsid = *pClsid;
62 pParser->lpVtbl = Parser_Vtbl;
63 pParser->refCount = 1;
64 InitializeCriticalSection(&pParser->csFilter);
65 pParser->csFilter.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ParserImpl.csFilter");
66 pParser->state = State_Stopped;
67 pParser->pClock = NULL;
68 pParser->fnDisconnect = fnDisconnect;
69 ZeroMemory(&pParser->filterInfo, sizeof(FILTER_INFO));
70 pParser->lastpinchange = GetTickCount();
72 pParser->cStreams = 0;
73 pParser->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
75 /* construct input pin */
76 piInput.dir = PINDIR_INPUT;
77 piInput.pFilter = (IBaseFilter *)pParser;
78 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
80 if (!current)
81 current = Parser_ChangeCurrent;
83 if (!stop)
84 stop = Parser_ChangeStop;
86 if (!rate)
87 rate = Parser_ChangeRate;
89 MediaSeekingImpl_Init((IBaseFilter*)pParser, stop, current, rate, &pParser->mediaSeeking, &pParser->csFilter);
90 pParser->mediaSeeking.lpVtbl = &Parser_Seeking_Vtbl;
92 hr = PullPin_Construct(&Parser_InputPin_Vtbl, &piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, fnCleanup, fnRequest, fnDone, &pParser->csFilter, (IPin **)&pParser->pInputPin);
94 if (SUCCEEDED(hr))
96 pParser->ppPins[0] = (IPin *)pParser->pInputPin;
97 pParser->pInputPin->fnPreConnect = fnPreConnect;
99 else
101 CoTaskMemFree(pParser->ppPins);
102 pParser->csFilter.DebugInfo->Spare[0] = 0;
103 DeleteCriticalSection(&pParser->csFilter);
104 CoTaskMemFree(pParser);
107 return hr;
110 HRESULT WINAPI Parser_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
112 ParserImpl *This = (ParserImpl *)iface;
113 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
115 *ppv = NULL;
117 if (IsEqualIID(riid, &IID_IUnknown))
118 *ppv = This;
119 else if (IsEqualIID(riid, &IID_IPersist))
120 *ppv = This;
121 else if (IsEqualIID(riid, &IID_IMediaFilter))
122 *ppv = This;
123 else if (IsEqualIID(riid, &IID_IBaseFilter))
124 *ppv = This;
125 else if (IsEqualIID(riid, &IID_IMediaSeeking))
126 *ppv = &This->mediaSeeking;
128 if (*ppv)
130 IUnknown_AddRef((IUnknown *)(*ppv));
131 return S_OK;
134 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
135 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
137 return E_NOINTERFACE;
140 ULONG WINAPI Parser_AddRef(IBaseFilter * iface)
142 ParserImpl *This = (ParserImpl *)iface;
143 ULONG refCount = InterlockedIncrement(&This->refCount);
145 TRACE("(%p/%p)->() AddRef from %d\n", This, iface, refCount - 1);
147 return refCount;
150 void Parser_Destroy(ParserImpl *This)
152 IPin *connected = NULL;
153 ULONG pinref;
155 assert(!This->refCount);
156 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
158 if (This->pClock)
159 IReferenceClock_Release(This->pClock);
161 /* Don't need to clean up output pins, freeing input pin will do that */
162 IPin_ConnectedTo((IPin *)This->pInputPin, &connected);
163 if (connected)
165 assert(IPin_Disconnect(connected) == S_OK);
166 IPin_Release(connected);
167 assert(IPin_Disconnect((IPin *)This->pInputPin) == S_OK);
169 pinref = IPin_Release((IPin *)This->pInputPin);
170 if (pinref)
172 /* Valgrind could find this, if I kill it here */
173 ERR("pinref should be null, is %u, destroying anyway\n", pinref);
174 assert((LONG)pinref > 0);
176 while (pinref)
177 pinref = IPin_Release((IPin *)This->pInputPin);
180 CoTaskMemFree(This->ppPins);
181 This->lpVtbl = NULL;
183 This->csFilter.DebugInfo->Spare[0] = 0;
184 DeleteCriticalSection(&This->csFilter);
186 TRACE("Destroying parser\n");
187 CoTaskMemFree(This);
190 ULONG WINAPI Parser_Release(IBaseFilter * iface)
192 ParserImpl *This = (ParserImpl *)iface;
193 ULONG refCount = InterlockedDecrement(&This->refCount);
195 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
197 if (!refCount)
198 Parser_Destroy(This);
200 return refCount;
203 /** IPersist methods **/
205 HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
207 ParserImpl *This = (ParserImpl *)iface;
209 TRACE("(%p)\n", pClsid);
211 *pClsid = This->clsid;
213 return S_OK;
216 /** IMediaFilter methods **/
218 HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
220 ParserImpl *This = (ParserImpl *)iface;
221 PullPin *pin = (PullPin *)This->ppPins[0];
222 ULONG i;
224 TRACE("()\n");
226 EnterCriticalSection(&pin->thread_lock);
228 IAsyncReader_BeginFlush(This->pInputPin->pReader);
229 EnterCriticalSection(&This->csFilter);
231 if (This->state == State_Stopped)
233 LeaveCriticalSection(&This->csFilter);
234 IAsyncReader_EndFlush(This->pInputPin->pReader);
235 LeaveCriticalSection(&pin->thread_lock);
236 return S_OK;
239 This->state = State_Stopped;
241 for (i = 1; i < (This->cStreams + 1); i++)
243 OutputPin_DecommitAllocator((OutputPin *)This->ppPins[i]);
246 LeaveCriticalSection(&This->csFilter);
248 PullPin_PauseProcessing(This->pInputPin);
249 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
250 IAsyncReader_EndFlush(This->pInputPin->pReader);
252 LeaveCriticalSection(&pin->thread_lock);
253 return S_OK;
256 HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
258 HRESULT hr = S_OK;
259 ParserImpl *This = (ParserImpl *)iface;
260 PullPin *pin = (PullPin *)This->ppPins[0];
262 TRACE("()\n");
264 EnterCriticalSection(&pin->thread_lock);
265 EnterCriticalSection(&This->csFilter);
267 if (This->state == State_Paused)
269 LeaveCriticalSection(&This->csFilter);
270 LeaveCriticalSection(&pin->thread_lock);
271 return S_OK;
274 if (This->state == State_Stopped)
276 LeaveCriticalSection(&This->csFilter);
277 hr = IBaseFilter_Run(iface, -1);
278 EnterCriticalSection(&This->csFilter);
281 if (SUCCEEDED(hr))
282 This->state = State_Paused;
284 LeaveCriticalSection(&This->csFilter);
285 LeaveCriticalSection(&pin->thread_lock);
287 return hr;
290 HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
292 HRESULT hr = S_OK;
293 ParserImpl *This = (ParserImpl *)iface;
294 PullPin *pin = (PullPin *)This->ppPins[0];
296 ULONG i;
298 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
300 EnterCriticalSection(&pin->thread_lock);
301 EnterCriticalSection(&This->csFilter);
303 HRESULT hr_any = VFW_E_NOT_CONNECTED;
305 if (This->state == State_Running || This->state == State_Paused)
307 This->state = State_Running;
308 LeaveCriticalSection(&This->csFilter);
309 LeaveCriticalSection(&pin->thread_lock);
310 return S_OK;
313 This->rtStreamStart = tStart;
315 for (i = 1; i < (This->cStreams + 1); i++)
317 hr = OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
318 if (SUCCEEDED(hr))
319 hr_any = hr;
322 hr = hr_any;
323 if (SUCCEEDED(hr))
325 LeaveCriticalSection(&This->csFilter);
326 hr = PullPin_StartProcessing(This->pInputPin);
327 EnterCriticalSection(&This->csFilter);
330 if (SUCCEEDED(hr))
331 This->state = State_Running;
333 LeaveCriticalSection(&This->csFilter);
334 LeaveCriticalSection(&pin->thread_lock);
336 return hr;
339 HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
341 ParserImpl *This = (ParserImpl *)iface;
342 PullPin *pin = (PullPin *)This->ppPins[0];
343 HRESULT hr = S_OK;
345 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
347 EnterCriticalSection(&pin->thread_lock);
348 EnterCriticalSection(&This->csFilter);
350 *pState = This->state;
352 LeaveCriticalSection(&This->csFilter);
354 if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
355 hr = VFW_S_STATE_INTERMEDIATE;
356 LeaveCriticalSection(&pin->thread_lock);
358 return hr;
361 HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
363 ParserImpl *This = (ParserImpl *)iface;
364 PullPin *pin = (PullPin *)This->ppPins[0];
366 TRACE("(%p)\n", pClock);
368 EnterCriticalSection(&pin->thread_lock);
369 EnterCriticalSection(&This->csFilter);
371 if (This->pClock)
372 IReferenceClock_Release(This->pClock);
373 This->pClock = pClock;
374 if (This->pClock)
375 IReferenceClock_AddRef(This->pClock);
377 LeaveCriticalSection(&This->csFilter);
378 LeaveCriticalSection(&pin->thread_lock);
380 return S_OK;
383 HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
385 ParserImpl *This = (ParserImpl *)iface;
387 TRACE("(%p)\n", ppClock);
389 EnterCriticalSection(&This->csFilter);
391 *ppClock = This->pClock;
392 if (This->pClock)
393 IReferenceClock_AddRef(This->pClock);
395 LeaveCriticalSection(&This->csFilter);
397 return S_OK;
400 /** IBaseFilter implementation **/
402 /* FIXME: WRONG */
403 static HRESULT Parser_GetPin(IBaseFilter *iface, ULONG pos, IPin **pin, DWORD *lastsynctick)
405 ParserImpl *This = (ParserImpl *)iface;
407 *lastsynctick = This->lastpinchange;
409 TRACE("Asking for pos %x\n", pos);
411 /* Input pin also has a pin, hence the > and not >= */
412 if (pos > This->cStreams)
413 return S_FALSE;
415 *pin = This->ppPins[pos];
416 IPin_AddRef(*pin);
417 return S_OK;
420 HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
422 ParserImpl *This = (ParserImpl *)iface;
424 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
426 return IEnumPinsImpl_Construct(ppEnum, Parser_GetPin, iface);
429 HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
431 FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
433 /* FIXME: critical section */
435 return E_NOTIMPL;
438 HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
440 ParserImpl *This = (ParserImpl *)iface;
442 TRACE("(%p)\n", pInfo);
444 strcpyW(pInfo->achName, This->filterInfo.achName);
445 pInfo->pGraph = This->filterInfo.pGraph;
447 if (pInfo->pGraph)
448 IFilterGraph_AddRef(pInfo->pGraph);
450 return S_OK;
453 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
455 HRESULT hr = S_OK;
456 ParserImpl *This = (ParserImpl *)iface;
458 TRACE("(%p, %s)\n", pGraph, debugstr_w(pName));
460 EnterCriticalSection(&This->csFilter);
462 if (pName)
463 strcpyW(This->filterInfo.achName, pName);
464 else
465 *This->filterInfo.achName = '\0';
466 This->filterInfo.pGraph = pGraph; /* NOTE: do NOT increase ref. count */
468 LeaveCriticalSection(&This->csFilter);
470 return hr;
473 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
475 TRACE("(%p)\n", pVendorInfo);
476 return E_NOTIMPL;
479 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
481 IPin ** ppOldPins;
482 HRESULT hr;
484 ppOldPins = This->ppPins;
486 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
487 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
489 hr = OutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, props, NULL, Parser_OutputPin_QueryAccept, &This->csFilter, This->ppPins + (This->cStreams + 1));
491 if (SUCCEEDED(hr))
493 IPin *pPin = This->ppPins[This->cStreams + 1];
494 Parser_OutputPin *pin = (Parser_OutputPin *)pPin;
495 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
496 CopyMediaType(pin->pmt, amt);
497 pin->dwSamplesProcessed = 0;
499 pin->pin.pin.pUserData = This->ppPins[This->cStreams + 1];
500 pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
501 pin->pin.custom_allocator = 1;
502 This->cStreams++;
503 This->lastpinchange = GetTickCount();
504 CoTaskMemFree(ppOldPins);
506 else
508 CoTaskMemFree(This->ppPins);
509 This->ppPins = ppOldPins;
510 ERR("Failed with error %x\n", hr);
513 return hr;
516 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
518 /* NOTE: should be in critical section when calling this function */
519 HRESULT hr;
520 ULONG i;
521 IPin ** ppOldPins = This->ppPins;
523 TRACE("(%p)\n", This);
525 /* reduce the pin array down to 1 (just our input pin) */
526 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
527 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
529 for (i = 0; i < This->cStreams; i++)
531 hr = OutputPin_DeliverDisconnect((OutputPin *)ppOldPins[i + 1]);
532 TRACE("Disconnect: %08x\n", hr);
533 IPin_Release(ppOldPins[i + 1]);
536 This->lastpinchange = GetTickCount();
537 This->cStreams = 0;
538 CoTaskMemFree(ppOldPins);
540 return S_OK;
543 static HRESULT Parser_ChangeCurrent(IBaseFilter *iface)
545 FIXME("(%p) filter hasn't implemented current position change!\n", iface);
546 return S_OK;
549 static HRESULT Parser_ChangeStop(IBaseFilter *iface)
551 FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
552 return S_OK;
555 static HRESULT Parser_ChangeRate(IBaseFilter *iface)
557 FIXME("(%p) filter hasn't implemented rate change!\n", iface);
558 return S_OK;
562 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
564 ParserImpl *This = impl_from_IMediaSeeking(iface);
566 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
569 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
571 ParserImpl *This = impl_from_IMediaSeeking(iface);
573 return IUnknown_AddRef((IUnknown *)This);
576 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
578 ParserImpl *This = impl_from_IMediaSeeking(iface);
580 return IUnknown_Release((IUnknown *)This);
583 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
585 Parser_Seeking_QueryInterface,
586 Parser_Seeking_AddRef,
587 Parser_Seeking_Release,
588 MediaSeekingImpl_GetCapabilities,
589 MediaSeekingImpl_CheckCapabilities,
590 MediaSeekingImpl_IsFormatSupported,
591 MediaSeekingImpl_QueryPreferredFormat,
592 MediaSeekingImpl_GetTimeFormat,
593 MediaSeekingImpl_IsUsingTimeFormat,
594 MediaSeekingImpl_SetTimeFormat,
595 MediaSeekingImpl_GetDuration,
596 MediaSeekingImpl_GetStopPosition,
597 MediaSeekingImpl_GetCurrentPosition,
598 MediaSeekingImpl_ConvertTimeFormat,
599 MediaSeekingImpl_SetPositions,
600 MediaSeekingImpl_GetPositions,
601 MediaSeekingImpl_GetAvailable,
602 MediaSeekingImpl_SetRate,
603 MediaSeekingImpl_GetRate,
604 MediaSeekingImpl_GetPreroll
607 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
609 Parser_OutputPin *This = (Parser_OutputPin *)iface;
611 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
613 *ppv = NULL;
615 if (IsEqualIID(riid, &IID_IUnknown))
616 *ppv = iface;
617 else if (IsEqualIID(riid, &IID_IPin))
618 *ppv = iface;
619 else if (IsEqualIID(riid, &IID_IMediaSeeking))
621 return IBaseFilter_QueryInterface(This->pin.pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
624 if (*ppv)
626 IUnknown_AddRef((IUnknown *)(*ppv));
627 return S_OK;
630 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
632 return E_NOINTERFACE;
635 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
637 Parser_OutputPin *This = (Parser_OutputPin *)iface;
638 ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
640 TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
642 if (!refCount)
644 FreeMediaType(This->pmt);
645 CoTaskMemFree(This->pmt);
646 FreeMediaType(&This->pin.pin.mtCurrent);
647 CoTaskMemFree(This);
648 return 0;
650 return refCount;
653 static HRESULT WINAPI Parser_OutputPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
655 ENUMMEDIADETAILS emd;
656 Parser_OutputPin *This = (Parser_OutputPin *)iface;
658 TRACE("(%p)\n", ppEnum);
660 /* override this method to allow enumeration of your types */
661 emd.cMediaTypes = 1;
662 emd.pMediaTypes = This->pmt;
664 return IEnumMediaTypesImpl_Construct(&emd, ppEnum);
667 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
669 Parser_OutputPin *This = (Parser_OutputPin *)iface;
670 ParserImpl *parser = (ParserImpl *)This->pin.pin.pinInfo.pFilter;
672 /* Set the allocator to our input pin's */
673 EnterCriticalSection(This->pin.pin.pCritSec);
674 This->pin.alloc = parser->pInputPin->pAlloc;
675 LeaveCriticalSection(This->pin.pin.pCritSec);
677 return OutputPin_Connect(iface, pReceivePin, pmt);
680 static HRESULT Parser_OutputPin_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
682 Parser_OutputPin *This = iface;
684 TRACE("()\n");
685 dump_AM_MEDIA_TYPE(pmt);
687 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
690 static const IPinVtbl Parser_OutputPin_Vtbl =
692 Parser_OutputPin_QueryInterface,
693 IPinImpl_AddRef,
694 Parser_OutputPin_Release,
695 Parser_OutputPin_Connect,
696 OutputPin_ReceiveConnection,
697 OutputPin_Disconnect,
698 IPinImpl_ConnectedTo,
699 IPinImpl_ConnectionMediaType,
700 IPinImpl_QueryPinInfo,
701 IPinImpl_QueryDirection,
702 IPinImpl_QueryId,
703 IPinImpl_QueryAccept,
704 Parser_OutputPin_EnumMediaTypes,
705 IPinImpl_QueryInternalConnections,
706 OutputPin_EndOfStream,
707 OutputPin_BeginFlush,
708 OutputPin_EndFlush,
709 OutputPin_NewSegment
712 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
714 HRESULT hr;
715 PullPin *This = (PullPin *)iface;
717 TRACE("()\n");
719 EnterCriticalSection(&This->thread_lock);
720 EnterCriticalSection(This->pin.pCritSec);
722 if (This->pin.pConnectedTo)
724 FILTER_STATE state;
725 ParserImpl *Parser = (ParserImpl *)This->pin.pinInfo.pFilter;
727 LeaveCriticalSection(This->pin.pCritSec);
728 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
729 EnterCriticalSection(This->pin.pCritSec);
731 if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
733 LeaveCriticalSection(This->pin.pCritSec);
734 PullPin_Disconnect(iface);
735 EnterCriticalSection(This->pin.pCritSec);
736 hr = Parser_RemoveOutputPins((ParserImpl *)This->pin.pinInfo.pFilter);
738 else
739 hr = VFW_E_NOT_STOPPED;
741 else
742 hr = S_FALSE;
744 LeaveCriticalSection(This->pin.pCritSec);
745 LeaveCriticalSection(&This->thread_lock);
747 return hr;
750 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
752 HRESULT hr;
754 TRACE("()\n");
756 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
757 if (FAILED(hr))
759 IPinImpl *This = (IPinImpl *)iface;
761 EnterCriticalSection(This->pCritSec);
762 Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
763 LeaveCriticalSection(This->pCritSec);
766 return hr;
769 static const IPinVtbl Parser_InputPin_Vtbl =
771 PullPin_QueryInterface,
772 IPinImpl_AddRef,
773 PullPin_Release,
774 InputPin_Connect,
775 Parser_PullPin_ReceiveConnection,
776 Parser_PullPin_Disconnect,
777 IPinImpl_ConnectedTo,
778 IPinImpl_ConnectionMediaType,
779 IPinImpl_QueryPinInfo,
780 IPinImpl_QueryDirection,
781 IPinImpl_QueryId,
782 IPinImpl_QueryAccept,
783 IPinImpl_EnumMediaTypes,
784 IPinImpl_QueryInternalConnections,
785 PullPin_EndOfStream,
786 PullPin_BeginFlush,
787 PullPin_EndFlush,
788 PullPin_NewSegment