Title: [237837] trunk
Revision
237837
Author
jer.no...@apple.com
Date
2018-11-05 16:45:01 -0800 (Mon, 05 Nov 2018)

Log Message

[MediaStream] An audio track should be muted when capture is interrupted by the OS.
Source/WebCore:

https://bugs.webkit.org/show_bug.cgi?id= 191283
 <rdar://problem/45773103>

Patch by Eric Carlson <eric.carl...@apple.com> on 2018-11-05
Reviewed by Jon Lee.

Test: fast/mediastream/media-stream-track-interrupted.html

* platform/mediastream/RealtimeMediaSource.cpp:
(WebCore::RealtimeMediaSource::setInterruptedForTesting):
* platform/mediastream/RealtimeMediaSource.h:
* platform/mediastream/mac/CoreAudioCaptureSource.cpp:
(WebCore::CoreAudioCaptureSource::beginInterruption):
(WebCore::CoreAudioCaptureSource::endInterruption):
* testing/Internals.cpp:
(WebCore::Internals::setMediaStreamSourceInterrupted):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

https://bugs.webkit.org/show_bug.cgi?id=191283
 <rdar://problem/45773103>

Patch by Eric Carlson <eric.carl...@apple.com> on 2018-11-05
Reviewed by Jon Lee.

* fast/mediastream/media-stream-track-interrupted-expected.txt: Added.
* fast/mediastream/media-stream-track-interrupted.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (237836 => 237837)


--- trunk/LayoutTests/ChangeLog	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/LayoutTests/ChangeLog	2018-11-06 00:45:01 UTC (rev 237837)
@@ -1,3 +1,14 @@
+2018-11-05  Eric Carlson  <eric.carl...@apple.com>
+
+        [MediaStream] An audio track should be muted when capture is interrupted by the OS.
+        https://bugs.webkit.org/show_bug.cgi?id=191283
+         <rdar://problem/45773103>
+
+        Reviewed by Jon Lee.
+
+        * fast/mediastream/media-stream-track-interrupted-expected.txt: Added.
+        * fast/mediastream/media-stream-track-interrupted.html: Added.
+
 2018-11-05  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Parsing support for text-underline-offset and text-decoration-thickness

Added: trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt (0 => 237837)


--- trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted-expected.txt	2018-11-06 00:45:01 UTC (rev 237837)
@@ -0,0 +1,6 @@
+
+
+PASS Create stream 
+PASS Interrupt video track 
+PASS Interrupt audio track 
+

Added: trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html (0 => 237837)


--- trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html	                        (rev 0)
+++ trunk/LayoutTests/fast/mediastream/media-stream-track-interrupted.html	2018-11-06 00:45:01 UTC (rev 237837)
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <title>Capture source interruption.</title>
+    <script src=""
+    <script src=""
+ </head>
+<body>
+    <video width=320 height=240></video>
+
+    <script>
+
+    let video;
+
+   if (window.testRunner)
+        testRunner.setUserMediaPermission(true);
+
+    function waitForPageStateChange(numberOfTries, originalState, resolve, reject)
+    {
+        let newState = internals.pageMediaState();
+        if (newState != originalState) {
+            resolve(newState);
+            return;
+        }
+
+        if (numberOfTries <= 0) {
+            reject('Page state did not change in time.');
+            return;
+        }
+
+        setTimeout(() => { waitForPageStateChange(--numberOfTries, originalState, resolve, reject); }, 10);
+    }
+
+    function testTrack(track, title)
+    {
+        promise_test((test) => {
+            return new Promise((resolve, reject) => {
+                let isVideo = track.kind == "video";
+                if (window.internals) {
+                    assert_false(internals.pageMediaState().includes('HasMutedVideoCaptureDevice'));
+                    assert_false(internals.pageMediaState().includes('HasMutedAudioCaptureDevice'));
+                }
+
+                track._onunmute_ = () => reject("Got 'unmute' event unexpectedly!");
+                track._onmute_ = () => {
+                    new Promise((innerResolve, innerReject) => {
+                        waitForPageStateChange(10, internals.pageMediaState(), innerResolve, innerReject)
+                    }).then((pageMediaState) => {
+
+                        track._onunmute_ = (evt) => {
+                            waitForPageStateChange(10, internals.pageMediaState(), resolve, reject)
+                        }
+
+                        if (window.internals) {
+                            assert_true(pageMediaState.includes(isVideo ? 'HasMutedVideoCaptureDevice' : 'HasMutedAudioCaptureDevice'));
+                            assert_false(pageMediaState.includes(isVideo ? 'HasMutedAudioCaptureDevice' : 'HasMutedVideoCaptureDevice'));
+                            assert_true(pageMediaState.includes(isVideo ? 'HasActiveAudioCaptureDevice' : 'HasActiveVideoCaptureDevice'));
+                            assert_false(pageMediaState.includes(isVideo ? 'HasActiveVideoCaptureDevice' : 'HasActiveAudioCaptureDevice'));
+                            internals.setMediaStreamSourceInterrupted(track, false)
+                        }
+                    })
+                }
+
+                if (window.internals)
+                    internals.setMediaStreamSourceInterrupted(track, true);
+                setTimeout(() => reject("Muted state did not change in 1 second"), 1000);
+            });
+        }, title);
+    }
+
+    promise_test((test) => {
+        return navigator.mediaDevices.getUserMedia({ video: true, audio: true})
+            .then((stream) => {
+                testTrack(stream.getVideoTracks()[0], "Interrupt video track");
+                testTrack(stream.getAudioTracks()[0], "Interrupt audio track");
+            });
+    }, "Create stream");
+
+
+    </script>
+
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (237836 => 237837)


--- trunk/Source/WebCore/ChangeLog	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/ChangeLog	2018-11-06 00:45:01 UTC (rev 237837)
@@ -1,3 +1,24 @@
+2018-11-05  Eric Carlson  <eric.carl...@apple.com>
+
+        [MediaStream] An audio track should be muted when capture is interrupted by the OS.
+        https://bugs.webkit.org/show_bug.cgi?id= 191283
+         <rdar://problem/45773103>
+
+        Reviewed by Jon Lee.
+
+        Test: fast/mediastream/media-stream-track-interrupted.html
+
+        * platform/mediastream/RealtimeMediaSource.cpp:
+        (WebCore::RealtimeMediaSource::setInterruptedForTesting):
+        * platform/mediastream/RealtimeMediaSource.h:
+        * platform/mediastream/mac/CoreAudioCaptureSource.cpp:
+        (WebCore::CoreAudioCaptureSource::beginInterruption):
+        (WebCore::CoreAudioCaptureSource::endInterruption):
+        * testing/Internals.cpp:
+        (WebCore::Internals::setMediaStreamSourceInterrupted):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2018-11-05  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Parsing support for text-underline-offset and text-decoration-thickness

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp (237836 => 237837)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.cpp	2018-11-06 00:45:01 UTC (rev 237837)
@@ -110,6 +110,11 @@
     notifyMutedObservers();
 }
 
+void RealtimeMediaSource::setInterruptedForTesting(bool interrupted)
+{
+    notifyMutedChange(interrupted);
+}
+
 void RealtimeMediaSource::forEachObserver(const WTF::Function<void(Observer&)>& apply) const
 {
     Vector<Observer*> observersCopy;

Modified: trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h (237836 => 237837)


--- trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/RealtimeMediaSource.h	2018-11-06 00:45:01 UTC (rev 237837)
@@ -172,6 +172,7 @@
 
     // Testing only
     virtual void delaySamples(Seconds) { };
+    void setInterruptedForTesting(bool);
 
 protected:
     RealtimeMediaSource(Type, String&& name, String&& deviceID = { }, String&& hashSalt = { });

Modified: trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp (237836 => 237837)


--- trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/platform/mediastream/mac/CoreAudioCaptureSource.cpp	2018-11-06 00:45:01 UTC (rev 237837)
@@ -920,6 +920,7 @@
     scheduleDeferredTask([this, &unit] {
         m_suspendType = unit.isProducingData() ? SuspensionType::WhilePlaying : SuspensionType::WhilePaused;
         unit.suspend();
+        notifyMutedChange(true);
         m_suspendPending = false;
     });
 }
@@ -940,8 +941,10 @@
     scheduleDeferredTask([this, type, &unit] {
         if (m_reconfigurationState == ReconfigurationState::Required)
             unit.reconfigureAudioUnit();
-        if (type == SuspensionType::WhilePlaying)
+        if (type == SuspensionType::WhilePlaying) {
             unit.resume();
+            notifyMutedChange(false);
+        }
         m_reconfigurationState = ReconfigurationState::None;
         m_resumePending = false;
     });

Modified: trunk/Source/WebCore/testing/Internals.cpp (237836 => 237837)


--- trunk/Source/WebCore/testing/Internals.cpp	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.cpp	2018-11-06 00:45:01 UTC (rev 237837)
@@ -4512,6 +4512,12 @@
 {
     track.setIdForTesting(WTFMove(id));
 }
+
+void Internals::setMediaStreamSourceInterrupted(MediaStreamTrack& track, bool interrupted)
+{
+    track.source().setInterruptedForTesting(interrupted);
+}
+
 #endif
 
 String Internals::audioSessionCategory() const

Modified: trunk/Source/WebCore/testing/Internals.h (237836 => 237837)


--- trunk/Source/WebCore/testing/Internals.h	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.h	2018-11-06 00:45:01 UTC (rev 237837)
@@ -678,6 +678,7 @@
     void removeMediaStreamTrack(MediaStream&, MediaStreamTrack&);
     void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack&);
     void setMediaStreamTrackIdentifier(MediaStreamTrack&, String&& id);
+    void setMediaStreamSourceInterrupted(MediaStreamTrack&, bool);
 #endif
 
     String audioSessionCategory() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (237836 => 237837)


--- trunk/Source/WebCore/testing/Internals.idl	2018-11-06 00:21:36 UTC (rev 237836)
+++ trunk/Source/WebCore/testing/Internals.idl	2018-11-06 00:45:01 UTC (rev 237837)
@@ -663,6 +663,7 @@
     [Conditional=MEDIA_STREAM] void removeMediaStreamTrack(MediaStream stream, MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void simulateMediaStreamTrackCaptureSourceFailure(MediaStreamTrack track);
     [Conditional=MEDIA_STREAM] void setMediaStreamTrackIdentifier(MediaStreamTrack track, DOMString identifier);
+    [Conditional=MEDIA_STREAM] void setMediaStreamSourceInterrupted(MediaStreamTrack track, boolean interrupted);
 
     unsigned long long documentIdentifier(Document document);
     boolean isDocumentAlive(unsigned long long documentIdentifier);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to