[WinCairo][MediaFoundation] Main thread can block when session is destroyed.
authorpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Dec 2015 19:27:49 +0000 (19:27 +0000)
committerpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Dec 2015 19:27:49 +0000 (19:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151803

Reviewed by Alex Christensen.

Set flag to make sure that the scheduler thread stops when the session ends.

* platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
(WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler):
(WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue):
(WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate):
* platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:
(WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopThread):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@193353 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h

index 179a046..50886de 100644 (file)
@@ -1,3 +1,19 @@
+2015-12-03  Per Arne Vollan  <peavo@outlook.com>
+
+        [WinCairo][MediaFoundation] Main thread can block when session is destroyed.
+        https://bugs.webkit.org/show_bug.cgi?id=151803
+
+        Reviewed by Alex Christensen.
+
+        Set flag to make sure that the scheduler thread stops when the session ends.
+
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
+        (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler):
+        (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue):
+        (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPrivate):
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:
+        (WebCore::MediaPlayerPrivateMediaFoundation::VideoScheduler::stopThread):
+
 2015-12-03  Jer Noble  <jer.noble@apple.com>
 
         [iOS] Fullscreen -> PiP should resume to Fullscreen, not inline
index 77269d1..c81a4af 100644 (file)
@@ -2202,14 +2202,8 @@ HRESULT MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler()
     if (!m_schedulerThread.isValid())
         return S_OK;
 
-    {
-        // Clearing the sample queue before we post the thread terminate message will make sure
-        // the thread exits quickly, and we will not be stuck waiting for it to finish.
-        LockHolder locker(m_lock);
-        m_scheduledSamples.clear();
-    }
-
     // Terminate the scheduler thread
+    stopThread();
     ::PostThreadMessage(m_threadID, EventTerminate, 0, 0);
 
     // Wait for the scheduler thread to finish.
@@ -2217,6 +2211,7 @@ HRESULT MediaPlayerPrivateMediaFoundation::VideoScheduler::stopScheduler()
 
     LockHolder locker(m_lock);
 
+    m_scheduledSamples.clear();
     m_schedulerThread.clear();
     m_flushEvent.clear();
 
@@ -2281,7 +2276,7 @@ HRESULT MediaPlayerPrivateMediaFoundation::VideoScheduler::processSamplesInQueue
 
     // Process samples as long as there are samples in the queue, and they have not arrived too early.
 
-    while (true) {
+    while (!m_exitThread) {
         COMPtr<IMFSample> sample;
 
         if (true) {
@@ -2400,15 +2395,15 @@ DWORD MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPriv
     SetEvent(m_threadReadyEvent.get());
 
     LONG wait = INFINITE;
-    bool exitThread = false;
-    while (!exitThread) {
+    m_exitThread = false;
+    while (!m_exitThread) {
         // Wait for messages
         DWORD result = MsgWaitForMultipleObjects(0, nullptr, FALSE, wait, QS_POSTMESSAGE);
 
         if (result == WAIT_TIMEOUT) {
             hr = processSamplesInQueue(wait);
             if (FAILED(hr))
-                exitThread = true;
+                m_exitThread = true;
         }
 
         while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
@@ -2416,7 +2411,7 @@ DWORD MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPriv
 
             switch (msg.message) {
             case EventTerminate:
-                exitThread = true;
+                m_exitThread = true;
                 break;
 
             case EventFlush:
@@ -2432,7 +2427,7 @@ DWORD MediaPlayerPrivateMediaFoundation::VideoScheduler::schedulerThreadProcPriv
                 if (processSamples) {
                     hr = processSamplesInQueue(wait);
                     if (FAILED(hr))
-                        exitThread = true;
+                        m_exitThread = true;
                     processSamples = (wait != INFINITE);
                 }
                 break;
index 2f0018d..563f90c 100644 (file)
@@ -231,6 +231,10 @@ private:
         float m_playbackRate { 1.0f };
         MFTIME m_frameDuration { 0 };
         MFTIME m_lastSampleTime { 0 };
+
+        std::atomic<bool> m_exitThread { false };
+
+        void stopThread() { m_exitThread = true; }
     };
 
     class Direct3DPresenter {