d2d1: Implement D2D1MakeSkewMatrix().
[wine.git] / dlls / quartz / pin.c
bloba3674f21ec0d56c9e38424e2a870084424a19b69
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;
141 static HRESULT deliver_endofstream(IPin* pin, LPVOID unused)
143 return IPin_EndOfStream( pin );
146 static HRESULT deliver_beginflush(IPin* pin, LPVOID unused)
148 return IPin_BeginFlush( pin );
151 static HRESULT deliver_endflush(IPin* pin, LPVOID unused)
153 return IPin_EndFlush( pin );
156 typedef struct newsegmentargs
158 REFERENCE_TIME tStart, tStop;
159 double rate;
160 } newsegmentargs;
162 static HRESULT deliver_newsegment(IPin *pin, LPVOID data)
164 newsegmentargs *args = data;
165 return IPin_NewSegment(pin, args->tStart, args->tStop, args->rate);
168 /*** PullPin implementation ***/
170 static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO *info,
171 SAMPLEPROC_PULL pSampleProc, void *pUserData, QUERYACCEPTPROC pQueryAccept,
172 CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone,
173 LPCRITICAL_SECTION pCritSec, PullPin *pPinImpl)
175 /* Common attributes */
176 pPinImpl->pin.IPin_iface.lpVtbl = PullPin_Vtbl;
177 pPinImpl->pin.refCount = 1;
178 pPinImpl->pin.pConnectedTo = NULL;
179 pPinImpl->pin.pCritSec = pCritSec;
180 /* avoid copying uninitialized data */
181 strcpyW(pPinImpl->pin.pinInfo.achName, info->achName);
182 pPinImpl->pin.pinInfo.dir = info->dir;
183 pPinImpl->pin.pinInfo.pFilter = info->pFilter;
184 ZeroMemory(&pPinImpl->pin.mtCurrent, sizeof(AM_MEDIA_TYPE));
186 /* Input pin attributes */
187 pPinImpl->pUserData = pUserData;
188 pPinImpl->fnQueryAccept = pQueryAccept;
189 pPinImpl->fnSampleProc = pSampleProc;
190 pPinImpl->fnCleanProc = pCleanUp;
191 pPinImpl->fnDone = pDone;
192 pPinImpl->fnPreConnect = NULL;
193 pPinImpl->pAlloc = NULL;
194 pPinImpl->prefAlloc = NULL;
195 pPinImpl->pReader = NULL;
196 pPinImpl->hThread = NULL;
197 pPinImpl->hEventStateChanged = CreateEventW(NULL, TRUE, TRUE, NULL);
198 pPinImpl->thread_sleepy = CreateEventW(NULL, FALSE, FALSE, NULL);
200 pPinImpl->rtStart = 0;
201 pPinImpl->rtCurrent = 0;
202 pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
203 pPinImpl->dRate = 1.0;
204 pPinImpl->state = Req_Die;
205 pPinImpl->fnCustomRequest = pCustomRequest;
206 pPinImpl->stop_playback = TRUE;
208 InitializeCriticalSection(&pPinImpl->thread_lock);
209 pPinImpl->thread_lock.DebugInfo->Spare[0] = (DWORD_PTR)( __FILE__ ": PullPin.thread_lock");
211 return S_OK;
214 HRESULT PullPin_Construct(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInfo,
215 SAMPLEPROC_PULL pSampleProc, LPVOID pUserData, QUERYACCEPTPROC pQueryAccept,
216 CLEANUPPROC pCleanUp, REQUESTPROC pCustomRequest, STOPPROCESSPROC pDone,
217 LPCRITICAL_SECTION pCritSec, IPin ** ppPin)
219 PullPin * pPinImpl;
221 *ppPin = NULL;
223 if (pPinInfo->dir != PINDIR_INPUT)
225 ERR("Pin direction(%x) != PINDIR_INPUT\n", pPinInfo->dir);
226 return E_INVALIDARG;
229 pPinImpl = CoTaskMemAlloc(sizeof(*pPinImpl));
231 if (!pPinImpl)
232 return E_OUTOFMEMORY;
234 if (SUCCEEDED(PullPin_Init(PullPin_Vtbl, pPinInfo, pSampleProc, pUserData, pQueryAccept, pCleanUp, pCustomRequest, pDone, pCritSec, pPinImpl)))
236 *ppPin = &pPinImpl->pin.IPin_iface;
237 return S_OK;
240 CoTaskMemFree(pPinImpl);
241 return E_FAIL;
244 static HRESULT PullPin_InitProcessing(PullPin * This);
246 HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
248 PIN_DIRECTION pindirReceive;
249 HRESULT hr = S_OK;
250 PullPin *This = impl_PullPin_from_IPin(iface);
252 TRACE("(%p/%p)->(%p, %p)\n", This, iface, pReceivePin, pmt);
253 dump_AM_MEDIA_TYPE(pmt);
255 EnterCriticalSection(This->pin.pCritSec);
256 if (!This->pin.pConnectedTo)
258 ALLOCATOR_PROPERTIES props;
260 props.cBuffers = 3;
261 props.cbBuffer = 64 * 1024; /* 64 KB */
262 props.cbAlign = 1;
263 props.cbPrefix = 0;
265 if (This->fnQueryAccept(This->pUserData, pmt) != S_OK)
266 hr = VFW_E_TYPE_NOT_ACCEPTED; /* FIXME: shouldn't we just map common errors onto
267 * VFW_E_TYPE_NOT_ACCEPTED and pass the value on otherwise? */
269 if (SUCCEEDED(hr))
271 IPin_QueryDirection(pReceivePin, &pindirReceive);
273 if (pindirReceive != PINDIR_OUTPUT)
275 ERR("Can't connect from non-output pin\n");
276 hr = VFW_E_INVALID_DIRECTION;
280 This->pReader = NULL;
281 This->pAlloc = NULL;
282 This->prefAlloc = NULL;
283 if (SUCCEEDED(hr))
285 hr = IPin_QueryInterface(pReceivePin, &IID_IAsyncReader, (LPVOID *)&This->pReader);
288 if (SUCCEEDED(hr) && This->fnPreConnect)
290 hr = This->fnPreConnect(iface, pReceivePin, &props);
294 * Some custom filters (such as the one used by Fallout 3
295 * and Fallout: New Vegas) expect to be passed a non-NULL
296 * preferred allocator.
298 if (SUCCEEDED(hr))
300 hr = StdMemAllocator_create(NULL, (LPVOID *) &This->prefAlloc);
303 if (SUCCEEDED(hr))
305 hr = IAsyncReader_RequestAllocator(This->pReader, This->prefAlloc, &props, &This->pAlloc);
308 if (SUCCEEDED(hr))
310 CopyMediaType(&This->pin.mtCurrent, pmt);
311 This->pin.pConnectedTo = pReceivePin;
312 IPin_AddRef(pReceivePin);
313 hr = IMemAllocator_Commit(This->pAlloc);
316 if (SUCCEEDED(hr))
317 hr = PullPin_InitProcessing(This);
319 if (FAILED(hr))
321 if (This->pReader)
322 IAsyncReader_Release(This->pReader);
323 This->pReader = NULL;
324 if (This->prefAlloc)
325 IMemAllocator_Release(This->prefAlloc);
326 This->prefAlloc = NULL;
327 if (This->pAlloc)
328 IMemAllocator_Release(This->pAlloc);
329 This->pAlloc = NULL;
332 else
333 hr = VFW_E_ALREADY_CONNECTED;
334 LeaveCriticalSection(This->pin.pCritSec);
335 return hr;
338 HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv)
340 PullPin *This = impl_PullPin_from_IPin(iface);
342 TRACE("(%p/%p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
344 *ppv = NULL;
346 if (IsEqualIID(riid, &IID_IUnknown))
347 *ppv = iface;
348 else if (IsEqualIID(riid, &IID_IPin))
349 *ppv = iface;
350 else if (IsEqualIID(riid, &IID_IMediaSeeking) ||
351 IsEqualIID(riid, &IID_IQualityControl))
353 return IBaseFilter_QueryInterface(This->pin.pinInfo.pFilter, riid, ppv);
356 if (*ppv)
358 IUnknown_AddRef((IUnknown *)(*ppv));
359 return S_OK;
362 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
364 return E_NOINTERFACE;
367 ULONG WINAPI PullPin_Release(IPin *iface)
369 PullPin *This = impl_PullPin_from_IPin(iface);
370 ULONG refCount = InterlockedDecrement(&This->pin.refCount);
372 TRACE("(%p)->() Release from %d\n", This, refCount + 1);
374 if (!refCount)
376 WaitForSingleObject(This->hEventStateChanged, INFINITE);
377 assert(!This->hThread);
379 if(This->prefAlloc)
380 IMemAllocator_Release(This->prefAlloc);
381 if(This->pAlloc)
382 IMemAllocator_Release(This->pAlloc);
383 if(This->pReader)
384 IAsyncReader_Release(This->pReader);
385 CloseHandle(This->thread_sleepy);
386 CloseHandle(This->hEventStateChanged);
387 This->thread_lock.DebugInfo->Spare[0] = 0;
388 DeleteCriticalSection(&This->thread_lock);
389 CoTaskMemFree(This);
390 return 0;
392 return refCount;
395 static void PullPin_Flush(PullPin *This)
397 IMediaSample *pSample;
398 TRACE("Flushing!\n");
400 if (This->pReader)
402 /* Do not allow state to change while flushing */
403 EnterCriticalSection(This->pin.pCritSec);
405 /* Flush outstanding samples */
406 IAsyncReader_BeginFlush(This->pReader);
408 for (;;)
410 DWORD_PTR dwUser;
412 pSample = NULL;
413 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
415 if (!pSample)
416 break;
418 assert(!IMediaSample_GetActualDataLength(pSample));
420 IMediaSample_Release(pSample);
423 IAsyncReader_EndFlush(This->pReader);
425 LeaveCriticalSection(This->pin.pCritSec);
429 static void PullPin_Thread_Process(PullPin *This)
431 HRESULT hr;
432 IMediaSample * pSample = NULL;
433 ALLOCATOR_PROPERTIES allocProps;
435 hr = IMemAllocator_GetProperties(This->pAlloc, &allocProps);
437 This->cbAlign = allocProps.cbAlign;
439 if (This->rtCurrent < This->rtStart)
440 This->rtCurrent = MEDIATIME_FROM_BYTES(ALIGNDOWN(BYTES_FROM_MEDIATIME(This->rtStart), This->cbAlign));
442 TRACE("Start\n");
444 if (This->rtCurrent >= This->rtStop)
446 IPin_EndOfStream(&This->pin.IPin_iface);
447 return;
450 /* There is no sample in our buffer */
451 hr = This->fnCustomRequest(This->pUserData);
453 if (FAILED(hr))
454 ERR("Request error: %x\n", hr);
456 EnterCriticalSection(This->pin.pCritSec);
457 SetEvent(This->hEventStateChanged);
458 LeaveCriticalSection(This->pin.pCritSec);
460 if (SUCCEEDED(hr))
463 DWORD_PTR dwUser;
465 TRACE("Process sample\n");
467 pSample = NULL;
468 hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
470 /* Return an empty sample on error to the implementation in case it does custom parsing, so it knows it's gone */
471 if (SUCCEEDED(hr))
473 hr = This->fnSampleProc(This->pUserData, pSample, dwUser);
475 else
477 if (hr == VFW_E_TIMEOUT)
479 if (pSample != NULL)
480 WARN("Non-NULL sample returned with VFW_E_TIMEOUT.\n");
481 hr = S_OK;
483 /* FIXME: Errors are not well handled yet! */
484 else
485 ERR("Processing error: %x\n", hr);
488 if (pSample)
490 IMediaSample_Release(pSample);
491 pSample = NULL;
493 } while (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback);
496 * Sample was rejected, and we are asked to terminate. When there is more than one buffer
497 * it is possible for a filter to have several queued samples, making it necessary to
498 * release all of these pending samples.
500 if (This->stop_playback || FAILED(hr))
502 DWORD_PTR dwUser;
506 if (pSample)
507 IMediaSample_Release(pSample);
508 pSample = NULL;
509 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
510 } while(pSample);
513 /* Can't reset state to Sleepy here because that might race, instead PauseProcessing will do that for us
514 * Flush remaining samples
516 if (This->fnDone)
517 This->fnDone(This->pUserData);
519 TRACE("End: %08x, %d\n", hr, This->stop_playback);
522 static void PullPin_Thread_Pause(PullPin *This)
524 PullPin_Flush(This);
526 EnterCriticalSection(This->pin.pCritSec);
527 This->state = Req_Sleepy;
528 SetEvent(This->hEventStateChanged);
529 LeaveCriticalSection(This->pin.pCritSec);
532 static void PullPin_Thread_Stop(PullPin *This)
534 TRACE("(%p)->()\n", This);
536 EnterCriticalSection(This->pin.pCritSec);
537 SetEvent(This->hEventStateChanged);
538 LeaveCriticalSection(This->pin.pCritSec);
540 IBaseFilter_Release(This->pin.pinInfo.pFilter);
542 CoUninitialize();
543 ExitThread(0);
546 static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
548 PullPin *This = pv;
549 CoInitializeEx(NULL, COINIT_MULTITHREADED);
551 PullPin_Flush(This);
553 for (;;)
555 WaitForSingleObject(This->thread_sleepy, INFINITE);
557 TRACE("State: %d\n", This->state);
559 switch (This->state)
561 case Req_Die: PullPin_Thread_Stop(This); break;
562 case Req_Run: PullPin_Thread_Process(This); break;
563 case Req_Pause: PullPin_Thread_Pause(This); break;
564 case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break;
565 default: ERR("Unknown state request: %d\n", This->state); break;
568 return 0;
571 static HRESULT PullPin_InitProcessing(PullPin * This)
573 HRESULT hr = S_OK;
575 TRACE("(%p)->()\n", This);
577 /* if we are connected */
578 if (This->pAlloc)
580 DWORD dwThreadId;
582 WaitForSingleObject(This->hEventStateChanged, INFINITE);
583 EnterCriticalSection(This->pin.pCritSec);
585 assert(!This->hThread);
586 assert(This->state == Req_Die);
587 assert(This->stop_playback);
588 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
589 This->state = Req_Sleepy;
591 /* AddRef the filter to make sure it and its pins will be around
592 * as long as the thread */
593 IBaseFilter_AddRef(This->pin.pinInfo.pFilter);
596 This->hThread = CreateThread(NULL, 0, PullPin_Thread_Main, This, 0, &dwThreadId);
597 if (!This->hThread)
599 hr = HRESULT_FROM_WIN32(GetLastError());
600 IBaseFilter_Release(This->pin.pinInfo.pFilter);
603 if (SUCCEEDED(hr))
605 SetEvent(This->hEventStateChanged);
606 /* If assert fails, that means a command was not processed before the thread previously terminated */
608 LeaveCriticalSection(This->pin.pCritSec);
611 TRACE(" -- %x\n", hr);
613 return hr;
616 HRESULT PullPin_StartProcessing(PullPin * This)
618 /* if we are connected */
619 TRACE("(%p)->()\n", This);
620 if(This->pAlloc)
622 assert(This->hThread);
624 PullPin_WaitForStateChange(This, INFINITE);
626 assert(This->state == Req_Sleepy);
628 /* Wake up! */
629 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
630 This->state = Req_Run;
631 This->stop_playback = FALSE;
632 ResetEvent(This->hEventStateChanged);
633 SetEvent(This->thread_sleepy);
636 return S_OK;
639 HRESULT PullPin_PauseProcessing(PullPin * This)
641 /* if we are connected */
642 TRACE("(%p)->()\n", This);
643 if(This->pAlloc)
645 assert(This->hThread);
647 PullPin_WaitForStateChange(This, INFINITE);
649 EnterCriticalSection(This->pin.pCritSec);
651 assert(!This->stop_playback);
652 assert(This->state == Req_Run|| This->state == Req_Sleepy);
654 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
656 This->state = Req_Pause;
657 This->stop_playback = TRUE;
658 ResetEvent(This->hEventStateChanged);
659 SetEvent(This->thread_sleepy);
661 /* Release any outstanding samples */
662 if (This->pReader)
664 IMediaSample *pSample;
665 DWORD_PTR dwUser;
669 pSample = NULL;
670 IAsyncReader_WaitForNext(This->pReader, 0, &pSample, &dwUser);
671 if (pSample)
672 IMediaSample_Release(pSample);
673 } while(pSample);
676 LeaveCriticalSection(This->pin.pCritSec);
679 return S_OK;
682 static HRESULT PullPin_StopProcessing(PullPin * This)
684 TRACE("(%p)->()\n", This);
686 /* if we are alive */
687 assert(This->hThread);
689 PullPin_WaitForStateChange(This, INFINITE);
691 assert(This->state == Req_Pause || This->state == Req_Sleepy);
693 This->stop_playback = TRUE;
694 This->state = Req_Die;
695 assert(WaitForSingleObject(This->thread_sleepy, 0) == WAIT_TIMEOUT);
696 ResetEvent(This->hEventStateChanged);
697 SetEvent(This->thread_sleepy);
698 return S_OK;
701 HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds)
703 if (WaitForSingleObject(This->hEventStateChanged, dwMilliseconds) == WAIT_TIMEOUT)
704 return S_FALSE;
705 return S_OK;
708 HRESULT WINAPI PullPin_QueryAccept(IPin * iface, const AM_MEDIA_TYPE * pmt)
710 PullPin *This = impl_PullPin_from_IPin(iface);
712 TRACE("(%p/%p)->(%p)\n", This, iface, pmt);
714 return (This->fnQueryAccept(This->pUserData, pmt) == S_OK ? S_OK : S_FALSE);
717 HRESULT WINAPI PullPin_EndOfStream(IPin * iface)
719 PullPin *This = impl_PullPin_from_IPin(iface);
720 HRESULT hr = S_FALSE;
722 TRACE("(%p)->()\n", iface);
724 EnterCriticalSection(This->pin.pCritSec);
725 hr = SendFurther( iface, deliver_endofstream, NULL, NULL );
726 SetEvent(This->hEventStateChanged);
727 LeaveCriticalSection(This->pin.pCritSec);
729 return hr;
732 HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
734 PullPin *This = impl_PullPin_from_IPin(iface);
735 TRACE("(%p)->()\n", This);
737 EnterCriticalSection(This->pin.pCritSec);
739 SendFurther( iface, deliver_beginflush, NULL, NULL );
741 LeaveCriticalSection(This->pin.pCritSec);
743 EnterCriticalSection(&This->thread_lock);
745 if (This->pReader)
746 IAsyncReader_BeginFlush(This->pReader);
747 PullPin_WaitForStateChange(This, INFINITE);
749 if (This->hThread && This->state == Req_Run)
751 PullPin_PauseProcessing(This);
752 PullPin_WaitForStateChange(This, INFINITE);
755 LeaveCriticalSection(&This->thread_lock);
757 EnterCriticalSection(This->pin.pCritSec);
759 This->fnCleanProc(This->pUserData);
761 LeaveCriticalSection(This->pin.pCritSec);
763 return S_OK;
766 HRESULT WINAPI PullPin_EndFlush(IPin * iface)
768 PullPin *This = impl_PullPin_from_IPin(iface);
770 TRACE("(%p)->()\n", iface);
772 /* Send further first: Else a race condition might terminate processing early */
773 EnterCriticalSection(This->pin.pCritSec);
774 SendFurther( iface, deliver_endflush, NULL, NULL );
775 LeaveCriticalSection(This->pin.pCritSec);
777 EnterCriticalSection(&This->thread_lock);
779 FILTER_STATE state;
781 if (This->pReader)
782 IAsyncReader_EndFlush(This->pReader);
784 IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
786 if (state != State_Stopped)
787 PullPin_StartProcessing(This);
789 PullPin_WaitForStateChange(This, INFINITE);
791 LeaveCriticalSection(&This->thread_lock);
793 return S_OK;
796 HRESULT WINAPI PullPin_Disconnect(IPin *iface)
798 HRESULT hr;
799 PullPin *This = impl_PullPin_from_IPin(iface);
801 TRACE("()\n");
803 EnterCriticalSection(This->pin.pCritSec);
805 if (FAILED(hr = IMemAllocator_Decommit(This->pAlloc)))
806 ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr);
808 if (This->pin.pConnectedTo)
810 IPin_Release(This->pin.pConnectedTo);
811 This->pin.pConnectedTo = NULL;
812 PullPin_StopProcessing(This);
814 FreeMediaType(&This->pin.mtCurrent);
815 ZeroMemory(&This->pin.mtCurrent, sizeof(This->pin.mtCurrent));
816 hr = S_OK;
818 else
819 hr = S_FALSE;
821 LeaveCriticalSection(This->pin.pCritSec);
823 WaitForSingleObject(This->hThread, INFINITE);
824 CloseHandle(This->hThread);
825 This->hThread = NULL;
827 return hr;
830 HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate)
832 newsegmentargs args;
833 FIXME("(%p)->(%s, %s, %g) stub\n", iface, wine_dbgstr_longlong(tStart), wine_dbgstr_longlong(tStop), dRate);
835 args.tStart = tStart;
836 args.tStop = tStop;
837 args.rate = dRate;
839 return SendFurther( iface, deliver_newsegment, &args, NULL );