Backed out changeset 6f025025d259 (bug 1213517)
authorIris Hsiao <ihsiao@mozilla.com>
Mon, 18 Jul 2016 15:40:41 +0800
changeset 330354 4e9cca9e01249e26ac496239fc92ef4a48dec00f
parent 330353 f925108ff4d308487c870d196d7f4cf98dbbcde8
child 330355 aa39f9c1df60ecc1aaa8948f88cda22b163caabd
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1213517
milestone50.0a1
backs out6f025025d2597e95ef01c04b8d97f12c047c941e
Backed out changeset 6f025025d259 (bug 1213517)
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -108,61 +108,45 @@ MediaEngineRemoteVideoSource::Allocate(
   LOG((__PRETTY_FUNCTION__));
   AssertIsOnOwningThread();
 
   if (!mInitDone) {
     LOG(("Init not done"));
     return NS_ERROR_FAILURE;
   }
 
-  AutoTArray<const NormalizedConstraints*, 10> allConstraints;
-  for (auto& registered : mRegisteredHandles) {
-    allConstraints.AppendElement(&registered->mConstraints);
-  }
   RefPtr<AllocationHandle> handle = new AllocationHandle(aConstraints);
-  allConstraints.AppendElement(&handle->mConstraints);
-
-  NormalizedConstraints netConstraints(allConstraints);
-  if (netConstraints.mOverconstrained) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (!ChooseCapability(netConstraints, aPrefs, aDeviceId)) {
-    return NS_ERROR_FAILURE;
-  }
+  mRegisteredHandles.AppendElement(handle);
 
   if (mState == kReleased) {
+    // Note: if shared, we don't allow a later opener to affect the resolution.
+    // (This may change depending on spec changes for Constraints/settings)
+
+    if (!ChooseCapability(handle->mConstraints, aPrefs, aDeviceId)) {
+      return NS_ERROR_UNEXPECTED;
+    }
+
     if (mozilla::camera::GetChildAndCall(
       &mozilla::camera::CamerasChild::AllocateCaptureDevice,
       mCapEngine, GetUUID().get(), kMaxUniqueIdLength, mCaptureIndex, aOrigin)) {
       return NS_ERROR_FAILURE;
     }
     mState = kAllocated;
     LOG(("Video device %d allocated for %s", mCaptureIndex,
          PromiseFlatCString(aOrigin).get()));
-  } else {
-    camera::GetChildAndCall(&camera::CamerasChild::StopCapture, mCapEngine,
-                            mCaptureIndex);
-    if (camera::GetChildAndCall(&camera::CamerasChild::StartCapture, mCapEngine,
-                                mCaptureIndex, mCapability, this)) {
-      LOG(("StartCapture failed"));
-      return NS_ERROR_FAILURE;
-    }
-    if (MOZ_LOG_TEST(GetMediaManagerLog(), mozilla::LogLevel::Debug)) {
-      MonitorAutoLock lock(mMonitor);
-      if (mSources.IsEmpty()) {
-        MOZ_ASSERT(mPrincipalHandles.IsEmpty());
-        LOG(("Video device %d reallocated", mCaptureIndex));
-      } else {
-        LOG(("Video device %d allocated shared", mCaptureIndex));
-      }
+  } else if (MOZ_LOG_TEST(GetMediaManagerLog(), mozilla::LogLevel::Debug)) {
+    MonitorAutoLock lock(mMonitor);
+    if (mSources.IsEmpty()) {
+      MOZ_ASSERT(mPrincipalHandles.IsEmpty());
+      LOG(("Video device %d reallocated", mCaptureIndex));
+    } else {
+      LOG(("Video device %d allocated shared", mCaptureIndex));
     }
   }
 
-  mRegisteredHandles.AppendElement(handle);
   ++mNrAllocations;
   handle.forget(aOutHandle);
   return NS_OK;
 }
 
 nsresult
 MediaEngineRemoteVideoSource::Deallocate(BaseAllocationHandle* aHandle)
 {
@@ -287,50 +271,33 @@ MediaEngineRemoteVideoSource::Restart(Ba
 {
   AssertIsOnOwningThread();
   if (!mInitDone) {
     LOG(("Init not done"));
     return NS_ERROR_FAILURE;
   }
   MOZ_ASSERT(aHandle);
   auto handle = static_cast<AllocationHandle*>(aHandle);
-  RefPtr<AllocationHandle> temp = new AllocationHandle(aConstraints);
-  temp->mConstraints = NormalizedConstraints(aConstraints);
-
-  AutoTArray<const NormalizedConstraints*, 10> allConstraints;
-  for (auto& registered : mRegisteredHandles) {
-    if (registered.get() == handle) {
-      continue; // Don't count old constraints
-    }
-    allConstraints.AppendElement(&registered->mConstraints);
-  }
-  allConstraints.AppendElement(&temp->mConstraints);
-
-  NormalizedConstraints netConstraints(allConstraints);
-  if (netConstraints.mOverconstrained) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (!ChooseCapability(netConstraints, aPrefs, aDeviceId)) {
-    return NS_ERROR_FAILURE;
+  handle->mConstraints = NormalizedConstraints(aConstraints);
+  if (!ChooseCapability(handle->mConstraints, aPrefs, aDeviceId)) {
+    return NS_ERROR_NOT_AVAILABLE;
   }
   if (mState != kStarted) {
     return NS_OK;
   }
 
   mozilla::camera::GetChildAndCall(
     &mozilla::camera::CamerasChild::StopCapture,
     mCapEngine, mCaptureIndex);
   if (mozilla::camera::GetChildAndCall(
     &mozilla::camera::CamerasChild::StartCapture,
     mCapEngine, mCaptureIndex, mCapability, this)) {
     LOG(("StartCapture failed"));
     return NS_ERROR_FAILURE;
   }
-  handle->mConstraints = temp->mConstraints;
   return NS_OK;
 }
 
 void
 MediaEngineRemoteVideoSource::NotifyPull(MediaStreamGraph* aGraph,
                                          SourceMediaStream* aSource,
                                          TrackID aID, StreamTime aDesiredTime,
                                          const PrincipalHandle& aPrincipalHandle)