Adding capture device selection capability for video_loopback. It will help to select any capture device to test the utility. In future we can add screen share as capture device.

BUG=webrtc:7719

Change-Id: Iddc66188341c0c90e96766dff671ac3863bf3f5d
Reviewed-on: https://chromium-review.googlesource.com/517523
Commit-Queue: Peter Boström <pbos@webrtc.org>
Reviewed-by: Peter Boström <pbos@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#18392}
diff --git a/AUTHORS b/AUTHORS
index c11e96d..4b387ed 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -46,6 +46,7 @@
 Silviu Caragea <silviu.cpp@gmail.com>
 Stefan Gula <steweg@gmail.com>
 Steve Reid <sreid@sea-to-sky.net>
+Tarun Chawla <trnkumarchawla@gmail.com>
 Vladimir Beloborodov <VladimirTechMan@gmail.com>
 Vicken Simonian <vsimon@gmail.com>
 Victor Costan <costan@gmail.com>
diff --git a/webrtc/test/vcm_capturer.cc b/webrtc/test/vcm_capturer.cc
index 69c2b6a..6418641 100644
--- a/webrtc/test/vcm_capturer.cc
+++ b/webrtc/test/vcm_capturer.cc
@@ -13,21 +13,23 @@
 #include "webrtc/base/logging.h"
 #include "webrtc/modules/video_capture/video_capture_factory.h"
 #include "webrtc/video_send_stream.h"
-
 namespace webrtc {
 namespace test {
 
 VcmCapturer::VcmCapturer() : started_(false), sink_(nullptr), vcm_(nullptr) {}
 
-bool VcmCapturer::Init(size_t width, size_t height, size_t target_fps) {
+bool VcmCapturer::Init(size_t width,
+                       size_t height,
+                       size_t target_fps,
+                       size_t capture_device_index) {
   std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
       VideoCaptureFactory::CreateDeviceInfo());
 
   char device_name[256];
   char unique_name[256];
-  if (device_info->GetDeviceName(0, device_name, sizeof(device_name),
-                                 unique_name, sizeof(unique_name)) !=
-      0) {
+  if (device_info->GetDeviceName(static_cast<uint32_t>(capture_device_index),
+                                 device_name, sizeof(device_name), unique_name,
+                                 sizeof(unique_name)) != 0) {
     Destroy();
     return false;
   }
@@ -54,9 +56,10 @@
 
 VcmCapturer* VcmCapturer::Create(size_t width,
                                  size_t height,
-                                 size_t target_fps) {
+                                 size_t target_fps,
+                                 size_t capture_device_index) {
   std::unique_ptr<VcmCapturer> vcm_capturer(new VcmCapturer());
-  if (!vcm_capturer->Init(width, height, target_fps)) {
+  if (!vcm_capturer->Init(width, height, target_fps, capture_device_index)) {
     LOG(LS_WARNING) << "Failed to create VcmCapturer(w = " << width
                     << ", h = " << height << ", fps = " << target_fps << ")";
     return nullptr;
diff --git a/webrtc/test/vcm_capturer.h b/webrtc/test/vcm_capturer.h
index 5e40c2b..08e8444 100644
--- a/webrtc/test/vcm_capturer.h
+++ b/webrtc/test/vcm_capturer.h
@@ -26,7 +26,10 @@
     : public VideoCapturer,
       public rtc::VideoSinkInterface<VideoFrame> {
  public:
-  static VcmCapturer* Create(size_t width, size_t height, size_t target_fps);
+  static VcmCapturer* Create(size_t width,
+                             size_t height,
+                             size_t target_fps,
+                             size_t capture_device_index);
   virtual ~VcmCapturer();
 
   void Start() override;
@@ -39,7 +42,10 @@
 
  private:
   VcmCapturer();
-  bool Init(size_t width, size_t height, size_t target_fps);
+  bool Init(size_t width,
+            size_t height,
+            size_t target_fps,
+            size_t capture_device_index);
   void Destroy();
 
   rtc::CriticalSection crit_;
diff --git a/webrtc/video/video_loopback.cc b/webrtc/video/video_loopback.cc
index ec206a8..6c2a163 100644
--- a/webrtc/video/video_loopback.cc
+++ b/webrtc/video/video_loopback.cc
@@ -35,6 +35,11 @@
   return static_cast<int>(FLAGS_fps);
 }
 
+DEFINE_int32(capture_device_index, 0, "Capture device to select");
+size_t GetCaptureDevice() {
+  return static_cast<size_t>(FLAGS_capture_device_index);
+}
+
 DEFINE_int32(min_bitrate, 50, "Call and stream min bitrate in kbps.");
 int MinBitrateKbps() {
   return static_cast<int>(FLAGS_min_bitrate);
@@ -259,7 +264,8 @@
                   flags::FLAGS_use_ulpfec,
                   flags::FLAGS_use_flexfec,
                   flags::EncodedFramePath(),
-                  flags::Clip()};
+                  flags::Clip(),
+                  flags::GetCaptureDevice()};
   params.audio = {flags::FLAGS_audio, flags::FLAGS_audio_video_sync,
       flags::FLAGS_audio_dtx};
   params.screenshare.enabled = false;
diff --git a/webrtc/video/video_quality_test.cc b/webrtc/video/video_quality_test.cc
index 86d61d6..76c743c 100644
--- a/webrtc/video/video_quality_test.cc
+++ b/webrtc/video/video_quality_test.cc
@@ -1566,7 +1566,8 @@
   } else {
     if (params_.video.clip_name.empty()) {
       video_capturer_.reset(test::VcmCapturer::Create(
-          params_.video.width, params_.video.height, params_.video.fps));
+          params_.video.width, params_.video.height, params_.video.fps,
+          params_.video.capture_device_index));
       if (!video_capturer_) {
         // Failed to get actual camera, use chroma generator as backup.
         video_capturer_.reset(test::FrameGeneratorCapturer::Create(
diff --git a/webrtc/video/video_quality_test.h b/webrtc/video/video_quality_test.h
index fac5e7c..5cf54bd 100644
--- a/webrtc/video/video_quality_test.h
+++ b/webrtc/video/video_quality_test.h
@@ -52,6 +52,7 @@
       bool flexfec;
       std::string encoded_frame_base_path;
       std::string clip_name;
+      size_t capture_device_index;
     } video;
     struct Audio {
       bool enabled;