[GPUP] Implement Legacy EME API in the GPU Process
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Mar 2020 05:13:09 +0000 (05:13 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Mar 2020 05:13:09 +0000 (05:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208402

Reviewed by Eric Carlson.

Prepare for running the LegacyCDM et. al. in the GPU process.

Slightly modernize LegacyCDM to allow all methods representaing a LegacyCDMFactory to be WTF::Functions.

Allow the list of registered factories to be cleared and reset at runtime.

Modify WebKitMediaKeys to notify the MediaPlayer when the keys object is added to a HTMLMediaElement.

Expose the pointer to the internal CDMPrivateInterface for use in WebKit.

* Modules/encryptedmedia/legacy/LegacyCDM.cpp:
(WebCore::LegacyCDM::platformRegisterFactories):
(WebCore::installedCDMFactories):
(WebCore::LegacyCDM::registerCDMFactory):
(WebCore::LegacyCDMFactoryForKeySystem):
(WebCore::LegacyCDM::supportsKeySystem):
(WebCore::LegacyCDM::keySystemSupportsMimeType):
(WebCore::LegacyCDM::LegacyCDM):
(WebCore::LegacyCDM::createSession):
* Modules/encryptedmedia/legacy/LegacyCDM.h:
* Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp:
(WebCore::WebKitMediaKeys::setMediaElement):
* WebCore.xcodeproj/project.pbxproj:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaEngineWasUpdated):
* platform/graphics/LegacyCDMSession.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::setCDM):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::setCDM):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDM.cpp
Source/WebCore/Modules/encryptedmedia/legacy/LegacyCDM.h
Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/platform/graphics/LegacyCDMSession.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h

index dfe0e4b..a93fb9c 100644 (file)
@@ -1,5 +1,44 @@
 2020-03-07  Jer Noble  <jer.noble@apple.com>
 
+        [GPUP] Implement Legacy EME API in the GPU Process
+        https://bugs.webkit.org/show_bug.cgi?id=208402
+
+        Reviewed by Eric Carlson.
+
+        Prepare for running the LegacyCDM et. al. in the GPU process.
+
+        Slightly modernize LegacyCDM to allow all methods representaing a LegacyCDMFactory to be WTF::Functions.
+
+        Allow the list of registered factories to be cleared and reset at runtime.
+
+        Modify WebKitMediaKeys to notify the MediaPlayer when the keys object is added to a HTMLMediaElement.
+
+        Expose the pointer to the internal CDMPrivateInterface for use in WebKit.
+
+        * Modules/encryptedmedia/legacy/LegacyCDM.cpp:
+        (WebCore::LegacyCDM::platformRegisterFactories):
+        (WebCore::installedCDMFactories):
+        (WebCore::LegacyCDM::registerCDMFactory):
+        (WebCore::LegacyCDMFactoryForKeySystem):
+        (WebCore::LegacyCDM::supportsKeySystem):
+        (WebCore::LegacyCDM::keySystemSupportsMimeType):
+        (WebCore::LegacyCDM::LegacyCDM):
+        (WebCore::LegacyCDM::createSession):
+        * Modules/encryptedmedia/legacy/LegacyCDM.h:
+        * Modules/encryptedmedia/legacy/WebKitMediaKeys.cpp:
+        (WebCore::WebKitMediaKeys::setMediaElement):
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaEngineWasUpdated):
+        * platform/graphics/LegacyCDMSession.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::setCDM):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::setCDM):
+
+2020-03-07  Jer Noble  <jer.noble@apple.com>
+
         [GPUP] LayoutTest debug assertion crashes: InitDataRegistry::registerInitDataType() called mulitple times with same type
         https://bugs.webkit.org/show_bug.cgi?id=208765
 
index 837df12..2982375 100644 (file)
 
 namespace WebCore {
 
-struct CDMFactory {
-    WTF_MAKE_NONCOPYABLE(CDMFactory); WTF_MAKE_FAST_ALLOCATED;
-public:
-    CDMFactory(CreateCDM&& constructor, CDMSupportsKeySystem supportsKeySystem, CDMSupportsKeySystemAndMimeType supportsKeySystemAndMimeType)
-        : constructor(WTFMove(constructor))
-        , supportsKeySystem(supportsKeySystem)
-        , supportsKeySystemAndMimeType(supportsKeySystemAndMimeType)
-    {
-    }
-
+struct LegacyCDMFactory {
     CreateCDM constructor;
     CDMSupportsKeySystem supportsKeySystem;
     CDMSupportsKeySystemAndMimeType supportsKeySystemAndMimeType;
 };
 
-static Vector<CDMFactory*>& installedCDMFactories()
+static void platformRegisterFactories(Vector<LegacyCDMFactory>& factories)
 {
-    static auto cdms = makeNeverDestroyed(Vector<CDMFactory*> {
-        new CDMFactory([](LegacyCDM* cdm) { return makeUnique<LegacyCDMPrivateClearKey>(cdm); },
-            LegacyCDMPrivateClearKey::supportsKeySystem, LegacyCDMPrivateClearKey::supportsKeySystemAndMimeType),
-
-        // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
-        new CDMFactory([](LegacyCDM* cdm) { return makeUnique<CDMPrivateMediaPlayer>(cdm); },
-            CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType),
-
+    factories.append({ [](LegacyCDM* cdm) { return makeUnique<LegacyCDMPrivateClearKey>(cdm); }, LegacyCDMPrivateClearKey::supportsKeySystem, LegacyCDMPrivateClearKey::supportsKeySystemAndMimeType });
+    // FIXME: initialize specific UA CDMs. http://webkit.org/b/109318, http://webkit.org/b/109320
+    factories.append({ [](LegacyCDM* cdm) { return makeUnique<CDMPrivateMediaPlayer>(cdm); }, CDMPrivateMediaPlayer::supportsKeySystem, CDMPrivateMediaPlayer::supportsKeySystemAndMimeType });
 #if (HAVE(AVCONTENTKEYSESSION) || HAVE(AVSTREAMSESSION)) && ENABLE(MEDIA_SOURCE)
-        new CDMFactory([](LegacyCDM* cdm) { return makeUnique<CDMPrivateMediaSourceAVFObjC>(cdm); },
-            CDMPrivateMediaSourceAVFObjC::supportsKeySystem, CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType),
+    factories.append({ [](LegacyCDM* cdm) { return makeUnique<CDMPrivateMediaSourceAVFObjC>(cdm); }, CDMPrivateMediaSourceAVFObjC::supportsKeySystem, CDMPrivateMediaSourceAVFObjC::supportsKeySystemAndMimeType });
 #endif
+}
+
+static Vector<LegacyCDMFactory>& installedCDMFactories()
+{
+    static auto cdms = makeNeverDestroyed<Vector<LegacyCDMFactory>>({ });
+    static std::once_flag registerDefaults;
+    std::call_once(registerDefaults, [&] {
+        platformRegisterFactories(cdms);
     });
     return cdms;
 }
 
-void LegacyCDM::registerCDMFactory(CreateCDM&& constructor, CDMSupportsKeySystem supportsKeySystem, CDMSupportsKeySystemAndMimeType supportsKeySystemAndMimeType)
+void LegacyCDM::resetFactories()
+{
+    clearFactories();
+    platformRegisterFactories(installedCDMFactories());
+}
+
+void LegacyCDM::clearFactories()
+{
+    installedCDMFactories().clear();
+}
+
+void LegacyCDM::registerCDMFactory(CreateCDM&& constructor, CDMSupportsKeySystem&& supportsKeySystem, CDMSupportsKeySystemAndMimeType&& supportsKeySystemAndMimeType)
 {
-    installedCDMFactories().append(new CDMFactory(WTFMove(constructor), supportsKeySystem, supportsKeySystemAndMimeType));
+    installedCDMFactories().append({ WTFMove(constructor), WTFMove(supportsKeySystem), WTFMove(supportsKeySystemAndMimeType) });
 }
 
-static CDMFactory* CDMFactoryForKeySystem(const String& keySystem)
+static LegacyCDMFactory* CDMFactoryForKeySystem(const String& keySystem)
 {
     for (auto& factory : installedCDMFactories()) {
-        if (factory->supportsKeySystem(keySystem))
-            return factory;
+        if (factory.supportsKeySystem(keySystem))
+            return &factory;
     }
     return nullptr;
 }
@@ -97,7 +101,7 @@ bool LegacyCDM::supportsKeySystem(const String& keySystem)
 
 bool LegacyCDM::keySystemSupportsMimeType(const String& keySystem, const String& mimeType)
 {
-    if (CDMFactory* factory = CDMFactoryForKeySystem(keySystem))
+    if (LegacyCDMFactory* factory = CDMFactoryForKeySystem(keySystem))
         return factory->supportsKeySystemAndMimeType(keySystem, mimeType);
     return false;
 }
index fb5da1f..11071d5 100644 (file)
@@ -39,9 +39,9 @@ class LegacyCDM;
 class CDMPrivateInterface;
 class MediaPlayer;
 
-using CreateCDM = WTF::Function<std::unique_ptr<CDMPrivateInterface> (LegacyCDM*)>;
-typedef bool (*CDMSupportsKeySystem)(const String&);
-typedef bool (*CDMSupportsKeySystemAndMimeType)(const String&, const String&);
+using CreateCDM = WTF::Function<std::unique_ptr<CDMPrivateInterface>(LegacyCDM*)>;
+using CDMSupportsKeySystem = WTF::Function<bool(const String&)>;
+using CDMSupportsKeySystemAndMimeType = WTF::Function<bool(const String&, const String&)>;
 
 class LegacyCDMClient {
 public:
@@ -50,7 +50,7 @@ public:
     virtual RefPtr<MediaPlayer> cdmMediaPlayer(const LegacyCDM*) const = 0;
 };
 
-class LegacyCDM final {
+class WEBCORE_EXPORT LegacyCDM final {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     explicit LegacyCDM(const String& keySystem);
@@ -59,9 +59,12 @@ public:
     static bool supportsKeySystem(const String&);
     static bool keySystemSupportsMimeType(const String& keySystem, const String& mimeType);
     static std::unique_ptr<LegacyCDM> create(const String& keySystem);
-    WEBCORE_EXPORT static void registerCDMFactory(CreateCDM&&, CDMSupportsKeySystem, CDMSupportsKeySystemAndMimeType);
+    static void registerCDMFactory(CreateCDM&&, CDMSupportsKeySystem&&, CDMSupportsKeySystemAndMimeType&&);
     ~LegacyCDM();
 
+    static void resetFactories();
+    static void clearFactories();
+
     bool supportsMIMEType(const String&) const;
     std::unique_ptr<LegacyCDMSession> createSession(LegacyCDMSessionClient&);
 
@@ -71,6 +74,7 @@ public:
     void setClient(LegacyCDMClient* client) { m_client = client; }
 
     RefPtr<MediaPlayer> mediaPlayer() const;
+    CDMPrivateInterface* cdmPrivate() const { return m_private.get(); }
 
 private:
     String m_keySystem;
index e537e60..bf646de 100644 (file)
@@ -128,13 +128,18 @@ bool WebKitMediaKeys::isTypeSupported(const String& keySystem, const String& mim
 
 void WebKitMediaKeys::setMediaElement(HTMLMediaElement* element)
 {
-    if (m_mediaElement && m_mediaElement->player())
+    if (m_mediaElement && m_mediaElement->player()) {
         m_mediaElement->player()->setCDMSession(nullptr);
+        m_mediaElement->player()->setCDM(nullptr);
+    }
 
     m_mediaElement = makeWeakPtr(element);
 
-    if (m_mediaElement && m_mediaElement->player() && !m_sessions.isEmpty())
-        m_mediaElement->player()->setCDMSession(m_sessions.last()->session());
+    if (m_mediaElement && m_mediaElement->player()) {
+        m_mediaElement->player()->setCDM(m_cdm.get());
+        if (!m_sessions.isEmpty())
+            m_mediaElement->player()->setCDMSession(m_sessions.last()->session());
+    }
 }
 
 RefPtr<MediaPlayer> WebKitMediaKeys::cdmMediaPlayer(const LegacyCDM*) const
index d1b0af8..822a4de 100644 (file)
                CDE3A85417F5FCE600C5BE20 /* AudioTrackPrivateAVF.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85217F5FCE600C5BE20 /* AudioTrackPrivateAVF.h */; };
                CDE3A85717F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */; };
                CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */; };
+               CDE555242405CCF2008A3DDB /* LegacyCDM.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA98E0A1603CD5900FEA3B1 /* LegacyCDM.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CDE555252405CCF2008A3DDB /* LegacyCDMPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CDA98E0C1603CF3C00FEA3B1 /* LegacyCDMPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CDE595951BF16DF300A1CBE8 /* CDMSessionAVContentKeySession.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE595931BF166AD00A1CBE8 /* CDMSessionAVContentKeySession.mm */; };
                CDE595971BF26E2100A1CBE8 /* CDMSessionMediaSourceAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE595961BF26E2100A1CBE8 /* CDMSessionMediaSourceAVFObjC.h */; };
                CDE5959D1BF2757100A1CBE8 /* CDMSessionMediaSourceAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE5959C1BF2757100A1CBE8 /* CDMSessionMediaSourceAVFObjC.mm */; };
                                11310CF220BA4A320065A8D0 /* LayoutTreeBuilder.h in Headers */,
                                141DC0481648348F00371E5A /* LayoutUnit.h in Headers */,
                                E451C6312394027900993190 /* LayoutUnits.h in Headers */,
+                               CDE555242405CCF2008A3DDB /* LegacyCDM.h in Headers */,
+                               CDE555252405CCF2008A3DDB /* LegacyCDMPrivate.h in Headers */,
                                CDE8B5ED1A69777300B4B66A /* LegacyCDMPrivateClearKey.h in Headers */,
                                CDF4B7121E0087AE00E235A2 /* LegacyCDMSession.h in Headers */,
                                CDE8B5F11A69778B00B4B66A /* LegacyCDMSessionClearKey.h in Headers */,
index 1e4cfbe..0ef54ac 100644 (file)
@@ -5128,6 +5128,11 @@ void HTMLMediaElement::mediaEngineWasUpdated()
         m_player->cdmInstanceAttached(m_mediaKeys->cdmInstance());
 #endif
 
+#if ENABLE(LEGACY_ENCRYPTED_MEDIA)
+    if (m_player && m_webKitMediaKeys)
+        m_player->setCDM(&m_webKitMediaKeys->cdm());
+#endif
+
 #if PLATFORM(IOS_FAMILY) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))
     if (!m_player)
         return;
index 25e79a6..2434968 100644 (file)
@@ -38,7 +38,7 @@ public:
     virtual ~LegacyCDMSessionClient() = default;
     virtual void sendMessage(Uint8Array*, String destinationURL) = 0;
 
-    enum {
+    enum : uint8_t {
         MediaKeyErrorUnknown = 1,
         MediaKeyErrorClient,
         MediaKeyErrorService,
@@ -58,9 +58,10 @@ enum LegacyCDMSessionType {
     CDMSessionTypeAVFoundationObjC,
     CDMSessionTypeAVStreamSession,
     CDMSessionTypeAVContentKeySession,
+    CDMSessionTypeRemote,
 };
 
-class LegacyCDMSession {
+class WEBCORE_EXPORT LegacyCDMSession {
 public:
     virtual ~LegacyCDMSession() = default;
 
index e0528f0..e9a423a 100644 (file)
@@ -626,6 +626,11 @@ std::unique_ptr<LegacyCDMSession> MediaPlayer::createSession(const String& keySy
     return m_private->createSession(keySystem, client);
 }
 
+void MediaPlayer::setCDM(LegacyCDM* cdm)
+{
+    m_private->setCDM(cdm);
+}
+
 void MediaPlayer::setCDMSession(LegacyCDMSession* session)
 {
     m_private->setCDMSession(session);
index 3d9514d..d28e594 100644 (file)
@@ -64,6 +64,7 @@ class CachedResourceLoader;
 class GraphicsContextGLOpenGL;
 class GraphicsContext;
 class InbandTextTrackPrivate;
+class LegacyCDM;
 class LegacyCDMSessionClient;
 class MediaPlaybackTarget;
 class MediaPlayer;
@@ -358,6 +359,7 @@ public:
     enum MediaKeyException { NoError, InvalidPlayerState, KeySystemNotSupported };
 
     std::unique_ptr<LegacyCDMSession> createSession(const String& keySystem, LegacyCDMSessionClient*);
+    void setCDM(LegacyCDM*);
     void setCDMSession(LegacyCDMSession*);
     void keyAdded();
 #endif
@@ -627,6 +629,8 @@ public:
     void requestInstallMissingPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback& callback) { client().requestInstallMissingPlugins(details, description, callback); }
 #endif
 
+    const MediaPlayerPrivateInterface* playerPrivate() const { return m_private.get(); }
+
 private:
     MediaPlayer(MediaPlayerClient&);
     MediaPlayer(MediaPlayerClient&, MediaPlayerEnums::MediaEngineIdentifier);
index 4d57cdb..3e74d42 100644 (file)
@@ -223,6 +223,7 @@ public:
 
 #if ENABLE(LEGACY_ENCRYPTED_MEDIA)
     virtual std::unique_ptr<LegacyCDMSession> createSession(const String&, LegacyCDMSessionClient*) { return nullptr; }
+    virtual void setCDM(LegacyCDM*) { }
     virtual void setCDMSession(LegacyCDMSession*) { }
     virtual void keyAdded() { }
 #endif