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
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -41,16 +41,17 @@ MediaEngineRemoteVideoSource::MediaEngin
, mMutex("MediaEngineRemoteVideoSource::mMutex")
, mRescalingBufferPool(/* zero_initialize */ false,
/* max_number_of_buffers */ 1)
, mSettings(MakeAndAddRef<media::Refcountable<MediaTrackSettings>>())
{
MOZ_ASSERT(aMediaSource != MediaSourceEnum::Other);
mSettings->mWidth.Construct(0);
mSettings->mHeight.Construct(0);
+ mSettings->mFrameRate.Construct(0);
Init();
}
void
MediaEngineRemoteVideoSource::Init()
{
LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
@@ -182,36 +183,38 @@ MediaEngineRemoteVideoSource::Allocate(
{
LOG((__PRETTY_FUNCTION__));
AssertIsOnOwningThread();
MOZ_ASSERT(mInitDone);
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(),
kMaxUniqueIdLength, mCaptureIndex,
aPrincipalInfo)) {
return NS_ERROR_FAILURE;
}
*aOutHandle = nullptr;
{
MutexAutoLock lock(mMutex);
mState = kAllocated;
+ mCapability = newCapability;
}
LOG(("Video device %d allocated", mCaptureIndex));
return NS_OK;
}
nsresult
MediaEngineRemoteVideoSource::Deallocate(const RefPtr<const AllocationHandle>& aHandle)
@@ -299,16 +302,23 @@ MediaEngineRemoteVideoSource::Start(cons
if (camera::GetChildAndCall(&camera::CamerasChild::StartCapture,
mCapEngine, mCaptureIndex, mCapability, this)) {
LOG(("StartCapture failed"));
MutexAutoLock lock(mMutex);
mState = kStopped;
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;
}
nsresult
MediaEngineRemoteVideoSource::Stop(const RefPtr<const AllocationHandle>& aHandle)
{
LOG((__PRETTY_FUNCTION__));
@@ -355,19 +365,21 @@ MediaEngineRemoteVideoSource::Reconfigur
return NS_ERROR_FAILURE;
}
LOG(("ChooseCapability(kFitness) for mTargetCapability (Reconfigure) --"));
if (mCapability == newCapability) {
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.
// We can safely pass nullptr below.
nsresult rv = Stop(nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}