--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1853,54 +1853,63 @@ private:
* EnumerateRawDevices - Enumerate a list of audio & video devices that
* satisfy passed-in constraints. List contains raw id's.
*/
already_AddRefed<MediaManager::PledgeSourceSet>
MediaManager::EnumerateRawDevices(uint64_t aWindowId,
MediaSourceEnum aVideoType,
MediaSourceEnum aAudioType,
- DeviceEnumerationType aVideoEnumType /* = Normal */,
- DeviceEnumerationType aAudioEnumType /* = Normal */)
+ DeviceEnumerationType aVideoEnumType /* = DeviceEnumerationType::Normal */,
+ DeviceEnumerationType aAudioEnumType /* = DeviceEnumerationType::Normal */)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aVideoType != MediaSourceEnum::Other ||
aAudioType != MediaSourceEnum::Other);
// Since the enums can take one of several values, the following asserts rely
// on short circuting behavior. E.g. aVideoEnumType != Fake will be true if
// the requested device is not fake and thus the assert will pass. However,
// if the device is fake, aVideoType == MediaSourceEnum::Camera will be
// checked as well, ensuring that fake devices are of the camera type.
- MOZ_ASSERT(aVideoEnumType != Fake || aVideoType == MediaSourceEnum::Camera,
+ MOZ_ASSERT(aVideoEnumType != DeviceEnumerationType::Fake ||
+ aVideoType == MediaSourceEnum::Camera,
"If fake cams are requested video type should be camera!");
- MOZ_ASSERT(aVideoEnumType != Loopback || aVideoType == MediaSourceEnum::Camera,
+ MOZ_ASSERT(aVideoEnumType != DeviceEnumerationType::Loopback ||
+ aVideoType == MediaSourceEnum::Camera,
"If loopback video is requested video type should be camera!");
- MOZ_ASSERT(aAudioEnumType != Fake || aAudioType == MediaSourceEnum::Microphone,
+ MOZ_ASSERT(aAudioEnumType != DeviceEnumerationType::Fake ||
+ aAudioType == MediaSourceEnum::Microphone,
"If fake mics are requested audio type should be microphone!");
- MOZ_ASSERT(aAudioEnumType != Loopback || aAudioType == MediaSourceEnum::Microphone,
+ MOZ_ASSERT(aAudioEnumType != DeviceEnumerationType::Loopback ||
+ aAudioType == MediaSourceEnum::Microphone,
"If loopback audio is requested audio type should be microphone!");
+ LOG(("%s: aWindowId=%" PRIu64 ", aVideoType=%" PRIu8 ", aAudioType=%" PRIu8
+ ", aVideoEnumType=%" PRIu8 ", aAudioEnumType=%" PRIu8,
+ __func__, aWindowId,
+ static_cast<uint8_t>(aVideoType), static_cast<uint8_t>(aAudioType),
+ static_cast<uint8_t>(aVideoEnumType), static_cast<uint8_t>(aAudioEnumType)));
RefPtr<PledgeSourceSet> p = new PledgeSourceSet();
uint32_t id = mOutstandingPledges.Append(*p);
bool hasVideo = aVideoType != MediaSourceEnum::Other;
bool hasAudio = aAudioType != MediaSourceEnum::Other;
// True of at least one of video or audio is a fake device
- bool fakeDeviceRequested = (aVideoEnumType == Fake && hasVideo) ||
- (aAudioEnumType == Fake && hasAudio);
+ bool fakeDeviceRequested = (aVideoEnumType == DeviceEnumerationType::Fake && hasVideo) ||
+ (aAudioEnumType == DeviceEnumerationType::Fake && hasAudio);
// True if at least one of video or audio is a real device
- bool realDeviceRequested = (aVideoEnumType != Fake && hasVideo) ||
- (aAudioEnumType != Fake && hasAudio);
+ bool realDeviceRequested = (aVideoEnumType != DeviceEnumerationType::Fake && hasVideo) ||
+ (aAudioEnumType != DeviceEnumerationType::Fake && hasAudio);
nsAutoCString videoLoopDev, audioLoopDev;
- if (hasVideo && aVideoEnumType == Loopback) {
+ if (hasVideo && aVideoEnumType == DeviceEnumerationType::Loopback) {
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
}
- if (hasAudio && aAudioEnumType == Loopback) {
+ if (hasAudio && aAudioEnumType == DeviceEnumerationType::Loopback) {
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
}
RefPtr<Runnable> task = NewTaskFrom([id, aWindowId, aVideoType, aAudioType,
aVideoEnumType, aAudioEnumType,
videoLoopDev, audioLoopDev,
hasVideo, hasAudio, fakeDeviceRequested,
realDeviceRequested]() {
@@ -1914,25 +1923,29 @@ MediaManager::EnumerateRawDevices(uint64
MOZ_RELEASE_ASSERT(manager); // Must exist while media thread is alive
realBackend = manager->GetBackend(aWindowId);
}
auto result = MakeUnique<SourceSet>();
if (hasVideo) {
SourceSet videos;
- GetSources(aVideoEnumType == Fake ? fakeBackend : realBackend,
+ LOG(("EnumerateRawDevices Task: Getting video sources with %s backend",
+ aVideoEnumType == DeviceEnumerationType::Fake ? "fake" : "real"));
+ GetSources(aVideoEnumType == DeviceEnumerationType::Fake ? fakeBackend : realBackend,
aWindowId, aVideoType, videos, videoLoopDev.get());
for (auto& source : videos) {
result->AppendElement(source);
}
}
if (hasAudio) {
SourceSet audios;
- GetSources(aAudioEnumType == Fake ? fakeBackend : realBackend,
+ LOG(("EnumerateRawDevices Task: Getting audio sources with %s backend",
+ aVideoEnumType == DeviceEnumerationType::Fake ? "fake" : "real"));
+ GetSources(aAudioEnumType == DeviceEnumerationType::Fake ? fakeBackend : realBackend,
aWindowId, aAudioType, audios, audioLoopDev.get());
for (auto& source : audios) {
result->AppendElement(source);
}
}
NS_DispatchToMainThread(NewRunnableFrom([id, result = Move(result)]() mutable {
MediaManager* mgr = MediaManager::GetIfExists();
if (!mgr) {
@@ -2736,51 +2749,60 @@ MediaManager::GetUserMedia(nsPIDOMWindow
MediaEnginePrefs prefs = mPrefs;
nsString callID;
rv = GenerateUUID(callID);
NS_ENSURE_SUCCESS(rv, rv);
bool hasVideo = videoType != MediaSourceEnum::Other;
bool hasAudio = audioType != MediaSourceEnum::Other;
- DeviceEnumerationType videoEnumerationType = Normal;
- DeviceEnumerationType audioEnumerationType = Normal;
+ DeviceEnumerationType videoEnumerationType = DeviceEnumerationType::Normal;
+ DeviceEnumerationType audioEnumerationType = DeviceEnumerationType::Normal;
// Handle loopback and fake requests. For gUM we don't consider resist
// fingerprinting as users should be prompted anyway.
bool wantFakes = c.mFake.WasPassed() ? c.mFake.Value() :
Preferences::GetBool("media.navigator.streams.fake");
nsAutoCString videoLoopDev, audioLoopDev;
// Video
if (videoType == MediaSourceEnum::Camera) {
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
// Loopback prefs take precedence over fake prefs
if (!videoLoopDev.IsEmpty()) {
- videoEnumerationType = Loopback;
+ videoEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
- videoEnumerationType = Fake;
+ videoEnumerationType = DeviceEnumerationType::Fake;
}
}
// Audio
if (audioType == MediaSourceEnum::Microphone) {
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
// Loopback prefs take precedence over fake prefs
if (!audioLoopDev.IsEmpty()) {
- audioEnumerationType = Loopback;
+ audioEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
- audioEnumerationType = Fake;
+ audioEnumerationType = DeviceEnumerationType::Fake;
}
}
- bool realDevicesRequested = (videoEnumerationType != Fake && hasVideo) ||
- (audioEnumerationType != Fake && hasAudio);
+ bool realDevicesRequested = (videoEnumerationType != DeviceEnumerationType::Fake && hasVideo) ||
+ (audioEnumerationType != DeviceEnumerationType::Fake && hasAudio);
bool askPermission =
(!privileged || Preferences::GetBool("media.navigator.permission.force")) &&
(realDevicesRequested || Preferences::GetBool("media.navigator.permission.fake"));
+ LOG(("%s: Preparing to enumerate devices. windowId=%" PRIu64
+ ", videoType=%" PRIu8 ", audioType=%" PRIu8
+ ", videoEnumerationType=%" PRIu8 ", audioEnumerationType=%" PRIu8
+ ", askPermission=%s",
+ __func__, windowID,
+ static_cast<uint8_t>(videoType), static_cast<uint8_t>(audioType),
+ static_cast<uint8_t>(videoEnumerationType), static_cast<uint8_t>(audioEnumerationType),
+ askPermission ? "true" : "false"));
+
RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowID, videoType,
audioType,
videoEnumerationType,
audioEnumerationType);
RefPtr<MediaManager> self = this;
p->Then([self, onSuccess, onFailure, windowID, c, windowListener,
sourceListener, askPermission, prefs, isHTTPS, isHandlingUserInput,
callID, principalInfo, isChrome, resistFingerprinting](SourceSet*& aDevices) mutable {
@@ -2991,20 +3013,26 @@ MediaManager::ToJSArray(SourceSet& aDevi
}
return var.forget();
}
already_AddRefed<MediaManager::PledgeSourceSet>
MediaManager::EnumerateDevicesImpl(uint64_t aWindowId,
MediaSourceEnum aVideoType,
MediaSourceEnum aAudioType,
- DeviceEnumerationType aVideoEnumType /* = Normal */,
- DeviceEnumerationType aAudioEnumType /* = Normal */)
+ DeviceEnumerationType aVideoEnumType /* = DeviceEnumerationType::Normal */,
+ DeviceEnumerationType aAudioEnumType /* = DeviceEnumerationType::Normal */)
{
MOZ_ASSERT(NS_IsMainThread());
+
+ LOG(("%s: aWindowId=%" PRIu64 ", aVideoType=%" PRIu8 ", aAudioType=%" PRIu8
+ ", aVideoEnumType=%" PRIu8 ", aAudioEnumType=%" PRIu8,
+ __func__, aWindowId,
+ static_cast<uint8_t>(aVideoType), static_cast<uint8_t>(aAudioType),
+ static_cast<uint8_t>(aVideoEnumType), static_cast<uint8_t>(aAudioEnumType)));
nsPIDOMWindowInner* window =
nsGlobalWindowInner::GetInnerWindowWithId(aWindowId)->AsInner();
// This function returns a pledge, a promise-like object with the future result
RefPtr<PledgeSourceSet> pledge = new PledgeSourceSet();
uint32_t id = mOutstandingPledges.Append(*pledge);
// To get a device list anonymized for a particular origin, we must:
@@ -3061,17 +3089,18 @@ MediaManager::EnumerateDevicesImpl(uint6
if (!mgr) {
return NS_OK;
}
// If we fetched any real cameras or mics, remove the "default" part of
// their IDs.
if (aVideoType == MediaSourceEnum::Camera &&
aAudioType == MediaSourceEnum::Microphone &&
- (aVideoEnumType != Fake || aAudioEnumType != Fake)) {
+ (aVideoEnumType != DeviceEnumerationType::Fake ||
+ aAudioEnumType != DeviceEnumerationType::Fake)) {
mgr->mDeviceIDs.Clear();
for (auto& device : *devices) {
nsString id;
device->GetId(id);
id.ReplaceSubstring(NS_LITERAL_STRING("default: "), NS_LITERAL_STRING(""));
if (!mgr->mDeviceIDs.Contains(id)) {
mgr->mDeviceIDs.AppendElement(id);
}
@@ -3116,43 +3145,43 @@ MediaManager::EnumerateDevices(nsPIDOMWi
AddWindowID(windowId, windowListener);
}
// Create an inactive SourceListener to act as a placeholder, so the
// window listener doesn't clean itself up until we're done.
RefPtr<SourceListener> sourceListener = new SourceListener();
windowListener->Register(sourceListener);
- DeviceEnumerationType videoEnumerationType = Normal;
- DeviceEnumerationType audioEnumerationType = Normal;
+ DeviceEnumerationType videoEnumerationType = DeviceEnumerationType::Normal;
+ DeviceEnumerationType audioEnumerationType = DeviceEnumerationType::Normal;
bool resistFingerprinting = nsContentUtils::ResistFingerprinting(aCallerType);
// In order of precedence: resist fingerprinting > loopback > fake pref
if (resistFingerprinting) {
- videoEnumerationType = Fake;
- audioEnumerationType = Fake;
+ videoEnumerationType = DeviceEnumerationType::Fake;
+ audioEnumerationType = DeviceEnumerationType::Fake;
} else {
// Handle loopback and fake requests
nsAutoCString videoLoopDev, audioLoopDev;
bool wantFakes = Preferences::GetBool("media.navigator.streams.fake");
// Video
Preferences::GetCString("media.video_loopback_dev", videoLoopDev);
// Loopback prefs take precedence over fake prefs
if (!videoLoopDev.IsEmpty()) {
- videoEnumerationType = Loopback;
+ videoEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
- videoEnumerationType = Fake;
+ videoEnumerationType = DeviceEnumerationType::Fake;
}
// Audio
Preferences::GetCString("media.audio_loopback_dev", audioLoopDev);
// Loopback prefs take precedence over fake prefs
if (!audioLoopDev.IsEmpty()) {
- audioEnumerationType = Loopback;
+ audioEnumerationType = DeviceEnumerationType::Loopback;
} else if (wantFakes) {
- audioEnumerationType = Fake;
+ audioEnumerationType = DeviceEnumerationType::Fake;
}
}
RefPtr<PledgeSourceSet> p = EnumerateDevicesImpl(windowId,
MediaSourceEnum::Camera,
MediaSourceEnum::Microphone,
videoEnumerationType,
audioEnumerationType);
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -226,34 +226,34 @@ private:
typedef media::Pledge<bool, dom::MediaStreamError*> PledgeVoid;
static nsresult GenerateUUID(nsAString& aResult);
static nsresult AnonymizeId(nsAString& aId, const nsACString& aOriginKey);
public: // TODO: make private once we upgrade to GCC 4.8+ on linux.
static void AnonymizeDevices(SourceSet& aDevices, const nsACString& aOriginKey);
static already_AddRefed<nsIWritableVariant> ToJSArray(SourceSet& aDevices);
private:
- enum DeviceEnumerationType {
+ enum class DeviceEnumerationType :uint8_t {
Normal, // Enumeration should not return loopback or fake devices
Fake, // Enumeration should return fake device(s)
Loopback /* Enumeration should return loopback device(s) (possibly in
addition to normal devices) */
};
already_AddRefed<PledgeSourceSet>
EnumerateRawDevices(uint64_t aWindowId,
dom::MediaSourceEnum aVideoType,
dom::MediaSourceEnum aAudioType,
- DeviceEnumerationType aVideoEnumType = Normal ,
- DeviceEnumerationType aAudioEnumType = Normal);
+ DeviceEnumerationType aVideoEnumType = DeviceEnumerationType::Normal,
+ DeviceEnumerationType aAudioEnumType = DeviceEnumerationType::Normal);
already_AddRefed<PledgeSourceSet>
EnumerateDevicesImpl(uint64_t aWindowId,
dom::MediaSourceEnum aVideoType,
dom::MediaSourceEnum aAudioType,
- DeviceEnumerationType aVideoEnumType = Normal,
- DeviceEnumerationType aAudioEnumType = Normal);
+ DeviceEnumerationType aVideoEnumType = DeviceEnumerationType::Normal,
+ DeviceEnumerationType aAudioEnumType = DeviceEnumerationType::Normal);
already_AddRefed<PledgeChar>
SelectSettings(
dom::MediaStreamConstraints& aConstraints,
bool aIsChrome,
RefPtr<media::Refcountable<UniquePtr<SourceSet>>>& aSources);
void GetPref(nsIPrefBranch *aBranch, const char *aPref,
const char *aData, int32_t *aVal);