Title: [220962] trunk/Source/WebCore
Revision
220962
Author
[email protected]
Date
2017-08-21 05:56:44 -0700 (Mon, 21 Aug 2017)

Log Message

[EME] HTMLMediaElement: basic implementations of 'Attempt to Decrypt', 'Attempt to Resume Playback If Necessary'
https://bugs.webkit.org/show_bug.cgi?id=175761

Reviewed by Xabier Rodriguez-Calvar.

Add initial and incomplete implementations of the 'Attempt to Decrypt' and
'Attempt to Resume Playback If Necessary' algorithms.  The implementations
are interleaved with the specification text for clarity.

'Attempt to Decrypt' implementation doesn't yet address the encrypted block
queue or the 'decryption blocked waiting for key' flag since it's not yet
clear whether it would make more sense for this state to reside lower, in
the platform layer. The gist of the algorithm is to invoke the decryption
attempt through the MediaPlayer object, passing along the CDMInstance object
retrieved from the MediaKeys object that is associated with this media
element.

'Attempt to Resume Playback if Necessary' implementation similarly for now
omits the various state flag operations. The main task at this point is to
dispatch the 'Attempt to Decrypt' algorithm.

HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary() method now
invokes the attemptToResumePlaybackIfNecessary() method.

MediaKeys::hasOpenSessions() is introduced, returning true if any session
that was created through this MediaKeys instance is still open. This allows
the 'Attempt to Decrypt' algorithm to proceed with the decryption attempt
dispatch into the MediaPlayer hierarchy.

For that, the MediaPlayer::attemptToDecryptWithInstance() method is added,
which simply dispatches the mirror method on MediaPlayerPrivate interface.
This will enable the platform-layer implementations to use the passed-in
CDMInstance object for decryption purposes.

* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/MediaKeys.cpp:
(WebCore::MediaKeys::hasOpenSessions const):
* Modules/encryptedmedia/MediaKeys.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::attemptToDecrypt):
(WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary):
(WebCore::HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary):
* html/HTMLMediaElement.h: Mark cdmClientAttemptToResumePlaybackIfNecessary() as final.
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::attemptToDecryptWithInstance):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::attemptToDecryptWithInstance):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (220961 => 220962)


--- trunk/Source/WebCore/ChangeLog	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/ChangeLog	2017-08-21 12:56:44 UTC (rev 220962)
@@ -1,3 +1,54 @@
+2017-08-21  Zan Dobersek  <[email protected]>
+
+        [EME] HTMLMediaElement: basic implementations of 'Attempt to Decrypt', 'Attempt to Resume Playback If Necessary'
+        https://bugs.webkit.org/show_bug.cgi?id=175761
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Add initial and incomplete implementations of the 'Attempt to Decrypt' and
+        'Attempt to Resume Playback If Necessary' algorithms.  The implementations
+        are interleaved with the specification text for clarity.
+
+        'Attempt to Decrypt' implementation doesn't yet address the encrypted block
+        queue or the 'decryption blocked waiting for key' flag since it's not yet
+        clear whether it would make more sense for this state to reside lower, in
+        the platform layer. The gist of the algorithm is to invoke the decryption
+        attempt through the MediaPlayer object, passing along the CDMInstance object
+        retrieved from the MediaKeys object that is associated with this media
+        element.
+
+        'Attempt to Resume Playback if Necessary' implementation similarly for now
+        omits the various state flag operations. The main task at this point is to
+        dispatch the 'Attempt to Decrypt' algorithm.
+
+        HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary() method now
+        invokes the attemptToResumePlaybackIfNecessary() method.
+
+        MediaKeys::hasOpenSessions() is introduced, returning true if any session
+        that was created through this MediaKeys instance is still open. This allows
+        the 'Attempt to Decrypt' algorithm to proceed with the decryption attempt
+        dispatch into the MediaPlayer hierarchy.
+
+        For that, the MediaPlayer::attemptToDecryptWithInstance() method is added,
+        which simply dispatches the mirror method on MediaPlayerPrivate interface.
+        This will enable the platform-layer implementations to use the passed-in
+        CDMInstance object for decryption purposes.
+
+        * Modules/encryptedmedia/MediaKeySession.h:
+        * Modules/encryptedmedia/MediaKeys.cpp:
+        (WebCore::MediaKeys::hasOpenSessions const):
+        * Modules/encryptedmedia/MediaKeys.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::attemptToDecrypt):
+        (WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary):
+        (WebCore::HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary):
+        * html/HTMLMediaElement.h: Mark cdmClientAttemptToResumePlaybackIfNecessary() as final.
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::attemptToDecryptWithInstance):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::attemptToDecryptWithInstance):
+
 2017-08-20  Zan Dobersek  <[email protected]>
 
         [EME] Add basic implementation of HTMLMediaElement::setMediaKeys()

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h (220961 => 220962)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeySession.h	2017-08-21 12:56:44 UTC (rev 220962)
@@ -60,6 +60,7 @@
     using RefCounted<MediaKeySession>::ref;
     using RefCounted<MediaKeySession>::deref;
 
+    bool isClosed() const { return m_closed; }
     void detachKeys();
 
     const String& sessionId() const;

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp (220961 => 220962)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.cpp	2017-08-21 12:56:44 UTC (rev 220962)
@@ -134,6 +134,14 @@
         cdmClient->cdmClientAttemptToResumePlaybackIfNecessary();
 }
 
+bool MediaKeys::hasOpenSessions() const
+{
+    return std::any_of(m_sessions.begin(), m_sessions.end(),
+        [](auto& session) {
+            return !session->isClosed();
+        });
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(ENCRYPTED_MEDIA)

Modified: trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h (220961 => 220962)


--- trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/Modules/encryptedmedia/MediaKeys.h	2017-08-21 12:56:44 UTC (rev 220962)
@@ -63,6 +63,7 @@
     void detachCDMClient(CDMClient&);
     void attemptToResumePlaybackOnClients();
 
+    bool hasOpenSessions() const;
     const CDMInstance& cdmInstance() const { return m_instance; }
 
 protected:

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (220961 => 220962)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-08-21 12:56:44 UTC (rev 220962)
@@ -2648,17 +2648,61 @@
     // 6. Return promise.
 }
 
+void HTMLMediaElement::attemptToDecrypt()
+{
+    // https://w3c.github.io/encrypted-media/#attempt-to-decrypt
+    // W3C Editor's Draft 23 June 2017
+
+    // 1. Let the media element be the specified HTMLMediaElement object.
+    // 2. If the media element's encrypted block queue is empty, abort these steps.
+    // FIXME: ^
+
+    // 3. If the media element's mediaKeys attribute is not null, run the following steps:
+    if (m_mediaKeys) {
+        // 3.1. Let media keys be the MediaKeys object referenced by that attribute.
+        // 3.2. Let cdm be the CDM instance represented by media keys's cdm instance value.
+        auto& cdmInstance = m_mediaKeys->cdmInstance();
+
+        // 3.3. If cdm is no longer usable for any reason, run the following steps:
+        //   3.3.1. Run the media data is corrupted steps of the resource fetch algorithm.
+        //   3.3.2. Run the CDM Unavailable algorithm on media keys.
+        //   3.3.3. Abort these steps.
+        // FIXME: ^
+
+        // 3.4. If there is at least one MediaKeySession created by the media keys that is not closed, run the following steps:
+        if (m_mediaKeys->hasOpenSessions()) {
+            // Continued in MediaPlayer::attemptToDecryptWithInstance().
+            if (m_player)
+                m_player->attemptToDecryptWithInstance(cdmInstance);
+        }
+    }
+
+    // 4. Set the media element's decryption blocked waiting for key value to true.
+    // FIXME: ^
+}
+
 void HTMLMediaElement::attemptToResumePlaybackIfNecessary()
 {
     // https://w3c.github.io/encrypted-media/#resume-playback
     // W3C Editor's Draft 23 June 2017
 
-    notImplemented();
+    // 1. Let the media element be the specified HTMLMediaElement object.
+    // 2. If the media element's playback blocked waiting for key is false, abort these steps.
+    // FIXME: ^
+
+    // 3. Run the Attempt to Decrypt algorithm on the media element.
+    attemptToDecrypt();
+
+    // 4. If the user agent can advance the current playback position in the direction of playback:
+    //   4.1. Set the media element's decryption blocked waiting for key value to false.
+    //   4.2. Set the media element's playback blocked waiting for key value to false.
+    //   4.3. Set the media element's readyState value to HAVE_CURRENT_DATA, HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA as appropriate.
+    // FIXME: ^
 }
 
 void HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary()
 {
-    notImplemented();
+    attemptToResumePlaybackIfNecessary();
 }
 
 #endif // ENABLE(ENCRYPTED_MEDIA)

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (220961 => 220962)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2017-08-21 12:56:44 UTC (rev 220962)
@@ -636,10 +636,11 @@
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
+    void attemptToDecrypt();
     void attemptToResumePlaybackIfNecessary();
 
     // CDMClient
-    void cdmClientAttemptToResumePlaybackIfNecessary() override;
+    void cdmClientAttemptToResumePlaybackIfNecessary() final;
 #endif
     
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (220961 => 220962)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2017-08-21 12:56:44 UTC (rev 220962)
@@ -594,6 +594,11 @@
 {
     m_private->cdmInstanceDetached(instance);
 }
+
+void MediaPlayer::attemptToDecryptWithInstance(const CDMInstance& instance)
+{
+    m_private->attemptToDecryptWithInstance(instance);
+}
 #endif
 
 MediaTime MediaPlayer::duration() const

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (220961 => 220962)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2017-08-21 12:56:44 UTC (rev 220962)
@@ -371,6 +371,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     void cdmInstanceAttached(const CDMInstance&);
     void cdmInstanceDetached(const CDMInstance&);
+    void attemptToDecryptWithInstance(const CDMInstance&);
 #endif
 
     bool paused() const;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (220961 => 220962)


--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2017-08-21 08:28:48 UTC (rev 220961)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2017-08-21 12:56:44 UTC (rev 220962)
@@ -239,6 +239,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     virtual void cdmInstanceAttached(const CDMInstance&) { }
     virtual void cdmInstanceDetached(const CDMInstance&) { }
+    virtual void attemptToDecryptWithInstance(const CDMInstance&) { }
 #endif
 
 #if ENABLE(VIDEO_TRACK)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to