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
This commit is contained in:
Andreas Pehrson 2018-02-01 17:00:59 +01:00
parent f52aa5b27e
commit 0c896f9aef

View File

@ -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<const AllocationHandle>& 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<AllocationHandle>& 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.