From 0c896f9aef5f3ca86d6d80e5e22d992dcc46528b Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Thu, 1 Feb 2018 17:00:59 +0100 Subject: [PATCH] Bug 1434946 - Set framerate in settings when capabilities are updated. r=jib This adds back the `framerate` update that was removed in bug 1299515. It also fixes a threading issue (not really an issue, but it broke the documented policy) where Start() wrote to mCapability without holding mMutex. MozReview-Commit-ID: Jda5moNhlkM --HG-- extra : rebase_source : a8f27f064b9f818eb29aa72a18605786c474631b --- .../webrtc/MediaEngineRemoteVideoSource.cpp | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index 243b9db0d1de..e2b0108401c9 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -46,6 +46,7 @@ MediaEngineRemoteVideoSource::MediaEngineRemoteVideoSource( MOZ_ASSERT(aMediaSource != MediaSourceEnum::Other); mSettings->mWidth.Construct(0); mSettings->mHeight.Construct(0); + mSettings->mFrameRate.Construct(0); Init(); } @@ -187,13 +188,14 @@ MediaEngineRemoteVideoSource::Allocate( MOZ_ASSERT(mState == kReleased); NormalizedConstraints constraints(aConstraints); - LOG(("ChooseCapability(kFitness) for mTargetCapability and mCapability (Allocate) ++")); - if (!ChooseCapability(constraints, aPrefs, aDeviceId, mCapability, kFitness)) { + webrtc::CaptureCapability newCapability; + LOG(("ChooseCapability(kFitness) for mCapability (Allocate) ++")); + if (!ChooseCapability(constraints, aPrefs, aDeviceId, newCapability, kFitness)) { *aOutBadConstraint = MediaConstraintsHelper::FindBadConstraint(constraints, this, aDeviceId); return NS_ERROR_FAILURE; } - LOG(("ChooseCapability(kFitness) for mTargetCapability and mCapability (Allocate) --")); + LOG(("ChooseCapability(kFitness) for mCapability (Allocate) --")); if (camera::GetChildAndCall(&camera::CamerasChild::AllocateCaptureDevice, mCapEngine, mUniqueId.get(), @@ -207,6 +209,7 @@ MediaEngineRemoteVideoSource::Allocate( { MutexAutoLock lock(mMutex); mState = kAllocated; + mCapability = newCapability; } LOG(("Video device %d allocated", mCaptureIndex)); @@ -304,6 +307,13 @@ MediaEngineRemoteVideoSource::Start(const RefPtr& aHandl return NS_ERROR_FAILURE; } + NS_DispatchToMainThread(NS_NewRunnableFunction( + "MediaEngineRemoteVideoSource::SetLastCapability", + [settings = mSettings, cap = mCapability]() mutable { + settings->mWidth.Value() = cap.width; + settings->mHeight.Value() = cap.height; + settings->mFrameRate.Value() = cap.maxFPS; + })); return NS_OK; } @@ -360,9 +370,11 @@ MediaEngineRemoteVideoSource::Reconfigure(const RefPtr& aHandl return NS_OK; } - // Start() applies mCapability on the device. - mCapability = newCapability; - + { + MutexAutoLock lock(mMutex); + // Start() applies mCapability on the device. + mCapability = newCapability; + } if (mState == kStarted) { // Allocate always returns a null AllocationHandle.