From 23899ed72dbb17d30197b90abbe0956ffbd88661 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Thu, 17 Apr 2008 13:24:51 -0700 Subject: [PATCH] quartz: Flush asyncreader in PullPin_BeginFlush --- dlls/quartz/pin.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 files changed, 39 insertions(+), 5 deletions(-) diff --git a/dlls/quartz/pin.c b/dlls/quartz/pin.c index 0c333f7..b641ff2 100644 --- a/dlls/quartz/pin.c +++ b/dlls/quartz/pin.c @@ -1357,6 +1357,8 @@ ULONG WINAPI PullPin_Release(IPin * iface) static DWORD WINAPI PullPin_Thread_Main(LPVOID pv) { + CoInitializeEx(NULL, COINIT_MULTITHREADED); + for (;;) SleepEx(INFINITE, TRUE); } @@ -1368,7 +1370,6 @@ static void CALLBACK PullPin_Thread_Process(ULONG_PTR iface) ALLOCATOR_PROPERTIES allocProps; - CoInitializeEx(NULL, COINIT_MULTITHREADED); EnterCriticalSection(This->pin.pCritSec); SetEvent(This->hEventStateChanged); @@ -1433,13 +1434,37 @@ static void CALLBACK PullPin_Thread_Process(ULONG_PTR iface) IMediaSample_Release(pSample); } while (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback); - CoUninitialize(); EnterCriticalSection(This->pin.pCritSec); This->state = State_Paused; LeaveCriticalSection(This->pin.pCritSec); TRACE("End\n"); } +static void CALLBACK PullPin_Thread_Flush(ULONG_PTR iface) +{ + PullPin *This = (PullPin *)iface; + IMediaSample *pSample; + + EnterCriticalSection(This->pin.pCritSec); + if (This->pReader) + { + /* Flush outstanding samples */ + IAsyncReader_BeginFlush(This->pReader); + + for (;;) + { + IMemAllocator_GetBuffer(This->pAlloc, &pSample, NULL, NULL, 0); + + if (!pSample) + break; + IMediaSample_Release(pSample); + } + + IAsyncReader_EndFlush(This->pReader); + } + LeaveCriticalSection(This->pin.pCritSec); +} + static void CALLBACK PullPin_Thread_Pause(ULONG_PTR iface) { PullPin *This = (PullPin *)iface; @@ -1454,7 +1479,6 @@ static void CALLBACK PullPin_Thread_Pause(ULONG_PTR iface) LeaveCriticalSection(This->pin.pCritSec); } - static void CALLBACK PullPin_Thread_Stop(ULONG_PTR iface) { PullPin *This = (PullPin *)iface; @@ -1477,6 +1501,7 @@ static void CALLBACK PullPin_Thread_Stop(ULONG_PTR iface) IBaseFilter_Release(This->pin.pinInfo.pFilter); + CoUninitialize(); ExitThread(0); } @@ -1567,8 +1592,8 @@ HRESULT PullPin_StopProcessing(PullPin * This) { TRACE("(%p)->()\n", This); - /* if we are connected */ - if (This->pAlloc && This->hThread) + /* if we are alive */ + if (This->hThread) { PullPin_WaitForStateChange(This, INFINITE); @@ -1613,6 +1638,15 @@ HRESULT WINAPI PullPin_BeginFlush(IPin * iface) PullPin_PauseProcessing(This); PullPin_WaitForStateChange(This, INFINITE); + + /* Workaround: The file async reader only cancels io on current thread + * only vista and newer have CancelIoEx, so try the thread context if available + * Anyone has some documentation on NtCancelFileIoEx? + */ + if (This->hThread) + QueueUserAPC(PullPin_Thread_Flush, This->hThread, (ULONG_PTR)This); + else + PullPin_Thread_Flush((ULONG_PTR)This); } LeaveCriticalSection(&This->thread_lock); -- 1.5.4.1