summaryrefslogtreecommitdiffstats
path: root/dom/media/GraphDriver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/GraphDriver.cpp')
-rw-r--r--dom/media/GraphDriver.cpp141
1 files changed, 132 insertions, 9 deletions
diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp
index 744de30bb5..b37aaa010a 100644
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -342,6 +342,13 @@ class AudioCallbackDriver::FallbackWrapper : public GraphInterface {
uint32_t aAlreadyBuffered) override {
MOZ_CRASH("Unexpected NotifyInputData from fallback SystemClockDriver");
}
+ void NotifySetRequestedInputProcessingParamsResult(
+ AudioCallbackDriver* aDriver,
+ cubeb_input_processing_params aRequestedParams,
+ Result<cubeb_input_processing_params, int>&& aResult) override {
+ MOZ_CRASH(
+ "Unexpected processing params result from fallback SystemClockDriver");
+ }
void DeviceChanged() override {
MOZ_CRASH("Unexpected DeviceChanged from fallback SystemClockDriver");
}
@@ -448,20 +455,17 @@ NS_IMPL_ISUPPORTS0(AudioCallbackDriver::FallbackWrapper)
/* static */
already_AddRefed<TaskQueue> AudioCallbackDriver::CreateTaskQueue() {
- RefPtr<SharedThreadPool> pool = CUBEB_TASK_THREAD;
- const uint32_t kIdleThreadTimeoutMs = 2000;
- pool->SetIdleThreadTimeout(PR_MillisecondsToInterval(kIdleThreadTimeoutMs));
-
- RefPtr<TaskQueue> queue =
- TaskQueue::Create(pool.forget(), "AudioCallbackDriver cubeb task queue");
- return queue.forget();
+ return TaskQueue::Create(CubebUtils::GetCubebOperationThread(),
+ "AudioCallbackDriver cubeb task queue")
+ .forget();
}
AudioCallbackDriver::AudioCallbackDriver(
GraphInterface* aGraphInterface, GraphDriver* aPreviousDriver,
uint32_t aSampleRate, uint32_t aOutputChannelCount,
uint32_t aInputChannelCount, CubebUtils::AudioDeviceID aOutputDeviceID,
- CubebUtils::AudioDeviceID aInputDeviceID, AudioInputType aAudioInputType)
+ CubebUtils::AudioDeviceID aInputDeviceID, AudioInputType aAudioInputType,
+ cubeb_input_processing_params aRequestedInputProcessingParams)
: GraphDriver(aGraphInterface, aPreviousDriver, aSampleRate),
mOutputChannelCount(aOutputChannelCount),
mInputChannelCount(aInputChannelCount),
@@ -469,6 +473,7 @@ AudioCallbackDriver::AudioCallbackDriver(
mInputDeviceID(aInputDeviceID),
mIterationDurationMS(MEDIA_GRAPH_TARGET_PERIOD_MS),
mCubebOperationThread(CreateTaskQueue()),
+ mRequestedInputProcessingParams(aRequestedInputProcessingParams),
mAudioThreadId(ProfilerThreadId{}),
mAudioThreadIdInCb(std::thread::id()),
mFallback("AudioCallbackDriver::mFallback"),
@@ -485,7 +490,12 @@ AudioCallbackDriver::AudioCallbackDriver(
if (aAudioInputType == AudioInputType::Voice &&
StaticPrefs::
media_getusermedia_microphone_prefer_voice_stream_with_processing_enabled()) {
- LOG(LogLevel::Debug, ("VOICE."));
+ LOG(LogLevel::Debug,
+ ("%p: AudioCallbackDriver %p ctor - using VOICE and requesting input "
+ "processing params %s.",
+ Graph(), this,
+ CubebUtils::ProcessingParamsToString(aRequestedInputProcessingParams)
+ .get()));
mInputDevicePreference = CUBEB_DEVICE_PREF_VOICE;
CubebUtils::SetInCommunication(true);
} else {
@@ -670,6 +680,10 @@ void AudioCallbackDriver::Init(const nsCString& aStreamName) {
PanOutputIfNeeded(inputWanted);
#endif
+ if (inputWanted && InputDevicePreference() == AudioInputType::Voice) {
+ SetInputProcessingParams(mRequestedInputProcessingParams);
+ }
+
cubeb_stream_register_device_changed_callback(
mAudioStream, AudioCallbackDriver::DeviceChangedCallback_s);
@@ -1256,6 +1270,11 @@ TimeDuration AudioCallbackDriver::AudioOutputLatency() {
mSampleRate);
}
+bool AudioCallbackDriver::HasFallback() const {
+ MOZ_ASSERT(InIteration());
+ return mFallbackDriverState != FallbackDriverState::None;
+}
+
bool AudioCallbackDriver::OnFallback() const {
MOZ_ASSERT(InIteration());
return mFallbackDriverState == FallbackDriverState::Running;
@@ -1309,6 +1328,9 @@ void AudioCallbackDriver::FallbackToSystemClockDriver() {
void AudioCallbackDriver::FallbackDriverStopped(GraphTime aIterationEnd,
GraphTime aStateComputedTime,
FallbackDriverState aState) {
+ LOG(LogLevel::Debug,
+ ("%p: AudioCallbackDriver %p Fallback driver has stopped.", Graph(),
+ this));
mIterationEnd = aIterationEnd;
mStateComputedTime = aStateComputedTime;
mNextReInitAttempt = TimeStamp();
@@ -1367,6 +1389,107 @@ void AudioCallbackDriver::MaybeStartAudioStream() {
Start();
}
+cubeb_input_processing_params
+AudioCallbackDriver::RequestedInputProcessingParams() const {
+ MOZ_ASSERT(InIteration());
+ return mRequestedInputProcessingParams;
+}
+
+void AudioCallbackDriver::SetRequestedInputProcessingParams(
+ cubeb_input_processing_params aParams) {
+ MOZ_ASSERT(InIteration());
+ if (mRequestedInputProcessingParams == aParams) {
+ return;
+ }
+ LOG(LogLevel::Info,
+ ("AudioCallbackDriver %p, Input processing params %s requested.", this,
+ CubebUtils::ProcessingParamsToString(aParams).get()));
+ mRequestedInputProcessingParams = aParams;
+ MOZ_ALWAYS_SUCCEEDS(mCubebOperationThread->Dispatch(
+ NS_NewRunnableFunction(__func__, [this, self = RefPtr(this), aParams] {
+ SetInputProcessingParams(aParams);
+ })));
+}
+
+void AudioCallbackDriver::SetInputProcessingParams(
+ cubeb_input_processing_params aParams) {
+ MOZ_ASSERT(OnCubebOperationThread());
+ auto requested = aParams;
+ auto result = ([&]() -> Maybe<Result<cubeb_input_processing_params, int>> {
+ // This function decides how to handle the request.
+ // Returning Nothing() does nothing, because either
+ // 1) there is no update since the previous state, or
+ // 2) handling is deferred to a later time.
+ // Returning Some() result will forward that result to
+ // AudioDataListener::OnInputProcessingParamsResult on the callback
+ // thread.
+ if (!mAudioStream) {
+ // No Init yet.
+ LOG(LogLevel::Debug, ("AudioCallbackDriver %p, has no cubeb stream to "
+ "set processing params on!",
+ this));
+ return Nothing();
+ }
+ if (mAudioStreamState == AudioStreamState::None) {
+ // Driver (and cubeb stream) was stopped.
+ return Nothing();
+ }
+ cubeb_input_processing_params supported;
+ auto handle = CubebUtils::GetCubeb();
+ int r = cubeb_get_supported_input_processing_params(handle->Context(),
+ &supported);
+ if (r != CUBEB_OK) {
+ LOG(LogLevel::Debug,
+ ("AudioCallbackDriver %p, no supported processing params", this));
+ return Some(Err(CUBEB_ERROR_NOT_SUPPORTED));
+ }
+ aParams &= supported;
+ LOG(LogLevel::Debug,
+ ("AudioCallbackDriver %p, requested processing params %s reduced to %s "
+ "by supported params %s",
+ this, CubebUtils::ProcessingParamsToString(requested).get(),
+ CubebUtils::ProcessingParamsToString(aParams).get(),
+ CubebUtils::ProcessingParamsToString(supported).get()));
+ if (aParams == mConfiguredInputProcessingParams) {
+ LOG(LogLevel::Debug,
+ ("AudioCallbackDriver %p, no change in processing params %s. Not "
+ "attempting reconfiguration.",
+ this, CubebUtils::ProcessingParamsToString(aParams).get()));
+ return Some(aParams);
+ }
+ mConfiguredInputProcessingParams = aParams;
+ r = cubeb_stream_set_input_processing_params(mAudioStream, aParams);
+ if (r == CUBEB_OK) {
+ LOG(LogLevel::Info,
+ ("AudioCallbackDriver %p, input processing params set to %s", this,
+ CubebUtils::ProcessingParamsToString(aParams).get()));
+ return Some(aParams);
+ }
+ LOG(LogLevel::Info,
+ ("AudioCallbackDriver %p, failed setting input processing params to "
+ "%s. r=%d",
+ this, CubebUtils::ProcessingParamsToString(aParams).get(), r));
+ return Some(Err(r));
+ })();
+ if (!result) {
+ return;
+ }
+ MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(
+ NS_NewRunnableFunction(__func__, [this, self = RefPtr(this), requested,
+ result = result.extract()]() mutable {
+ LOG(LogLevel::Debug,
+ ("AudioCallbackDriver %p, Notifying of input processing params %s. "
+ "r=%d",
+ this,
+ CubebUtils::ProcessingParamsToString(
+ result.unwrapOr(CUBEB_INPUT_PROCESSING_PARAM_NONE))
+ .get(),
+ result.isErr() ? result.inspectErr() : CUBEB_OK));
+ mGraphInterface->NotifySetRequestedInputProcessingParamsResult(
+ this, requested, std::move(result));
+ })));
+}
+
} // namespace mozilla
// avoid redefined macro in unified build