msvcrt: Write directly to the console in _putwch.
[wine/multimedia.git] / dlls / quartz / pin.c
blob8377be575590b5c380f279bfd723bb61ec25ece0
1 /*
2 * Generic Implementation of IPin Interface
4 * Copyright 2003 Robert Shearman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "quartz_private.h"
22 #include "pin.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26 #include "uuids.h"
27 #include "vfwmsgs.h"
28 #include <assert.h>
30 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
32 static const IPinVtbl PullPin_Vtbl;
34 #define ALIGNDOWN(value,boundary) ((value)/(boundary)*(boundary))
35 #define ALIGNUP(value,boundary) (ALIGNDOWN((value)+(boundary)-1, (boundary)))
37 typedef HRESULT (*SendPinFunc)( IPin *to, LPVOID arg );
39 /** Helper function, there are a lot of places where the error code is inherited
40 * The following rules apply:
42 * Return the first received error code (E_NOTIMPL is ignored)
43 * If no errors occur: return the first received non-error-code that isn't S_OK
45 static HRESULT updatehres( HRESULT original, HRESULT new )
47 if (FAILED( original ) || new == E_NOTIMPL)
48 return original;
50 if (FAILED( new ) || original == S_OK)
51 return new;
53 return original;
56 /** Sends a message from a pin further to other, similar pins
57 * fnMiddle is called on each pin found further on the stream.
58 * fnEnd (can be NULL) is called when the message can't be sent any further (this is a renderer or source)
60 * If the pin given is an input pin, the message will be sent downstream to other input pins
61 * If the pin given is an output pin, the message will be sent upstream to other output pins
63 static HRESULT SendFurther( IPin *from, SendPinFunc fnMiddle, LPVOID arg, SendPinFunc fnEnd )
65 PIN_INFO pin_info;
66 ULONG amount = 0;
67 HRESULT hr = S_OK;
68 HRESULT hr_return = S_OK;
69 IEnumPins *enumpins = NULL;
70 BOOL foundend = TRUE;
71 PIN_DIRECTION from_dir;
73 IPin_QueryDirection( from, &from_dir );
75 hr = IPin_QueryInternalConnections( from, NULL, &amount );
76 if (hr != E_NOTIMPL && amount)
77 FIXME("Use QueryInternalConnections!\n");
79 pin_info.pFilter = NULL;
80 hr = IPin_QueryPinInfo( from, &pin_info );
81 if (FAILED(hr))
82 goto out;
84 hr = IBaseFilter_EnumPins( pin_info.pFilter, &enumpins );
85 if (FAILED(hr))
86 goto out;
88 hr = IEnumPins_Reset( enumpins );
89 while (hr == S_OK) {
90 IPin *pin = NULL;
91 hr = IEnumPins_Next( enumpins, 1, &pin, NULL );
92 if (hr == VFW_E_ENUM_OUT_OF_SYNC)
94 hr = IEnumPins_Reset( enumpins );
95 continue;
97 if (pin)
99 PIN_DIRECTION dir;
101 IPin_QueryDirection( pin, &dir );
102 if (dir != from_dir)
104 IPin *connected = NULL;
106 foundend = FALSE;
107 IPin_ConnectedTo( pin, &connected );
108 if (connected)
110 HRESULT hr_local;
112 hr_local = fnMiddle( connected, arg );
113 hr_return = updatehres( hr_return, hr_local );
114 IPin_Release(connected);
117 IPin_Release( pin );
119 else
121 hr = S_OK;
122 break;
126 if (!foundend)
127 hr = hr_return;
128 else if (fnEnd) {
129 HRESULT hr_local;
131 hr_local = fnEnd( from, arg );
132 hr_return = updatehres( hr_return, hr_local );
135 out:
136 if (enumpins)
137 IEnumPins_Release( enumpins );
138 if (pin_info.pFilter)
139 IBaseFilter_Release( pin_info.pFilter );
140 return hr;
144 static void Copy_PinInfo(PIN_INFO * pDest, const PIN_INFO * pSrc)
146 /* Tempting to just do a memcpy, but the name field is
147 128 characters long! We will probably never exceed 10
148 most of the time, so we are better off copying
149 each field manually */
150 strcpyW(pDest->achName, pSrc->achName);
151 pDest->dir = pSrc->dir;
152 pDest->pFilter = pSrc->pFilter;
155 static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
157 return IPin_EndOfStream( pin );
160 static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
162 return IPin_BeginFlush( pin );
165 static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
167 return IPin_EndFlush( pin );
170 typedef struct newsegmentargs
172 REFERENCE_TIME tStart, tStop;
173 double rate;
174 } newsegmentargs;
176 static HRESULT deliver_newsegment(IPin *pin, LPVOID data)
178 newsegmentargs *args = data;
179 return IPin_NewSegment(pin, args->tStart, args->tStop, args->rate);
182 /*** PullPin implementation ***/
184 static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PULL pSampleProc, LPVOID pUserData,
185 QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone, LPCRITICAL_SECTION pCritSec, PullPin * pPinImpl)
187 /* Common attributes */
188 pPinImpl->pin.IPin_iface.lpVtbl = PullPin_Vtbl;
189 pPinImpl->pin.refCount = 1;
190 pPinImpl->pin.pConnectedTo = NULL;
191 pPinImpl->pin.pCritSec = pCritSec;
192 Copy_PinInfo(&pPinImpl->pin.pinInfo, pPinInfo);
193 ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
195 /* Input pin attributes */
196 pPinImpl->pUserData = pUserData;
197 pPinImpl->fnQueryAccept = pQueryAccept;
198 pPinImpl->fnSampleProc = pSampleProc;
199 pPinImpl->fnCleanProc = pCleanUp;
200 pPinImpl->fnDone = pDone;
201 pPinImpl->fnPreConnect = NULL;
202 pPinImpl->pAlloc = NULL;
203 pPinImpl->prefAlloc = NULL;
204 pPinImpl->pReader = NULL;
205 pPinImpl->hThread = NULL;
206 pPinImpl->hEventStateChanged = CreateEventW(NULL, TRUE, TRUE, NULL);
207 pPinImpl->thread_sleepy = CreateEventW(NULL, FALSE, FALSE, NULL);
209 pPinImpl->rtStart = 0;
210 pPinImpl->rtCurrent = 0;
211 pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
212 pPinImpl->dRate = 1.0;
213 pPinImpl->state = Req_Die;
214 pPinImpl->fnCustomRequest = pCustomRequest;
215 pPinImpl->stop_playback = 1;
217 InitializeCriticalSection(&pPinImpl->thread_lock);
218 pPinImpl->thread_lock.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": PullPin.thread_lock");
220 return S_OK;
223 HRESULT PullPin_Construct(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PULL pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone, LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
225 PullPin * pPinImpl;
227 *ppPin = NULL;
229 if (pPinInfo->dir != PINDIR_INPUT)
231 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
232 return E_INVALIDARG;
235 pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
237 if (!pPinImpl)
238 return E_OUTOFMEMORY;
240 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl, pPinInfo, pSampleProc, pUserData, pQueryAccept, pCleanUp, pCustomRequest, pDone, pCritSec, pPinImpl)))
242 *ppPin = &pPinImpl->pin.IPin_iface;
243 return S_OK;
246 CoTaskMemFree(pPinImpl);
247 return E_FAIL;
250 static HRESULT PullPin_InitProcessing(PullPin * This);
252 HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
254 PIN_DIRECTION pindirReceive;
255 HRESULT hr = S_OK;
256 PullPin *This = impl_PullPin_from_IPin(iface);
258 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
259 dump_AM_MEDIA_TYPE(pmt);
261 EnterCriticalSection(This->pin.pCritSec);
262 if (!This->pin.pConnectedTo)
264 ALLOCATOR_PROPERTIES props;
266 props.cBuffers = 3;
267 props.cbBuffer = 64 * 1024; /* 64 KB */
268 props.cbAlign = 1;
269 props.cbPrefix = 0;
271 if (This->fnQueryAccept(This->pUserData, pmt) != S_OK)
272 hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
273 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
275 if (SUCCEEDED(hr))
277 IPin_QueryDirection(pReceivePin, &pindirReceive);
279 if (pindirReceive != PINDIR_OUTPUT)
281 ERR("Can't connect from non-output pin\n");
282 hr = VFW_E_INVALID_DIRECTION;
286 This->pReader = NULL;
287 This->pAlloc = NULL;
288 This->prefAlloc = NULL;
289 if (SUCCEEDED(hr))
291 hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
294 if (SUCCEEDED(hr) && This->fnPreConnect)
296 hr = This->fnPreConnect(iface, pReceivePin, &props);
300 * Some custom filters (such as the one used by Fallout 3
301 * and Fallout: New Vegas) expect to be passed a non-NULL
302 * preferred allocator.
304 if (SUCCEEDED(hr))
306 hr = StdMemAllocator_create(NULL, (LPVOID *) &This->prefAlloc);
309 if (SUCCEEDED(hr))
311 hr = IAsyncReader_RequestAllocator(This->pReader, This->prefAlloc, &props, &This->pAlloc);
314 if (SUCCEEDED(hr))
316 CopyMediaType(&This->pin.mtCurrent, pmt);
317 This->pin.pConnectedTo = pReceivePin;
318 IPin_AddRef(pReceivePin);
319 hr = IMemAllocator_Commit(This->pAlloc);
322 if (SUCCEEDED(hr))
323 hr = PullPin_InitProcessing(This);
325 if (FAILED(hr))
327 if (This->pReader)
328 IAsyncReader_Release(This->pReader);
329 This->pReader = NULL;
330 if (This->prefAlloc)
331 IMemAllocator_Release(This->prefAlloc);
332 This->prefAlloc = NULL;
333 if (This->pAlloc)
334 IMemAllocator_Release(This->pAlloc);
335 This->pAlloc = NULL;
338 else
339 hr = VFW_E_ALREADY_CONNECTED;
340 LeaveCriticalSection(This->pin.pCritSec);
341 return hr;
344 HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
346 PullPin *This = impl_PullPin_from_IPin(iface);
348 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
350 *ppv = NULL;
352 if (IsEqualIID(riid, &IID_IUnknown))
353 *ppv = iface;
354 else if (IsEqualIID(riid, &IID_IPin))
355 *ppv = iface;
356 else if (IsEqualIID(riid, &IID_IMediaSeeking) ||
357 IsEqualIID(riid, &IID_IQualityControl))
359 return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, riid, ppv);
362 if (*ppv)
364 IUnknown_AddRef((IUnknown *)(*ppv));
365 return S_OK;
368 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
370 return E_NOINTERFACE;
373 ULONG WINAPI PullPin_Release(IPin *iface)
375 PullPin *This = impl_PullPin_from_IPin(iface);
376 ULONG refCount = InterlockedDecrement(&This->pin.refCount);
378 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
380 if (!refCount)
382 WaitForSingleObject(This->hEventStateChanged, INFINITE);
383 assert(!This->hThread);
385 if(This->prefAlloc)
386 IMemAllocator_Release(This->prefAlloc);
387 if(This->pAlloc)
388 IMemAllocator_Release(This->pAlloc);
389 if(This->pReader)
390 IAsyncReader_Release(This->pReader);
391 CloseHandle(This->thread_sleepy);
392 CloseHandle(This->hEventStateChanged);
393 This->thread_lock.DebugInfo->Spare[0] = 0;
394 DeleteCriticalSection(&This->thread_lock);
395 CoTaskMemFree(This);
396 return 0;
398 return refCount;
401 static void PullPin_Flush(PullPin *This)
403 IMediaSample *pSample;
404 TRACE("Flushing!\n");
406 if (This->pReader)
408 /* Do not allow state to change while flushing */
409 EnterCriticalSection(This->pin.pCritSec);
411 /* Flush outstanding samples */
412 IAsyncReader_BeginFlush(This->pReader);
414 for (;;)
416 DWORD_PTR dwUser;
418 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
420 if (!pSample)
421 break;
423 assert(!IMediaSample_GetActualDataLength(pSample));
425 IMediaSample_Release(pSample);
428 IAsyncReader_EndFlush(This->pReader);
430 LeaveCriticalSection(This->pin.pCritSec);
434 static void PullPin_Thread_Process(PullPin *This)
436 HRESULT hr;
437 IMediaSample * pSample = NULL;
438 ALLOCATOR_PROPERTIES allocProps;
440 hr = IMemAllocator_GetProperties(This->pAlloc, &allocProps);
442 This->cbAlign = allocProps.cbAlign;
444 if (This->rtCurrent < This->rtStart)
445 This->rtCurrent = MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This->rtStart), This->cbAlign));
447 TRACE("Start\n");
449 if (This->rtCurrent >= This->rtStop)
451 IPin_EndOfStream(&This->pin.IPin_iface);
452 return;
455 /* There is no sample in our buffer */
456 hr = This->fnCustomRequest(This->pUserData);
458 if (FAILED(hr))
459 ERR("Request error: %x\n", hr);
461 EnterCriticalSection(This->pin.pCritSec);
462 SetEvent(This->hEventStateChanged);
463 LeaveCriticalSection(This->pin.pCritSec);
465 if (SUCCEEDED(hr))
468 DWORD_PTR dwUser;
470 TRACE("Process sample\n");
472 pSample = NULL;
473 hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
475 /* Return an empty sample on error to the implementation in case it does custom parsing, so it knows it's gone */
476 if (SUCCEEDED(hr))
478 hr = This->fnSampleProc(This->pUserData, pSample, dwUser);
480 else
482 if (hr == VFW_E_TIMEOUT)
484 if (pSample != NULL)
485 WARN("Non-NULL sample returned with VFW_E_TIMEOUT.\n");
486 hr = S_OK;
488 /* FIXME: Errors are not well handled yet! */
489 else
490 ERR("Processing error: %x\n", hr);
493 if (pSample)
495 IMediaSample_Release(pSample);
496 pSample = NULL;
498 } while (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback);
501 * Sample was rejected, and we are asked to terminate. When there is more than one buffer
502 * it is possible for a filter to have several queued samples, making it necessary to
503 * release all of these pending samples.
505 if (This->stop_playback || FAILED(hr))
507 DWORD_PTR dwUser;
511 if (pSample)
512 IMediaSample_Release(pSample);
513 pSample = NULL;
514 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
515 } while(pSample);
518 /* Can't reset state to Sleepy here because that might race, instead PauseProcessing will do that for us
519 * Flush remaining samples
521 if (This->fnDone)
522 This->fnDone(This->pUserData);
524 TRACE("End: %08x, %d\n", hr, This->stop_playback);
527 static void PullPin_Thread_Pause(PullPin *This)
529 PullPin_Flush(This);
531 EnterCriticalSection(This->pin.pCritSec);
532 This->state = Req_Sleepy;
533 SetEvent(This->hEventStateChanged);
534 LeaveCriticalSection(This->pin.pCritSec);
537 static void PullPin_Thread_Stop(PullPin *This)
539 TRACE("(%p)->()\n", This);
541 EnterCriticalSection(This->pin.pCritSec);
543 CloseHandle(This->hThread);
544 This->hThread = NULL;
545 SetEvent(This->hEventStateChanged);
547 LeaveCriticalSection(This->pin.pCritSec);
549 IBaseFilter_Release(This->pin.pinInfo.pFilter);
551 CoUninitialize();
552 ExitThread(0);
555 static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
557 PullPin *This = pv;
558 CoInitializeEx(NULL, COINIT_MULTITHREADED);
560 PullPin_Flush(This);
562 for (;;)
564 WaitForSingleObject(This->thread_sleepy, INFINITE);
566 TRACE("State: %d\n", This->state);
568 switch (This->state)
570 case Req_Die: PullPin_Thread_Stop(This); break;
571 case Req_Run: PullPin_Thread_Process(This); break;
572 case Req_Pause: PullPin_Thread_Pause(This); break;
573 case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break;
574 default: ERR("Unknown state request: %d\n", This->state); break;
577 return 0;
580 static HRESULT PullPin_InitProcessing(PullPin * This)
582 HRESULT hr = S_OK;
584 TRACE("(%p)->()\n", This);
586 /* if we are connected */
587 if (This->pAlloc)
589 DWORD dwThreadId;
591 WaitForSingleObject(This->hEventStateChanged, INFINITE);
592 EnterCriticalSection(This->pin.pCritSec);
594 assert(!This->hThread);
595 assert(This->state == Req_Die);
596 assert(This->stop_playback);
597 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
598 This->state = Req_Sleepy;
600 /* AddRef the filter to make sure it and its pins will be around
601 * as long as the thread */
602 IBaseFilter_AddRef(This->pin.pinInfo.pFilter);
605 This->hThread = CreateThread(NULL, 0, PullPin_Thread_Main, This, 0, &dwThreadId);
606 if (!This->hThread)
608 hr = HRESULT_FROM_WIN32(GetLastError());
609 IBaseFilter_Release(This->pin.pinInfo.pFilter);
612 if (SUCCEEDED(hr))
614 SetEvent(This->hEventStateChanged);
615 /* If assert fails, that means a command was not processed before the thread previously terminated */
617 LeaveCriticalSection(This->pin.pCritSec);
620 TRACE(" -- %x\n", hr);
622 return hr;
625 HRESULT PullPin_StartProcessing(PullPin * This)
627 /* if we are connected */
628 TRACE("(%p)->()\n", This);
629 if(This->pAlloc)
631 assert(This->hThread);
633 PullPin_WaitForStateChange(This, INFINITE);
635 assert(This->state == Req_Sleepy);
637 /* Wake up! */
638 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
639 This->state = Req_Run;
640 This->stop_playback = 0;
641 ResetEvent(This->hEventStateChanged);
642 SetEvent(This->thread_sleepy);
645 return S_OK;
648 HRESULT PullPin_PauseProcessing(PullPin * This)
650 /* if we are connected */
651 TRACE("(%p)->()\n", This);
652 if(This->pAlloc)
654 assert(This->hThread);
656 PullPin_WaitForStateChange(This, INFINITE);
658 EnterCriticalSection(This->pin.pCritSec);
660 assert(!This->stop_playback);
661 assert(This->state == Req_Run|| This->state == Req_Sleepy);
663 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
665 This->state = Req_Pause;
666 This->stop_playback = 1;
667 ResetEvent(This->hEventStateChanged);
668 SetEvent(This->thread_sleepy);
670 /* Release any outstanding samples */
671 if (This->pReader)
673 IMediaSample *pSample;
674 DWORD_PTR dwUser;
678 pSample = NULL;
679 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
680 if (pSample)
681 IMediaSample_Release(pSample);
682 } while(pSample);
685 LeaveCriticalSection(This->pin.pCritSec);
688 return S_OK;
691 static HRESULT PullPin_StopProcessing(PullPin * This)
693 TRACE("(%p)->()\n", This);
695 /* if we are alive */
696 assert(This->hThread);
698 PullPin_WaitForStateChange(This, INFINITE);
700 assert(This->state == Req_Pause || This->state == Req_Sleepy);
702 This->stop_playback = 1;
703 This->state = Req_Die;
704 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
705 ResetEvent(This->hEventStateChanged);
706 SetEvent(This->thread_sleepy);
707 return S_OK;
710 HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds)
712 if (WaitForSingleObject(This->hEventStateChanged, dwMilliseconds) == WAIT_TIMEOUT)
713 return S_FALSE;
714 return S_OK;
717 HRESULT WINAPI PullPin_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
719 PullPin *This = impl_PullPin_from_IPin(iface);
721 TRACE("(%p/%p)->(%p)\n", This, iface, pmt);
723 return (This->fnQueryAccept(This->pUserData, pmt) == S_OK ? S_OK : S_FALSE);
726 HRESULT WINAPI PullPin_EndOfStream(IPin * iface)
728 PullPin *This = impl_PullPin_from_IPin(iface);
729 HRESULT hr = S_FALSE;
731 TRACE("(%p)->()\n", iface);
733 EnterCriticalSection(This->pin.pCritSec);
734 hr = SendFurther( iface, deliver_endofstream, NULL, NULL );
735 SetEvent(This->hEventStateChanged);
736 LeaveCriticalSection(This->pin.pCritSec);
738 return hr;
741 HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
743 PullPin *This = impl_PullPin_from_IPin(iface);
744 TRACE("(%p)->()\n", This);
746 EnterCriticalSection(This->pin.pCritSec);
748 SendFurther( iface, deliver_beginflush, NULL, NULL );
750 LeaveCriticalSection(This->pin.pCritSec);
752 EnterCriticalSection(&This->thread_lock);
754 if (This->pReader)
755 IAsyncReader_BeginFlush(This->pReader);
756 PullPin_WaitForStateChange(This, INFINITE);
758 if (This->hThread && This->state == Req_Run)
760 PullPin_PauseProcessing(This);
761 PullPin_WaitForStateChange(This, INFINITE);
764 LeaveCriticalSection(&This->thread_lock);
766 EnterCriticalSection(This->pin.pCritSec);
768 This->fnCleanProc(This->pUserData);
770 LeaveCriticalSection(This->pin.pCritSec);
772 return S_OK;
775 HRESULT WINAPI PullPin_EndFlush(IPin * iface)
777 PullPin *This = impl_PullPin_from_IPin(iface);
779 TRACE("(%p)->()\n", iface);
781 /* Send further first: Else a race condition might terminate processing early */
782 EnterCriticalSection(This->pin.pCritSec);
783 SendFurther( iface, deliver_endflush, NULL, NULL );
784 LeaveCriticalSection(This->pin.pCritSec);
786 EnterCriticalSection(&This->thread_lock);
788 FILTER_STATE state;
790 if (This->pReader)
791 IAsyncReader_EndFlush(This->pReader);
793 IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
795 if (state != State_Stopped)
796 PullPin_StartProcessing(This);
798 PullPin_WaitForStateChange(This, INFINITE);
800 LeaveCriticalSection(&This->thread_lock);
802 return S_OK;
805 HRESULT WINAPI PullPin_Disconnect(IPin *iface)
807 HRESULT hr;
808 PullPin *This = impl_PullPin_from_IPin(iface);
810 TRACE("()\n");
812 EnterCriticalSection(This->pin.pCritSec);
814 if (FAILED(hr = IMemAllocator_Decommit(This->pAlloc)))
815 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr);
817 if (This->pin.pConnectedTo)
819 IPin_Release(This->pin.pConnectedTo);
820 This->pin.pConnectedTo = NULL;
821 PullPin_StopProcessing(This);
823 FreeMediaType(&This->pin.mtCurrent);
824 ZeroMemory(&This->pin.mtCurrent, sizeof(This->pin.mtCurrent));
825 hr = S_OK;
827 else
828 hr = S_FALSE;
830 LeaveCriticalSection(This->pin.pCritSec);
832 return hr;
835 HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
837 newsegmentargs args;
838 FIXME("(%p)->(%s, %s, %g) stub\n", iface, wine_dbgstr_longlong(tStart), wine_dbgstr_longlong(tStop), dRate);
840 args.tStart = tStart;
841 args.tStop = tStop;
842 args.rate = dRate;
844 return SendFurther( iface, deliver_newsegment, &args, NULL );
847 static const IPinVtbl PullPin_Vtbl =
849 PullPin_QueryInterface,
850 BasePinImpl_AddRef,
851 PullPin_Release,
852 BaseInputPinImpl_Connect,
853 PullPin_ReceiveConnection,
854 PullPin_Disconnect,
855 BasePinImpl_ConnectedTo,
856 BasePinImpl_ConnectionMediaType,
857 BasePinImpl_QueryPinInfo,
858 BasePinImpl_QueryDirection,
859 BasePinImpl_QueryId,
860 PullPin_QueryAccept,
861 BasePinImpl_EnumMediaTypes,
862 BasePinImpl_QueryInternalConnections,
863 PullPin_EndOfStream,
864 PullPin_BeginFlush,
865 PullPin_EndFlush,
866 PullPin_NewSegment