Maarten Lankhorst : quartz: Flux AsyncReader in PullPin_BeginFlush.

Alexandre Julliard julliard at winehq.org
Mon Apr 21 07:46:35 CDT 2008


Module: wine
Branch: master
Commit: d16639d1fad14ff2b7afa43acc57d78122478432
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d16639d1fad14ff2b7afa43acc57d78122478432

Author: Maarten Lankhorst <m.b.lankhorst at gmail.com>
Date:   Thu Apr 17 13:24:51 2008 -0700

quartz: Flux 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);
 




More information about the wine-cvs mailing list