2015-08-31 15:51:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "MediaEngineRemoteVideoSource.h"
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-08-31 15:51:29 +03:00
|
|
|
#include "VideoUtils.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "MediaTrackConstraints.h"
|
|
|
|
#include "CamerasChild.h"
|
|
|
|
|
2015-11-15 16:49:01 +03:00
|
|
|
extern mozilla::LogModule* GetMediaManagerLog();
|
2015-08-31 15:51:29 +03:00
|
|
|
#define LOG(msg) MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Debug, msg)
|
|
|
|
#define LOGFRAME(msg) MOZ_LOG(GetMediaManagerLog(), mozilla::LogLevel::Verbose, msg)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-01-18 19:15:05 +03:00
|
|
|
// These need a definition somewhere because template
|
|
|
|
// code is allowed to take their address, and they aren't
|
|
|
|
// guaranteed to have one without this.
|
|
|
|
const unsigned int MediaEngineSource::kMaxDeviceNameLength;
|
|
|
|
const unsigned int MediaEngineSource::kMaxUniqueIdLength;;
|
|
|
|
|
2015-08-31 15:51:29 +03:00
|
|
|
using dom::ConstrainLongRange;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS0(MediaEngineRemoteVideoSource)
|
|
|
|
|
|
|
|
MediaEngineRemoteVideoSource::MediaEngineRemoteVideoSource(
|
|
|
|
int aIndex, mozilla::camera::CaptureEngine aCapEngine,
|
|
|
|
dom::MediaSourceEnum aMediaSource, const char* aMonitorName)
|
|
|
|
: MediaEngineCameraVideoSource(aIndex, aMonitorName),
|
|
|
|
mMediaSource(aMediaSource),
|
2016-07-13 23:07:03 +03:00
|
|
|
mCapEngine(aCapEngine)
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aMediaSource != dom::MediaSourceEnum::Other);
|
2016-06-20 07:38:25 +03:00
|
|
|
mSettings.mWidth.Construct(0);
|
|
|
|
mSettings.mHeight.Construct(0);
|
|
|
|
mSettings.mFrameRate.Construct(0);
|
2015-08-31 15:51:29 +03:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineRemoteVideoSource::Init()
|
|
|
|
{
|
|
|
|
LOG((__PRETTY_FUNCTION__));
|
|
|
|
char deviceName[kMaxDeviceNameLength];
|
|
|
|
char uniqueId[kMaxUniqueIdLength];
|
2016-01-18 19:15:05 +03:00
|
|
|
if (mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::GetCaptureDevice,
|
|
|
|
mCapEngine, mCaptureIndex,
|
|
|
|
deviceName, kMaxDeviceNameLength,
|
|
|
|
uniqueId, kMaxUniqueIdLength)) {
|
2015-08-31 15:51:29 +03:00
|
|
|
LOG(("Error initializing RemoteVideoSource (GetCaptureDevice)"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetName(NS_ConvertUTF8toUTF16(deviceName));
|
|
|
|
SetUUID(uniqueId);
|
|
|
|
|
|
|
|
mInitDone = true;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MediaEngineRemoteVideoSource::Shutdown()
|
|
|
|
{
|
|
|
|
LOG((__PRETTY_FUNCTION__));
|
|
|
|
if (!mInitDone) {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-13 23:07:03 +03:00
|
|
|
Super::Shutdown();
|
2015-08-31 15:51:29 +03:00
|
|
|
if (mState == kStarted) {
|
|
|
|
SourceMediaStream *source;
|
|
|
|
bool empty;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
empty = mSources.IsEmpty();
|
|
|
|
if (empty) {
|
2016-04-06 15:56:44 +03:00
|
|
|
MOZ_ASSERT(mPrincipalHandles.IsEmpty());
|
2015-08-31 15:51:29 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
source = mSources[0];
|
|
|
|
}
|
|
|
|
Stop(source, kVideoTrack); // XXX change to support multiple tracks
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(mState == kStopped);
|
|
|
|
}
|
|
|
|
|
2016-06-30 22:43:24 +03:00
|
|
|
for (auto& registered : mRegisteredHandles) {
|
|
|
|
MOZ_ASSERT(mState == kAllocated || mState == kStopped);
|
|
|
|
Deallocate(registered.get());
|
2015-08-31 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
2016-06-30 22:43:24 +03:00
|
|
|
MOZ_ASSERT(mState == kReleased);
|
2015-08-31 15:51:29 +03:00
|
|
|
mInitDone = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-06-30 22:43:24 +03:00
|
|
|
MediaEngineRemoteVideoSource::Allocate(
|
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const nsString& aDeviceId,
|
|
|
|
const nsACString& aOrigin,
|
2016-07-13 06:25:07 +03:00
|
|
|
AllocationHandle** aOutHandle,
|
2016-06-16 02:25:07 +03:00
|
|
|
const char** aOutBadConstraint)
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
LOG((__PRETTY_FUNCTION__));
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-08-31 15:51:29 +03:00
|
|
|
|
2015-10-14 20:08:33 +03:00
|
|
|
if (!mInitDone) {
|
|
|
|
LOG(("Init not done"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:07:03 +03:00
|
|
|
nsresult rv = Super::Allocate(aConstraints, aPrefs, aDeviceId, aOrigin,
|
|
|
|
aOutHandle, aOutBadConstraint);
|
2016-06-18 23:11:54 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2016-06-06 20:15:50 +03:00
|
|
|
}
|
2016-06-18 23:11:54 +03:00
|
|
|
if (mState == kStarted &&
|
|
|
|
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));
|
2015-08-31 15:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-13 06:25:07 +03:00
|
|
|
MediaEngineRemoteVideoSource::Deallocate(AllocationHandle* aHandle)
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
2015-10-14 20:08:33 +03:00
|
|
|
LOG((__PRETTY_FUNCTION__));
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-06-30 22:43:24 +03:00
|
|
|
|
2016-07-13 23:07:03 +03:00
|
|
|
Super::Deallocate(aHandle);
|
|
|
|
|
|
|
|
if (!mRegisteredHandles.Length()) {
|
2015-08-31 15:51:29 +03:00
|
|
|
if (mState != kStopped && mState != kAllocated) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-01-18 19:15:05 +03:00
|
|
|
mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::ReleaseCaptureDevice,
|
|
|
|
mCapEngine, mCaptureIndex);
|
2015-08-31 15:51:29 +03:00
|
|
|
mState = kReleased;
|
|
|
|
LOG(("Video device %d deallocated", mCaptureIndex));
|
|
|
|
} else {
|
|
|
|
LOG(("Video device %d deallocated but still in use", mCaptureIndex));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-04-06 15:56:44 +03:00
|
|
|
MediaEngineRemoteVideoSource::Start(SourceMediaStream* aStream, TrackID aID,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
LOG((__PRETTY_FUNCTION__));
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-08-31 15:51:29 +03:00
|
|
|
if (!mInitDone || !aStream) {
|
|
|
|
LOG(("No stream or init not done"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mSources.AppendElement(aStream);
|
2016-04-06 15:56:44 +03:00
|
|
|
mPrincipalHandles.AppendElement(aPrincipalHandle);
|
|
|
|
MOZ_ASSERT(mSources.Length() == mPrincipalHandles.Length());
|
2015-08-31 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aStream->AddTrack(aID, 0, new VideoSegment(), SourceMediaStream::ADDTRACK_QUEUED);
|
|
|
|
|
|
|
|
if (mState == kStarted) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-04-11 17:13:26 +03:00
|
|
|
mImageContainer =
|
|
|
|
layers::LayerManager::CreateImageContainer(layers::ImageContainer::ASYNCHRONOUS);
|
2015-08-31 15:51:29 +03:00
|
|
|
|
|
|
|
mState = kStarted;
|
|
|
|
mTrackID = aID;
|
|
|
|
|
2016-01-18 19:15:05 +03:00
|
|
|
if (mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::StartCapture,
|
|
|
|
mCapEngine, mCaptureIndex, mCapability, this)) {
|
2015-08-31 15:51:29 +03:00
|
|
|
LOG(("StartCapture failed"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
MediaEngineRemoteVideoSource::Stop(mozilla::SourceMediaStream* aSource,
|
|
|
|
mozilla::TrackID aID)
|
|
|
|
{
|
|
|
|
LOG((__PRETTY_FUNCTION__));
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
2016-04-06 15:56:44 +03:00
|
|
|
size_t i = mSources.IndexOf(aSource);
|
|
|
|
if (i == mSources.NoIndex) {
|
2015-08-31 15:51:29 +03:00
|
|
|
// Already stopped - this is allowed
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-06 15:56:44 +03:00
|
|
|
MOZ_ASSERT(mSources.Length() == mPrincipalHandles.Length());
|
|
|
|
mSources.RemoveElementAt(i);
|
|
|
|
mPrincipalHandles.RemoveElementAt(i);
|
|
|
|
|
2015-08-31 15:51:29 +03:00
|
|
|
aSource->EndTrack(aID);
|
|
|
|
|
|
|
|
if (!mSources.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (mState != kStarted) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mState = kStopped;
|
|
|
|
// Drop any cached image so we don't start with a stale image on next
|
|
|
|
// usage
|
|
|
|
mImage = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-18 19:15:05 +03:00
|
|
|
mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::StopCapture,
|
|
|
|
mCapEngine, mCaptureIndex);
|
2015-08-31 15:51:29 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
nsresult
|
2016-07-13 06:25:07 +03:00
|
|
|
MediaEngineRemoteVideoSource::Restart(AllocationHandle* aHandle,
|
2016-05-25 08:52:15 +03:00
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
2015-09-21 01:45:57 +03:00
|
|
|
const MediaEnginePrefs& aPrefs,
|
2016-06-16 02:25:07 +03:00
|
|
|
const nsString& aDeviceId,
|
|
|
|
const char** aOutBadConstraint)
|
2015-09-21 01:45:57 +03:00
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-09-20 17:04:51 +03:00
|
|
|
if (!mInitDone) {
|
|
|
|
LOG(("Init not done"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-05-25 08:52:15 +03:00
|
|
|
MOZ_ASSERT(aHandle);
|
2016-06-18 21:16:47 +03:00
|
|
|
NormalizedConstraints constraints(aConstraints);
|
2016-07-13 23:07:03 +03:00
|
|
|
return ReevaluateAllocation(aHandle, &constraints, aPrefs, aDeviceId,
|
|
|
|
aOutBadConstraint);
|
2016-06-18 21:16:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-07-13 23:07:03 +03:00
|
|
|
MediaEngineRemoteVideoSource::UpdateSingleSource(
|
|
|
|
const AllocationHandle* aHandle,
|
|
|
|
const NormalizedConstraints& aNetConstraints,
|
|
|
|
const MediaEnginePrefs& aPrefs,
|
|
|
|
const nsString& aDeviceId,
|
|
|
|
const char** aOutBadConstraint)
|
2016-06-18 21:16:47 +03:00
|
|
|
{
|
2016-07-13 23:07:03 +03:00
|
|
|
if (!ChooseCapability(aNetConstraints, aPrefs, aDeviceId)) {
|
|
|
|
*aOutBadConstraint = FindBadConstraint(aNetConstraints, *this, aDeviceId);
|
2016-06-06 20:15:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-09-20 17:04:51 +03:00
|
|
|
}
|
2016-06-18 23:11:54 +03:00
|
|
|
|
|
|
|
switch (mState) {
|
|
|
|
case kReleased:
|
|
|
|
MOZ_ASSERT(aHandle);
|
|
|
|
if (camera::GetChildAndCall(&camera::CamerasChild::AllocateCaptureDevice,
|
|
|
|
mCapEngine, GetUUID().get(),
|
|
|
|
kMaxUniqueIdLength, mCaptureIndex,
|
|
|
|
aHandle->mOrigin)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mState = kAllocated;
|
2016-06-20 07:38:25 +03:00
|
|
|
SetLastCapability(mCapability);
|
2016-06-18 23:11:54 +03:00
|
|
|
LOG(("Video device %d allocated for %s", mCaptureIndex,
|
|
|
|
aHandle->mOrigin.get()));
|
|
|
|
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;
|
|
|
|
}
|
2016-06-20 07:38:25 +03:00
|
|
|
SetLastCapability(mCapability);
|
2016-06-18 23:11:54 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-06-19 02:09:39 +03:00
|
|
|
default:
|
|
|
|
LOG(("Video device %d %s in ignored state %d", mCaptureIndex,
|
2016-06-18 23:11:54 +03:00
|
|
|
(aHandle? aHandle->mOrigin.get() : ""), mState));
|
2016-06-19 02:09:39 +03:00
|
|
|
break;
|
2016-06-18 21:16:47 +03:00
|
|
|
}
|
2015-09-21 01:45:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-20 07:38:25 +03:00
|
|
|
void
|
|
|
|
MediaEngineRemoteVideoSource::SetLastCapability(
|
|
|
|
const webrtc::CaptureCapability& aCapability)
|
|
|
|
{
|
|
|
|
mLastCapability = mCapability;
|
|
|
|
|
|
|
|
webrtc::CaptureCapability cap = aCapability;
|
|
|
|
RefPtr<MediaEngineRemoteVideoSource> that = this;
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(media::NewRunnableFrom([this, that, cap]() mutable {
|
|
|
|
mSettings.mWidth.Value() = cap.width;
|
|
|
|
mSettings.mHeight.Value() = cap.height;
|
|
|
|
mSettings.mFrameRate.Value() = cap.maxFPS;
|
|
|
|
return NS_OK;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2015-08-31 15:51:29 +03:00
|
|
|
void
|
|
|
|
MediaEngineRemoteVideoSource::NotifyPull(MediaStreamGraph* aGraph,
|
|
|
|
SourceMediaStream* aSource,
|
2016-04-06 15:56:44 +03:00
|
|
|
TrackID aID, StreamTime aDesiredTime,
|
|
|
|
const PrincipalHandle& aPrincipalHandle)
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
VideoSegment segment;
|
|
|
|
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
StreamTime delta = aDesiredTime - aSource->GetEndOfAppendedData(aID);
|
|
|
|
|
|
|
|
if (delta > 0) {
|
|
|
|
// nullptr images are allowed
|
2016-04-06 15:56:44 +03:00
|
|
|
AppendToTrack(aSource, mImage, aID, delta, aPrincipalHandle);
|
2015-08-31 15:51:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
MediaEngineRemoteVideoSource::FrameSizeChange(unsigned int w, unsigned int h,
|
|
|
|
unsigned int streams)
|
|
|
|
{
|
|
|
|
mWidth = w;
|
|
|
|
mHeight = h;
|
|
|
|
LOG(("MediaEngineRemoteVideoSource Video FrameSizeChange: %ux%u", w, h));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
MediaEngineRemoteVideoSource::DeliverFrame(unsigned char* buffer,
|
2015-11-18 23:03:25 +03:00
|
|
|
size_t size,
|
2015-08-31 15:51:29 +03:00
|
|
|
uint32_t time_stamp,
|
|
|
|
int64_t ntp_time,
|
|
|
|
int64_t render_time,
|
|
|
|
void *handle)
|
|
|
|
{
|
|
|
|
// Check for proper state.
|
|
|
|
if (mState != kStarted) {
|
|
|
|
LOG(("DeliverFrame: video not started"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-18 23:03:25 +03:00
|
|
|
if ((size_t) (mWidth*mHeight + 2*(((mWidth+1)/2)*((mHeight+1)/2))) != size) {
|
2015-08-31 15:51:29 +03:00
|
|
|
MOZ_ASSERT(false, "Wrong size frame in DeliverFrame!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a video frame and append it to the track.
|
2015-11-17 11:09:01 +03:00
|
|
|
RefPtr<layers::PlanarYCbCrImage> image = mImageContainer->CreatePlanarYCbCrImage();
|
2015-08-31 15:51:29 +03:00
|
|
|
|
|
|
|
uint8_t* frame = static_cast<uint8_t*> (buffer);
|
|
|
|
const uint8_t lumaBpp = 8;
|
|
|
|
const uint8_t chromaBpp = 4;
|
|
|
|
|
|
|
|
// Take lots of care to round up!
|
|
|
|
layers::PlanarYCbCrData data;
|
|
|
|
data.mYChannel = frame;
|
|
|
|
data.mYSize = IntSize(mWidth, mHeight);
|
|
|
|
data.mYStride = (mWidth * lumaBpp + 7)/ 8;
|
|
|
|
data.mCbCrStride = (mWidth * chromaBpp + 7) / 8;
|
|
|
|
data.mCbChannel = frame + mHeight * data.mYStride;
|
|
|
|
data.mCrChannel = data.mCbChannel + ((mHeight+1)/2) * data.mCbCrStride;
|
|
|
|
data.mCbCrSize = IntSize((mWidth+1)/ 2, (mHeight+1)/ 2);
|
|
|
|
data.mPicX = 0;
|
|
|
|
data.mPicY = 0;
|
|
|
|
data.mPicSize = IntSize(mWidth, mHeight);
|
|
|
|
data.mStereoMode = StereoMode::MONO;
|
|
|
|
|
2016-04-19 06:12:41 +03:00
|
|
|
if (!image->CopyData(data)) {
|
2015-11-03 14:24:26 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-31 15:51:29 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static uint32_t frame_num = 0;
|
2015-10-21 00:50:42 +03:00
|
|
|
LOGFRAME(("frame %d (%dx%d); timestamp %u, ntp_time %" PRIu64 ", render_time %" PRIu64,
|
|
|
|
frame_num++, mWidth, mHeight, time_stamp, ntp_time, render_time));
|
2015-08-31 15:51:29 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// we don't touch anything in 'this' until here (except for snapshot,
|
|
|
|
// which has it's own lock)
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
|
|
|
|
// implicitly releases last image
|
|
|
|
mImage = image.forget();
|
|
|
|
|
2016-03-08 14:13:22 +03:00
|
|
|
// We'll push the frame into the MSG on the next NotifyPull. This will avoid
|
|
|
|
// swamping the MSG with frames should it be taking longer than normal to run
|
|
|
|
// an iteration.
|
2015-08-31 15:51:29 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2016-06-21 03:15:39 +03:00
|
|
|
MediaEngineRemoteVideoSource::NumCapabilities() const
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
2016-01-18 19:15:05 +03:00
|
|
|
int num = mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::NumberOfCapabilities,
|
|
|
|
mCapEngine,
|
|
|
|
GetUUID().get());
|
2015-08-31 15:51:29 +03:00
|
|
|
if (num > 0) {
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(mMediaSource) {
|
|
|
|
case dom::MediaSourceEnum::Camera:
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Mac doesn't support capabilities.
|
|
|
|
//
|
|
|
|
// Hardcode generic desktop capabilities modeled on OSX camera.
|
|
|
|
// Note: Values are empirically picked to be OSX friendly, as on OSX, values
|
|
|
|
// other than these cause the source to not produce.
|
|
|
|
|
|
|
|
if (mHardcodedCapabilities.IsEmpty()) {
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
webrtc::CaptureCapability c;
|
|
|
|
c.width = 1920 - i*128;
|
|
|
|
c.height = 1080 - i*72;
|
|
|
|
c.maxFPS = 30;
|
|
|
|
mHardcodedCapabilities.AppendElement(c);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
webrtc::CaptureCapability c;
|
|
|
|
c.width = 640 - i*40;
|
|
|
|
c.height = 480 - i*30;
|
|
|
|
c.maxFPS = 30;
|
|
|
|
mHardcodedCapabilities.AppendElement(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
webrtc::CaptureCapability c;
|
|
|
|
// The default for devices that don't return discrete capabilities: treat
|
|
|
|
// them as supporting all capabilities orthogonally. E.g. screensharing.
|
|
|
|
c.width = 0; // 0 = accept any value
|
|
|
|
c.height = 0;
|
|
|
|
c.maxFPS = 0;
|
|
|
|
mHardcodedCapabilities.AppendElement(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mHardcodedCapabilities.Length();
|
|
|
|
}
|
|
|
|
|
2015-10-05 18:05:00 +03:00
|
|
|
bool
|
2016-05-25 08:52:15 +03:00
|
|
|
MediaEngineRemoteVideoSource::ChooseCapability(
|
|
|
|
const NormalizedConstraints &aConstraints,
|
2015-10-05 18:05:00 +03:00
|
|
|
const MediaEnginePrefs &aPrefs,
|
|
|
|
const nsString& aDeviceId)
|
|
|
|
{
|
2015-10-14 20:08:34 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-10-05 18:05:00 +03:00
|
|
|
|
|
|
|
switch(mMediaSource) {
|
|
|
|
case dom::MediaSourceEnum::Screen:
|
|
|
|
case dom::MediaSourceEnum::Window:
|
|
|
|
case dom::MediaSourceEnum::Application: {
|
|
|
|
FlattenedConstraints c(aConstraints);
|
2016-06-30 23:08:45 +03:00
|
|
|
// The actual resolution to constrain around is not easy to find ahead of
|
|
|
|
// time (and may in fact change over time), so as a hack, we push ideal
|
|
|
|
// and max constraints down to desktop_capture_impl.cc and finish the
|
|
|
|
// algorithm there.
|
|
|
|
mCapability.width = (c.mWidth.mIdeal.valueOr(0) & 0xffff) << 16 |
|
|
|
|
(c.mWidth.mMax & 0xffff);
|
|
|
|
mCapability.height = (c.mHeight.mIdeal.valueOr(0) & 0xffff) << 16 |
|
|
|
|
(c.mHeight.mMax & 0xffff);
|
|
|
|
mCapability.maxFPS = c.mFrameRate.Clamp(c.mFrameRate.mIdeal.valueOr(aPrefs.mFPS));
|
2015-10-05 18:05:00 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return MediaEngineCameraVideoSource::ChooseCapability(aConstraints, aPrefs, aDeviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-31 15:51:29 +03:00
|
|
|
void
|
|
|
|
MediaEngineRemoteVideoSource::GetCapability(size_t aIndex,
|
2016-06-21 03:15:39 +03:00
|
|
|
webrtc::CaptureCapability& aOut) const
|
2015-08-31 15:51:29 +03:00
|
|
|
{
|
|
|
|
if (!mHardcodedCapabilities.IsEmpty()) {
|
|
|
|
MediaEngineCameraVideoSource::GetCapability(aIndex, aOut);
|
|
|
|
}
|
2016-01-18 19:15:05 +03:00
|
|
|
mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::GetCaptureCapability,
|
|
|
|
mCapEngine,
|
|
|
|
GetUUID().get(),
|
|
|
|
aIndex,
|
|
|
|
aOut);
|
2015-08-31 15:51:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MediaEngineRemoteVideoSource::Refresh(int aIndex) {
|
|
|
|
// NOTE: mCaptureIndex might have changed when allocated!
|
|
|
|
// Use aIndex to update information, but don't change mCaptureIndex!!
|
|
|
|
// Caller looked up this source by uniqueId, so it shouldn't change
|
|
|
|
char deviceName[kMaxDeviceNameLength];
|
|
|
|
char uniqueId[kMaxUniqueIdLength];
|
|
|
|
|
2016-01-18 19:15:05 +03:00
|
|
|
if (mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::GetCaptureDevice,
|
|
|
|
mCapEngine, aIndex,
|
|
|
|
deviceName, sizeof(deviceName),
|
|
|
|
uniqueId, sizeof(uniqueId))) {
|
2015-08-31 15:51:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetName(NS_ConvertUTF8toUTF16(deviceName));
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(GetUUID().Equals(uniqueId));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|