Bug 1786306 merge AudioStreamTrack::SetAudioOutputDevice() into AddAudioOutput() r=padenot

The SetAudioOutputDevice() implementation required a subsequent
AddAudioOutput() call, so there is no need to have separate methods.

Differential Revision: https://phabricator.services.mozilla.com/D158310
This commit is contained in:
Karl Tomlinson 2022-09-30 04:13:35 +00:00
Родитель c61cd6d03d
Коммит 703b1dbfda
3 изменённых файлов: 29 добавлений и 48 удалений

Просмотреть файл

@ -764,11 +764,8 @@ class HTMLMediaElement::MediaStreamRenderer
for (const auto& t : mAudioTracks) {
if (t) {
if (mAudioOutputSink) {
t->AsAudioStreamTrack()->SetAudioOutputDevice(mAudioOutputKey,
mAudioOutputSink);
}
t->AsAudioStreamTrack()->AddAudioOutput(mAudioOutputKey);
t->AsAudioStreamTrack()->AddAudioOutput(mAudioOutputKey,
mAudioOutputSink);
t->AsAudioStreamTrack()->SetAudioOutputVolume(mAudioOutputKey,
mAudioOutputVolume);
}
@ -831,13 +828,9 @@ class HTMLMediaElement::MediaStreamRenderer
nsTArray<RefPtr<GenericPromise>> promises;
for (const auto& t : mAudioTracks) {
// SetAudioOutputDevice will create a new output MediaTrack, so the
// AudioOutput is removed for the current MediaTrack and re-added after
// the new MediaTrack has been created.
t->AsAudioStreamTrack()->RemoveAudioOutput(mAudioOutputKey);
promises.AppendElement(t->AsAudioStreamTrack()->SetAudioOutputDevice(
promises.AppendElement(t->AsAudioStreamTrack()->AddAudioOutput(
mAudioOutputKey, mAudioOutputSink));
t->AsAudioStreamTrack()->AddAudioOutput(mAudioOutputKey);
t->AsAudioStreamTrack()->SetAudioOutputVolume(mAudioOutputKey,
mAudioOutputVolume);
}
@ -855,10 +848,7 @@ class HTMLMediaElement::MediaStreamRenderer
mAudioTracks.AppendElement(aTrack);
EnsureGraphTimeDummy();
if (mRendering) {
if (mAudioOutputSink) {
aTrack->SetAudioOutputDevice(mAudioOutputKey, mAudioOutputSink);
}
aTrack->AddAudioOutput(mAudioOutputKey);
aTrack->AddAudioOutput(mAudioOutputKey, mAudioOutputSink);
aTrack->SetAudioOutputVolume(mAudioOutputKey, mAudioOutputVolume);
}
}

Просмотреть файл

@ -10,15 +10,29 @@
namespace mozilla::dom {
void AudioStreamTrack::AddAudioOutput(void* aKey) {
RefPtr<GenericPromise> AudioStreamTrack::AddAudioOutput(
void* aKey, AudioDeviceInfo* aSink) {
MOZ_ASSERT(!mCrossGraphs.Get(aKey),
"A previous audio output for this aKey should have been removed");
if (Ended()) {
return;
return GenericPromise::CreateAndResolve(true, __func__);
}
if (CrossGraphPort* cgm = mCrossGraphs.Get(aKey)) {
cgm->AddAudioOutput(aKey);
return;
UniquePtr<CrossGraphPort> manager;
if (!aSink || !(manager = CrossGraphPort::Connect(this, aSink, mWindow))) {
// We are setting the default output device.
mTrack->AddAudioOutput(aKey);
return GenericPromise::CreateAndResolve(true, __func__);
}
mTrack->AddAudioOutput(aKey);
// We are setting a non-default output device.
const UniquePtr<CrossGraphPort>& crossGraph = mCrossGraphs.WithEntryHandle(
aKey, [&manager](auto entry) -> UniquePtr<CrossGraphPort>& {
return entry.Insert(std::move(manager));
});
crossGraph->AddAudioOutput(aKey);
return crossGraph->EnsureConnected();
}
void AudioStreamTrack::RemoveAudioOutput(void* aKey) {
@ -67,29 +81,4 @@ void AudioStreamTrack::SetReadyState(MediaStreamTrackState aState) {
MediaStreamTrack::SetReadyState(aState);
}
RefPtr<GenericPromise> AudioStreamTrack::SetAudioOutputDevice(
void* aKey, AudioDeviceInfo* aSink) {
MOZ_ASSERT(aSink);
MOZ_ASSERT(!mCrossGraphs.Get(aKey),
"A previous audio output for this aKey should have been removed");
if (Ended()) {
return GenericPromise::CreateAndResolve(true, __func__);
}
UniquePtr<CrossGraphPort> manager =
CrossGraphPort::Connect(this, aSink, mWindow);
if (!manager) {
// We are setting the default output device.
return GenericPromise::CreateAndResolve(true, __func__);
}
// We are setting a non-default output device.
const UniquePtr<CrossGraphPort>& crossGraph = mCrossGraphs.WithEntryHandle(
aKey, [&manager](auto entry) -> UniquePtr<CrossGraphPort>& {
return entry.Insert(std::move(manager));
});
return crossGraph->EnsureConnected();
}
} // namespace mozilla::dom

Просмотреть файл

@ -27,11 +27,13 @@ class AudioStreamTrack : public MediaStreamTrack {
AudioStreamTrack* AsAudioStreamTrack() override { return this; }
const AudioStreamTrack* AsAudioStreamTrack() const override { return this; }
void AddAudioOutput(void* aKey);
// Direct output to aSink, or the default output device if aSink is null.
// No more than one output may exist for a single aKey at any one time.
// Returns a promise that resolves immediately for the default device or
// when a non-default device is processing audio.
RefPtr<GenericPromise> AddAudioOutput(void* aKey, AudioDeviceInfo* aSink);
void RemoveAudioOutput(void* aKey);
void SetAudioOutputVolume(void* aKey, float aVolume);
RefPtr<GenericPromise> SetAudioOutputDevice(void* key,
AudioDeviceInfo* aSink);
// WebIDL
void GetKind(nsAString& aKind) override { aKind.AssignLiteral("audio"); }