Title: [185424] trunk/Source/WebCore
Revision
185424
Author
[email protected]
Date
2015-06-10 11:43:52 -0700 (Wed, 10 Jun 2015)

Log Message

Explicitly keep track of active HTMLMediaElements in MediaSessions.
https://bugs.webkit.org/show_bug.cgi?id=145829

Patch by Matt Rajca <[email protected]> on 2015-06-10
Reviewed by Eric Carlson.

* Modules/mediasession/MediaSession.cpp: Add support for keeping track of active media elements.
(WebCore::MediaSession::addActiveMediaElement):
* Modules/mediasession/MediaSession.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::playInternal): If the paused attribute is true and the readyState attribute has the
  value HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, the media element becomes an active participating element of the
  media session.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (185423 => 185424)


--- trunk/Source/WebCore/ChangeLog	2015-06-10 18:15:23 UTC (rev 185423)
+++ trunk/Source/WebCore/ChangeLog	2015-06-10 18:43:52 UTC (rev 185424)
@@ -1,3 +1,18 @@
+2015-06-10  Matt Rajca  <[email protected]>
+
+        Explicitly keep track of active HTMLMediaElements in MediaSessions.
+        https://bugs.webkit.org/show_bug.cgi?id=145829
+
+        Reviewed by Eric Carlson.
+
+        * Modules/mediasession/MediaSession.cpp: Add support for keeping track of active media elements.
+        (WebCore::MediaSession::addActiveMediaElement):
+        * Modules/mediasession/MediaSession.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::playInternal): If the paused attribute is true and the readyState attribute has the
+          value HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, the media element becomes an active participating element of the
+          media session.
+
 2015-06-10  Chris Dumez  <[email protected]>
 
         Drop unused argument for Node::didNotifySubtreeInsertions()

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp (185423 => 185424)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-10 18:15:23 UTC (rev 185423)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-10 18:43:52 UTC (rev 185424)
@@ -66,16 +66,9 @@
     m_participatingElements.remove(m_participatingElements.find(&element));
 }
 
-Vector<HTMLMediaElement*> MediaSession::activeParticipatingElements() const
+void MediaSession::addActiveMediaElement(HTMLMediaElement& element)
 {
-    Vector<HTMLMediaElement*> elements;
-
-    for (auto* element : m_participatingElements) {
-        if (element->isPlaying())
-            elements.append(element);
-    }
-
-    return elements;
+    m_activeParticipatingElements.add(&element);
 }
 
 void MediaSession::releaseSession()
@@ -84,7 +77,7 @@
 
 void MediaSession::togglePlayback()
 {
-    for (auto* element : activeParticipatingElements()) {
+    for (auto* element : m_activeParticipatingElements) {
         if (element->paused())
             element->play();
         else

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.h (185423 => 185424)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-10 18:15:23 UTC (rev 185423)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-10 18:43:52 UTC (rev 185424)
@@ -65,10 +65,11 @@
     void addMediaElement(HTMLMediaElement&);
     void removeMediaElement(HTMLMediaElement&);
 
-    Vector<HTMLMediaElement*> activeParticipatingElements() const;
+    void addActiveMediaElement(HTMLMediaElement&);
 
     State m_currentState { State::Idle };
     Vector<HTMLMediaElement*> m_participatingElements;
+    HashSet<HTMLMediaElement*> m_activeParticipatingElements;
 
     const String m_kind;
     RefPtr<MediaRemoteControls> m_controls;

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (185423 => 185424)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-10 18:15:23 UTC (rev 185423)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-10 18:43:52 UTC (rev 185424)
@@ -2829,6 +2829,19 @@
             scheduleEvent(eventNames().waitingEvent);
         else if (m_readyState >= HAVE_FUTURE_DATA)
             scheduleEvent(eventNames().playingEvent);
+
+#if ENABLE(MEDIA_SESSION)
+        // 6.3 Activating a media session from a media element
+        // When the play() method is invoked, the paused attribute is true, and the readyState attribute has the value
+        // HAVE_FUTURE_DATA or HAVE_ENOUGH_DATA, then
+        // 1. Let media session be the value of the current media session.
+        // 2. If we are not currently in media session's list of active participating media elements then append
+        //    ourselves to this list.
+        if (m_readyState == HAVE_ENOUGH_DATA || m_readyState == HAVE_FUTURE_DATA) {
+            if (m_session)
+                m_session->addActiveMediaElement(*this);
+        }
+#endif
     }
     m_autoplaying = false;
     updatePlayState();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to