From 7248b40344092d002cb06f9f6c5867f7238e85cd Mon Sep 17 00:00:00 2001 From: Johnny Lee Date: Mon, 28 Jan 2019 11:29:26 -0500 Subject: [PATCH] Added VcmCapturer::Create loop to allow nonzero device index. Bug: webrtc:10181 Change-Id: I29c701ed756416b63d377e9b9137fffeba1f7f2e Reviewed-on: https://webrtc-review.googlesource.com/c/116440 Commit-Queue: Niels Moller Reviewed-by: Niels Moller Reviewed-by: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#26437} --- examples/peerconnection/client/conductor.cc | 20 +++++++++++++++----- test/vcm_capturer.cc | 3 +++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/peerconnection/client/conductor.cc b/examples/peerconnection/client/conductor.cc index 03f820a60a..8fc07228d9 100644 --- a/examples/peerconnection/client/conductor.cc +++ b/examples/peerconnection/client/conductor.cc @@ -74,13 +74,23 @@ class CapturerTrackSource : public webrtc::VideoTrackSource { const size_t kWidth = 640; const size_t kHeight = 480; const size_t kFps = 30; - const size_t kDeviceIndex = 0; - std::unique_ptr capturer = absl::WrapUnique( - webrtc::test::VcmCapturer::Create(kWidth, kHeight, kFps, kDeviceIndex)); - if (!capturer) { + std::unique_ptr capturer; + std::unique_ptr info( + webrtc::VideoCaptureFactory::CreateDeviceInfo()); + if (!info) { return nullptr; } - return new rtc::RefCountedObject(std::move(capturer)); + int num_devices = info->NumberOfDevices(); + for (int i = 0; i < num_devices; ++i) { + capturer = absl::WrapUnique( + webrtc::test::VcmCapturer::Create(kWidth, kHeight, kFps, i)); + if (capturer) { + return new + rtc::RefCountedObject(std::move(capturer)); + } + } + + return nullptr; } protected: diff --git a/test/vcm_capturer.cc b/test/vcm_capturer.cc index 353be0a317..3854e9fadd 100644 --- a/test/vcm_capturer.cc +++ b/test/vcm_capturer.cc @@ -39,6 +39,9 @@ bool VcmCapturer::Init(size_t width, } vcm_ = webrtc::VideoCaptureFactory::Create(unique_name); + if (!vcm_) { + return false; + } vcm_->RegisterCaptureDataCallback(this); device_info->GetCapability(vcm_->CurrentDeviceName(), 0, capability_);