Title: [288086] trunk
Revision
288086
Author
[email protected]
Date
2022-01-16 22:41:57 -0800 (Sun, 16 Jan 2022)

Log Message

Queue a task to fire MediaStreamTrack ended event
https://bugs.webkit.org/show_bug.cgi?id=235227

Reviewed by Eric Carlson.

Source/WebCore:

Adding a specific readyState slot to match the spec and queue a task to stop the track instead of firing the event synchronously.
Covered by updated test.

* Modules/mediastream/MediaStreamTrack.cpp:
* Modules/mediastream/MediaStreamTrack.h:

LayoutTests:

* fast/mediastream/media-stream-track-source-failure.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288085 => 288086)


--- trunk/LayoutTests/ChangeLog	2022-01-17 05:18:06 UTC (rev 288085)
+++ trunk/LayoutTests/ChangeLog	2022-01-17 06:41:57 UTC (rev 288086)
@@ -1,3 +1,12 @@
+2022-01-16  Youenn Fablet  <[email protected]>
+
+        Queue a task to fire MediaStreamTrack ended event
+        https://bugs.webkit.org/show_bug.cgi?id=235227
+
+        Reviewed by Eric Carlson.
+
+        * fast/mediastream/media-stream-track-source-failure.html:
+
 2022-01-16  Brady Eidson  <[email protected]>
 
         database names leak cross-origin within the same browser session

Modified: trunk/LayoutTests/fast/mediastream/media-stream-track-source-failure.html (288085 => 288086)


--- trunk/LayoutTests/fast/mediastream/media-stream-track-source-failure.html	2022-01-17 05:18:06 UTC (rev 288085)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-source-failure.html	2022-01-17 06:41:57 UTC (rev 288086)
@@ -34,7 +34,10 @@
         promise_test((test) => {
             return new Promise((resolve, reject) => {
                 const mediaState = internals.pageMediaState();
+                let trackEndedEventFired = false;
                 track._onended_ = () => {
+                    assert_equals(track.readyState, "ended");
+                    trackEndedEventFired = true;
                     new Promise((innerResolve, innerReject) => {
                         waitForPageStateChange(10, mediaState, innerResolve, innerReject)
                     }).then((pageMediaState) => {
@@ -59,8 +62,13 @@
                     })
                 }
 
-                if (window.internals)
+                if (window.internals) {
                     internals.simulateMediaStreamTrackCaptureSourceFailure(track);
+                    assert_equals(track.readyState, "live");
+                    setTimeout(() => {
+                        assert_true(trackEndedEventFired, "ended");
+                    }, 0);
+                }
                 setTimeout(() => reject("Device state did not change in 5 second"), 5000);
 
             });

Modified: trunk/Source/WebCore/ChangeLog (288085 => 288086)


--- trunk/Source/WebCore/ChangeLog	2022-01-17 05:18:06 UTC (rev 288085)
+++ trunk/Source/WebCore/ChangeLog	2022-01-17 06:41:57 UTC (rev 288086)
@@ -1,3 +1,16 @@
+2022-01-16  Youenn Fablet  <[email protected]>
+
+        Queue a task to fire MediaStreamTrack ended event
+        https://bugs.webkit.org/show_bug.cgi?id=235227
+
+        Reviewed by Eric Carlson.
+
+        Adding a specific readyState slot to match the spec and queue a task to stop the track instead of firing the event synchronously.
+        Covered by updated test.
+
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        * Modules/mediastream/MediaStreamTrack.h:
+
 2022-01-16  Lauro Moura  <[email protected]>
 
         Fix C++20 build warnings with GCC

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp (288085 => 288086)


--- trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp	2022-01-17 05:18:06 UTC (rev 288085)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp	2022-01-17 06:41:57 UTC (rev 288086)
@@ -203,11 +203,6 @@
     return m_muted;
 }
 
-auto MediaStreamTrack::readyState() const -> State
-{
-    return ended() ? State::Ended : State::Live;
-}
-
 bool MediaStreamTrack::ended() const
 {
     return m_ended || m_private->ended();
@@ -220,7 +215,13 @@
 
     ALWAYS_LOG(LOGIDENTIFIER);
 
-    return MediaStreamTrack::create(*scriptExecutionContext(), m_private->clone());
+    auto clone = MediaStreamTrack::create(*scriptExecutionContext(), m_private->clone());
+
+    clone->m_readyState = m_readyState;
+    if (clone->ended() && clone->m_readyState == State::Live)
+        trackEnded(clone->m_private);
+
+    return clone;
 }
 
 void MediaStreamTrack::stopTrack(StopMode mode)
@@ -235,8 +236,10 @@
 
     // An 'ended' event is not posted if m_ended is true when trackEnded is called, so set it now if we are
     // not supposed to post the event.
-    if (mode == StopMode::Silently)
+    if (mode == StopMode::Silently) {
         m_ended = true;
+        m_readyState = State::Ended;
+    }
 
     m_private->endTrack();
     m_ended = true;
@@ -562,29 +565,31 @@
     if (m_isCaptureTrack && m_private->type() == RealtimeMediaSource::Type::Audio)
         PlatformMediaSessionManager::sharedManager().removeAudioCaptureSource(*this);
 
-    // http://w3c.github.io/mediacapture-main/#life-cycle
-    // When a MediaStreamTrack track ends for any reason other than the stop() method being invoked, the User Agent must queue a task that runs the following steps:
-    // 1. If the track's readyState attribute has the value ended already, then abort these steps.
-    if (m_ended)
-        return;
-
     ALWAYS_LOG(LOGIDENTIFIER);
 
     if (m_isCaptureTrack && m_private->source().captureDidFail())
         scriptExecutionContext()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "A MediaStreamTrack ended due to a capture failure"_s);
 
-    // 2. Set track's readyState attribute to ended.
-    m_ended = true;
+    // http://w3c.github.io/mediacapture-main/#life-cycle
+    // When a MediaStreamTrack track ends for any reason other than the stop() method being invoked, the User Agent must queue a task that runs the following steps:
+    queueTaskKeepingObjectAlive(*this, TaskSource::Networking, [this, muted = m_private->muted()] {
+        // 1. If the track's readyState attribute has the value ended already, then abort these steps.
+        if (!isAllowedToRunScript() || m_readyState == State::Ended)
+            return;
 
-    if (scriptExecutionContext()->activeDOMObjectsAreSuspended() || scriptExecutionContext()->activeDOMObjectsAreStopped())
-        return;
+        // 2. Set track's readyState attribute to ended.
+        m_readyState = State::Ended;
 
-    ALWAYS_LOG(LOGIDENTIFIER, "firing 'ended' event");
+        ALWAYS_LOG(LOGIDENTIFIER, "firing 'ended' event");
 
-    // 3. Notify track's source that track is ended so that the source may be stopped, unless other MediaStreamTrack objects depend on it.
-    // 4. Fire a simple event named ended at the object.
-    dispatchEvent(Event::create(eventNames().endedEvent, Event::CanBubble::No, Event::IsCancelable::No));
+        // 3. Notify track's source that track is ended so that the source may be stopped, unless other MediaStreamTrack objects depend on it.
+        // 4. Fire a simple event named ended at the object.
+        dispatchEvent(Event::create(eventNames().endedEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    });
 
+    if (m_ended)
+        return;
+
     for (auto& observer : m_observers)
         observer->trackDidEnd();
 

Modified: trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h (288085 => 288086)


--- trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2022-01-17 05:18:06 UTC (rev 288085)
+++ trunk/Source/WebCore/Modules/mediastream/MediaStreamTrack.h	2022-01-17 06:41:57 UTC (rev 288086)
@@ -90,7 +90,7 @@
     bool mutedForBindings() const;
 
     enum class State { Live, Ended };
-    State readyState() const;
+    State readyState() const { return m_readyState; }
 
     bool ended() const;
 
@@ -202,6 +202,7 @@
     MediaTrackConstraints m_constraints;
     std::unique_ptr<DOMPromiseDeferred<void>> m_promise;
 
+    State m_readyState { State::Live };
     bool m_muted { false };
     bool m_ended { false };
     const bool m_isCaptureTrack { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to