Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / quartz / parser.c
blobcf4a2608496528fdf9b8e2dd431bfcc9ccea1936
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_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt);
48 static HRESULT WINAPI Parser_OutputPin_DecideAllocator(BaseOutputPin *This, IMemInputPin *pPin, IMemAllocator **pAlloc);
49 static HRESULT WINAPI Parser_OutputPin_BreakConnect(BaseOutputPin *This);
51 static inline ParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
53 return (ParserImpl *)((char*)iface - FIELD_OFFSET(ParserImpl, sourceSeeking.lpVtbl));
56 /* FIXME: WRONG */
57 static IPin* WINAPI Parser_GetPin(BaseFilter *iface, int pos)
59 ParserImpl *This = (ParserImpl *)iface;
61 TRACE("Asking for pos %x\n", pos);
63 /* Input pin also has a pin, hence the > and not >= */
64 if (pos > This->cStreams || pos < 0)
65 return NULL;
67 IPin_AddRef(This->ppPins[pos]);
68 return This->ppPins[pos];
71 static LONG WINAPI Parser_GetPinCount(BaseFilter *iface)
73 ParserImpl *This = (ParserImpl *)iface;
75 return This->cStreams;
78 static const BaseFilterFuncTable BaseFuncTable = {
79 Parser_GetPin,
80 Parser_GetPinCount
83 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)
85 HRESULT hr;
86 PIN_INFO piInput;
88 /* pTransformFilter is already allocated */
89 BaseFilter_Init(&pParser->filter, Parser_Vtbl, pClsid, (DWORD_PTR)(__FILE__ ": ParserImpl.csFilter"), &BaseFuncTable);
91 pParser->fnDisconnect = fnDisconnect;
93 pParser->cStreams = 0;
94 pParser->ppPins = CoTaskMemAlloc(1 * sizeof(IPin *));
96 /* construct input pin */
97 piInput.dir = PINDIR_INPUT;
98 piInput.pFilter = (IBaseFilter *)pParser;
99 lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
101 if (!start)
102 start = Parser_ChangeStart;
104 if (!stop)
105 stop = Parser_ChangeStop;
107 if (!rate)
108 rate = Parser_ChangeRate;
110 SourceSeeking_Init(&pParser->sourceSeeking, &Parser_Seeking_Vtbl, stop, start, rate, &pParser->filter.csFilter);
112 hr = PullPin_Construct(&Parser_InputPin_Vtbl, &piInput, fnProcessSample, (LPVOID)pParser, fnQueryAccept, fnCleanup, fnRequest, fnDone, &pParser->filter.csFilter, (IPin **)&pParser->pInputPin);
114 if (SUCCEEDED(hr))
116 pParser->ppPins[0] = (IPin *)pParser->pInputPin;
117 pParser->pInputPin->fnPreConnect = fnPreConnect;
119 else
121 CoTaskMemFree(pParser->ppPins);
122 BaseFilterImpl_Release((IBaseFilter*)pParser);
123 CoTaskMemFree(pParser);
126 return hr;
129 HRESULT WINAPI Parser_QueryInterface(IBaseFilter * iface, REFIID riid, LPVOID * ppv)
131 ParserImpl *This = (ParserImpl *)iface;
132 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
134 *ppv = NULL;
136 if ( IsEqualIID(riid, &IID_IUnknown)
137 || IsEqualIID(riid, &IID_IPersist)
138 || IsEqualIID(riid, &IID_IMediaFilter)
139 || IsEqualIID(riid, &IID_IBaseFilter) )
140 *ppv = This;
142 if (*ppv)
144 IUnknown_AddRef((IUnknown *)(*ppv));
145 return S_OK;
148 if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
149 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
151 return E_NOINTERFACE;
154 ULONG WINAPI Parser_AddRef(IBaseFilter * iface)
156 return BaseFilterImpl_AddRef(iface);
159 void Parser_Destroy(ParserImpl *This)
161 IPin *connected = NULL;
162 ULONG pinref;
164 assert(!This->filter.refCount);
165 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
167 /* Don't need to clean up output pins, freeing input pin will do that */
168 IPin_ConnectedTo((IPin *)This->pInputPin, &connected);
169 if (connected)
171 assert(IPin_Disconnect(connected) == S_OK);
172 IPin_Release(connected);
173 assert(IPin_Disconnect((IPin *)This->pInputPin) == S_OK);
175 pinref = IPin_Release((IPin *)This->pInputPin);
176 if (pinref)
178 /* Valgrind could find this, if I kill it here */
179 ERR("pinref should be null, is %u, destroying anyway\n", pinref);
180 assert((LONG)pinref > 0);
182 while (pinref)
183 pinref = IPin_Release((IPin *)This->pInputPin);
186 CoTaskMemFree(This->ppPins);
188 TRACE("Destroying parser\n");
189 CoTaskMemFree(This);
192 ULONG WINAPI Parser_Release(IBaseFilter * iface)
194 ParserImpl *This = (ParserImpl *)iface;
195 ULONG refCount = BaseFilterImpl_Release(iface);
197 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
199 if (!refCount)
200 Parser_Destroy(This);
202 return refCount;
205 /** IPersist methods **/
207 HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
209 ParserImpl *This = (ParserImpl *)iface;
211 TRACE("(%p)\n", pClsid);
213 *pClsid = This->filter.clsid;
215 return S_OK;
218 /** IMediaFilter methods **/
220 HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
222 ParserImpl *This = (ParserImpl *)iface;
223 PullPin *pin = (PullPin *)This->ppPins[0];
224 ULONG i;
226 TRACE("()\n");
228 EnterCriticalSection(&pin->thread_lock);
230 IAsyncReader_BeginFlush(This->pInputPin->pReader);
231 EnterCriticalSection(&This->filter.csFilter);
233 if (This->filter.state == State_Stopped)
235 LeaveCriticalSection(&This->filter.csFilter);
236 IAsyncReader_EndFlush(This->pInputPin->pReader);
237 LeaveCriticalSection(&pin->thread_lock);
238 return S_OK;
241 This->filter.state = State_Stopped;
243 for (i = 1; i < (This->cStreams + 1); i++)
245 BaseOutputPinImpl_Inactive((BaseOutputPin *)This->ppPins[i]);
248 LeaveCriticalSection(&This->filter.csFilter);
250 PullPin_PauseProcessing(This->pInputPin);
251 PullPin_WaitForStateChange(This->pInputPin, INFINITE);
252 IAsyncReader_EndFlush(This->pInputPin->pReader);
254 LeaveCriticalSection(&pin->thread_lock);
255 return S_OK;
258 HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
260 HRESULT hr = S_OK;
261 ParserImpl *This = (ParserImpl *)iface;
262 PullPin *pin = (PullPin *)This->ppPins[0];
264 TRACE("()\n");
266 EnterCriticalSection(&pin->thread_lock);
267 EnterCriticalSection(&This->filter.csFilter);
269 if (This->filter.state == State_Paused)
271 LeaveCriticalSection(&This->filter.csFilter);
272 LeaveCriticalSection(&pin->thread_lock);
273 return S_OK;
276 if (This->filter.state == State_Stopped)
278 LeaveCriticalSection(&This->filter.csFilter);
279 hr = IBaseFilter_Run(iface, -1);
280 EnterCriticalSection(&This->filter.csFilter);
283 if (SUCCEEDED(hr))
284 This->filter.state = State_Paused;
286 LeaveCriticalSection(&This->filter.csFilter);
287 LeaveCriticalSection(&pin->thread_lock);
289 return hr;
292 HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
294 HRESULT hr = S_OK;
295 ParserImpl *This = (ParserImpl *)iface;
296 PullPin *pin = (PullPin *)This->ppPins[0];
298 ULONG i;
300 TRACE("(%s)\n", wine_dbgstr_longlong(tStart));
302 EnterCriticalSection(&pin->thread_lock);
303 EnterCriticalSection(&This->filter.csFilter);
305 HRESULT hr_any = VFW_E_NOT_CONNECTED;
307 if (This->filter.state == State_Running || This->filter.state == State_Paused)
309 This->filter.state = State_Running;
310 LeaveCriticalSection(&This->filter.csFilter);
311 LeaveCriticalSection(&pin->thread_lock);
312 return S_OK;
315 This->filter.rtStreamStart = tStart;
317 for (i = 1; i < (This->cStreams + 1); i++)
319 hr = BaseOutputPinImpl_Active((BaseOutputPin *)This->ppPins[i]);
320 if (SUCCEEDED(hr))
321 hr_any = hr;
324 hr = hr_any;
325 if (SUCCEEDED(hr))
327 LeaveCriticalSection(&This->filter.csFilter);
328 hr = PullPin_StartProcessing(This->pInputPin);
329 EnterCriticalSection(&This->filter.csFilter);
332 if (SUCCEEDED(hr))
333 This->filter.state = State_Running;
335 LeaveCriticalSection(&This->filter.csFilter);
336 LeaveCriticalSection(&pin->thread_lock);
338 return hr;
341 HRESULT WINAPI Parser_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
343 ParserImpl *This = (ParserImpl *)iface;
344 PullPin *pin = (PullPin *)This->ppPins[0];
345 HRESULT hr = S_OK;
347 TRACE("(%d, %p)\n", dwMilliSecsTimeout, pState);
349 EnterCriticalSection(&pin->thread_lock);
350 EnterCriticalSection(&This->filter.csFilter);
352 *pState = This->filter.state;
354 LeaveCriticalSection(&This->filter.csFilter);
356 if (This->pInputPin && (PullPin_WaitForStateChange(This->pInputPin, dwMilliSecsTimeout) == S_FALSE))
357 hr = VFW_S_STATE_INTERMEDIATE;
358 LeaveCriticalSection(&pin->thread_lock);
360 return hr;
363 HRESULT WINAPI Parser_SetSyncSource(IBaseFilter * iface, IReferenceClock *pClock)
365 ParserImpl *This = (ParserImpl *)iface;
366 PullPin *pin = (PullPin *)This->ppPins[0];
368 TRACE("(%p)\n", pClock);
370 EnterCriticalSection(&pin->thread_lock);
371 BaseFilterImpl_SetSyncSource(iface,pClock);
372 LeaveCriticalSection(&pin->thread_lock);
374 return S_OK;
377 HRESULT WINAPI Parser_GetSyncSource(IBaseFilter * iface, IReferenceClock **ppClock)
379 return BaseFilterImpl_GetSyncSource(iface, ppClock);
382 /** IBaseFilter implementation **/
384 HRESULT WINAPI Parser_EnumPins(IBaseFilter * iface, IEnumPins **ppEnum)
386 return BaseFilterImpl_EnumPins(iface,ppEnum);
389 HRESULT WINAPI Parser_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
391 FIXME("(%p)->(%s,%p)\n", iface, debugstr_w(Id), ppPin);
393 /* FIXME: critical section */
395 return E_NOTIMPL;
398 HRESULT WINAPI Parser_QueryFilterInfo(IBaseFilter * iface, FILTER_INFO *pInfo)
400 return BaseFilterImpl_QueryFilterInfo(iface, pInfo);
403 HRESULT WINAPI Parser_JoinFilterGraph(IBaseFilter * iface, IFilterGraph *pGraph, LPCWSTR pName)
405 return BaseFilterImpl_JoinFilterGraph(iface, pGraph, pName);
408 HRESULT WINAPI Parser_QueryVendorInfo(IBaseFilter * iface, LPWSTR *pVendorInfo)
410 return BaseFilterImpl_QueryVendorInfo(iface, pVendorInfo);
413 static const BasePinFuncTable output_BaseFuncTable = {
414 NULL,
415 BaseOutputPinImpl_AttemptConnection,
416 BasePinImpl_GetMediaTypeVersion,
417 Parser_OutputPin_GetMediaType
420 static const BaseOutputPinFuncTable output_BaseOutputFuncTable = {
421 Parser_OutputPin_DecideBufferSize,
422 Parser_OutputPin_DecideAllocator,
423 Parser_OutputPin_BreakConnect
426 HRESULT Parser_AddPin(ParserImpl * This, const PIN_INFO * piOutput, ALLOCATOR_PROPERTIES * props, const AM_MEDIA_TYPE * amt)
428 IPin ** ppOldPins;
429 HRESULT hr;
431 ppOldPins = This->ppPins;
433 This->ppPins = CoTaskMemAlloc((This->cStreams + 2) * sizeof(IPin *));
434 memcpy(This->ppPins, ppOldPins, (This->cStreams + 1) * sizeof(IPin *));
436 hr = BaseOutputPin_Construct(&Parser_OutputPin_Vtbl, sizeof(Parser_OutputPin), piOutput, &output_BaseFuncTable, &output_BaseOutputFuncTable, &This->filter.csFilter, This->ppPins + (This->cStreams + 1));
438 if (SUCCEEDED(hr))
440 IPin *pPin = This->ppPins[This->cStreams + 1];
441 Parser_OutputPin *pin = (Parser_OutputPin *)pPin;
442 pin->pmt = CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
443 CopyMediaType(pin->pmt, amt);
444 pin->dwSamplesProcessed = 0;
446 pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
447 pin->allocProps = *props;
448 This->cStreams++;
449 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
450 CoTaskMemFree(ppOldPins);
452 else
454 CoTaskMemFree(This->ppPins);
455 This->ppPins = ppOldPins;
456 ERR("Failed with error %x\n", hr);
459 return hr;
462 static HRESULT Parser_RemoveOutputPins(ParserImpl * This)
464 /* NOTE: should be in critical section when calling this function */
465 HRESULT hr;
466 ULONG i;
467 IPin ** ppOldPins = This->ppPins;
469 TRACE("(%p)\n", This);
471 /* reduce the pin array down to 1 (just our input pin) */
472 This->ppPins = CoTaskMemAlloc(sizeof(IPin *) * 1);
473 memcpy(This->ppPins, ppOldPins, sizeof(IPin *) * 1);
475 for (i = 0; i < This->cStreams; i++)
477 hr = ((BaseOutputPin *)ppOldPins[i + 1])->pFuncsTable->pfnBreakConnect((BaseOutputPin *)ppOldPins[i + 1]);
478 TRACE("Disconnect: %08x\n", hr);
479 IPin_Release(ppOldPins[i + 1]);
482 BaseFilterImpl_IncrementPinVersion((BaseFilter*)This);
483 This->cStreams = 0;
484 CoTaskMemFree(ppOldPins);
486 return S_OK;
489 static HRESULT WINAPI Parser_ChangeStart(IMediaSeeking *iface)
491 FIXME("(%p) filter hasn't implemented start position change!\n", iface);
492 return S_OK;
495 static HRESULT WINAPI Parser_ChangeStop(IMediaSeeking *iface)
497 FIXME("(%p) filter hasn't implemented stop position change!\n", iface);
498 return S_OK;
501 static HRESULT WINAPI Parser_ChangeRate(IMediaSeeking *iface)
503 FIXME("(%p) filter hasn't implemented rate change!\n", iface);
504 return S_OK;
508 static HRESULT WINAPI Parser_Seeking_QueryInterface(IMediaSeeking * iface, REFIID riid, LPVOID * ppv)
510 ParserImpl *This = impl_from_IMediaSeeking(iface);
512 return IUnknown_QueryInterface((IUnknown *)This, riid, ppv);
515 static ULONG WINAPI Parser_Seeking_AddRef(IMediaSeeking * iface)
517 ParserImpl *This = impl_from_IMediaSeeking(iface);
519 return IUnknown_AddRef((IUnknown *)This);
522 static ULONG WINAPI Parser_Seeking_Release(IMediaSeeking * iface)
524 ParserImpl *This = impl_from_IMediaSeeking(iface);
526 return IUnknown_Release((IUnknown *)This);
529 static const IMediaSeekingVtbl Parser_Seeking_Vtbl =
531 Parser_Seeking_QueryInterface,
532 Parser_Seeking_AddRef,
533 Parser_Seeking_Release,
534 SourceSeekingImpl_GetCapabilities,
535 SourceSeekingImpl_CheckCapabilities,
536 SourceSeekingImpl_IsFormatSupported,
537 SourceSeekingImpl_QueryPreferredFormat,
538 SourceSeekingImpl_GetTimeFormat,
539 SourceSeekingImpl_IsUsingTimeFormat,
540 SourceSeekingImpl_SetTimeFormat,
541 SourceSeekingImpl_GetDuration,
542 SourceSeekingImpl_GetStopPosition,
543 SourceSeekingImpl_GetCurrentPosition,
544 SourceSeekingImpl_ConvertTimeFormat,
545 SourceSeekingImpl_SetPositions,
546 SourceSeekingImpl_GetPositions,
547 SourceSeekingImpl_GetAvailable,
548 SourceSeekingImpl_SetRate,
549 SourceSeekingImpl_GetRate,
550 SourceSeekingImpl_GetPreroll
553 static HRESULT WINAPI Parser_OutputPin_DecideBufferSize(BaseOutputPin *iface, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
555 Parser_OutputPin *This = (Parser_OutputPin *)iface;
556 ALLOCATOR_PROPERTIES actual;
558 if (ppropInputRequest->cbAlign && ppropInputRequest->cbAlign != This->allocProps.cbAlign)
559 FIXME("Requested Buffer cbAlign mismatch %i,%i\n",This->allocProps.cbAlign, ppropInputRequest->cbAlign);
560 if (ppropInputRequest->cbPrefix)
561 FIXME("Requested Buffer cbPrefix mismatch %i,%i\n",This->allocProps.cbPrefix, ppropInputRequest->cbPrefix);
562 if (ppropInputRequest->cbBuffer)
563 FIXME("Requested Buffer cbBuffer mismatch %i,%i\n",This->allocProps.cbBuffer, ppropInputRequest->cbBuffer);
564 if (ppropInputRequest->cBuffers)
565 FIXME("Requested Buffer cBuffers mismatch %i,%i\n",This->allocProps.cBuffers, ppropInputRequest->cBuffers);
567 return IMemAllocator_SetProperties(pAlloc, &This->allocProps, &actual);
570 static HRESULT WINAPI Parser_OutputPin_GetMediaType(BasePin *iface, int iPosition, AM_MEDIA_TYPE *pmt)
572 Parser_OutputPin *This = (Parser_OutputPin *)iface;
573 if (iPosition < 0)
574 return E_INVALIDARG;
575 if (iPosition > 0)
576 return VFW_S_NO_MORE_ITEMS;
577 CopyMediaType(pmt, This->pmt);
578 return S_OK;
581 static HRESULT WINAPI Parser_OutputPin_DecideAllocator(BaseOutputPin *iface, IMemInputPin *pPin, IMemAllocator **pAlloc)
583 Parser_OutputPin *This = (Parser_OutputPin *)iface;
584 HRESULT hr;
586 pAlloc = NULL;
588 if (This->alloc)
589 hr = IMemInputPin_NotifyAllocator(pPin, This->alloc, This->readonly);
590 else
591 hr = VFW_E_NO_ALLOCATOR;
593 return hr;
596 static HRESULT WINAPI Parser_OutputPin_BreakConnect(BaseOutputPin *This)
598 HRESULT hr;
600 TRACE("(%p)->()\n", This);
602 EnterCriticalSection(This->pin.pCritSec);
603 if (!This->pin.pConnectedTo || !This->pMemInputPin)
604 hr = VFW_E_NOT_CONNECTED;
605 else
607 hr = IPin_Disconnect(This->pin.pConnectedTo);
608 IPin_Disconnect((IPin *)This);
610 LeaveCriticalSection(This->pin.pCritSec);
612 return hr;
616 static HRESULT WINAPI Parser_OutputPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
618 Parser_OutputPin *This = (Parser_OutputPin *)iface;
620 TRACE("(%s, %p)\n", qzdebugstr_guid(riid), ppv);
622 *ppv = NULL;
624 if (IsEqualIID(riid, &IID_IUnknown))
625 *ppv = iface;
626 else if (IsEqualIID(riid, &IID_IPin))
627 *ppv = iface;
628 else if (IsEqualIID(riid, &IID_IMediaSeeking))
630 return IBaseFilter_QueryInterface(This->pin.pin.pinInfo.pFilter, &IID_IMediaSeeking, ppv);
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_Connect(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
664 Parser_OutputPin *This = (Parser_OutputPin *)iface;
665 ParserImpl *parser = (ParserImpl *)This->pin.pin.pinInfo.pFilter;
667 /* Set the allocator to our input pin's */
668 EnterCriticalSection(This->pin.pin.pCritSec);
669 This->alloc = parser->pInputPin->pAlloc;
670 LeaveCriticalSection(This->pin.pin.pCritSec);
672 return BaseOutputPinImpl_Connect(iface, pReceivePin, pmt);
675 static HRESULT WINAPI Parser_OutputPin_QueryAccept(IPin *iface, const AM_MEDIA_TYPE * pmt)
677 Parser_OutputPin *This = (Parser_OutputPin *)iface;
679 TRACE("()\n");
680 dump_AM_MEDIA_TYPE(pmt);
682 return (memcmp(This->pmt, pmt, sizeof(AM_MEDIA_TYPE)) == 0);
685 static const IPinVtbl Parser_OutputPin_Vtbl =
687 Parser_OutputPin_QueryInterface,
688 BasePinImpl_AddRef,
689 Parser_OutputPin_Release,
690 Parser_OutputPin_Connect,
691 BaseOutputPinImpl_ReceiveConnection,
692 BaseOutputPinImpl_Disconnect,
693 BasePinImpl_ConnectedTo,
694 BasePinImpl_ConnectionMediaType,
695 BasePinImpl_QueryPinInfo,
696 BasePinImpl_QueryDirection,
697 BasePinImpl_QueryId,
698 Parser_OutputPin_QueryAccept,
699 BasePinImpl_EnumMediaTypes,
700 BasePinImpl_QueryInternalConnections,
701 BaseOutputPinImpl_EndOfStream,
702 BaseOutputPinImpl_BeginFlush,
703 BaseOutputPinImpl_EndFlush,
704 BasePinImpl_NewSegment
707 static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
709 HRESULT hr;
710 PullPin *This = (PullPin *)iface;
712 TRACE("()\n");
714 EnterCriticalSection(&This->thread_lock);
715 EnterCriticalSection(This->pin.pCritSec);
717 if (This->pin.pConnectedTo)
719 FILTER_STATE state;
720 ParserImpl *Parser = (ParserImpl *)This->pin.pinInfo.pFilter;
722 LeaveCriticalSection(This->pin.pCritSec);
723 hr = IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
724 EnterCriticalSection(This->pin.pCritSec);
726 if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
728 LeaveCriticalSection(This->pin.pCritSec);
729 PullPin_Disconnect(iface);
730 EnterCriticalSection(This->pin.pCritSec);
731 hr = Parser_RemoveOutputPins((ParserImpl *)This->pin.pinInfo.pFilter);
733 else
734 hr = VFW_E_NOT_STOPPED;
736 else
737 hr = S_FALSE;
739 LeaveCriticalSection(This->pin.pCritSec);
740 LeaveCriticalSection(&This->thread_lock);
742 return hr;
745 static HRESULT WINAPI Parser_PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
747 HRESULT hr;
749 TRACE("()\n");
751 hr = PullPin_ReceiveConnection(iface, pReceivePin, pmt);
752 if (FAILED(hr))
754 BasePin *This = (BasePin *)iface;
756 EnterCriticalSection(This->pCritSec);
757 Parser_RemoveOutputPins((ParserImpl *)This->pinInfo.pFilter);
758 LeaveCriticalSection(This->pCritSec);
761 return hr;
764 static HRESULT WINAPI Parser_PullPin_EnumMediaTypes(IPin *iface, IEnumMediaTypes **ppEnum)
766 BasePin *This = (BasePin *)iface;
768 TRACE("(%p/%p)->(%p)\n", This, iface, ppEnum);
770 return EnumMediaTypes_Construct(This, BasePinImpl_GetMediaType, BasePinImpl_GetMediaTypeVersion, ppEnum);
773 static const IPinVtbl Parser_InputPin_Vtbl =
775 PullPin_QueryInterface,
776 BasePinImpl_AddRef,
777 PullPin_Release,
778 BaseInputPinImpl_Connect,
779 Parser_PullPin_ReceiveConnection,
780 Parser_PullPin_Disconnect,
781 BasePinImpl_ConnectedTo,
782 BasePinImpl_ConnectionMediaType,
783 BasePinImpl_QueryPinInfo,
784 BasePinImpl_QueryDirection,
785 BasePinImpl_QueryId,
786 PullPin_QueryAccept,
787 Parser_PullPin_EnumMediaTypes,
788 BasePinImpl_QueryInternalConnections,
789 PullPin_EndOfStream,
790 PullPin_BeginFlush,
791 PullPin_EndFlush,
792 PullPin_NewSegment