MediaStream should fire ended event when all tracks are ended
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Sep 2013 15:34:21 +0000 (15:34 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Sep 2013 15:34:21 +0000 (15:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120871

Reviewed by Jer Noble.

Merge https://chromium.googlesource.com/chromium/blink/+/bebd179b65be69e46f2f434a3ec8b1e4aa85cc42

Source/WebCore:

Test: fast/mediastream/MediaStream-onended.html

* Modules/mediastream/MediaStream.cpp:
(WebCore::MediaStream::trackEnded): New.
* Modules/mediastream/MediaStream.h:

* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::sourceChangedState): Call didEndTrack when state changes to ReadyStateEnded.
(WebCore::MediaStreamTrack::didEndTrack): New.
(WebCore::MediaStreamTrack::stop): Call didEndTrack.
* Modules/mediastream/MediaStreamTrack.h:

* platform/mediastream/MediaStreamDescriptor.h:
(WebCore::MediaStreamDescriptor::MediaStreamDescriptor): Require didEndTrack.

LayoutTests:

* fast/mediastream/MediaStream-onended-expected.txt: Added.
* fast/mediastream/MediaStream-onended.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@155249 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/mediastream/MediaStream-onended-expected.txt [new file with mode: 0644]
LayoutTests/fast/mediastream/MediaStream-onended.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h
Source/WebCore/platform/mediastream/MediaStreamDescriptor.h

index 93b463c..8686698 100644 (file)
@@ -1,3 +1,15 @@
+2013-09-07  Eric Carlson  <eric.carlson@apple.com>
+
+        MediaStream should fire ended event when all tracks are ended
+        https://bugs.webkit.org/show_bug.cgi?id=120871
+
+        Reviewed by Jer Noble.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/bebd179b65be69e46f2f434a3ec8b1e4aa85cc42
+
+        * fast/mediastream/MediaStream-onended-expected.txt: Added.
+        * fast/mediastream/MediaStream-onended.html: Added.
+
 2013-09-06  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         [CSS Shapes] Floats with shape-outside aren't painting in the correct order
diff --git a/LayoutTests/fast/mediastream/MediaStream-onended-expected.txt b/LayoutTests/fast/mediastream/MediaStream-onended-expected.txt
new file mode 100644 (file)
index 0000000..491b35b
--- /dev/null
@@ -0,0 +1,12 @@
+Tests MediaStream::onended callback.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS stream.ended is false
+PASS streamEnded was called.
+PASS stream.ended is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/mediastream/MediaStream-onended.html b/LayoutTests/fast/mediastream/MediaStream-onended.html
new file mode 100644 (file)
index 0000000..153f5b5
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description("Tests MediaStream::onended callback.");
+
+function error() {
+    testFailed('Stream generation failed.');
+    finishJSTest();
+}
+
+function getUserMedia(dictionary, callback) {
+    try {
+        navigator.webkitGetUserMedia(dictionary, callback, error);
+    } catch (e) {
+        testFailed('webkitGetUserMedia threw exception :' + e);
+        finishJSTest();
+    }
+}
+
+var stream;
+
+function streamEnded() {
+    testPassed('streamEnded was called.');
+    shouldBeTrue('stream.ended');
+    finishJSTest();
+}
+
+function gotStream(s) {
+    stream = new webkitMediaStream(s);
+    shouldBeFalse('stream.ended');
+    try {
+        stream.onended = streamEnded;
+        s.stop();
+    } catch (e) {
+        testFailed('LocalMediaStream threw exception :' + e);
+        finishJSTest();
+    }
+}
+
+getUserMedia({audio:true, video:true}, gotStream);
+
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 61df694..5a5111e 100644 (file)
@@ -1,3 +1,27 @@
+2013-09-07  Eric Carlson  <eric.carlson@apple.com>
+
+        MediaStream should fire ended event when all tracks are ended
+        https://bugs.webkit.org/show_bug.cgi?id=120871
+
+        Reviewed by Jer Noble.
+
+        Merge https://chromium.googlesource.com/chromium/blink/+/bebd179b65be69e46f2f434a3ec8b1e4aa85cc42
+
+        Test: fast/mediastream/MediaStream-onended.html
+
+        * Modules/mediastream/MediaStream.cpp:
+        (WebCore::MediaStream::trackEnded): New.
+        * Modules/mediastream/MediaStream.h:
+
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::sourceChangedState): Call didEndTrack when state changes to ReadyStateEnded. 
+        (WebCore::MediaStreamTrack::didEndTrack): New.
+        (WebCore::MediaStreamTrack::stop): Call didEndTrack.
+        * Modules/mediastream/MediaStreamTrack.h:
+
+        * platform/mediastream/MediaStreamDescriptor.h:
+        (WebCore::MediaStreamDescriptor::MediaStreamDescriptor): Require didEndTrack.
+
 2013-09-06  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
 
         Get MEDIA_STREAM compiling for other ports (EFL and GTK)
index d9542f4..73052cb 100644 (file)
@@ -221,6 +221,19 @@ MediaStreamTrack* MediaStream::getTrackById(String id)
     return 0;
 }
 
+void MediaStream::trackEnded()
+{
+    for (size_t i = 0; i < m_audioTracks.size(); ++i)
+        if (!m_audioTracks[i]->ended())
+            return;
+    
+    for (size_t i = 0; i < m_videoTracks.size(); ++i)
+        if (!m_videoTracks[i]->ended())
+            return;
+    
+    streamEnded();
+}
+
 void MediaStream::streamEnded()
 {
     if (ended())
index 0c7f707..d323e91 100644 (file)
@@ -66,6 +66,7 @@ public:
     DEFINE_ATTRIBUTE_EVENT_LISTENER(removetrack);
 
     // MediaStreamDescriptorClient
+    virtual void trackEnded() OVERRIDE;
     virtual void streamEnded() OVERRIDE;
 
     virtual bool isLocal() const { return false; }
index 8999b41..64ba377 100644 (file)
@@ -135,10 +135,20 @@ void MediaStreamTrack::sourceChangedState()
         break;
     case MediaStreamSource::ReadyStateEnded:
         dispatchEvent(Event::create(eventNames().endedEvent, false, false));
+        didEndTrack();
         break;
     }
 }
 
+void MediaStreamTrack::didEndTrack()
+{
+    MediaStreamDescriptorClient* client = m_component->stream()->client();
+    if (!client)
+        return;
+    
+    client->trackEnded();
+}
+
 MediaStreamComponent* MediaStreamTrack::component()
 {
     return m_component.get();
@@ -147,6 +157,7 @@ MediaStreamComponent* MediaStreamTrack::component()
 void MediaStreamTrack::stop()
 {
     m_stopped = true;
+    didEndTrack();
 }
 
 const AtomicString& MediaStreamTrack::interfaceName() const
index cefac11..0ab4d0a 100644 (file)
@@ -53,6 +53,8 @@ public:
     bool enabled() const;
     void setEnabled(bool);
 
+    void didEndTrack();
+    
     String readyState() const;
 
     DEFINE_ATTRIBUTE_EVENT_LISTENER(mute);
index ee32a14..48338e2 100644 (file)
@@ -44,6 +44,7 @@ class MediaStreamDescriptorClient {
 public:
     virtual ~MediaStreamDescriptorClient() { }
 
+    virtual void trackEnded() = 0;
     virtual void streamEnded() = 0;
     virtual void addRemoteTrack(MediaStreamComponent*) = 0;
     virtual void removeRemoteTrack(MediaStreamComponent*) = 0;