2013-03-27 05:32:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AudioStreamTrack.h"
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
#include "MediaTrackGraph.h"
|
2017-10-13 06:57:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-07-31 10:58:17 +03:00
|
|
|
void AudioStreamTrack::AddAudioOutput(void* aKey) {
|
|
|
|
if (Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 17:03:30 +03:00
|
|
|
if (UniquePtr<CrossGraphManager>* cgm = mCrossGraphs.Get(aKey)) {
|
|
|
|
(*cgm)->AddAudioOutput(aKey);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-02 13:23:02 +03:00
|
|
|
mTrack->AddAudioOutput(aKey);
|
2019-07-31 10:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamTrack::RemoveAudioOutput(void* aKey) {
|
|
|
|
if (Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 17:03:30 +03:00
|
|
|
if (UniquePtr<CrossGraphManager>* cgm = mCrossGraphs.Get(aKey)) {
|
|
|
|
(*cgm)->RemoveAudioOutput(aKey);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-02 13:23:02 +03:00
|
|
|
mTrack->RemoveAudioOutput(aKey);
|
2019-07-31 10:58:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioStreamTrack::SetAudioOutputVolume(void* aKey, float aVolume) {
|
|
|
|
if (Ended()) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 17:03:30 +03:00
|
|
|
if (UniquePtr<CrossGraphManager>* cgm = mCrossGraphs.Get(aKey)) {
|
|
|
|
(*cgm)->SetAudioOutputVolume(aKey, aVolume);
|
|
|
|
return;
|
|
|
|
}
|
2019-10-02 13:23:02 +03:00
|
|
|
mTrack->SetAudioOutputVolume(aKey, aVolume);
|
2019-07-31 10:58:17 +03:00
|
|
|
}
|
|
|
|
|
2017-10-13 06:57:25 +03:00
|
|
|
void AudioStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) {
|
|
|
|
if (nsContentUtils::ResistFingerprinting(aCallerType)) {
|
|
|
|
aLabel.AssignLiteral("Internal Microphone");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MediaStreamTrack::GetLabel(aLabel, aCallerType);
|
|
|
|
}
|
|
|
|
|
2019-08-19 22:26:25 +03:00
|
|
|
already_AddRefed<MediaStreamTrack> AudioStreamTrack::CloneInternal() {
|
2019-10-02 13:23:02 +03:00
|
|
|
return do_AddRef(new AudioStreamTrack(mWindow, mInputTrack, mSource,
|
2019-11-20 18:24:34 +03:00
|
|
|
ReadyState(), Muted(), mConstraints));
|
2019-08-19 22:26:25 +03:00
|
|
|
}
|
|
|
|
|
2020-06-12 17:03:30 +03:00
|
|
|
void AudioStreamTrack::SetReadyState(MediaStreamTrackState aState) {
|
|
|
|
if (!mCrossGraphs.IsEmpty() && !Ended() &&
|
|
|
|
mReadyState == MediaStreamTrackState::Live &&
|
|
|
|
aState == MediaStreamTrackState::Ended) {
|
|
|
|
for (auto iter = mCrossGraphs.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
(*iter.Data())->Destroy();
|
|
|
|
(*iter.Data()).reset();
|
|
|
|
}
|
|
|
|
mCrossGraphs.Clear();
|
|
|
|
}
|
|
|
|
MediaStreamTrack::SetReadyState(aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<GenericPromise> AudioStreamTrack::SetAudioOutputDevice(
|
|
|
|
void* key, AudioDeviceInfo* aSink) {
|
2020-07-09 17:32:21 +03:00
|
|
|
MOZ_ASSERT(aSink);
|
|
|
|
if (Ended()) {
|
|
|
|
return GenericPromise::CreateAndResolve(true, __func__);
|
|
|
|
}
|
2020-06-12 17:03:30 +03:00
|
|
|
CrossGraphManager* manager = CrossGraphManager::Connect(this, aSink, mWindow);
|
|
|
|
if (!manager) {
|
|
|
|
auto entry = mCrossGraphs.Lookup(key);
|
|
|
|
MOZ_ASSERT(entry);
|
|
|
|
(*entry.Data())->Destroy();
|
|
|
|
entry.Remove();
|
|
|
|
return GenericPromise::CreateAndResolve(true, __func__);
|
|
|
|
}
|
|
|
|
UniquePtr<CrossGraphManager>* crossGraphPtr = mCrossGraphs.LookupOrAdd(key);
|
|
|
|
if (*crossGraphPtr) {
|
|
|
|
(*crossGraphPtr)->Destroy();
|
|
|
|
}
|
|
|
|
(*crossGraphPtr).reset(manager);
|
|
|
|
return manager->EnsureConnected();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|