2015-08-31 15:51:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et ft=cpp : */
|
2012-07-12 15:53:08 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
#include "MediaEngineWebRTC.h"
|
2013-02-20 19:18:54 +04:00
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
#include "AllocationHandle.h"
|
|
|
|
#include "CamerasChild.h"
|
2013-01-12 03:30:20 +04:00
|
|
|
#include "CSFLog.h"
|
2014-06-27 16:23:55 +04:00
|
|
|
#include "MediaEngineTabVideoSource.h"
|
2015-08-31 15:51:29 +03:00
|
|
|
#include "MediaEngineRemoteVideoSource.h"
|
2014-04-18 23:15:10 +04:00
|
|
|
#include "MediaTrackConstraints.h"
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
#include "mozilla/Logging.h"
|
|
|
|
#include "nsIComponentRegistrar.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsITabSource.h"
|
|
|
|
#include "prenv.h"
|
2013-10-18 00:48:30 +04:00
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
static mozilla::LazyLogModule sGetUserMediaLog("GetUserMedia");
|
2013-05-02 16:00:12 +04:00
|
|
|
#undef LOG
|
2016-05-06 16:11:17 +03:00
|
|
|
#define LOG(args) MOZ_LOG(sGetUserMediaLog, mozilla::LogLevel::Debug, args)
|
2013-05-02 16:00:12 +04:00
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
namespace mozilla {
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2016-01-23 04:40:26 +03:00
|
|
|
// statics from AudioInputCubeb
|
2016-01-23 06:36:26 +03:00
|
|
|
nsTArray<int>* AudioInputCubeb::mDeviceIndexes;
|
2016-04-21 08:42:50 +03:00
|
|
|
int AudioInputCubeb::mDefaultDevice = -1;
|
2016-01-23 06:36:26 +03:00
|
|
|
nsTArray<nsCString>* AudioInputCubeb::mDeviceNames;
|
2017-05-25 08:28:24 +03:00
|
|
|
cubeb_device_collection AudioInputCubeb::mDevices = { nullptr, 0 };
|
2016-01-21 19:51:36 +03:00
|
|
|
bool AudioInputCubeb::mAnyInUse = false;
|
2016-04-01 07:18:13 +03:00
|
|
|
StaticMutex AudioInputCubeb::sMutex;
|
2017-06-30 07:01:17 +03:00
|
|
|
uint32_t AudioInputCubeb::sUserChannelCount = 0;
|
2016-01-21 19:51:36 +03:00
|
|
|
|
2016-03-08 20:11:09 +03:00
|
|
|
// AudioDeviceID is an annoying opaque value that's really a string
|
|
|
|
// pointer, and is freed when the cubeb_device_collection is destroyed
|
|
|
|
|
|
|
|
void AudioInputCubeb::UpdateDeviceList()
|
|
|
|
{
|
2018-03-26 21:14:47 +03:00
|
|
|
// We keep all the device names, but wipe the mappings and rebuild them.
|
|
|
|
// Do this first so that if cubeb has failed we've unmapped our devices
|
|
|
|
// before we early return. Otherwise we'd keep the old list.
|
|
|
|
for (auto& device_index : (*mDeviceIndexes)) {
|
|
|
|
device_index = -1; // unmapped
|
|
|
|
}
|
|
|
|
|
2016-08-31 03:20:10 +03:00
|
|
|
cubeb* cubebContext = CubebUtils::GetCubebContext();
|
|
|
|
if (!cubebContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-25 08:28:24 +03:00
|
|
|
cubeb_device_collection devices = { nullptr, 0 };
|
2016-03-08 20:11:09 +03:00
|
|
|
|
2016-08-31 03:20:10 +03:00
|
|
|
if (CUBEB_OK != cubeb_enumerate_devices(cubebContext,
|
2016-03-08 20:11:09 +03:00
|
|
|
CUBEB_DEVICE_TYPE_INPUT,
|
|
|
|
&devices)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate translation from existing mDevices to new devices. Note we
|
|
|
|
// never end up with less devices than before, since people have
|
|
|
|
// stashed indexes.
|
|
|
|
// For some reason the "fake" device for automation is marked as DISABLED,
|
|
|
|
// so white-list it.
|
2016-04-21 08:42:50 +03:00
|
|
|
mDefaultDevice = -1;
|
2017-05-25 08:28:24 +03:00
|
|
|
for (uint32_t i = 0; i < devices.count; i++) {
|
2016-09-15 16:33:34 +03:00
|
|
|
LOG(("Cubeb device %u: type 0x%x, state 0x%x, name %s, id %p",
|
2017-05-25 08:28:24 +03:00
|
|
|
i, devices.device[i].type, devices.device[i].state,
|
|
|
|
devices.device[i].friendly_name, devices.device[i].device_id));
|
|
|
|
if (devices.device[i].type == CUBEB_DEVICE_TYPE_INPUT && // paranoia
|
2018-04-12 00:12:28 +03:00
|
|
|
devices.device[i].state == CUBEB_DEVICE_STATE_ENABLED )
|
2016-03-08 20:11:09 +03:00
|
|
|
{
|
2017-05-25 08:28:24 +03:00
|
|
|
auto j = mDeviceNames->IndexOf(devices.device[i].device_id);
|
2016-03-08 20:11:09 +03:00
|
|
|
if (j != nsTArray<nsCString>::NoIndex) {
|
|
|
|
// match! update the mapping
|
|
|
|
(*mDeviceIndexes)[j] = i;
|
|
|
|
} else {
|
|
|
|
// new device, add to the array
|
|
|
|
mDeviceIndexes->AppendElement(i);
|
2017-05-25 08:28:24 +03:00
|
|
|
mDeviceNames->AppendElement(devices.device[i].device_id);
|
2016-11-20 10:04:21 +03:00
|
|
|
j = mDeviceIndexes->Length()-1;
|
2016-03-08 20:11:09 +03:00
|
|
|
}
|
2017-05-25 08:28:24 +03:00
|
|
|
if (devices.device[i].preferred & CUBEB_DEVICE_PREF_VOICE) {
|
2016-04-21 08:42:50 +03:00
|
|
|
// There can be only one... we hope
|
|
|
|
NS_ASSERTION(mDefaultDevice == -1, "multiple default cubeb input devices!");
|
2016-10-24 18:26:07 +03:00
|
|
|
mDefaultDevice = j;
|
2016-04-21 08:42:50 +03:00
|
|
|
}
|
2016-03-08 20:11:09 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-15 16:33:34 +03:00
|
|
|
LOG(("Cubeb default input device %d", mDefaultDevice));
|
2016-04-01 07:18:13 +03:00
|
|
|
StaticMutexAutoLock lock(sMutex);
|
2016-03-08 20:11:09 +03:00
|
|
|
// swap state
|
2017-05-25 08:28:24 +03:00
|
|
|
cubeb_device_collection_destroy(cubebContext, &mDevices);
|
2016-03-08 20:11:09 +03:00
|
|
|
mDevices = devices;
|
|
|
|
}
|
|
|
|
|
2013-12-06 23:34:40 +04:00
|
|
|
MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
: mMutex("MediaEngineWebRTC::mMutex"),
|
2016-01-21 19:51:36 +03:00
|
|
|
mAudioInput(nullptr),
|
2016-04-20 03:20:45 +03:00
|
|
|
mFullDuplex(aPrefs.mFullDuplex),
|
2017-10-17 23:27:20 +03:00
|
|
|
mDelayAgnostic(aPrefs.mDelayAgnostic),
|
|
|
|
mExtendedFilter(aPrefs.mExtendedFilter),
|
2016-08-16 06:06:50 +03:00
|
|
|
mHasTabVideoSource(false)
|
2013-10-18 00:48:30 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIComponentRegistrar> compMgr;
|
|
|
|
NS_GetComponentRegistrar(getter_AddRefs(compMgr));
|
|
|
|
if (compMgr) {
|
|
|
|
compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
|
|
|
|
}
|
2016-08-11 20:04:49 +03:00
|
|
|
|
|
|
|
camera::GetChildAndCall(
|
|
|
|
&camera::CamerasChild::AddDeviceChangeCallback,
|
|
|
|
this);
|
2013-10-18 00:48:30 +04:00
|
|
|
}
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2016-08-09 11:37:04 +03:00
|
|
|
void
|
|
|
|
MediaEngineWebRTC::SetFakeDeviceChangeEvents()
|
|
|
|
{
|
|
|
|
camera::GetChildAndCall(
|
|
|
|
&camera::CamerasChild::SetFakeDeviceChangeEvents);
|
|
|
|
}
|
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
void
|
2018-05-07 20:33:41 +03:00
|
|
|
MediaEngineWebRTC::EnumerateVideoDevices(uint64_t aWindowId,
|
|
|
|
dom::MediaSourceEnum aMediaSource,
|
|
|
|
nsTArray<RefPtr<MediaEngineSource> >* aSources)
|
2012-07-12 15:53:08 +04:00
|
|
|
{
|
2018-05-07 20:33:41 +03:00
|
|
|
mMutex.AssertCurrentThreadOwns();
|
2013-05-02 16:00:12 +04:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
mozilla::camera::CaptureEngine capEngine = mozilla::camera::InvalidEngine;
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
bool scaryKind = false; // flag sources with cross-origin exploit potential
|
|
|
|
|
|
|
|
switch (aMediaSource) {
|
|
|
|
case dom::MediaSourceEnum::Window:
|
|
|
|
capEngine = mozilla::camera::WinEngine;
|
|
|
|
break;
|
|
|
|
case dom::MediaSourceEnum::Application:
|
|
|
|
capEngine = mozilla::camera::AppEngine;
|
|
|
|
break;
|
|
|
|
case dom::MediaSourceEnum::Screen:
|
|
|
|
capEngine = mozilla::camera::ScreenEngine;
|
|
|
|
scaryKind = true;
|
|
|
|
break;
|
|
|
|
case dom::MediaSourceEnum::Browser:
|
|
|
|
capEngine = mozilla::camera::BrowserEngine;
|
|
|
|
scaryKind = true;
|
|
|
|
break;
|
|
|
|
case dom::MediaSourceEnum::Camera:
|
|
|
|
capEngine = mozilla::camera::CameraEngine;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("No valid video engine");
|
|
|
|
break;
|
|
|
|
}
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
/*
|
|
|
|
* We still enumerate every time, in case a new device was plugged in since
|
|
|
|
* the last call. TODO: Verify that WebRTC actually does deal with hotplugging
|
|
|
|
* new devices (with or without new engine creation) and accordingly adjust.
|
|
|
|
* Enumeration is not neccessary if GIPS reports the same set of devices
|
|
|
|
* for a given instance of the engine. Likewise, if a device was plugged out,
|
|
|
|
* mVideoSources must be updated.
|
|
|
|
*/
|
|
|
|
int num;
|
|
|
|
num = mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::NumberOfCaptureDevices,
|
|
|
|
capEngine);
|
|
|
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
|
|
|
char deviceName[MediaEngineSource::kMaxDeviceNameLength];
|
|
|
|
char uniqueId[MediaEngineSource::kMaxUniqueIdLength];
|
|
|
|
bool scarySource = false;
|
|
|
|
|
|
|
|
// paranoia
|
|
|
|
deviceName[0] = '\0';
|
|
|
|
uniqueId[0] = '\0';
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::GetCaptureDevice,
|
|
|
|
capEngine,
|
|
|
|
i, deviceName,
|
|
|
|
sizeof(deviceName), uniqueId,
|
|
|
|
sizeof(uniqueId),
|
|
|
|
&scarySource);
|
|
|
|
if (error) {
|
|
|
|
LOG(("camera:GetCaptureDevice: Failed %d", error ));
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-13 05:46:52 +04:00
|
|
|
#ifdef DEBUG
|
2018-05-07 20:33:41 +03:00
|
|
|
LOG((" Capture Device Index %d, Name %s", i, deviceName));
|
|
|
|
|
|
|
|
webrtc::CaptureCapability cap;
|
|
|
|
int numCaps = mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::NumberOfCapabilities,
|
|
|
|
capEngine,
|
|
|
|
uniqueId);
|
|
|
|
LOG(("Number of Capabilities %d", numCaps));
|
|
|
|
for (int j = 0; j < numCaps; j++) {
|
|
|
|
if (mozilla::camera::GetChildAndCall(
|
|
|
|
&mozilla::camera::CamerasChild::GetCaptureCapability,
|
|
|
|
capEngine,
|
|
|
|
uniqueId,
|
|
|
|
j, cap) != 0) {
|
|
|
|
break;
|
2012-10-04 20:09:35 +04:00
|
|
|
}
|
2018-05-07 20:33:41 +03:00
|
|
|
LOG(("type=%d width=%d height=%d maxFPS=%d",
|
|
|
|
cap.rawType, cap.width, cap.height, cap.maxFPS ));
|
|
|
|
}
|
2012-10-04 20:09:35 +04:00
|
|
|
#endif
|
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
if (uniqueId[0] == '\0') {
|
|
|
|
// In case a device doesn't set uniqueId!
|
|
|
|
strncpy(uniqueId, deviceName, sizeof(uniqueId));
|
|
|
|
uniqueId[sizeof(uniqueId)-1] = '\0'; // strncpy isn't safe
|
|
|
|
}
|
2018-01-31 21:02:00 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
NS_ConvertUTF8toUTF16 uuid(uniqueId);
|
|
|
|
RefPtr<MediaEngineSource> vSource;
|
2018-01-31 21:02:00 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineSource>*
|
|
|
|
devicesForThisWindow = mVideoSources.LookupOrAdd(aWindowId);
|
|
|
|
|
|
|
|
if (devicesForThisWindow->Get(uuid, getter_AddRefs(vSource)) &&
|
|
|
|
vSource->RequiresSharing()) {
|
|
|
|
// We've already seen this shared device, just refresh and append.
|
|
|
|
static_cast<MediaEngineRemoteVideoSource*>(vSource.get())->Refresh(i);
|
|
|
|
aSources->AppendElement(vSource.get());
|
|
|
|
} else {
|
|
|
|
vSource = new MediaEngineRemoteVideoSource(i, capEngine, aMediaSource,
|
|
|
|
scaryKind || scarySource);
|
|
|
|
devicesForThisWindow->Put(uuid, vSource);
|
|
|
|
aSources->AppendElement(vSource);
|
2012-10-17 04:53:55 +04:00
|
|
|
}
|
2018-05-07 20:33:41 +03:00
|
|
|
}
|
2015-07-24 15:28:16 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
if (mHasTabVideoSource || dom::MediaSourceEnum::Browser == aMediaSource) {
|
|
|
|
aSources->AppendElement(new MediaEngineTabVideoSource());
|
|
|
|
}
|
|
|
|
}
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
void
|
|
|
|
MediaEngineWebRTC::EnumerateMicrophoneDevices(uint64_t aWindowId,
|
|
|
|
nsTArray<RefPtr<MediaEngineSource> >* aSources)
|
|
|
|
{
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
2012-07-12 15:53:08 +04:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
if (!mAudioInput) {
|
|
|
|
if (!SupportsDuplex()) {
|
|
|
|
return;
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
}
|
2018-05-07 20:33:41 +03:00
|
|
|
mAudioInput = new mozilla::AudioInputCubeb();
|
|
|
|
}
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
int nDevices = 0;
|
|
|
|
mAudioInput->GetNumOfRecordingDevices(nDevices);
|
|
|
|
int i;
|
2017-07-24 03:08:55 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2018-05-07 20:33:41 +03:00
|
|
|
i = 0; // Bug 1037025 - let the OS handle defaulting for now on android/b2g
|
2014-07-10 21:15:26 +04:00
|
|
|
#else
|
2018-05-07 20:33:41 +03:00
|
|
|
// -1 is "default communications device" depending on OS in webrtc.org code
|
|
|
|
i = -1;
|
2014-07-10 21:15:26 +04:00
|
|
|
#endif
|
2018-05-07 20:33:41 +03:00
|
|
|
for (; i < nDevices; i++) {
|
|
|
|
// We use constants here because GetRecordingDeviceName takes char[128].
|
|
|
|
char deviceName[128];
|
|
|
|
char uniqueId[128];
|
|
|
|
// paranoia; jingle doesn't bother with this
|
|
|
|
deviceName[0] = '\0';
|
|
|
|
uniqueId[0] = '\0';
|
|
|
|
|
|
|
|
int error = mAudioInput->GetRecordingDeviceName(i, deviceName, uniqueId);
|
|
|
|
if (error) {
|
|
|
|
LOG((" AudioInput::GetRecordingDeviceName: Failed %d", error));
|
|
|
|
continue;
|
|
|
|
}
|
2012-10-17 04:53:55 +04:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
if (uniqueId[0] == '\0') {
|
|
|
|
// Mac and Linux don't set uniqueId!
|
|
|
|
strcpy(uniqueId, deviceName); // safe given assert and initialization/error-check
|
|
|
|
}
|
2018-01-31 21:02:00 +03:00
|
|
|
|
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
RefPtr<MediaEngineSource> aSource;
|
|
|
|
NS_ConvertUTF8toUTF16 uuid(uniqueId);
|
2018-01-31 21:02:00 +03:00
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineSource>*
|
|
|
|
devicesForThisWindow = mAudioSources.LookupOrAdd(aWindowId);
|
|
|
|
|
|
|
|
if (devicesForThisWindow->Get(uuid, getter_AddRefs(aSource)) &&
|
|
|
|
aSource->RequiresSharing()) {
|
|
|
|
// We've already seen this device, just append.
|
|
|
|
aSources->AppendElement(aSource.get());
|
|
|
|
} else {
|
|
|
|
aSource = new MediaEngineWebRTCMicrophoneSource(
|
|
|
|
new mozilla::AudioInputCubeb(i),
|
|
|
|
i, deviceName, uniqueId,
|
|
|
|
mDelayAgnostic, mExtendedFilter);
|
|
|
|
devicesForThisWindow->Put(uuid, aSource);
|
|
|
|
aSources->AppendElement(aSource);
|
2012-10-17 04:53:55 +04:00
|
|
|
}
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-07 20:33:41 +03:00
|
|
|
void
|
|
|
|
MediaEngineWebRTC::EnumerateDevices(uint64_t aWindowId,
|
|
|
|
dom::MediaSourceEnum aMediaSource,
|
|
|
|
nsTArray<RefPtr<MediaEngineSource> >* aSources)
|
|
|
|
{
|
|
|
|
// We spawn threads to handle gUM runnables, so we must protect the member vars
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
if (MediaEngineSource::IsVideo(aMediaSource)) {
|
|
|
|
EnumerateVideoDevices(aWindowId, aMediaSource, aSources);
|
|
|
|
} else if (aMediaSource == dom::MediaSourceEnum::AudioCapture) {
|
|
|
|
RefPtr<MediaEngineWebRTCAudioCaptureSource> audioCaptureSource =
|
|
|
|
new MediaEngineWebRTCAudioCaptureSource(nullptr);
|
|
|
|
aSources->AppendElement(audioCaptureSource);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aMediaSource == dom::MediaSourceEnum::Microphone);
|
|
|
|
EnumerateMicrophoneDevices(aWindowId, aSources);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1299515 - Flatten MediaEngineSource class hierarchy. r=jib
The scope of flattening this hierarchy quickly grows large, so this patch does
a couple more things:
- Creates a pure interface MediaEngineSourceInterface and a base class
MediaEngineSource with common defaults and refcount support (no state!)
- Breaks out some of the helper classes to dedicated files, e.g.,
AllocationHandle, MediaEnginePrefs.
- Clarifies the threading model (written on one thread *and* under lock,
read under either)
- Fixes style, indentation, include-sorting in the affected files
- Adds comments, especially for clarifying what responsibilities methods have,
and thread usage of class members
- Changes Monitors to Mutexes since we only use them as Mutexes anyhow
- Makes MediaEngineRemoteVideoSource no longer a shared source since we now
support scaling in this source and CamerasChild can act as a broker of frames.
This greatly simplifies it. The only shared source is now
MediaEngineWebRTCMicrophoneSource, so the sharing specific common methods have
been moved to that source.
MozReview-Commit-ID: KeVZQo6gLm2
--HG--
rename : dom/media/webrtc/MediaEngine.h => dom/media/webrtc/MediaEnginePrefs.h
extra : rebase_source : c785a5feb896312912170475d6b8d997e712e48f
2018-01-24 18:49:13 +03:00
|
|
|
bool
|
|
|
|
MediaEngineWebRTC::SupportsDuplex()
|
|
|
|
{
|
|
|
|
return mFullDuplex;
|
|
|
|
}
|
|
|
|
|
2018-01-31 21:02:00 +03:00
|
|
|
void
|
|
|
|
MediaEngineWebRTC::ReleaseResourcesForWindow(uint64_t aWindowId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineSource>*
|
|
|
|
audioDevicesForThisWindow = mAudioSources.Get(aWindowId);
|
|
|
|
|
|
|
|
if (audioDevicesForThisWindow) {
|
|
|
|
for (auto iter = audioDevicesForThisWindow->Iter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
iter.UserData()->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This makes audioDevicesForThisWindow invalid.
|
|
|
|
mAudioSources.Remove(aWindowId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, MediaEngineSource>*
|
|
|
|
videoDevicesForThisWindow = mVideoSources.Get(aWindowId);
|
|
|
|
if (videoDevicesForThisWindow) {
|
|
|
|
for (auto iter = videoDevicesForThisWindow->Iter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
iter.UserData()->Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This makes videoDevicesForThisWindow invalid.
|
|
|
|
mVideoSources.Remove(aWindowId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
template<typename T>
|
|
|
|
void ShutdownSources(T& aHashTable)
|
|
|
|
{
|
|
|
|
for (auto iter = aHashTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
for (auto iterInner = iter.UserData()->Iter(); !iterInner.Done();
|
|
|
|
iterInner.Next()) {
|
|
|
|
MediaEngineSource* source = iterInner.UserData();
|
|
|
|
source->Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-12 15:53:08 +04:00
|
|
|
void
|
|
|
|
MediaEngineWebRTC::Shutdown()
|
|
|
|
{
|
2012-10-18 22:03:00 +04:00
|
|
|
// This is likely paranoia
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
2016-08-11 20:04:49 +03:00
|
|
|
if (camera::GetCamerasChildIfExists()) {
|
|
|
|
camera::GetChildAndCall(
|
|
|
|
&camera::CamerasChild::RemoveDeviceChangeCallback, this);
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:28:03 +03:00
|
|
|
LOG(("%s", __FUNCTION__));
|
|
|
|
// Shutdown all the sources, since we may have dangling references to the
|
|
|
|
// sources in nsDOMUserMediaStreams waiting for GC/CC
|
2018-01-31 21:02:00 +03:00
|
|
|
ShutdownSources(mVideoSources);
|
|
|
|
ShutdownSources(mAudioSources);
|
2015-05-29 21:28:03 +03:00
|
|
|
|
2015-08-31 15:51:29 +03:00
|
|
|
mozilla::camera::Shutdown();
|
2016-01-21 19:51:36 +03:00
|
|
|
AudioInputCubeb::CleanupGlobalData();
|
2012-07-12 15:53:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|