mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1628779 - Add a method on DOMWindowUtils to query an estimate of the round trip latency of the default audio devices. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D75333
This commit is contained in:
parent
6b95c980a2
commit
4bbaca0e14
@ -2218,6 +2218,50 @@ nsDOMWindowUtils::GetCurrentPreferredSampleRate(uint32_t* aRate) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::DefaultDevicesRoundTripLatency(Promise** aOutPromise) {
|
||||
NS_ENSURE_ARG_POINTER(aOutPromise);
|
||||
*aOutPromise = nullptr;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> outer = do_QueryReferent(mWindow);
|
||||
NS_ENSURE_STATE(outer);
|
||||
nsCOMPtr<nsPIDOMWindowInner> inner = outer->GetCurrentInnerWindow();
|
||||
NS_ENSURE_STATE(inner);
|
||||
|
||||
ErrorResult err;
|
||||
RefPtr<Promise> promise = Promise::Create(inner->AsGlobal(), err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
NS_ADDREF(promise.get());
|
||||
void* p = reinterpret_cast<void*>(promise.get());
|
||||
NS_DispatchBackgroundTask(
|
||||
NS_NewRunnableFunction("DefaultDevicesRoundTripLatency", [p]() {
|
||||
double mean, stddev;
|
||||
bool success =
|
||||
CubebUtils::EstimatedRoundTripLatencyDefaultDevices(&mean, &stddev);
|
||||
|
||||
NS_DispatchToMainThread(NS_NewRunnableFunction(
|
||||
"DefaultDevicesRoundTripLatency", [p, success, mean, stddev]() {
|
||||
Promise* promise = reinterpret_cast<Promise*>(p);
|
||||
if (!success) {
|
||||
promise->MaybeReject(NS_ERROR_FAILURE);
|
||||
NS_RELEASE(promise);
|
||||
return;
|
||||
}
|
||||
nsTArray<double> a;
|
||||
a.AppendElement(mean);
|
||||
a.AppendElement(stddev);
|
||||
promise->MaybeResolve(a);
|
||||
NS_RELEASE(promise);
|
||||
}));
|
||||
}));
|
||||
|
||||
promise.forget(aOutPromise);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMWindowUtils::AudioDevices(uint16_t aSide, nsIArray** aDevices) {
|
||||
NS_ENSURE_ARG_POINTER(aDevices);
|
||||
|
@ -1346,6 +1346,13 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
*/
|
||||
readonly attribute unsigned long currentMaxAudioChannels;
|
||||
|
||||
/**
|
||||
* Returns the mean round trip latency in seconds for the default input and
|
||||
* output device, and the stddev of this latency, as a two element array when
|
||||
* the Promise succeeds.
|
||||
*/
|
||||
Promise defaultDevicesRoundTripLatency();
|
||||
|
||||
/**
|
||||
* Returns the preferred sample rate of the current audio device.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user