[GStreamer][EME][Clearkey] Take a lock in keys() method
authorcturner@igalia.com <cturner@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 12:14:04 +0000 (12:14 +0000)
committercturner@igalia.com <cturner@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 12:14:04 +0000 (12:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195900

Reviewed by Xabier Rodriguez-Calvar.

This isn't ideal, since we're taking a lock for every frame to
decode. But there's no good way around it when keys can be
made unavailable at any time via an update() call, so we can't
cache key IDs in the decryptor.

Covered by test imported/w3c/web-platform-tests/encrypted-media/clearkey-mp4-playback-temporary-multikey.https.html

* platform/encryptedmedia/clearkey/CDMClearKey.cpp:
(WebCore::CDMInstanceClearKey::keys const): This method is called
from GStreamer's decode() method, which runs off the main thread,
therefore we need to take a lock.
* platform/encryptedmedia/clearkey/CDMClearKey.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.cpp
Source/WebCore/platform/encryptedmedia/clearkey/CDMClearKey.h

index 23988a5..9f3031d 100644 (file)
@@ -1,3 +1,23 @@
+2019-03-21  Charlie Turner  <cturner@igalia.com>
+
+        [GStreamer][EME][Clearkey] Take a lock in keys() method
+        https://bugs.webkit.org/show_bug.cgi?id=195900
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        This isn't ideal, since we're taking a lock for every frame to
+        decode. But there's no good way around it when keys can be
+        made unavailable at any time via an update() call, so we can't
+        cache key IDs in the decryptor.
+
+        Covered by test imported/w3c/web-platform-tests/encrypted-media/clearkey-mp4-playback-temporary-multikey.https.html
+
+        * platform/encryptedmedia/clearkey/CDMClearKey.cpp:
+        (WebCore::CDMInstanceClearKey::keys const): This method is called
+        from GStreamer's decode() method, which runs off the main thread,
+        therefore we need to take a lock.
+        * platform/encryptedmedia/clearkey/CDMClearKey.h:
+
 2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK][WPE] Add API to provide geolocation information
index 8544871..697699a 100644 (file)
@@ -507,6 +507,7 @@ const Vector<CDMInstanceClearKey::Key> CDMInstanceClearKey::keys() const
 {
     // Return the keys of all sessions.
     Vector<CDMInstanceClearKey::Key> allKeys { };
+    auto locker = holdLock(m_keysMutex);
     size_t initialCapacity = 0;
     for (auto& key : ClearKeyState::singleton().keys().values())
         initialCapacity += key.size();
index 43d5b5f..e3aa032 100644 (file)
@@ -97,6 +97,9 @@ public:
     };
 
     const Vector<Key> keys() const;
+
+private:
+    mutable Lock m_keysMutex;
 };
 
 class CDMInstanceSessionClearKey final : public CDMInstanceSession, public CanMakeWeakPtr<CDMInstanceSessionClearKey> {