Title: [236006] trunk/Source/WebCore
Revision
236006
Author
[email protected]
Date
2018-09-14 08:37:14 -0700 (Fri, 14 Sep 2018)

Log Message

[EME] Add support the waitingforkey event
https://bugs.webkit.org/show_bug.cgi?id=189616

Reviewed by Philippe Normand.

Crossplatform support to fire the waitingforkey event from the
player to the element. The element implements the W3C specified
algorithm.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerWaitingForKey):
(WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary):
* html/HTMLMediaElement.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::waitingForKey):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerWaitingForKey):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (236005 => 236006)


--- trunk/Source/WebCore/ChangeLog	2018-09-14 15:16:09 UTC (rev 236005)
+++ trunk/Source/WebCore/ChangeLog	2018-09-14 15:37:14 UTC (rev 236006)
@@ -1,3 +1,23 @@
+2018-09-14  Xabier Rodriguez Calvar  <[email protected]>
+
+        [EME] Add support the waitingforkey event
+        https://bugs.webkit.org/show_bug.cgi?id=189616
+
+        Reviewed by Philippe Normand.
+
+        Crossplatform support to fire the waitingforkey event from the
+        player to the element. The element implements the W3C specified
+        algorithm.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerWaitingForKey):
+        (WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary):
+        * html/HTMLMediaElement.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::waitingForKey):
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaPlayerWaitingForKey):
+
 2018-09-14  Mike Gorse  <[email protected]>
 
         builtins directory causes name conflict on Python 3

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (236005 => 236006)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2018-09-14 15:16:09 UTC (rev 236005)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2018-09-14 15:37:14 UTC (rev 236006)
@@ -2787,6 +2787,63 @@
     m_asyncEventQueue.enqueueEvent(MediaEncryptedEvent::create(eventNames().encryptedEvent, initializer, Event::IsTrusted::Yes));
 }
 
+void HTMLMediaElement::mediaPlayerWaitingForKey()
+{
+    // https://www.w3.org/TR/encrypted-media/#wait-for-key
+    // W3C Recommendation 18 September 2017
+
+    // The Wait for Key algorithm queues a waitingforkey event and
+    // updates readyState. It should only be called when the
+    // HTMLMediaElement object is potentially playing and its
+    // readyState is equal to HAVE_FUTURE_DATA or greater. Requests to
+    // run this algorithm include a target HTMLMediaElement object.
+
+    // The following steps are run:
+
+    // 1. Let the media element be the specified HTMLMediaElement
+    // object.
+    // 2. If the media element's playback blocked waiting for key
+    // value is true, abort these steps.
+    if (m_playbackBlockedWaitingForKey)
+        return;
+
+    // 3. Set the media element's playback blocked waiting for key
+    // value to true.
+    m_playbackBlockedWaitingForKey = true;
+
+    // NOTE
+    // As a result of the above step, the media element will become a
+    // blocked media element if it wasn't already. In that case, the
+    // media element will stop playback.
+
+    // 4. Follow the steps for the first matching condition from the
+    // following list:
+
+    // If data for the immediate current playback position is
+    // available
+    // Set the readyState of media element to HAVE_CURRENT_DATA.
+    // Otherwise
+    // Set the readyState of media element to HAVE_METADATA.
+    ReadyState nextReadyState = buffered()->contain(currentTime()) ? HAVE_CURRENT_DATA : HAVE_METADATA;
+    if (nextReadyState < m_readyState)
+        setReadyState(static_cast<MediaPlayer::ReadyState>(nextReadyState));
+
+    // NOTE
+    // In other words, if the video frame and audio data for the
+    // current playback position have been decoded because they were
+    // unencrypted and/or successfully decrypted, set readyState to
+    // HAVE_CURRENT_DATA. Otherwise, including if this was previously
+    // the case but the data is no longer available, set readyState to
+    // HAVE_METADATA.
+
+    // 5. Queue a task to fire a simple event named waitingforkey at the
+    // media element.
+    scheduleEvent(eventNames().waitingforkeyEvent);
+
+    // 6. Suspend playback.
+    // GStreamer handles this without suspending explicitly.
+}
+
 void HTMLMediaElement::attemptToDecrypt()
 {
     // https://w3c.github.io/encrypted-media/#attempt-to-decrypt
@@ -2827,7 +2884,8 @@
 
     // 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: ^
+    if (!m_playbackBlockedWaitingForKey)
+        return;
 
     // 3. Run the Attempt to Decrypt algorithm on the media element.
     attemptToDecrypt();
@@ -2834,9 +2892,12 @@
 
     // 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.
+    // FIXME: ^
     //   4.2. Set the media element's playback blocked waiting for key value to false.
+    m_playbackBlockedWaitingForKey = false;
+
     //   4.3. Set the media element's readyState value to HAVE_CURRENT_DATA, HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA as appropriate.
-    // FIXME: ^
+    setReadyState(m_player->readyState());
 }
 
 void HTMLMediaElement::cdmClientAttemptToResumePlaybackIfNecessary()

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (236005 => 236006)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2018-09-14 15:16:09 UTC (rev 236005)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2018-09-14 15:37:14 UTC (rev 236006)
@@ -673,6 +673,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
     void mediaPlayerInitializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&) final;
+    void mediaPlayerWaitingForKey() final;
 
     void attemptToDecrypt();
     void attemptToResumePlaybackIfNecessary();
@@ -1148,6 +1149,7 @@
 #if ENABLE(ENCRYPTED_MEDIA)
     RefPtr<MediaKeys> m_mediaKeys;
     bool m_attachingMediaKeys { false };
+    bool m_playbackBlockedWaitingForKey { false };
     GenericTaskQueue<Timer> m_encryptedMediaQueue;
 #endif
 

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (236005 => 236006)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2018-09-14 15:16:09 UTC (rev 236005)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2018-09-14 15:37:14 UTC (rev 236006)
@@ -1266,6 +1266,10 @@
     client().mediaPlayerInitializationDataEncountered(initDataType, WTFMove(initData));
 }
 
+void MediaPlayer::waitingForKey()
+{
+    client().mediaPlayerWaitingForKey();
+}
 #endif
 
 String MediaPlayer::referrer() const

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (236005 => 236006)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2018-09-14 15:16:09 UTC (rev 236005)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2018-09-14 15:37:14 UTC (rev 236006)
@@ -169,6 +169,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
     virtual void mediaPlayerInitializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&) { }
+    virtual void mediaPlayerWaitingForKey() { }
 #endif
     
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -487,6 +488,7 @@
 
 #if ENABLE(ENCRYPTED_MEDIA)
     void initializationDataEncountered(const String&, RefPtr<ArrayBuffer>&&);
+    void waitingForKey();
 #endif
 
     String referrer() const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to