bug 1041493 - add support for browser to mediaSource constraint r=rjesup,khuey
authorBrad Lassey <blassey@mozilla.com>
Mon, 21 Jul 2014 08:31:31 -0400
changeset 196291 3a53a1cc3dbffee8a361d47c50efb8957ac2f4e8
parent 196290 7e44cabb92bcb093f718dd2a9e69571f1300f139
child 196292 1b21108d2a5db118aa15d28d07144381b2a5d001
push id27209
push usercbook@mozilla.com
push dateMon, 28 Jul 2014 13:49:10 +0000
treeherdermozilla-central@d77f6a96ff96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrjesup, khuey
bugs1041493
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1041493 - add support for browser to mediaSource constraint r=rjesup,khuey
content/media/webrtc/MediaEngine.h
content/media/webrtc/MediaEngineTabVideoSource.h
content/media/webrtc/MediaEngineWebRTC.cpp
content/media/webrtc/MediaEngineWebRTC.h
dom/media/MediaManager.cpp
dom/webidl/Constraints.webidl
media/webrtc/trunk/webrtc/video_engine/browser_capture_impl.h
media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
--- a/content/media/webrtc/MediaEngine.h
+++ b/content/media/webrtc/MediaEngine.h
@@ -41,17 +41,17 @@ enum {
 };
 
 // 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
+  Browser = (int) dom::MediaSourceEnum::Browser, // proposed in WG, unclear if it's useful
   Microphone
 };
 
 class MediaEngine
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaEngine)
 
--- a/content/media/webrtc/MediaEngineTabVideoSource.h
+++ b/content/media/webrtc/MediaEngineTabVideoSource.h
@@ -25,16 +25,20 @@ class MediaEngineTabVideoSource : public
     virtual nsresult Deallocate();
     virtual nsresult Start(mozilla::SourceMediaStream*, mozilla::TrackID);
     virtual void SetDirectListeners(bool aHasDirectListeners) {};
     virtual nsresult Snapshot(uint32_t, nsIDOMFile**);
     virtual void NotifyPull(mozilla::MediaStreamGraph*, mozilla::SourceMediaStream*, mozilla::TrackID, mozilla::StreamTime, mozilla::TrackTicks&);
     virtual nsresult Stop(mozilla::SourceMediaStream*, mozilla::TrackID);
     virtual nsresult Config(bool, uint32_t, bool, uint32_t, bool, uint32_t, int32_t);
     virtual bool IsFake();
+    virtual const MediaSourceType GetMediaSource() {
+      return MediaSourceType::Browser;
+    }
+
     void Draw();
 
     class StartRunnable : public nsRunnable {
     public:
       StartRunnable(MediaEngineTabVideoSource *videoSource) : mVideoSource(videoSource) {}
       NS_IMETHOD Run();
       nsRefPtr<MediaEngineTabVideoSource> mVideoSource;
     };
--- a/content/media/webrtc/MediaEngineWebRTC.cpp
+++ b/content/media/webrtc/MediaEngineWebRTC.cpp
@@ -42,23 +42,25 @@ GetUserMediaLog()
 #undef LOG
 #define LOG(args) PR_LOG(GetUserMediaLog(), PR_LOG_DEBUG, args)
 
 namespace mozilla {
 
 MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
     : mMutex("mozilla::MediaEngineWebRTC")
     , mScreenEngine(nullptr)
+    , mBrowserEngine(nullptr)
     , mWinEngine(nullptr)
     , mAppEngine(nullptr)
     , mVideoEngine(nullptr)
     , mVoiceEngine(nullptr)
     , mVideoEngineInit(false)
     , mAudioEngineInit(false)
     , mScreenEngineInit(false)
+    , mBrowserEngineInit(false)
     , mAppEngineInit(false)
 {
 #ifndef MOZ_B2G_CAMERA
   nsCOMPtr<nsIComponentRegistrar> compMgr;
   NS_GetComponentRegistrar(getter_AddRefs(compMgr));
   if (compMgr) {
     compMgr->IsContractIDRegistered(NS_TABSOURCESERVICE_CONTRACTID, &mHasTabVideoSource);
   }
@@ -166,16 +168,27 @@ MediaEngineWebRTC::EnumerateVideoDevices
       if (!mScreenEngine) {
         if (!(mScreenEngine = webrtc::VideoEngine::Create(mScreenEngineConfig))) {
           return;
         }
       }
       videoEngine = mScreenEngine;
       videoEngineInit = &mScreenEngineInit;
       break;
+    case MediaSourceType::Browser:
+      mBrowserEngineConfig.Set<webrtc::CaptureDeviceInfo>(
+          new webrtc::CaptureDeviceInfo(webrtc::CaptureDeviceType::Browser));
+      if (!mBrowserEngine) {
+        if (!(mBrowserEngine = webrtc::VideoEngine::Create(mBrowserEngineConfig))) {
+          return;
+        }
+      }
+      videoEngine = mBrowserEngine;
+      videoEngineInit = &mBrowserEngineInit;
+      break;
     case MediaSourceType::Camera:
       // fall through
     default:
       if (!mVideoEngine) {
         if (!(mVideoEngine = webrtc::VideoEngine::Create())) {
           return;
         }
       }
@@ -372,29 +385,33 @@ MediaEngineWebRTC::Shutdown()
     mVideoSources.Clear();
     mVideoEngine->SetTraceCallback(nullptr);
     webrtc::VideoEngine::Delete(mVideoEngine);
   }
 
   if (mScreenEngine) {
     webrtc::VideoEngine::Delete(mScreenEngine);
   }
+  if (mBrowserEngine) {
+    webrtc::VideoEngine::Delete(mBrowserEngine);
+  }
   if (mAppEngine) {
     webrtc::VideoEngine::Delete(mAppEngine);
   }
 
   if (mVoiceEngine) {
     mAudioSources.Clear();
     mVoiceEngine->SetTraceCallback(nullptr);
     webrtc::VoiceEngine::Delete(mVoiceEngine);
   }
 
   mVideoEngine = nullptr;
   mVoiceEngine = nullptr;
   mScreenEngine = nullptr;
+  mBrowserEngine = nullptr;
   mAppEngine = nullptr;
 
   if (mThread) {
     mThread->Shutdown();
     mThread = nullptr;
   }
 }
 
--- a/content/media/webrtc/MediaEngineWebRTC.h
+++ b/content/media/webrtc/MediaEngineWebRTC.h
@@ -409,30 +409,33 @@ private:
   }
 
   nsCOMPtr<nsIThread> mThread;
 
   Mutex mMutex;
 
   // protected with mMutex:
   webrtc::VideoEngine* mScreenEngine;
+  webrtc::VideoEngine* mBrowserEngine;
   webrtc::VideoEngine* mWinEngine;
   webrtc::VideoEngine* mAppEngine;
   webrtc::VideoEngine* mVideoEngine;
   webrtc::VoiceEngine* mVoiceEngine;
 
   // specialized configurations
   webrtc::Config mAppEngineConfig;
   webrtc::Config mWinEngineConfig;
   webrtc::Config mScreenEngineConfig;
+  webrtc::Config mBrowserEngineConfig;
 
   // Need this to avoid unneccesary WebRTC calls while enumerating.
   bool mVideoEngineInit;
   bool mAudioEngineInit;
   bool mScreenEngineInit;
+  bool mBrowserEngineInit;
   bool mWinEngineInit;
   bool mAppEngineInit;
   bool mHasTabVideoSource;
 
   // Store devices we've already seen in a hashtable for quick return.
   // Maps UUID to MediaEngineSource (one set for audio, one for video).
   nsRefPtrHashtable<nsStringHashKey, MediaEngineWebRTCVideoSource > mVideoSources;
   nsRefPtrHashtable<nsStringHashKey, MediaEngineWebRTCAudioSource > mAudioSources;
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -1487,17 +1487,17 @@ MediaManager::GetUserMedia(bool aPrivile
     runnable = new GetUserMediaRunnable(c, onSuccess.forget(),
       onError.forget(), windowID, listener, mPrefs);
   }
 
   // deny screensharing request if support is disabled
   if (c.mVideo.IsMediaTrackConstraints() &&
       !Preferences::GetBool("media.getusermedia.screensharing.enabled", false)) {
     auto& tc = c.mVideo.GetAsMediaTrackConstraints();
-    if (tc.mMediaSource != dom::MediaSourceEnum::Camera) {
+    if (tc.mMediaSource != dom::MediaSourceEnum::Camera && tc.mMediaSource != dom::MediaSourceEnum::Browser) {
       return runnable->Denied(NS_LITERAL_STRING("PERMISSION_DENIED"));
     }
   }
 
 #ifdef MOZ_B2G_CAMERA
   if (mCameraManager == nullptr) {
     mCameraManager = nsDOMCameraManager::CreateInstance(aWindow);
   }
--- a/dom/webidl/Constraints.webidl
+++ b/dom/webidl/Constraints.webidl
@@ -13,17 +13,18 @@ enum VideoFacingModeEnum {
     "left",
     "right"
 };
 
 enum MediaSourceEnum {
     "camera",
     "screen",
     "application",
-    "window"
+    "window",
+    "browser"
 };
 
 dictionary ConstrainLongRange {
     long min = -2147483647; // +1 works around windows compiler bug
     long max = 2147483647;
 };
 
 dictionary ConstrainDoubleRange {
new file mode 100644
--- /dev/null
+++ b/media/webrtc/trunk/webrtc/video_engine/browser_capture_impl.h
@@ -0,0 +1,63 @@
+#ifndef WEBRTC_MODULES_BROWSER_CAPTURE_MAIN_SOURCE_BROWSER_CAPTURE_IMPL_H_
+#define WEBRTC_MODULES_BROWSER_CAPTURE_MAIN_SOURCE_BROWSER_CAPTURE_IMPL_H_
+
+#include "webrtc/modules/video_capture/include/video_capture.h"
+
+using namespace webrtc::videocapturemodule;
+
+namespace webrtc {
+
+  class BrowserDeviceInfoImpl : public VideoCaptureModule::DeviceInfo {
+  public:
+    virtual uint32_t NumberOfDevices() { return 1; }
+
+    virtual int32_t GetDeviceName(uint32_t deviceNumber,
+                                  char* deviceNameUTF8,
+                                  uint32_t deviceNameLength,
+                                  char* deviceUniqueIdUTF8,
+                                  uint32_t deviceUniqueIdUTF8Length,
+                                  char* productUniqueIdUTF8 = NULL,
+                                  uint32_t productUniqueIdUTF8Length = 0) {
+      deviceNameUTF8 = const_cast<char*>(kDeviceName);
+      deviceUniqueIdUTF8 = const_cast<char*>(kUniqueDeviceName);
+      productUniqueIdUTF8 =  const_cast<char*>(kProductUniqueId);
+      return 1;
+    };
+
+
+    virtual int32_t NumberOfCapabilities(const char* deviceUniqueIdUTF8) {
+      return 0;
+    }
+
+    virtual int32_t GetCapability(const char* deviceUniqueIdUTF8,
+                                  const uint32_t deviceCapabilityNumber,
+                                  VideoCaptureCapability& capability) { return 0;};
+
+    virtual int32_t GetOrientation(const char* deviceUniqueIdUTF8,
+                                   VideoCaptureRotation& orientation) { return 0; }
+
+    virtual int32_t GetBestMatchedCapability(const char* deviceUniqueIdUTF8,
+                                             const VideoCaptureCapability& requested,
+                                             VideoCaptureCapability& resulting) { return 0;}
+
+    virtual int32_t DisplayCaptureSettingsDialogBox(const char* deviceUniqueIdUTF8,
+                                                    const char* dialogTitleUTF8,
+                                                    void* parentWindow,
+                                                    uint32_t positionX,
+                                                    uint32_t positionY) { return 0; }
+
+    BrowserDeviceInfoImpl() : kDeviceName("browser"), kUniqueDeviceName("browser"), kProductUniqueId("browser") {}
+
+    static BrowserDeviceInfoImpl* CreateDeviceInfo() {
+      return new BrowserDeviceInfoImpl();
+    }
+    virtual ~BrowserDeviceInfoImpl() {}
+
+  private:
+    const char* kDeviceName;
+    const char* kUniqueDeviceName;
+    const char* kProductUniqueId;
+
+  };
+}
+#endif
--- a/media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
+++ b/media/webrtc/trunk/webrtc/video_engine/include/vie_capture.h
@@ -46,17 +46,18 @@ struct CaptureCapability {
     interlaced = false;
   }
 };
 
 enum CaptureDeviceType {
   Camera = 0,
   Screen = 1,
   Application = 2,
-  Window = 3
+  Window = 3,
+  Browser = 4
 };
 struct CaptureDeviceInfo {
   CaptureDeviceType type;
 
   CaptureDeviceInfo() : type(CaptureDeviceType::Camera) {}
   CaptureDeviceInfo(CaptureDeviceType t) : type(t) {}
 };
 
--- a/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
@@ -18,16 +18,17 @@
 #include "webrtc/modules/video_coding/main/interface/video_coding_defines.h"
 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
 #include "webrtc/system_wrappers/interface/trace.h"
 #include "webrtc/video_engine/include/vie_errors.h"
 #include "webrtc/video_engine/vie_capturer.h"
 #include "webrtc/video_engine/vie_defines.h"
 #include "webrtc/video_engine/desktop_capture_impl.h"
+#include "webrtc/video_engine/browser_capture_impl.h"
 
 namespace webrtc {
 
 ViEInputManager::ViEInputManager(const int engine_id, const Config& config)
     : config_(config),
       engine_id_(engine_id),
       map_cs_(CriticalSectionWrapper::CreateCriticalSection()),
       device_info_cs_(CriticalSectionWrapper::CreateCriticalSection()),
@@ -422,16 +423,19 @@ VideoCaptureModule::DeviceInfo* ViEInput
       case CaptureDeviceType::Screen:
       case CaptureDeviceType::Application:
       case CaptureDeviceType::Window:
 #if !defined(ANDROID)
         capture_device_info_ = DesktopCaptureImpl::CreateDeviceInfo(ViEModuleId(engine_id_),
                                                                     type);
 #endif
         break;
+      case CaptureDeviceType::Browser:
+        capture_device_info_ = BrowserDeviceInfoImpl::CreateDeviceInfo();
+        break;
       case CaptureDeviceType::Camera:
         capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(ViEModuleId(engine_id_));
         break;
       default:
         // Don't try to build anything for unknown/unsupported types
         break;
     }
   }