Title: [186123] trunk/Source/WebCore
Revision
186123
Author
[email protected]
Date
2015-06-30 11:10:55 -0700 (Tue, 30 Jun 2015)

Log Message

Media Session: implement algorithm for updating a media element's session (6.1)
https://bugs.webkit.org/show_bug.cgi?id=146460

Reviewed by Darin Adler.

In addition to storing a pointer to the new media session, we now:

- pause the media element if it is 'active' in the current media session
- remove the media element from the current media session
- release the current media session if there are no more active media elements
- set the default media session if the new media session is null
- update the 'kind' attribute to match the kind of the new media session

* Modules/mediasession/MediaSession.cpp:
(WebCore::MediaSession::isMediaElementActive):
(WebCore::MediaSession::hasActiveMediaElements):
* Modules/mediasession/MediaSession.h:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setSession):
(WebCore::HTMLMediaElement::setSessionInternal):
* html/HTMLMediaElement.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (186122 => 186123)


--- trunk/Source/WebCore/ChangeLog	2015-06-30 18:08:19 UTC (rev 186122)
+++ trunk/Source/WebCore/ChangeLog	2015-06-30 18:10:55 UTC (rev 186123)
@@ -1,3 +1,27 @@
+2015-06-30  Matt Rajca  <[email protected]>
+
+        Media Session: implement algorithm for updating a media element's session (6.1)
+        https://bugs.webkit.org/show_bug.cgi?id=146460
+
+        Reviewed by Darin Adler.
+
+        In addition to storing a pointer to the new media session, we now:
+
+        - pause the media element if it is 'active' in the current media session
+        - remove the media element from the current media session
+        - release the current media session if there are no more active media elements
+        - set the default media session if the new media session is null
+        - update the 'kind' attribute to match the kind of the new media session
+
+        * Modules/mediasession/MediaSession.cpp:
+        (WebCore::MediaSession::isMediaElementActive):
+        (WebCore::MediaSession::hasActiveMediaElements):
+        * Modules/mediasession/MediaSession.h:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setSession):
+        (WebCore::HTMLMediaElement::setSessionInternal):
+        * html/HTMLMediaElement.h:
+
 2015-06-29  Anders Carlsson  <[email protected]>
 
         Get rid of unused WKSI functions

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp (186122 => 186123)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-30 18:08:19 UTC (rev 186122)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.cpp	2015-06-30 18:10:55 UTC (rev 186123)
@@ -125,6 +125,16 @@
     m_activeParticipatingElements.add(&element);
 }
 
+bool MediaSession::isMediaElementActive(HTMLMediaElement& element)
+{
+    return m_activeParticipatingElements.contains(&element);
+}
+
+bool MediaSession::hasActiveMediaElements()
+{
+    return !m_activeParticipatingElements.isEmpty();
+}
+
 void MediaSession::setMetadata(const Dictionary& metadata)
 {
     // 5.1.3

Modified: trunk/Source/WebCore/Modules/mediasession/MediaSession.h (186122 => 186123)


--- trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-30 18:08:19 UTC (rev 186122)
+++ trunk/Source/WebCore/Modules/mediasession/MediaSession.h	2015-06-30 18:10:55 UTC (rev 186123)
@@ -88,6 +88,8 @@
     void removeMediaElement(HTMLMediaElement&);
 
     void addActiveMediaElement(HTMLMediaElement&);
+    bool isMediaElementActive(HTMLMediaElement&);
+    bool hasActiveMediaElements();
 
     void releaseInternal();
 

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (186122 => 186123)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-30 18:08:19 UTC (rev 186122)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-30 18:10:55 UTC (rev 186123)
@@ -6452,15 +6452,46 @@
 
 void HTMLMediaElement::setSession(MediaSession* session)
 {
-    if (m_session)
+    // 6.1
+    // 1. Let m be the media element in question.
+    // 2. Let old media session be m's current media session, if it has one, and null otherwise.
+    // 3. Let new media session be null.
+    // 4. Set m's current media session to null, if it currently has one.
+    // 5. Let m's current media session be the new value or the top-level browsing context's media session if the new
+    //    value is null.
+    // 6. If the new value is null, then set the m's kind IDL attribute to the empty string. Otherwise, set m's kind IDL
+    //    attribute to the value of current media session's kind attribute.
+    // 7. Let new media session be m's current media session.
+    // 8. Update media sessions: If old media session and new media session are the same (whether both null or both the
+    //    same media session), then terminate these steps.
+    // 9. If m is an active audio-producing participant of old media session, then pause m and remove m from old media
+    //    session's active audio-producing participants.
+    // 10. If old media session is not null and no longer has one or more active audio-producing participants, then run
+    //     the media session release algorithm for old media session.
+
+    if (m_session) {
+        if (m_session->isMediaElementActive(*this))
+            pause();
+
         m_session->removeMediaElement(*this);
 
-    m_session = session;
+        if (!m_session->hasActiveMediaElements())
+            m_session->releaseSession();
+    }
 
     if (session)
-        session->addMediaElement(*this);
+        setSessionInternal(*session);
+    else
+        setSessionInternal(document().defaultMediaSession());
 }
 
+void HTMLMediaElement::setSessionInternal(MediaSession& session)
+{
+    m_session = &session;
+    session.addMediaElement(*this);
+    m_kind = session.kind();
+}
+
 #endif
 
 }

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (186122 => 186123)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2015-06-30 18:08:19 UTC (rev 186122)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2015-06-30 18:10:55 UTC (rev 186123)
@@ -556,6 +556,10 @@
     virtual bool dispatchEvent(PassRefPtr<Event>) override;
 #endif
 
+#if ENABLE(MEDIA_SESSION)
+    void setSessionInternal(MediaSession&);
+#endif
+
     virtual String mediaPlayerReferrer() const override;
     virtual String mediaPlayerUserAgent() const override;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to