Allow AudioContext to start when getUserMedia is on
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 17:26:34 +0000 (17:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 17:26:34 +0000 (17:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180680

Patch by Youenn Fablet <youenn@apple.com> on 2017-12-12
Reviewed by Eric Carlson.

Source/WebCore:

Test: webrtc/getUserMedia-webaudio-autoplay.html

* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::willBeginPlayback):

LayoutTests:

* webrtc/getUserMedia-webaudio-autoplay-expected.txt: Added.
* webrtc/getUserMedia-webaudio-autoplay.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/webrtc/getUserMedia-webaudio-autoplay-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/getUserMedia-webaudio-autoplay.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioContext.cpp

index 8fbc9ac..5fa4622 100644 (file)
@@ -1,3 +1,13 @@
+2017-12-12  Youenn Fablet  <youenn@apple.com>
+
+        Allow AudioContext to start when getUserMedia is on
+        https://bugs.webkit.org/show_bug.cgi?id=180680
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/getUserMedia-webaudio-autoplay-expected.txt: Added.
+        * webrtc/getUserMedia-webaudio-autoplay.html: Added.
+
 2017-12-12  Ms2ger  <Ms2ger@igalia.com>
 
         [WPE] Enable some wpt tests.
diff --git a/LayoutTests/webrtc/getUserMedia-webaudio-autoplay-expected.txt b/LayoutTests/webrtc/getUserMedia-webaudio-autoplay-expected.txt
new file mode 100644 (file)
index 0000000..8333534
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS Ensuring autoplay does not work when starting an audio node and getUserMedia is off 
+PASS Ensuring autoplay works when resuming audio context and getUserMedia is off 
+PASS Ensuring autoplay works when starting an audio node and getUserMedia is on 
+PASS Ensuring autoplay works when resuming audio context and getUserMedia is on 
+
diff --git a/LayoutTests/webrtc/getUserMedia-webaudio-autoplay.html b/LayoutTests/webrtc/getUserMedia-webaudio-autoplay.html
new file mode 100644 (file)
index 0000000..723e7a9
--- /dev/null
@@ -0,0 +1,73 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing webaudio autoplay in case of camera capture</title>
+        <script src="../resources/testharness.js"></script>
+        <script src="../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script>
+test(() => {
+    assert_true(!!window.internals, "Test requires internals API");
+
+    var context = new webkitAudioContext();
+    internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+    var node = context.createBufferSource();
+    node.connect(context.destination);
+    node.start();
+}, "Ensuring autoplay does not work when starting an audio node and getUserMedia is off");
+
+promise_test((test) => {
+    if (!window.internals)
+        return Promise.reject("Test requires internals API");
+
+    var context = new webkitAudioContext();
+    internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+    var node = context.createBufferSource();
+    node.connect(context.destination);
+
+    var resolve, reject;
+    var promise = new Promise((res, rej) => {
+        resolve = res;
+        reject = rej;
+    });
+    context.resume().then(() => {
+        reject("context should not have resumed");
+    });
+    setTimeout(() => {
+        resolve();
+    }, 50);
+    return promise;
+}, "Ensuring autoplay works when resuming audio context and getUserMedia is off");
+
+promise_test((test) => {
+    if (!window.internals)
+        return Promise.reject("Test requires internals API");
+    return navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
+        var context = new webkitAudioContext();
+        internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+        var node = context.createBufferSource();
+        node.connect(context.destination);
+        node.start();
+    });
+}, "Ensuring autoplay works when starting an audio node and getUserMedia is on");
+
+promise_test((test) => {
+    if (!window.internals)
+        return Promise.reject("Test requires internals API");
+    return navigator.mediaDevices.getUserMedia({audio: true}).then((stream) => {
+        var context = new webkitAudioContext();
+        internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+        var node = context.createBufferSource();
+        node.connect(context.destination);
+        return context.resume();
+    });
+}, "Ensuring autoplay works when resuming audio context and getUserMedia is on");
+        </script>
+    </body>
+</html>
index 6c72bd2..94b8154 100644 (file)
@@ -1,3 +1,15 @@
+2017-12-12  Youenn Fablet  <youenn@apple.com>
+
+        Allow AudioContext to start when getUserMedia is on
+        https://bugs.webkit.org/show_bug.cgi?id=180680
+
+        Reviewed by Eric Carlson.
+
+        Test: webrtc/getUserMedia-webaudio-autoplay.html
+
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::willBeginPlayback):
+
 2017-12-12  Romain Bellessort  <romain.bellessort@crf.canon.fr>
 
         [Readable Streams API] Throw RangeError if a size is provided when creating a readable byte stream
index a1101ae..e5732dc 100644 (file)
@@ -984,7 +984,7 @@ void AudioContext::nodeWillBeginPlayback()
 bool AudioContext::willBeginPlayback()
 {
     if (userGestureRequiredForAudioStart()) {
-        if (!processingUserGestureForMedia())
+        if (!processingUserGestureForMedia() && !document()->isCapturing())
             return false;
         removeBehaviorRestriction(AudioContext::RequireUserGestureForAudioStartRestriction);
     }