From 9ce1941985c3fa47a466b0443bb81ff3e8215837 Mon Sep 17 00:00:00 2001 From: Jan-Ivar Bruaroey Date: Tue, 20 Jan 2015 10:31:59 -0500 Subject: [PATCH] Bug 1006707 - add microphone to mediaSource and remove redundant enum in c++. r=rjesup --- dom/media/MediaManager.cpp | 16 +++++++--------- dom/media/MediaManager.h | 10 +++++----- dom/media/webrtc/MediaEngine.h | 16 +++------------- .../webrtc/MediaEngineCameraVideoSource.h | 4 ++-- dom/media/webrtc/MediaEngineDefault.cpp | 6 +++--- dom/media/webrtc/MediaEngineDefault.h | 12 ++++++------ dom/media/webrtc/MediaEngineTabVideoSource.h | 4 ++-- dom/media/webrtc/MediaEngineWebRTC.cpp | 18 +++++++++--------- dom/media/webrtc/MediaEngineWebRTC.h | 14 +++++++------- 9 files changed, 44 insertions(+), 56 deletions(-) diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index fd60b78fe94b..fed395f34cc4 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -522,9 +522,9 @@ MediaDevice::GetFacingMode(nsAString& aFacingMode) NS_IMETHODIMP MediaDevice::GetMediaSource(nsAString& aMediaSource) { - if (mMediaSource == MediaSourceType::Microphone) { + if (mMediaSource == dom::MediaSourceEnum::Microphone) { aMediaSource.Assign(NS_LITERAL_STRING("microphone")); - } else if (mMediaSource == MediaSourceType::Window) { // this will go away + } else if (mMediaSource == dom::MediaSourceEnum::Window) { // this will go away aMediaSource.Assign(NS_LITERAL_STRING("window")); } else { // all the rest are shared aMediaSource.Assign(NS_ConvertUTF8toUTF16( @@ -948,7 +948,7 @@ template static void GetSources(MediaEngine *engine, ConstraintsType &aConstraints, - void (MediaEngine::* aEnumerate)(MediaSourceType, + void (MediaEngine::* aEnumerate)(dom::MediaSourceEnum, nsTArray >*), nsTArray>& aResult, const char* media_device_name = nullptr) @@ -960,10 +960,8 @@ static void SourceSet candidateSet; { nsTArray > sources; - // all MediaSourceEnums are contained in MediaSourceType - (engine->*aEnumerate)((MediaSourceType)(aConstraints.mMediaSourceEnumValue), - &sources); + (engine->*aEnumerate)(aConstraints.mMediaSourceEnumValue, &sources); /** * We're allowing multiple tabs to access the same camera for parity * with Chrome. See bug 811757 for some of the issues surrounding @@ -2403,9 +2401,9 @@ GetUserMediaCallbackMediaStreamListener::StopScreenWindowSharing() { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); if (mVideoSource && !mStopped && - (mVideoSource->GetMediaSource() == MediaSourceType::Screen || - mVideoSource->GetMediaSource() == MediaSourceType::Application || - mVideoSource->GetMediaSource() == MediaSourceType::Window)) { + (mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Screen || + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Application || + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Window)) { // Stop the whole stream if there's no audio; just the video track if we have both MediaManager::GetMessageLoop()->PostTask(FROM_HERE, new MediaOperationTask(mAudioSource ? MEDIA_STOP_TRACK : MEDIA_STOP, diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 74bbe06fe05a..5802ba1a40d9 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -116,7 +116,7 @@ public: { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); return mVideoSource && !mStopped && - mVideoSource->GetMediaSource() == MediaSourceType::Camera && + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Camera && (!mVideoSource->IsFake() || Preferences::GetBool("media.navigator.permission.fake")); } @@ -131,19 +131,19 @@ public: { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); return mVideoSource && !mStopped && !mVideoSource->IsAvailable() && - mVideoSource->GetMediaSource() == MediaSourceType::Screen; + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Screen; } bool CapturingWindow() { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); return mVideoSource && !mStopped && !mVideoSource->IsAvailable() && - mVideoSource->GetMediaSource() == MediaSourceType::Window; + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Window; } bool CapturingApplication() { NS_ASSERTION(NS_IsMainThread(), "Only call on main thread"); return mVideoSource && !mStopped && !mVideoSource->IsAvailable() && - mVideoSource->GetMediaSource() == MediaSourceType::Application; + mVideoSource->GetMediaSource() == dom::MediaSourceEnum::Application; } void SetStopped() @@ -508,7 +508,7 @@ protected: nsString mID; bool mHasFacingMode; dom::VideoFacingModeEnum mFacingMode; - MediaSourceType mMediaSource; + dom::MediaSourceEnum mMediaSource; nsRefPtr mSource; }; diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index b7c33405b9c3..be8745eb1532 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -39,16 +39,6 @@ enum MediaEngineState { kReleased }; -// includes everything from dom::MediaSourceEnum (really video sources), plus audio sources -enum MediaSourceType { - Camera = (int) dom::MediaSourceEnum::Camera, - Screen = (int) dom::MediaSourceEnum::Screen, - Application = (int) dom::MediaSourceEnum::Application, - Window, // = (int) dom::MediaSourceEnum::Window, // XXX bug 1038926 - Browser = (int) dom::MediaSourceEnum::Browser, // proposed in WG, unclear if it's useful - Microphone -}; - class MediaEngine { public: @@ -64,12 +54,12 @@ public: /* Populate an array of video sources in the nsTArray. Also include devices * that are currently unavailable. */ - virtual void EnumerateVideoDevices(MediaSourceType, + virtual void EnumerateVideoDevices(dom::MediaSourceEnum, nsTArray >*) = 0; /* Populate an array of audio sources in the nsTArray. Also include devices * that are currently unavailable. */ - virtual void EnumerateAudioDevices(MediaSourceType, + virtual void EnumerateAudioDevices(dom::MediaSourceEnum, nsTArray >*) = 0; protected: @@ -127,7 +117,7 @@ public: virtual bool IsFake() = 0; /* Returns the type of media source (camera, microphone, screen, window, etc) */ - virtual const MediaSourceType GetMediaSource() = 0; + virtual const dom::MediaSourceEnum GetMediaSource() = 0; // Callback interface for TakePhoto(). Either PhotoComplete() or PhotoError() // should be called. diff --git a/dom/media/webrtc/MediaEngineCameraVideoSource.h b/dom/media/webrtc/MediaEngineCameraVideoSource.h index ce493960a4ca..06bcc5df9bb4 100644 --- a/dom/media/webrtc/MediaEngineCameraVideoSource.h +++ b/dom/media/webrtc/MediaEngineCameraVideoSource.h @@ -49,8 +49,8 @@ public: return false; } - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { - return MediaSourceType::Camera; + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { + return dom::MediaSourceEnum::Camera; } virtual nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index bb0015da25b0..76ff52c461fe 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -469,12 +469,12 @@ MediaEngineDefaultAudioSource::Notify(nsITimer* aTimer) } void -MediaEngineDefault::EnumerateVideoDevices(MediaSourceType aMediaSource, +MediaEngineDefault::EnumerateVideoDevices(dom::MediaSourceEnum aMediaSource, nsTArray >* aVSources) { MutexAutoLock lock(mMutex); // only supports camera sources (for now). See Bug 1038241 - if (aMediaSource != MediaSourceType::Camera) { + if (aMediaSource != dom::MediaSourceEnum::Camera) { return; } @@ -490,7 +490,7 @@ MediaEngineDefault::EnumerateVideoDevices(MediaSourceType aMediaSource, } void -MediaEngineDefault::EnumerateAudioDevices(MediaSourceType aMediaSource, +MediaEngineDefault::EnumerateAudioDevices(dom::MediaSourceEnum aMediaSource, nsTArray >* aASources) { MutexAutoLock lock(mMutex); int32_t len = mASources.Length(); diff --git a/dom/media/webrtc/MediaEngineDefault.h b/dom/media/webrtc/MediaEngineDefault.h index 064423439abf..7be158150de1 100644 --- a/dom/media/webrtc/MediaEngineDefault.h +++ b/dom/media/webrtc/MediaEngineDefault.h @@ -64,8 +64,8 @@ public: return true; } - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { - return MediaSourceType::Camera; + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { + return dom::MediaSourceEnum::Camera; } virtual nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE @@ -127,8 +127,8 @@ public: return true; } - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { - return MediaSourceType::Microphone; + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { + return dom::MediaSourceEnum::Microphone; } virtual nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE @@ -158,9 +158,9 @@ public: , mMutex("mozilla::MediaEngineDefault") {} - virtual void EnumerateVideoDevices(MediaSourceType, + virtual void EnumerateVideoDevices(dom::MediaSourceEnum, nsTArray >*); - virtual void EnumerateAudioDevices(MediaSourceType, + virtual void EnumerateAudioDevices(dom::MediaSourceEnum, nsTArray >*); protected: diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.h b/dom/media/webrtc/MediaEngineTabVideoSource.h index 3bec54be6cf0..7b6a3615bc77 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.h +++ b/dom/media/webrtc/MediaEngineTabVideoSource.h @@ -29,8 +29,8 @@ class MediaEngineTabVideoSource : public MediaEngineVideoSource, nsIDOMEventList virtual nsresult Stop(mozilla::SourceMediaStream*, mozilla::TrackID) MOZ_OVERRIDE; virtual nsresult Config(bool, uint32_t, bool, uint32_t, bool, uint32_t, int32_t) MOZ_OVERRIDE; virtual bool IsFake() MOZ_OVERRIDE; - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { - return MediaSourceType::Browser; + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { + return dom::MediaSourceEnum::Browser; } virtual bool SatisfiesConstraintSets( const nsTArray& aConstraintSets) MOZ_OVERRIDE diff --git a/dom/media/webrtc/MediaEngineWebRTC.cpp b/dom/media/webrtc/MediaEngineWebRTC.cpp index 54807ffbdd8a..aafb4a02dfe2 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.cpp +++ b/dom/media/webrtc/MediaEngineWebRTC.cpp @@ -72,14 +72,14 @@ MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs) } void -MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, +MediaEngineWebRTC::EnumerateVideoDevices(dom::MediaSourceEnum aMediaSource, nsTArray >* aVSources) { // We spawn threads to handle gUM runnables, so we must protect the member vars MutexAutoLock lock(mMutex); #ifdef MOZ_B2G_CAMERA - if (aMediaSource != MediaSourceType::Camera) { + if (aMediaSource != dom::MediaSourceEnum::Camera) { // only supports camera sources return; } @@ -137,7 +137,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, #endif switch (aMediaSource) { - case MediaSourceType::Window: + case dom::MediaSourceEnum::Window: mWinEngineConfig.Set( new webrtc::CaptureDeviceInfo(webrtc::CaptureDeviceType::Window)); if (!mWinEngine) { @@ -148,7 +148,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, videoEngine = mWinEngine; videoEngineInit = &mWinEngineInit; break; - case MediaSourceType::Application: + case dom::MediaSourceEnum::Application: mAppEngineConfig.Set( new webrtc::CaptureDeviceInfo(webrtc::CaptureDeviceType::Application)); if (!mAppEngine) { @@ -159,7 +159,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, videoEngine = mAppEngine; videoEngineInit = &mAppEngineInit; break; - case MediaSourceType::Screen: + case dom::MediaSourceEnum::Screen: mScreenEngineConfig.Set( new webrtc::CaptureDeviceInfo(webrtc::CaptureDeviceType::Screen)); if (!mScreenEngine) { @@ -170,7 +170,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, videoEngine = mScreenEngine; videoEngineInit = &mScreenEngineInit; break; - case MediaSourceType::Browser: + case dom::MediaSourceEnum::Browser: mBrowserEngineConfig.Set( new webrtc::CaptureDeviceInfo(webrtc::CaptureDeviceType::Browser)); if (!mBrowserEngine) { @@ -181,7 +181,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, videoEngine = mBrowserEngine; videoEngineInit = &mBrowserEngineInit; break; - case MediaSourceType::Camera: + case dom::MediaSourceEnum::Camera: // fall through default: if (!mVideoEngine) { @@ -274,7 +274,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, } } - if (mHasTabVideoSource || MediaSourceType::Browser == aMediaSource) + if (mHasTabVideoSource || dom::MediaSourceEnum::Browser == aMediaSource) aVSources->AppendElement(new MediaEngineTabVideoSource()); return; @@ -282,7 +282,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(MediaSourceType aMediaSource, } void -MediaEngineWebRTC::EnumerateAudioDevices(MediaSourceType aMediaSource, +MediaEngineWebRTC::EnumerateAudioDevices(dom::MediaSourceEnum aMediaSource, nsTArray >* aASources) { ScopedCustomReleasePtr ptrVoEBase; diff --git a/dom/media/webrtc/MediaEngineWebRTC.h b/dom/media/webrtc/MediaEngineWebRTC.h index 5d0958089b6b..94c925d0e5c4 100644 --- a/dom/media/webrtc/MediaEngineWebRTC.h +++ b/dom/media/webrtc/MediaEngineWebRTC.h @@ -79,7 +79,7 @@ public: virtual bool IsTextureSupported() MOZ_OVERRIDE { return false; } MediaEngineWebRTCVideoSource(webrtc::VideoEngine* aVideoEnginePtr, int aIndex, - MediaSourceType aMediaSource = MediaSourceType::Camera) + dom::MediaSourceEnum aMediaSource = dom::MediaSourceEnum::Camera) : MediaEngineCameraVideoSource(aIndex, "WebRTCCamera.Monitor") , mVideoEngine(aVideoEnginePtr) , mMinFps(-1) @@ -99,7 +99,7 @@ public: TrackID aId, StreamTime aDesiredTime) MOZ_OVERRIDE; - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { return mMediaSource; } virtual nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE @@ -127,7 +127,7 @@ private: webrtc::ViERender* mViERender; int mMinFps; // Min rate we want to accept - MediaSourceType mMediaSource; // source of media (camera | application | screen) + dom::MediaSourceEnum mMediaSource; // source of media (camera | application | screen) static bool SatisfiesConstraintSet(const dom::MediaTrackConstraintSet& aConstraints, const webrtc::CaptureCapability& aCandidate); @@ -185,8 +185,8 @@ public: return false; } - virtual const MediaSourceType GetMediaSource() MOZ_OVERRIDE { - return MediaSourceType::Microphone; + virtual const dom::MediaSourceEnum GetMediaSource() MOZ_OVERRIDE { + return dom::MediaSourceEnum::Microphone; } virtual nsresult TakePhoto(PhotoCallback* aCallback) MOZ_OVERRIDE @@ -254,9 +254,9 @@ public: // before invoking Shutdown on this class. void Shutdown(); - virtual void EnumerateVideoDevices(MediaSourceType, + virtual void EnumerateVideoDevices(dom::MediaSourceEnum, nsTArray >*); - virtual void EnumerateAudioDevices(MediaSourceType, + virtual void EnumerateAudioDevices(dom::MediaSourceEnum, nsTArray >*); private: ~MediaEngineWebRTC() {