Beispiel #1
0
nsresult
MediaEngineRemoteVideoSource::UpdateSingleSource(
    const AllocationHandle* aHandle,
    const NormalizedConstraints& aNetConstraints,
    const MediaEnginePrefs& aPrefs,
    const nsString& aDeviceId,
    const char** aOutBadConstraint)
{
  if (!ChooseCapability(aNetConstraints, aPrefs, aDeviceId)) {
    *aOutBadConstraint = FindBadConstraint(aNetConstraints, *this, aDeviceId);
    return NS_ERROR_FAILURE;
  }

  switch (mState) {
    case kReleased:
      MOZ_ASSERT(aHandle);
      if (camera::GetChildAndCall(&camera::CamerasChild::AllocateCaptureDevice,
                                  mCapEngine, GetUUID().get(),
                                  kMaxUniqueIdLength, mCaptureIndex,
                                  aHandle->mPrincipalInfo)) {
        return NS_ERROR_FAILURE;
      }
      mState = kAllocated;
      SetLastCapability(mCapability);
      LOG(("Video device %d allocated", mCaptureIndex));
      break;

    case kStarted:
      if (mCapability != mLastCapability) {
        camera::GetChildAndCall(&camera::CamerasChild::StopCapture,
                                mCapEngine, mCaptureIndex);
        if (camera::GetChildAndCall(&camera::CamerasChild::StartCapture,
                                    mCapEngine, mCaptureIndex, mCapability,
                                    this)) {
          LOG(("StartCapture failed"));
          return NS_ERROR_FAILURE;
        }
        SetLastCapability(mCapability);
      }
      break;

    default:
      LOG(("Video device %d in ignored state %d", mCaptureIndex, mState));
      break;
  }
  return NS_OK;
}
const char*
MediaConstraintsHelper::FindBadConstraint(
    const NormalizedConstraints& aConstraints,
    const MediaEngineSourceType& aMediaEngineSource,
    const nsString& aDeviceId)
{
  class MockDevice
  {
  public:
    NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MockDevice);

    explicit MockDevice(const MediaEngineSourceType* aMediaEngineSource,
                        const nsString& aDeviceId)
    : mMediaEngineSource(aMediaEngineSource),
      // The following dud code exists to avoid 'unused typedef' error on linux.
      mDeviceId(MockDevice::HasThreadSafeRefCnt::value ? aDeviceId : nsString()) {}

    uint32_t GetBestFitnessDistance(
        const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
        bool aIsChrome)
    {
      return mMediaEngineSource->GetBestFitnessDistance(aConstraintSets,
                                                        mDeviceId);
    }

  private:
    ~MockDevice() {}

    const MediaEngineSourceType* mMediaEngineSource;
    nsString mDeviceId;
  };

  Unused << typename MockDevice::HasThreadSafeRefCnt();

  nsTArray<RefPtr<MockDevice>> devices;
  devices.AppendElement(new MockDevice(&aMediaEngineSource, aDeviceId));
  return FindBadConstraint(aConstraints, devices);
}