strmbase: Add an implementation of BaseFilterImpl_EnumPins.
[wine] / dlls / quartz / parser.c
1 /*
2  * Parser (Base for parsers and splitters)
3  *
4  * Copyright 2003 Robert Shearman
5  * Copyright 2004-2005 Christian Costa
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include "quartz_private.h"
23 #include "control_private.h"
24 #include "pin.h"
25
26 #include "vfwmsgs.h"
27 #include "amvideo.h"
28
29 #include "wine/unicode.h"
30 #include "wine/debug.h"
31
32 #include <math.h>
33 #include <assert.h>
34
35 #include "parser.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
38
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;
43
44 static HRESULT Parser_ChangeCurrent(IBaseFilter *iface);
45 static HRESULT Parser_ChangeStop(IBaseFilter *iface);
46 static HRESULT Parser_ChangeRate(IBaseFilter *iface);
47
48 static inline ParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
49 {
50     return (ParserImpl *)((char*)iface - FIELD_OFFSET(ParserImpl, mediaSeeking.lpVtbl));
51 }
52
53 /* FIXME: WRONG */
54 static IPin* WINAPI Parser_GetPin(IBaseFilter *iface, int pos)
55 {
56     ParserImpl *This = (ParserImpl *)iface;
57
58     TRACE("Asking for pos %x\n", pos);
59
60     /* Input pin also has a pin, hence the > and not >= */
61     if (pos > This->cStreams || pos < 0)
62         return NULL;
63
64     IPin_AddRef(This->ppPins[pos]);
65     return This->ppPins[pos];
66 }
67
68 static LONG WINAPI Parser_GetPinCount(IBaseFilter *iface)
69 {
70     ParserImpl *This = (ParserImpl *)iface;
71
72     return This->cStreams;
73 }
74
75 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)
76 {
77     HRESULT hr;
78     PIN_INFO piInput;
79
80     /* pTransformFilter is already allocated */
81     BaseFilter_Init(&pParser->filter, Parser_Vtbl, pClsid, (DWORD_PTR)(__FILE__ ": ParserImpl.csFilter"), Parser_GetPin, Parser_GetPinCount);
82
83     pParser->fnDisconnect = fnDisconnect;
84
85     pParser->cStreams = 0;
86     pParser->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
87
88     /* construct input pin */
89     piInput.dir = PINDIR_INPUT;
90     piInput.pFilter = (IBaseFilter *)pParser;
91     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
92
93     if (!current)
94         current = Parser_ChangeCurrent;
95
96     if (!stop)
97         stop = Parser_ChangeStop;
98
99     if (!rate)
100         rate = Parser_ChangeRate;
101
102     MediaSeekingImpl_Init((IBaseFilter*)pParser, stop, current, rate, &pParser->mediaSeeking, &pParser->filter.csFilter);
103     pParser->mediaSeeking.lpVtbl = &Parser_Seeking_Vtbl;
104
105     hr = PullPin_Construct(&Parser_InputPin_Vtbl, &piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, fnCleanup, fnRequest, fnDone, &pParser->filter.csFilter, (IPin **)&pParser->pInputPin);
106
107     if (SUCCEEDED(hr))
108     {
109         pParser->ppPins[0] = (IPin *)pParser->pInputPin;
110         pParser->pInputPin->fnPreConnect = fnPreConnect;
111     }
112     else
113     {
114         CoTaskMemFree(pParser->ppPins);
115         BaseFilterImpl_Release((IBaseFilter*)pParser);
116         CoTaskMemFree(pParser);
117     }
118
119     return hr;
120 }
121
122 HRESULT WINAPI Parser_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
123 {
124     ParserImpl *This = (ParserImpl *)iface;
125     TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
126
127     *ppv = NULL;
128
129     if ( IsEqualIID(riid, &IID_IUnknown)
130       || IsEqualIID(riid, &IID_IPersist)
131       || IsEqualIID(riid, &IID_IMediaFilter)
132       || IsEqualIID(riid, &IID_IBaseFilter) )
133         *ppv = This;
134
135     if (*ppv)
136     {
137         IUnknown_AddRef((IUnknown *)(*ppv));
138         return S_OK;
139     }
140
141     if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
142         FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
143
144     return E_NOINTERFACE;
145 }
146
147 ULONG WINAPI Parser_AddRef(IBaseFilter * iface)
148 {
149     return BaseFilterImpl_AddRef(iface);
150 }
151
152 void Parser_Destroy(ParserImpl *This)
153 {
154     IPin *connected = NULL;
155     ULONG pinref;
156
157     assert(!This->filter.refCount);
158     PullPin_WaitForStateChange(This->pInputPin, INFINITE);
159
160     /* Don't need to clean up output pins, freeing input pin will do that */
161     IPin_ConnectedTo((IPin *)This->pInputPin, &connected);
162     if (connected)
163     {
164         assert(IPin_Disconnect(connected) == S_OK);
165         IPin_Release(connected);
166         assert(IPin_Disconnect((IPin *)This->pInputPin) == S_OK);
167     }
168     pinref = IPin_Release((IPin *)This->pInputPin);
169     if (pinref)
170     {
171         /* Valgrind could find this, if I kill it here */
172         ERR("pinref should be null, is %u, destroying anyway\n", pinref);
173         assert((LONG)pinref > 0);
174
175         while (pinref)
176             pinref = IPin_Release((IPin *)This->pInputPin);
177     }
178
179     CoTaskMemFree(This->ppPins);
180
181     TRACE("Destroying parser\n");
182     CoTaskMemFree(This);
183 }
184
185 ULONG WINAPI Parser_Release(IBaseFilter * iface)
186 {
187     ParserImpl *This = (ParserImpl *)iface;
188     ULONG refCount = BaseFilterImpl_Release(iface);
189
190     TRACE("(%p)->() Release from %d\n", This, refCount + 1);
191
192     if (!refCount)
193         Parser_Destroy(This);
194
195     return refCount;
196 }
197
198 /** IPersist methods **/
199
200 HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
201 {
202     ParserImpl *This = (ParserImpl *)iface;
203
204     TRACE("(%p)\n", pClsid);
205
206     *pClsid = This->filter.clsid;
207
208     return S_OK;
209 }
210
211 /** IMediaFilter methods **/
212
213 HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
214 {
215     ParserImpl *This = (ParserImpl *)iface;
216     PullPin *pin = (PullPin *)This->ppPins[0];
217     ULONG i;
218
219     TRACE("()\n");
220
221     EnterCriticalSection(&pin->thread_lock);
222
223     IAsyncReader_BeginFlush(This->pInputPin->pReader);
224     EnterCriticalSection(&This->filter.csFilter);
225
226     if (This->filter.state == State_Stopped)
227     {
228         LeaveCriticalSection(&This->filter.csFilter);
229         IAsyncReader_EndFlush(This->pInputPin->pReader);
230         LeaveCriticalSection(&pin->thread_lock);
231         return S_OK;
232     }
233
234     This->filter.state = State_Stopped;
235
236     for (i = 1; i < (This->cStreams + 1); i++)
237     {
238         BaseOutputPinImpl_Inactive((BaseOutputPin *)This->ppPins[i]);
239     }
240
241     LeaveCriticalSection(&This->filter.csFilter);
242
243     PullPin_PauseProcessing(This->pInputPin);
244     PullPin_WaitForStateChange(This->pInputPin, INFINITE);
245     IAsyncReader_EndFlush(This->pInputPin->pReader);
246
247     LeaveCriticalSection(&pin->thread_lock);
248     return S_OK;
249 }
250
251 HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
252 {
253     HRESULT hr = S_OK;
254     ParserImpl *This = (ParserImpl *)iface;
255     PullPin *pin = (PullPin *)This->ppPins[0];
256
257     TRACE("()\n");
258
259     EnterCriticalSection(&pin->thread_lock);
260     EnterCriticalSection(&This->filter.csFilter);
261
262     if (This->filter.state == State_Paused)
263     {
264         LeaveCriticalSection(&This->filter.csFilter);
265         LeaveCriticalSection(&pin->thread_lock);
266         return S_OK;
267     }
268
269     if (This->filter.state == State_Stopped)
270     {
271         LeaveCriticalSection(&This->filter.csFilter);
272         hr = IBaseFilter_Run(iface, -1);
273         EnterCriticalSection(&This->filter.csFilter);
274     }
275
276     if (SUCCEEDED(hr))
277         This->filter.state = State_Paused;
278
279     LeaveCriticalSection(&This->filter.csFilter);
280     LeaveCriticalSection(&pin->thread_lock);
281
282     return hr;
283 }
284
285 HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
286 {
287     HRESULT hr = S_OK;
288     ParserImpl *This = (ParserImpl *)iface;
289     PullPin *pin = (PullPin *)This->ppPins[0];
290
291     ULONG i;
292
293     TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
294
295     EnterCriticalSection(&pin->thread_lock);
296     EnterCriticalSection(&This->filter.csFilter);
297     {
298         HRESULT hr_any = VFW_E_NOT_CONNECTED;
299
300         if (This->filter.state == State_Running || This->filter.state == State_Paused)
301         {
302             This->filter.state = State_Running;
303             LeaveCriticalSection(&This->filter.csFilter);
304             LeaveCriticalSection(&pin->thread_lock);
305             return S_OK;
306         }
307
308         This->filter.rtStreamStart = tStart;
309
310         for (i = 1; i < (This->cStreams + 1); i++)
311         {
312             hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
313             if (SUCCEEDED(hr))
314                 hr_any = hr;
315         }
316
317         hr = hr_any;
318         if (SUCCEEDED(hr))
319         {
320             LeaveCriticalSection(&This->filter.csFilter);
321             hr = PullPin_StartProcessing(This->pInputPin);
322             EnterCriticalSection(&This->filter.csFilter);
323         }
324
325         if (SUCCEEDED(hr))
326             This->filter.state = State_Running;
327     }
328     LeaveCriticalSection(&This->filter.csFilter);
329     LeaveCriticalSection(&pin->thread_lock);
330
331     return hr;
332 }
333
334 HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
335 {
336     ParserImpl *This = (ParserImpl *)iface;
337     PullPin *pin = (PullPin *)This->ppPins[0];
338     HRESULT hr = S_OK;
339
340     TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
341
342     EnterCriticalSection(&pin->thread_lock);
343     EnterCriticalSection(&This->filter.csFilter);
344     {
345         *pState = This->filter.state;
346     }
347     LeaveCriticalSection(&This->filter.csFilter);
348
349     if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
350         hr = VFW_S_STATE_INTERMEDIATE;
351     LeaveCriticalSection(&pin->thread_lock);
352
353     return hr;
354 }
355
356 HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
357 {
358     ParserImpl *This = (ParserImpl *)iface;
359     PullPin *pin = (PullPin *)This->ppPins[0];
360
361     TRACE("(%p)\n", pClock);
362
363     EnterCriticalSection(&pin->thread_lock);
364     BaseFilterImpl_SetSyncSource(iface,pClock);
365     LeaveCriticalSection(&pin->thread_lock);
366
367     return S_OK;
368 }
369
370 HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
371 {
372     return BaseFilterImpl_GetSyncSource(iface, ppClock);
373 }
374
375 /** IBaseFilter implementation **/
376
377 HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
378 {
379     return BaseFilterImpl_EnumPins(iface,ppEnum);
380 }
381
382 HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
383 {
384     FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
385
386     /* FIXME: critical section */
387
388     return E_NOTIMPL;
389 }
390
391 HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
392 {
393     return BaseFilterImpl_QueryFilterInfo(iface, pInfo);
394 }
395
396 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
397 {
398     return BaseFilterImpl_JoinFilterGraph(iface, pGraph, pName);
399 }
400
401 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
402 {
403     return BaseFilterImpl_QueryVendorInfo(iface, pVendorInfo);
404 }
405
406 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
407 {
408     IPin ** ppOldPins;
409     HRESULT hr;
410
411     ppOldPins = This->ppPins;
412
413     This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
414     memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
415
416     hr = BaseOutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, props, NULL, &This->filter.csFilter, This->ppPins + (This->cStreams + 1));
417
418     if (SUCCEEDED(hr))
419     {
420         IPin *pPin = This->ppPins[This->cStreams + 1];
421         Parser_OutputPin *pin = (Parser_OutputPin *)pPin;
422         pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
423         CopyMediaType(pin->pmt, amt);
424         pin->dwSamplesProcessed = 0;
425
426         pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
427         pin->pin.custom_allocator = 1;
428         This->cStreams++;
429         BaseFilterImpl_IncrementPinVersion((IBaseFilter*)This);
430         CoTaskMemFree(ppOldPins);
431     }
432     else
433     {
434         CoTaskMemFree(This->ppPins);
435         This->ppPins = ppOldPins;
436         ERR("Failed with error %x\n", hr);
437     }
438
439     return hr;
440 }
441
442 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
443 {
444     /* NOTE: should be in critical section when calling this function */
445     HRESULT hr;
446     ULONG i;
447     IPin ** ppOldPins = This->ppPins;
448
449     TRACE("(%p)\n", This);
450
451     /* reduce the pin array down to 1 (just our input pin) */
452     This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
453     memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
454
455     for (i = 0; i < This->cStreams; i++)
456     {
457         hr = BaseOutputPinImpl_BreakConnect((BaseOutputPin *)ppOldPins[i + 1]);
458         TRACE("Disconnect: %08x\n", hr);
459         IPin_Release(ppOldPins[i + 1]);
460     }
461
462     BaseFilterImpl_IncrementPinVersion((IBaseFilter*)This);
463     This->cStreams = 0;
464     CoTaskMemFree(ppOldPins);
465
466     return S_OK;
467 }
468
469 static HRESULT Parser_ChangeCurrent(IBaseFilter *iface)
470 {
471     FIXME("(%p) filter hasn't implemented current position change!\n", iface);
472     return S_OK;
473 }
474
475 static HRESULT Parser_ChangeStop(IBaseFilter *iface)
476 {
477     FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
478     return S_OK;
479 }
480
481 static HRESULT Parser_ChangeRate(IBaseFilter *iface)
482 {
483     FIXME("(%p) filter hasn't implemented rate change!\n", iface);
484     return S_OK;
485 }
486
487
488 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
489 {
490     ParserImpl *This = impl_from_IMediaSeeking(iface);
491
492     return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
493 }
494
495 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
496 {
497     ParserImpl *This = impl_from_IMediaSeeking(iface);
498
499     return IUnknown_AddRef((IUnknown *)This);
500 }
501
502 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
503 {
504     ParserImpl *This = impl_from_IMediaSeeking(iface);
505
506     return IUnknown_Release((IUnknown *)This);
507 }
508
509 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
510 {
511     Parser_Seeking_QueryInterface,
512     Parser_Seeking_AddRef,
513     Parser_Seeking_Release,
514     MediaSeekingImpl_GetCapabilities,
515     MediaSeekingImpl_CheckCapabilities,
516     MediaSeekingImpl_IsFormatSupported,
517     MediaSeekingImpl_QueryPreferredFormat,
518     MediaSeekingImpl_GetTimeFormat,
519     MediaSeekingImpl_IsUsingTimeFormat,
520     MediaSeekingImpl_SetTimeFormat,
521     MediaSeekingImpl_GetDuration,
522     MediaSeekingImpl_GetStopPosition,
523     MediaSeekingImpl_GetCurrentPosition,
524     MediaSeekingImpl_ConvertTimeFormat,
525     MediaSeekingImpl_SetPositions,
526     MediaSeekingImpl_GetPositions,
527     MediaSeekingImpl_GetAvailable,
528     MediaSeekingImpl_SetRate,
529     MediaSeekingImpl_GetRate,
530     MediaSeekingImpl_GetPreroll
531 };
532
533 static HRESULT WINAPI Parser_OutputPin_GetMediaType(IPin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
534 {
535     Parser_OutputPin *This = (Parser_OutputPin *)iface;
536     if (iPosition < 0)
537         return E_INVALIDARG;
538     if (iPosition > 0)
539         return VFW_S_NO_MORE_ITEMS;
540     CopyMediaType(pmt, This->pmt);
541     return S_OK;
542 }
543
544 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
545 {
546     Parser_OutputPin *This = (Parser_OutputPin *)iface;
547
548     TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
549
550     *ppv = NULL;
551
552     if (IsEqualIID(riid, &IID_IUnknown))
553         *ppv = iface;
554     else if (IsEqualIID(riid, &IID_IPin))
555         *ppv = iface;
556     else if (IsEqualIID(riid, &IID_IMediaSeeking))
557     {
558         return IBaseFilter_QueryInterface(This->pin.pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
559     }
560
561     if (*ppv)
562     {
563         IUnknown_AddRef((IUnknown *)(*ppv));
564         return S_OK;
565     }
566
567     FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
568
569     return E_NOINTERFACE;
570 }
571
572 static ULONG WINAPI Parser_OutputPin_Release(IPin * iface)
573 {
574     Parser_OutputPin *This = (Parser_OutputPin *)iface;
575     ULONG refCount = InterlockedDecrement(&This->pin.pin.refCount);
576     
577     TRACE("(%p)->() Release from %d\n", iface, refCount + 1);
578
579     if (!refCount)
580     {
581         FreeMediaType(This->pmt);
582         CoTaskMemFree(This->pmt);
583         FreeMediaType(&This->pin.pin.mtCurrent);
584         CoTaskMemFree(This);
585         return 0;
586     }
587     return refCount;
588 }
589
590 static HRESULT WINAPI Parser_OutputPin_EnumMediaTypes(IPin * iface, IEnumMediaTypes ** ppEnum)
591 {
592     TRACE("(%p)\n", ppEnum);
593
594     /* override this method to allow enumeration of your types */
595
596     return EnumMediaTypes_Construct(iface, Parser_OutputPin_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
597 }
598
599 static HRESULT WINAPI Parser_OutputPin_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
600 {
601     Parser_OutputPin *This = (Parser_OutputPin *)iface;
602     ParserImpl *parser = (ParserImpl *)This->pin.pin.pinInfo.pFilter;
603
604     /* Set the allocator to our input pin's */
605     EnterCriticalSection(This->pin.pin.pCritSec);
606     This->pin.alloc = parser->pInputPin->pAlloc;
607     LeaveCriticalSection(This->pin.pin.pCritSec);
608
609     return BaseOutputPinImpl_Connect(iface, pReceivePin, pmt);
610 }
611
612 static HRESULT WINAPI Parser_OutputPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE * pmt)
613 {
614     Parser_OutputPin *This = (Parser_OutputPin *)iface;
615
616     TRACE("()\n");
617     dump_AM_MEDIA_TYPE(pmt);
618
619     return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
620 }
621
622 static const IPinVtbl Parser_OutputPin_Vtbl = 
623 {
624     Parser_OutputPin_QueryInterface,
625     BasePinImpl_AddRef,
626     Parser_OutputPin_Release,
627     Parser_OutputPin_Connect,
628     BaseOutputPinImpl_ReceiveConnection,
629     BaseOutputPinImpl_Disconnect,
630     BasePinImpl_ConnectedTo,
631     BasePinImpl_ConnectionMediaType,
632     BasePinImpl_QueryPinInfo,
633     BasePinImpl_QueryDirection,
634     BasePinImpl_QueryId,
635     Parser_OutputPin_QueryAccept,
636     Parser_OutputPin_EnumMediaTypes,
637     BasePinImpl_QueryInternalConnections,
638     BaseOutputPinImpl_EndOfStream,
639     BaseOutputPinImpl_BeginFlush,
640     BaseOutputPinImpl_EndFlush,
641     BaseOutputPinImpl_NewSegment
642 };
643
644 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
645 {
646     HRESULT hr;
647     PullPin *This = (PullPin *)iface;
648
649     TRACE("()\n");
650
651     EnterCriticalSection(&This->thread_lock);
652     EnterCriticalSection(This->pin.pCritSec);
653     {
654         if (This->pin.pConnectedTo)
655         {
656             FILTER_STATE state;
657             ParserImpl *Parser = (ParserImpl *)This->pin.pinInfo.pFilter;
658
659             LeaveCriticalSection(This->pin.pCritSec);
660             hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
661             EnterCriticalSection(This->pin.pCritSec);
662
663             if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
664             {
665                 LeaveCriticalSection(This->pin.pCritSec);
666                 PullPin_Disconnect(iface);
667                 EnterCriticalSection(This->pin.pCritSec);
668                 hr = Parser_RemoveOutputPins((ParserImpl *)This->pin.pinInfo.pFilter);
669             }
670             else
671                 hr = VFW_E_NOT_STOPPED;
672         }
673         else
674             hr = S_FALSE;
675     }
676     LeaveCriticalSection(This->pin.pCritSec);
677     LeaveCriticalSection(&This->thread_lock);
678
679     return hr;
680 }
681
682 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
683 {
684     HRESULT hr;
685
686     TRACE("()\n");
687
688     hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
689     if (FAILED(hr))
690     {
691         BasePin *This = (BasePin *)iface;
692
693         EnterCriticalSection(This->pCritSec);
694         Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
695         LeaveCriticalSection(This->pCritSec);
696     }
697
698     return hr;
699 }
700
701 static const IPinVtbl Parser_InputPin_Vtbl =
702 {
703     PullPin_QueryInterface,
704     BasePinImpl_AddRef,
705     PullPin_Release,
706     BaseInputPinImpl_Connect,
707     Parser_PullPin_ReceiveConnection,
708     Parser_PullPin_Disconnect,
709     BasePinImpl_ConnectedTo,
710     BasePinImpl_ConnectionMediaType,
711     BasePinImpl_QueryPinInfo,
712     BasePinImpl_QueryDirection,
713     BasePinImpl_QueryId,
714     PullPin_QueryAccept,
715     BasePinImpl_EnumMediaTypes,
716     BasePinImpl_QueryInternalConnections,
717     PullPin_EndOfStream,
718     PullPin_BeginFlush,
719     PullPin_EndFlush,
720     PullPin_NewSegment
721 };