winehid.sys: Implement handing internal ioctls.
[wine.git] / dlls / quartz / pin.c
bloba2651fd49b55109ff60ae0297db7e35909fa76f4
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 #define ALIGNDOWN(value,boundary) ((value)/(boundary)*(boundary))
33 #define ALIGNUP(value,boundary) (ALIGNDOWN((value)+(boundary)-1, (boundary)))
35 typedef HRESULT (*SendPinFunc)( IPin *to, LPVOID arg );
37 /** Helper function, there are a lot of places where the error code is inherited
38 * The following rules apply:
40 * Return the first received error code (E_NOTIMPL is ignored)
41 * If no errors occur: return the first received non-error-code that isn't S_OK
43 static HRESULT updatehres( HRESULT original, HRESULT new )
45 if (FAILED( original ) || new == E_NOTIMPL)
46 return original;
48 if (FAILED( new ) || original == S_OK)
49 return new;
51 return original;
54 /** Sends a message from a pin further to other, similar pins
55 * fnMiddle is called on each pin found further on the stream.
56 * fnEnd (can be NULL) is called when the message can't be sent any further (this is a renderer or source)
58 * If the pin given is an input pin, the message will be sent downstream to other input pins
59 * If the pin given is an output pin, the message will be sent upstream to other output pins
61 static HRESULT SendFurther( IPin *from, SendPinFunc fnMiddle, LPVOID arg, SendPinFunc fnEnd )
63 PIN_INFO pin_info;
64 ULONG amount = 0;
65 HRESULT hr = S_OK;
66 HRESULT hr_return = S_OK;
67 IEnumPins *enumpins = NULL;
68 BOOL foundend = TRUE;
69 PIN_DIRECTION from_dir;
71 IPin_QueryDirection( from, &from_dir );
73 hr = IPin_QueryInternalConnections( from, NULL, &amount );
74 if (hr != E_NOTIMPL && amount)
75 FIXME("Use QueryInternalConnections!\n");
77 pin_info.pFilter = NULL;
78 hr = IPin_QueryPinInfo( from, &pin_info );
79 if (FAILED(hr))
80 goto out;
82 hr = IBaseFilter_EnumPins( pin_info.pFilter, &enumpins );
83 if (FAILED(hr))
84 goto out;
86 hr = IEnumPins_Reset( enumpins );
87 while (hr == S_OK) {
88 IPin *pin = NULL;
89 hr = IEnumPins_Next( enumpins, 1, &pin, NULL );
90 if (hr == VFW_E_ENUM_OUT_OF_SYNC)
92 hr = IEnumPins_Reset( enumpins );
93 continue;
95 if (pin)
97 PIN_DIRECTION dir;
99 IPin_QueryDirection( pin, &dir );
100 if (dir != from_dir)
102 IPin *connected = NULL;
104 foundend = FALSE;
105 IPin_ConnectedTo( pin, &connected );
106 if (connected)
108 HRESULT hr_local;
110 hr_local = fnMiddle( connected, arg );
111 hr_return = updatehres( hr_return, hr_local );
112 IPin_Release(connected);
115 IPin_Release( pin );
117 else
119 hr = S_OK;
120 break;
124 if (!foundend)
125 hr = hr_return;
126 else if (fnEnd) {
127 HRESULT hr_local;
129 hr_local = fnEnd( from, arg );
130 hr_return = updatehres( hr_return, hr_local );
133 out:
134 if (enumpins)
135 IEnumPins_Release( enumpins );
136 if (pin_info.pFilter)
137 IBaseFilter_Release( pin_info.pFilter );
138 return hr;
142 static void Copy_PinInfo(PIN_INFO * pDest, const PIN_INFO * pSrc)
144 /* Tempting to just do a memcpy, but the name field is
145 128 characters long! We will probably never exceed 10
146 most of the time, so we are better off copying
147 each field manually */
148 strcpyW(pDest->achName, pSrc->achName);
149 pDest->dir = pSrc->dir;
150 pDest->pFilter = pSrc->pFilter;
153 static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
155 return IPin_EndOfStream( pin );
158 static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
160 return IPin_BeginFlush( pin );
163 static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
165 return IPin_EndFlush( pin );
168 typedef struct newsegmentargs
170 REFERENCE_TIME tStart, tStop;
171 double rate;
172 } newsegmentargs;
174 static HRESULT deliver_newsegment(IPin *pin, LPVOID data)
176 newsegmentargs *args = data;
177 return IPin_NewSegment(pin, args->tStart, args->tStop, args->rate);
180 /*** PullPin implementation ***/
182 static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo, SAMPLEPROC_PULL pSampleProc, LPVOID pUserData,
183 QUERYACCEPTPROC pQueryAccept, CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone, LPCRITICAL_SECTION pCritSec, PullPin * pPinImpl)
185 /* Common attributes */
186 pPinImpl->pin.IPin_iface.lpVtbl = PullPin_Vtbl;
187 pPinImpl->pin.refCount = 1;
188 pPinImpl->pin.pConnectedTo = NULL;
189 pPinImpl->pin.pCritSec = pCritSec;
190 Copy_PinInfo(&pPinImpl->pin.pinInfo, pPinInfo);
191 ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
193 /* Input pin attributes */
194 pPinImpl->pUserData = pUserData;
195 pPinImpl->fnQueryAccept = pQueryAccept;
196 pPinImpl->fnSampleProc = pSampleProc;
197 pPinImpl->fnCleanProc = pCleanUp;
198 pPinImpl->fnDone = pDone;
199 pPinImpl->fnPreConnect = NULL;
200 pPinImpl->pAlloc = NULL;
201 pPinImpl->prefAlloc = NULL;
202 pPinImpl->pReader = NULL;
203 pPinImpl->hThread = NULL;
204 pPinImpl->hEventStateChanged = CreateEventW(NULL, TRUE, TRUE, NULL);
205 pPinImpl->thread_sleepy = CreateEventW(NULL, FALSE, FALSE, NULL);
207 pPinImpl->rtStart = 0;
208 pPinImpl->rtCurrent = 0;
209 pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
210 pPinImpl->dRate = 1.0;
211 pPinImpl->state = Req_Die;
212 pPinImpl->fnCustomRequest = pCustomRequest;
213 pPinImpl->stop_playback = TRUE;
215 InitializeCriticalSection(&pPinImpl->thread_lock);
216 pPinImpl->thread_lock.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": PullPin.thread_lock");
218 return S_OK;
221 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)
223 PullPin * pPinImpl;
225 *ppPin = NULL;
227 if (pPinInfo->dir != PINDIR_INPUT)
229 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
230 return E_INVALIDARG;
233 pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
235 if (!pPinImpl)
236 return E_OUTOFMEMORY;
238 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl, pPinInfo, pSampleProc, pUserData, pQueryAccept, pCleanUp, pCustomRequest, pDone, pCritSec, pPinImpl)))
240 *ppPin = &pPinImpl->pin.IPin_iface;
241 return S_OK;
244 CoTaskMemFree(pPinImpl);
245 return E_FAIL;
248 static HRESULT PullPin_InitProcessing(PullPin * This);
250 HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
252 PIN_DIRECTION pindirReceive;
253 HRESULT hr = S_OK;
254 PullPin *This = impl_PullPin_from_IPin(iface);
256 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
257 dump_AM_MEDIA_TYPE(pmt);
259 EnterCriticalSection(This->pin.pCritSec);
260 if (!This->pin.pConnectedTo)
262 ALLOCATOR_PROPERTIES props;
264 props.cBuffers = 3;
265 props.cbBuffer = 64 * 1024; /* 64 KB */
266 props.cbAlign = 1;
267 props.cbPrefix = 0;
269 if (This->fnQueryAccept(This->pUserData, pmt) != S_OK)
270 hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
271 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
273 if (SUCCEEDED(hr))
275 IPin_QueryDirection(pReceivePin, &pindirReceive);
277 if (pindirReceive != PINDIR_OUTPUT)
279 ERR("Can't connect from non-output pin\n");
280 hr = VFW_E_INVALID_DIRECTION;
284 This->pReader = NULL;
285 This->pAlloc = NULL;
286 This->prefAlloc = NULL;
287 if (SUCCEEDED(hr))
289 hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
292 if (SUCCEEDED(hr) && This->fnPreConnect)
294 hr = This->fnPreConnect(iface, pReceivePin, &props);
298 * Some custom filters (such as the one used by Fallout 3
299 * and Fallout: New Vegas) expect to be passed a non-NULL
300 * preferred allocator.
302 if (SUCCEEDED(hr))
304 hr = StdMemAllocator_create(NULL, (LPVOID *) &This->prefAlloc);
307 if (SUCCEEDED(hr))
309 hr = IAsyncReader_RequestAllocator(This->pReader, This->prefAlloc, &props, &This->pAlloc);
312 if (SUCCEEDED(hr))
314 CopyMediaType(&This->pin.mtCurrent, pmt);
315 This->pin.pConnectedTo = pReceivePin;
316 IPin_AddRef(pReceivePin);
317 hr = IMemAllocator_Commit(This->pAlloc);
320 if (SUCCEEDED(hr))
321 hr = PullPin_InitProcessing(This);
323 if (FAILED(hr))
325 if (This->pReader)
326 IAsyncReader_Release(This->pReader);
327 This->pReader = NULL;
328 if (This->prefAlloc)
329 IMemAllocator_Release(This->prefAlloc);
330 This->prefAlloc = NULL;
331 if (This->pAlloc)
332 IMemAllocator_Release(This->pAlloc);
333 This->pAlloc = NULL;
336 else
337 hr = VFW_E_ALREADY_CONNECTED;
338 LeaveCriticalSection(This->pin.pCritSec);
339 return hr;
342 HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
344 PullPin *This = impl_PullPin_from_IPin(iface);
346 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
348 *ppv = NULL;
350 if (IsEqualIID(riid, &IID_IUnknown))
351 *ppv = iface;
352 else if (IsEqualIID(riid, &IID_IPin))
353 *ppv = iface;
354 else if (IsEqualIID(riid, &IID_IMediaSeeking) ||
355 IsEqualIID(riid, &IID_IQualityControl))
357 return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, riid, ppv);
360 if (*ppv)
362 IUnknown_AddRef((IUnknown *)(*ppv));
363 return S_OK;
366 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
368 return E_NOINTERFACE;
371 ULONG WINAPI PullPin_Release(IPin *iface)
373 PullPin *This = impl_PullPin_from_IPin(iface);
374 ULONG refCount = InterlockedDecrement(&This->pin.refCount);
376 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
378 if (!refCount)
380 WaitForSingleObject(This->hEventStateChanged, INFINITE);
381 assert(!This->hThread);
383 if(This->prefAlloc)
384 IMemAllocator_Release(This->prefAlloc);
385 if(This->pAlloc)
386 IMemAllocator_Release(This->pAlloc);
387 if(This->pReader)
388 IAsyncReader_Release(This->pReader);
389 CloseHandle(This->thread_sleepy);
390 CloseHandle(This->hEventStateChanged);
391 This->thread_lock.DebugInfo->Spare[0] = 0;
392 DeleteCriticalSection(&This->thread_lock);
393 CoTaskMemFree(This);
394 return 0;
396 return refCount;
399 static void PullPin_Flush(PullPin *This)
401 IMediaSample *pSample;
402 TRACE("Flushing!\n");
404 if (This->pReader)
406 /* Do not allow state to change while flushing */
407 EnterCriticalSection(This->pin.pCritSec);
409 /* Flush outstanding samples */
410 IAsyncReader_BeginFlush(This->pReader);
412 for (;;)
414 DWORD_PTR dwUser;
416 pSample = NULL;
417 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
419 if (!pSample)
420 break;
422 assert(!IMediaSample_GetActualDataLength(pSample));
424 IMediaSample_Release(pSample);
427 IAsyncReader_EndFlush(This->pReader);
429 LeaveCriticalSection(This->pin.pCritSec);
433 static void PullPin_Thread_Process(PullPin *This)
435 HRESULT hr;
436 IMediaSample * pSample = NULL;
437 ALLOCATOR_PROPERTIES allocProps;
439 hr = IMemAllocator_GetProperties(This->pAlloc, &allocProps);
441 This->cbAlign = allocProps.cbAlign;
443 if (This->rtCurrent < This->rtStart)
444 This->rtCurrent = MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This->rtStart), This->cbAlign));
446 TRACE("Start\n");
448 if (This->rtCurrent >= This->rtStop)
450 IPin_EndOfStream(&This->pin.IPin_iface);
451 return;
454 /* There is no sample in our buffer */
455 hr = This->fnCustomRequest(This->pUserData);
457 if (FAILED(hr))
458 ERR("Request error: %x\n", hr);
460 EnterCriticalSection(This->pin.pCritSec);
461 SetEvent(This->hEventStateChanged);
462 LeaveCriticalSection(This->pin.pCritSec);
464 if (SUCCEEDED(hr))
467 DWORD_PTR dwUser;
469 TRACE("Process sample\n");
471 pSample = NULL;
472 hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
474 /* Return an empty sample on error to the implementation in case it does custom parsing, so it knows it's gone */
475 if (SUCCEEDED(hr))
477 hr = This->fnSampleProc(This->pUserData, pSample, dwUser);
479 else
481 if (hr == VFW_E_TIMEOUT)
483 if (pSample != NULL)
484 WARN("Non-NULL sample returned with VFW_E_TIMEOUT.\n");
485 hr = S_OK;
487 /* FIXME: Errors are not well handled yet! */
488 else
489 ERR("Processing error: %x\n", hr);
492 if (pSample)
494 IMediaSample_Release(pSample);
495 pSample = NULL;
497 } while (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback);
500 * Sample was rejected, and we are asked to terminate. When there is more than one buffer
501 * it is possible for a filter to have several queued samples, making it necessary to
502 * release all of these pending samples.
504 if (This->stop_playback || FAILED(hr))
506 DWORD_PTR dwUser;
510 if (pSample)
511 IMediaSample_Release(pSample);
512 pSample = NULL;
513 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
514 } while(pSample);
517 /* Can't reset state to Sleepy here because that might race, instead PauseProcessing will do that for us
518 * Flush remaining samples
520 if (This->fnDone)
521 This->fnDone(This->pUserData);
523 TRACE("End: %08x, %d\n", hr, This->stop_playback);
526 static void PullPin_Thread_Pause(PullPin *This)
528 PullPin_Flush(This);
530 EnterCriticalSection(This->pin.pCritSec);
531 This->state = Req_Sleepy;
532 SetEvent(This->hEventStateChanged);
533 LeaveCriticalSection(This->pin.pCritSec);
536 static void PullPin_Thread_Stop(PullPin *This)
538 TRACE("(%p)->()\n", This);
540 EnterCriticalSection(This->pin.pCritSec);
542 CloseHandle(This->hThread);
543 This->hThread = NULL;
544 SetEvent(This->hEventStateChanged);
546 LeaveCriticalSection(This->pin.pCritSec);
548 IBaseFilter_Release(This->pin.pinInfo.pFilter);
550 CoUninitialize();
551 ExitThread(0);
554 static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
556 PullPin *This = pv;
557 CoInitializeEx(NULL, COINIT_MULTITHREADED);
559 PullPin_Flush(This);
561 for (;;)
563 WaitForSingleObject(This->thread_sleepy, INFINITE);
565 TRACE("State: %d\n", This->state);
567 switch (This->state)
569 case Req_Die: PullPin_Thread_Stop(This); break;
570 case Req_Run: PullPin_Thread_Process(This); break;
571 case Req_Pause: PullPin_Thread_Pause(This); break;
572 case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break;
573 default: ERR("Unknown state request: %d\n", This->state); break;
576 return 0;
579 static HRESULT PullPin_InitProcessing(PullPin * This)
581 HRESULT hr = S_OK;
583 TRACE("(%p)->()\n", This);
585 /* if we are connected */
586 if (This->pAlloc)
588 DWORD dwThreadId;
590 WaitForSingleObject(This->hEventStateChanged, INFINITE);
591 EnterCriticalSection(This->pin.pCritSec);
593 assert(!This->hThread);
594 assert(This->state == Req_Die);
595 assert(This->stop_playback);
596 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
597 This->state = Req_Sleepy;
599 /* AddRef the filter to make sure it and its pins will be around
600 * as long as the thread */
601 IBaseFilter_AddRef(This->pin.pinInfo.pFilter);
604 This->hThread = CreateThread(NULL, 0, PullPin_Thread_Main, This, 0, &dwThreadId);
605 if (!This->hThread)
607 hr = HRESULT_FROM_WIN32(GetLastError());
608 IBaseFilter_Release(This->pin.pinInfo.pFilter);
611 if (SUCCEEDED(hr))
613 SetEvent(This->hEventStateChanged);
614 /* If assert fails, that means a command was not processed before the thread previously terminated */
616 LeaveCriticalSection(This->pin.pCritSec);
619 TRACE(" -- %x\n", hr);
621 return hr;
624 HRESULT PullPin_StartProcessing(PullPin * This)
626 /* if we are connected */
627 TRACE("(%p)->()\n", This);
628 if(This->pAlloc)
630 assert(This->hThread);
632 PullPin_WaitForStateChange(This, INFINITE);
634 assert(This->state == Req_Sleepy);
636 /* Wake up! */
637 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
638 This->state = Req_Run;
639 This->stop_playback = FALSE;
640 ResetEvent(This->hEventStateChanged);
641 SetEvent(This->thread_sleepy);
644 return S_OK;
647 HRESULT PullPin_PauseProcessing(PullPin * This)
649 /* if we are connected */
650 TRACE("(%p)->()\n", This);
651 if(This->pAlloc)
653 assert(This->hThread);
655 PullPin_WaitForStateChange(This, INFINITE);
657 EnterCriticalSection(This->pin.pCritSec);
659 assert(!This->stop_playback);
660 assert(This->state == Req_Run|| This->state == Req_Sleepy);
662 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
664 This->state = Req_Pause;
665 This->stop_playback = TRUE;
666 ResetEvent(This->hEventStateChanged);
667 SetEvent(This->thread_sleepy);
669 /* Release any outstanding samples */
670 if (This->pReader)
672 IMediaSample *pSample;
673 DWORD_PTR dwUser;
677 pSample = NULL;
678 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
679 if (pSample)
680 IMediaSample_Release(pSample);
681 } while(pSample);
684 LeaveCriticalSection(This->pin.pCritSec);
687 return S_OK;
690 static HRESULT PullPin_StopProcessing(PullPin * This)
692 TRACE("(%p)->()\n", This);
694 /* if we are alive */
695 assert(This->hThread);
697 PullPin_WaitForStateChange(This, INFINITE);
699 assert(This->state == Req_Pause || This->state == Req_Sleepy);
701 This->stop_playback = TRUE;
702 This->state = Req_Die;
703 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
704 ResetEvent(This->hEventStateChanged);
705 SetEvent(This->thread_sleepy);
706 return S_OK;
709 HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds)
711 if (WaitForSingleObject(This->hEventStateChanged, dwMilliseconds) == WAIT_TIMEOUT)
712 return S_FALSE;
713 return S_OK;
716 HRESULT WINAPI PullPin_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
718 PullPin *This = impl_PullPin_from_IPin(iface);
720 TRACE("(%p/%p)->(%p)\n", This, iface, pmt);
722 return (This->fnQueryAccept(This->pUserData, pmt) == S_OK ? S_OK : S_FALSE);
725 HRESULT WINAPI PullPin_EndOfStream(IPin * iface)
727 PullPin *This = impl_PullPin_from_IPin(iface);
728 HRESULT hr = S_FALSE;
730 TRACE("(%p)->()\n", iface);
732 EnterCriticalSection(This->pin.pCritSec);
733 hr = SendFurther( iface, deliver_endofstream, NULL, NULL );
734 SetEvent(This->hEventStateChanged);
735 LeaveCriticalSection(This->pin.pCritSec);
737 return hr;
740 HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
742 PullPin *This = impl_PullPin_from_IPin(iface);
743 TRACE("(%p)->()\n", This);
745 EnterCriticalSection(This->pin.pCritSec);
747 SendFurther( iface, deliver_beginflush, NULL, NULL );
749 LeaveCriticalSection(This->pin.pCritSec);
751 EnterCriticalSection(&This->thread_lock);
753 if (This->pReader)
754 IAsyncReader_BeginFlush(This->pReader);
755 PullPin_WaitForStateChange(This, INFINITE);
757 if (This->hThread && This->state == Req_Run)
759 PullPin_PauseProcessing(This);
760 PullPin_WaitForStateChange(This, INFINITE);
763 LeaveCriticalSection(&This->thread_lock);
765 EnterCriticalSection(This->pin.pCritSec);
767 This->fnCleanProc(This->pUserData);
769 LeaveCriticalSection(This->pin.pCritSec);
771 return S_OK;
774 HRESULT WINAPI PullPin_EndFlush(IPin * iface)
776 PullPin *This = impl_PullPin_from_IPin(iface);
778 TRACE("(%p)->()\n", iface);
780 /* Send further first: Else a race condition might terminate processing early */
781 EnterCriticalSection(This->pin.pCritSec);
782 SendFurther( iface, deliver_endflush, NULL, NULL );
783 LeaveCriticalSection(This->pin.pCritSec);
785 EnterCriticalSection(&This->thread_lock);
787 FILTER_STATE state;
789 if (This->pReader)
790 IAsyncReader_EndFlush(This->pReader);
792 IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
794 if (state != State_Stopped)
795 PullPin_StartProcessing(This);
797 PullPin_WaitForStateChange(This, INFINITE);
799 LeaveCriticalSection(&This->thread_lock);
801 return S_OK;
804 HRESULT WINAPI PullPin_Disconnect(IPin *iface)
806 HRESULT hr;
807 PullPin *This = impl_PullPin_from_IPin(iface);
809 TRACE("()\n");
811 EnterCriticalSection(This->pin.pCritSec);
813 if (FAILED(hr = IMemAllocator_Decommit(This->pAlloc)))
814 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr);
816 if (This->pin.pConnectedTo)
818 IPin_Release(This->pin.pConnectedTo);
819 This->pin.pConnectedTo = NULL;
820 PullPin_StopProcessing(This);
822 FreeMediaType(&This->pin.mtCurrent);
823 ZeroMemory(&This->pin.mtCurrent, sizeof(This->pin.mtCurrent));
824 hr = S_OK;
826 else
827 hr = S_FALSE;
829 LeaveCriticalSection(This->pin.pCritSec);
831 return hr;
834 HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
836 newsegmentargs args;
837 FIXME("(%p)->(%s, %s, %g) stub\n", iface, wine_dbgstr_longlong(tStart), wine_dbgstr_longlong(tStop), dRate);
839 args.tStart = tStart;
840 args.tStop = tStop;
841 args.rate = dRate;
843 return SendFurther( iface, deliver_newsegment, &args, NULL );