Bug 1829068 don't reject for setSinkId() on media element because of MediaElementAudioSourceNode r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D181974
This commit is contained in:
Karl Tomlinson 2023-06-27 08:53:50 +00:00
parent 41a31832a4
commit 7fa10acf9d
3 changed files with 53 additions and 2 deletions

View File

@ -4438,8 +4438,8 @@ RefPtr<GenericPromise> MediaDecoderStateMachine::SetSink(
}
if (mOutputCaptureState != MediaDecoder::OutputCaptureState::None) {
// Not supported yet.
return GenericPromise::CreateAndReject(NS_ERROR_ABORT, __func__);
// Nothing to do.
return GenericPromise::CreateAndResolve(IsPlaying(), __func__);
}
if (mSinkDevice.Ref() != aDevice) {

View File

@ -0,0 +1,2 @@
[setSinkId-with-MediaElementAudioSourceNode.https.html]
prefs: [media.setsinkid.enabled:true]

View File

@ -0,0 +1,49 @@
<!doctype html>
<head>
<title>Test HTMLMediaElement.setSinkId() with MediaElementAudioSourceNode</title>
<link rel="help" href="https://webaudio.github.io/web-audio-api/#MediaElementAudioSourceNode">
</head>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script>
"use strict";
/*
MediaElementAudioSourceNode silences HTMLMediaElement output to underlying
devices but setSinkId() should still function as if there were no
MediaElementAudioSourceNode according to
"The HTMLMediaElement MUST behave in an identical fashion after the
MediaElementAudioSourceNode has been created, except that the rendered audio
will no longer be heard directly, but instead will be heard as a consequence
of the MediaElementAudioSourceNode being connected through the routing graph."
*/
let audio;
promise_setup(async () => {
audio = new Audio();
audio.src = "/media/sound_5.oga";
audio.autoplay = true;
audio.loop = true;
new AudioContext().createMediaElementSource(audio);
await new Promise(r => audio.onplay = r);
});
promise_test(t => audio.setSinkId(""), "setSinkId on default audio output should always work");
promise_test(t => promise_rejects_dom(t, "NotFoundError", audio.setSinkId("nonexistent_device_id")),
"setSinkId fails with NotFoundError on made up deviceid");
promise_test(async t => {
await test_driver.bless('transient activation for selectAudioOutput()');
const {deviceId} = await navigator.mediaDevices.selectAudioOutput();
assert_greater_than(deviceId.length, 0, "deviceId.length");
const p1 = audio.setSinkId(deviceId);
assert_equals(audio.sinkId, "", "before it resolves, setSinkId is unchanged");
await p1;
assert_equals(audio.sinkId, deviceId, "setSinkId updates sinkId to the requested deviceId");
await audio.setSinkId("");
assert_equals(audio.sinkId, "", "resetting sink ID to default audio output should always work");
}, "setSinkId() with output device ID exposed by selectAudioOutput() should resolve");
</script>