summaryrefslogtreecommitdiffstats
path: root/dom/media/DeviceInputTrack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/DeviceInputTrack.cpp')
-rw-r--r--dom/media/DeviceInputTrack.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/dom/media/DeviceInputTrack.cpp b/dom/media/DeviceInputTrack.cpp
index 5d69f7107a..3bf2e87558 100644
--- a/dom/media/DeviceInputTrack.cpp
+++ b/dom/media/DeviceInputTrack.cpp
@@ -316,6 +316,20 @@ bool DeviceInputTrack::HasVoiceInput() const {
return false;
}
+cubeb_input_processing_params DeviceInputTrack::RequestedProcessingParams()
+ const {
+ AssertOnGraphThreadOrNotRunning();
+ Maybe<cubeb_input_processing_params> params;
+ for (const auto& listener : mListeners) {
+ if (params) {
+ *params &= listener->RequestedInputProcessingParams(mGraph);
+ } else {
+ params = Some(listener->RequestedInputProcessingParams(mGraph));
+ }
+ }
+ return params.valueOr(CUBEB_INPUT_PROCESSING_PARAM_NONE);
+}
+
void DeviceInputTrack::DeviceChanged(MediaTrackGraph* aGraph) const {
AssertOnGraphThreadOrNotRunning();
MOZ_ASSERT(aGraph == mGraph,
@@ -326,6 +340,16 @@ void DeviceInputTrack::DeviceChanged(MediaTrackGraph* aGraph) const {
}
}
+void DeviceInputTrack::NotifySetRequestedProcessingParamsResult(
+ MediaTrackGraph* aGraph, cubeb_input_processing_params aRequestedParams,
+ const Result<cubeb_input_processing_params, int>& aResult) {
+ AssertOnGraphThread();
+ for (const auto& listener : mListeners) {
+ listener->NotifySetRequestedInputProcessingParamsResult(
+ mGraph, aRequestedParams, aResult);
+ }
+}
+
void DeviceInputTrack::ReevaluateInputDevice() {
MOZ_ASSERT(NS_IsMainThread());
QueueControlMessageWithNoShutdown([self = RefPtr{this}, this] {
@@ -491,6 +515,8 @@ void NonNativeInputTrack::ProcessInput(GraphTime aFrom, GraphTime aTo,
// GraphRunner keeps the same thread.
MOZ_ASSERT(!HasGraphThreadChanged());
+ ReevaluateProcessingParams();
+
AudioSegment data = mAudioSource->GetAudioSegment(delta, consumer);
MOZ_ASSERT(data.GetDuration() == delta);
GetData<AudioSegment>()->AppendFrom(&data);
@@ -512,6 +538,8 @@ void NonNativeInputTrack::StartAudio(
mGraphThreadId = std::this_thread::get_id();
#endif
mAudioSource = std::move(aAudioInputSource);
+ mAudioSource->Init();
+ ReevaluateProcessingParams();
mAudioSource->Start();
}
@@ -571,6 +599,35 @@ AudioInputSource::Id NonNativeInputTrack::GenerateSourceId() {
return mSourceIdNumber++;
}
+void NonNativeInputTrack::ReevaluateProcessingParams() {
+ AssertOnGraphThread();
+ MOZ_ASSERT(mAudioSource);
+ auto params = RequestedProcessingParams();
+ if (mRequestedProcessingParams == params) {
+ return;
+ }
+ mRequestedProcessingParams = params;
+ using Promise = AudioInputSource::SetRequestedProcessingParamsPromise;
+ mAudioSource->SetRequestedProcessingParams(params)->Then(
+ GetMainThreadSerialEventTarget(), __func__,
+ [this, self = RefPtr(this),
+ params](Promise::ResolveOrRejectValue&& aValue) {
+ if (IsDestroyed()) {
+ return;
+ }
+ auto result = ([&]() -> Result<cubeb_input_processing_params, int> {
+ if (aValue.IsResolve()) {
+ return aValue.ResolveValue();
+ }
+ return Err(aValue.RejectValue());
+ })();
+ QueueControlMessageWithNoShutdown(
+ [this, self = RefPtr(this), params, result = std::move(result)] {
+ NotifySetRequestedProcessingParamsResult(Graph(), params, result);
+ });
+ });
+}
+
#ifdef DEBUG
bool NonNativeInputTrack::HasGraphThreadChanged() {
AssertOnGraphThread();