From 210228f94eae33ad86fefc7cc38580e10f76eefd Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 14 Feb 2018 16:35:45 +0100 Subject: [PATCH] Bug 1436074 - Reduce turn-off timer by time since we turned on. r=jib MozReview-Commit-ID: 2AvnJxUSTmy --HG-- extra : rebase_source : c0f0755c15e9ed564f333856125a1c1a9e05b4bf --- dom/media/MediaManager.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 44d18c6b727a..fa0e16eaef24 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -174,6 +174,10 @@ struct DeviceState { // MainThread only. bool mTrackEnabled = false; + // Time when the application last enabled mDevice. + // MainThread only. + TimeStamp mTrackEnabledTime; + // true if an operation to Start() or Stop() mDevice has been dispatched to // the media thread and is not finished yet. // MainThread only. @@ -3904,6 +3908,7 @@ SourceListener::InitializeAsync() state->mDeviceEnabled = true; state->mTrackEnabled = true; + state->mTrackEnabledTime = TimeStamp::Now(); } return InitPromise::CreateAndResolve(true, __func__); }, [self = RefPtr(this), this](RefPtr&& aResult) @@ -4079,14 +4084,20 @@ SourceListener::SetEnabledFor(TrackID aTrackID, bool aEnable) RefPtr timerPromise; if (aEnable) { timerPromise = MediaTimerPromise::CreateAndResolve(true, __func__); + state.mTrackEnabledTime = TimeStamp::Now(); } else { - const TimeDuration offDelay = TimeDuration::FromMilliseconds( + const TimeDuration maxDelay = TimeDuration::FromMilliseconds( Preferences::GetUint( aTrackID == kAudioTrack ? "media.getusermedia.microphone.off_while_disabled.delay_ms" : "media.getusermedia.camera.off_while_disabled.delay_ms", 3000)); - timerPromise = state.mDisableTimer->WaitFor(offDelay, __func__); + const TimeDuration durationEnabled = + TimeStamp::Now() - state.mTrackEnabledTime; + const TimeDuration delay = + TimeDuration::Max(TimeDuration::FromMilliseconds(0), + maxDelay - durationEnabled); + timerPromise = state.mDisableTimer->WaitFor(delay, __func__); } typedef MozPromise DeviceOperationPromise;