Bug 983504 - ViEInputManager & config changes for screen sharing. r=gcp
authorMatthew A. Miller <linuxwolf@outer-planes.net>
Mon, 07 Jul 2014 09:55:00 +0200
changeset 215209 77ec03dc289a751d711368b8c8bc6a10433674bc
parent 215208 47007b47379f75a868fd98d4c5244538d9699b37
child 215210 911234d51c81820df05b0b7222289a6543e316a4
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs983504
milestone33.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 983504 - ViEInputManager & config changes for screen sharing. r=gcp
media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
--- a/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.cc
@@ -17,16 +17,17 @@
 #include "webrtc/modules/video_coding/main/interface/video_coding.h"
 #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"
 
 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()),
@@ -57,64 +58,56 @@ void ViEInputManager::SetModuleProcessTh
   assert(!module_process_thread_);
   module_process_thread_ = module_process_thread;
 }
 
 int ViEInputManager::NumberOfCaptureDevices() {
   WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), "%s",
                __FUNCTION__);
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   return capture_device_info_->NumberOfDevices();
 }
 
 int ViEInputManager::GetDeviceName(uint32_t device_number,
                                    char* device_nameUTF8,
                                    uint32_t device_name_length,
                                    char* device_unique_idUTF8,
                                    uint32_t device_unique_idUTF8Length) {
   WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_),
                "%s(device_number: %d)", __FUNCTION__, device_number);
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   return capture_device_info_->GetDeviceName(device_number, device_nameUTF8,
                                              device_name_length,
                                              device_unique_idUTF8,
                                              device_unique_idUTF8Length);
 }
 
 int ViEInputManager::NumberOfCaptureCapabilities(
   const char* device_unique_idUTF8) {
   WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_), "%s",
                __FUNCTION__);
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   return capture_device_info_->NumberOfCapabilities(device_unique_idUTF8);
 }
 
 int ViEInputManager::GetCaptureCapability(
     const char* device_unique_idUTF8,
     const uint32_t device_capability_number,
     CaptureCapability& capability) {
   WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_),
                "%s(device_unique_idUTF8: %s, device_capability_number: %d)",
                __FUNCTION__, device_unique_idUTF8, device_capability_number);
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   VideoCaptureCapability module_capability;
   int result = capture_device_info_->GetCapability(device_unique_idUTF8,
                                                    device_capability_number,
                                                    module_capability);
   if (result != 0)
     return result;
 
@@ -130,19 +123,17 @@ int ViEInputManager::GetCaptureCapabilit
 }
 
 int ViEInputManager::GetOrientation(const char* device_unique_idUTF8,
                                     RotateCapturedFrame& orientation) {
   WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideo, ViEId(engine_id_),
                "%s(device_unique_idUTF8: %s,)", __FUNCTION__,
                device_unique_idUTF8);
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   VideoCaptureRotation module_orientation;
   int result = capture_device_info_->GetOrientation(device_unique_idUTF8,
                                                     module_orientation);
   // Copy from module type to public type.
   switch (module_orientation) {
     case kCameraRotate0:
       orientation = RotateCapturedFrame_0;
@@ -162,19 +153,17 @@ int ViEInputManager::GetOrientation(cons
 
 int ViEInputManager::DisplayCaptureSettingsDialogBox(
     const char* device_unique_idUTF8,
     const char* dialog_titleUTF8,
     void* parent_window,
     uint32_t positionX,
     uint32_t positionY) {
   CriticalSectionScoped cs(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   return capture_device_info_->DisplayCaptureSettingsDialogBox(
            device_unique_idUTF8, dialog_titleUTF8, parent_window, positionX,
            positionY);
 }
 
 int ViEInputManager::CreateCaptureDevice(
     const char* device_unique_idUTF8,
@@ -200,19 +189,17 @@ int ViEInputManager::CreateCaptureDevice
         return kViECaptureDeviceAlreadyAllocated;
       }
     }
   }
 
   // Make sure the device name is valid.
   bool found_device = false;
   CriticalSectionScoped cs_devinfo(device_info_cs_.get());
-  if (capture_device_info_ == NULL)
-    capture_device_info_ = VideoCaptureFactory::CreateDeviceInfo(
-        ViEModuleId(engine_id_));
+  GetDeviceInfo();
   assert(capture_device_info_);
   for (uint32_t device_index = 0;
        device_index < capture_device_info_->NumberOfDevices(); ++device_index) {
     if (device_unique_idUTF8Length > kVideoCaptureUniqueNameLength) {
       // User's string length is longer than the max.
       return -1;
     }
 
@@ -421,16 +408,44 @@ ViEFrameProviderBase* ViEInputManager::V
 ViECapturer* ViEInputManager::ViECapturePtr(int capture_id) const {
   if (!(capture_id >= kViECaptureIdBase &&
         capture_id <= kViECaptureIdBase + kViEMaxCaptureDevices))
     return NULL;
 
   return static_cast<ViECapturer*>(ViEFrameProvider(capture_id));
 }
 
+// Create different DeviceInfo by _config;
+VideoCaptureModule::DeviceInfo* ViEInputManager::GetDeviceInfo() {
+  CaptureDeviceType type = config_.Get<CaptureDeviceInfo>().type;
+
+  if (capture_device_info_ == NULL) {
+    switch (type) {
+      case CaptureDeviceType::Screen:
+#if !defined(ANDROID)
+        capture_device_info_ = DesktopCaptureImpl::CreateDeviceInfo(ViEModuleId(engine_id_),
+                                                                    false);
+#endif
+        break;
+      case CaptureDeviceType::Application:
+#if !defined(ANDROID)
+        capture_device_info_ = DesktopCaptureImpl::CreateDeviceInfo(ViEModuleId(engine_id_),
+                                                                    true);
+#endif
+        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;
+    }
+  }
+  return capture_device_info_;
+}
 ViEInputManagerScoped::ViEInputManagerScoped(
     const ViEInputManager& vie_input_manager)
     : ViEManagerScopedBase(vie_input_manager) {
 }
 
 ViECapturer* ViEInputManagerScoped::Capture(int capture_id) const {
   return static_cast<const ViEInputManager*>(vie_manager_)->ViECapturePtr(
       capture_id);
--- a/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
+++ b/media/webrtc/trunk/webrtc/video_engine/vie_input_manager.h
@@ -72,17 +72,18 @@ class ViEInputManager : private ViEManag
   int CreateCaptureDevice(const char* device_unique_idUTF8,
                           const uint32_t device_unique_idUTF8Length,
                           int& capture_id);
   int CreateCaptureDevice(VideoCaptureModule* capture_module,
                           int& capture_id);
   int CreateExternalCaptureDevice(ViEExternalCapture*& external_capture,
                                   int& capture_id);
   int DestroyCaptureDevice(int capture_id);
-
+ protected:
+  VideoCaptureModule::DeviceInfo* GetDeviceInfo();
  private:
   // Gets and allocates a free capture device id. Assumed protected by caller.
   bool GetFreeCaptureId(int* freecapture_id);
 
   // Frees a capture id assigned in GetFreeCaptureId.
   void ReturnCaptureId(int capture_id);
 
   // Gets the ViEFrameProvider for this capture observer.