nsresult MediaEngineWebRTCVideoSource::Allocate(const dom::MediaTrackConstraints &aConstraints, const MediaEnginePrefs &aPrefs) { LOG((__FUNCTION__)); if (mState == kReleased && mInitDone) { // 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(aConstraints, aPrefs)) { return NS_ERROR_UNEXPECTED; } if (mViECapture->AllocateCaptureDevice(GetUUID().get(), kMaxUniqueIdLength, mCaptureIndex)) { return NS_ERROR_FAILURE; } mState = kAllocated; LOG(("Video device %d allocated", mCaptureIndex)); } else if (MOZ_LOG_TEST(GetMediaManagerLog(), LogLevel::Debug)) { MonitorAutoLock lock(mMonitor); if (mSources.IsEmpty()) { LOG(("Video device %d reallocated", mCaptureIndex)); } else { LOG(("Video device %d allocated shared", mCaptureIndex)); } } return NS_OK; }
nsresult MediaEngineGonkVideoSource::Allocate(const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs, const nsString& aDeviceId, const nsACString& aOrigin, AllocationHandle** aOutHandle, const char** aOutBadConstraint) { LOG((__FUNCTION__)); ReentrantMonitorAutoEnter sync(mCallbackMonitor); if (mState == kReleased && mInitDone) { NormalizedConstraints constraints(aConstraints); ChooseCapability(constraints, aPrefs, aDeviceId); NS_DispatchToMainThread(WrapRunnable(RefPtr<MediaEngineGonkVideoSource>(this), &MediaEngineGonkVideoSource::AllocImpl)); mCallbackMonitor.Wait(); if (mState != kAllocated) { return NS_ERROR_FAILURE; } } *aOutHandle = nullptr; return NS_OK; }
nsresult MediaEngineWebRTCVideoSource::Allocate(const VideoTrackConstraintsN &aConstraints, const MediaEnginePrefs &aPrefs) { LOG((__FUNCTION__)); if (mState == kReleased && mInitDone) { // Note: if shared, we don't allow a later opener to affect the resolution. // (This may change depending on spec changes for Constraints/settings) ChooseCapability(aConstraints, aPrefs); if (mViECapture->AllocateCaptureDevice(NS_ConvertUTF16toUTF8(mUniqueId).get(), kMaxUniqueIdLength, mCaptureIndex)) { return NS_ERROR_FAILURE; } mState = kAllocated; LOG(("Video device %d allocated", mCaptureIndex)); } else if (mSources.IsEmpty()) { LOG(("Video device %d reallocated", mCaptureIndex)); } else { LOG(("Video device %d allocated shared", mCaptureIndex)); } return NS_OK; }
nsresult MediaEngineWebRTCVideoSource::Allocate(const MediaEnginePrefs &aPrefs) { LOG((__FUNCTION__)); #ifdef MOZ_B2G_CAMERA ReentrantMonitorAutoEnter sync(mCallbackMonitor); if (mState == kReleased && mInitDone) { ChooseCapability(aPrefs); NS_DispatchToMainThread(WrapRunnable(this, &MediaEngineWebRTCVideoSource::AllocImpl)); mCallbackMonitor.Wait(); if (mState != kAllocated) { return NS_ERROR_FAILURE; } } #else if (mState == kReleased && mInitDone) { // Note: if shared, we don't allow a later opener to affect the resolution. // (This may change depending on spec changes for Constraints/settings) ChooseCapability(aPrefs); if (mViECapture->AllocateCaptureDevice(NS_ConvertUTF16toUTF8(mUniqueId).get(), KMaxUniqueIdLength, mCaptureIndex)) { return NS_ERROR_FAILURE; } mState = kAllocated; LOG(("Video device %d allocated", mCaptureIndex)); } else if (mSources.IsEmpty()) { LOG(("Video device %d reallocated", mCaptureIndex)); } else { LOG(("Video device %d allocated shared", mCaptureIndex)); } #endif return NS_OK; }
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; }
nsresult MediaEngineGonkVideoSource::Allocate(const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs) { LOG((__FUNCTION__)); ReentrantMonitorAutoEnter sync(mCallbackMonitor); if (mState == kReleased && mInitDone) { ChooseCapability(aConstraints, aPrefs); NS_DispatchToMainThread(WrapRunnable(nsRefPtr<MediaEngineGonkVideoSource>(this), &MediaEngineGonkVideoSource::AllocImpl)); mCallbackMonitor.Wait(); if (mState != kAllocated) { return NS_ERROR_FAILURE; } } return NS_OK; }
nsresult MediaEngineRemoteVideoSource::Restart(const dom::MediaTrackConstraints& aConstraints, const MediaEnginePrefs& aPrefs, const nsString& aDeviceId) { if (!mInitDone) { LOG(("Init not done")); return NS_ERROR_FAILURE; } if (!ChooseCapability(aConstraints, aPrefs, aDeviceId)) { return NS_ERROR_NOT_AVAILABLE; } if (mState != kStarted) { return NS_OK; } mozilla::camera::StopCapture(mCapEngine, mCaptureIndex); if (mozilla::camera::StartCapture(mCapEngine, mCaptureIndex, mCapability, this)) { LOG(("StartCapture failed")); return NS_ERROR_FAILURE; } return NS_OK; }