From 0a59535ce732138add46bbd96803a1f170715786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Wed, 2 Jan 2019 15:12:38 +0100 Subject: [PATCH] Update unityplugin to use VcmCapturer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces use of WebRtcVideoDeviceCapturerFactory. Bug: webrtc:6353 Change-Id: I3c1626af46cb56817190739a39842c4c5a51560d Reviewed-on: https://webrtc-review.googlesource.com/c/115960 Reviewed-by: Kári Helgason Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#26117} --- examples/BUILD.gn | 2 + .../unityplugin/simple_peer_connection.cc | 72 +++++++++---------- examples/unityplugin/simple_peer_connection.h | 1 - 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 3fded23736..d5aef6a79a 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -868,7 +868,9 @@ if (is_win || is_android) { "../modules/audio_processing:audio_processing", "../modules/video_capture:video_capture_module", "../pc:libjingle_peerconnection", + "../pc:peerconnection", "../rtc_base:rtc_base", + "../test:video_test_common", "//third_party/abseil-cpp/absl/memory", ] if (is_android) { diff --git a/examples/unityplugin/simple_peer_connection.cc b/examples/unityplugin/simple_peer_connection.cc index bf6a6827b0..e1a2552aba 100644 --- a/examples/unityplugin/simple_peer_connection.cc +++ b/examples/unityplugin/simple_peer_connection.cc @@ -20,12 +20,13 @@ #include "media/engine/internaldecoderfactory.h" #include "media/engine/internalencoderfactory.h" #include "media/engine/multiplexcodecfactory.h" -#include "media/engine/webrtcvideocapturerfactory.h" #include "media/engine/webrtcvideodecoderfactory.h" #include "media/engine/webrtcvideoencoderfactory.h" #include "modules/audio_device/include/audio_device.h" #include "modules/audio_processing/include/audio_processing.h" #include "modules/video_capture/video_capture_factory.h" +#include "pc/videotracksource.h" +#include "test/vcm_capturer.h" #if defined(WEBRTC_ANDROID) #include "examples/unityplugin/classreferenceholder.h" @@ -50,6 +51,34 @@ static rtc::scoped_refptr // relies on the app to dispose the capturer when the peerconnection // shuts down. static jobject g_camera = nullptr; +#else +class CapturerTrackSource : public webrtc::VideoTrackSource { + public: + static rtc::scoped_refptr Create() { + 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) { + return nullptr; + } + return new rtc::RefCountedObject(std::move(capturer)); + } + + protected: + explicit CapturerTrackSource( + std::unique_ptr capturer) + : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {} + + private: + rtc::VideoSourceInterface* source() override { + return capturer_.get(); + } + std::unique_ptr capturer_; +}; + #endif std::string GetEnvVarOrDefault(const char* env_var_name, @@ -388,37 +417,6 @@ void SimplePeerConnection::OnAddStream( SetAudioControl(); } -std::unique_ptr -SimplePeerConnection::OpenVideoCaptureDevice() { - std::vector device_names; - { - std::unique_ptr info( - webrtc::VideoCaptureFactory::CreateDeviceInfo()); - if (!info) { - return nullptr; - } - int num_devices = info->NumberOfDevices(); - for (int i = 0; i < num_devices; ++i) { - const uint32_t kSize = 256; - char name[kSize] = {0}; - char id[kSize] = {0}; - if (info->GetDeviceName(i, name, kSize, id, kSize) != -1) { - device_names.push_back(name); - } - } - } - - cricket::WebRtcVideoDeviceCapturerFactory factory; - std::unique_ptr capturer; - for (const auto& name : device_names) { - capturer = factory.Create(cricket::Device(name, 0)); - if (capturer) { - break; - } - } - return capturer; -} - void SimplePeerConnection::AddStreams(bool audio_only) { if (active_streams_.find(kStreamId) != active_streams_.end()) return; // Already added. @@ -470,12 +468,12 @@ void SimplePeerConnection::AddStreams(bool audio_only) { proxy_source.release())); stream->AddTrack(video_track); #else - std::unique_ptr capture = OpenVideoCaptureDevice(); - if (capture) { + rtc::scoped_refptr video_device = + CapturerTrackSource::Create(); + if (video_device) { rtc::scoped_refptr video_track( - g_peer_connection_factory->CreateVideoTrack( - kVideoLabel, g_peer_connection_factory->CreateVideoSource( - std::move(capture), nullptr))); + g_peer_connection_factory->CreateVideoTrack(kVideoLabel, + video_device)); stream->AddTrack(video_track); } diff --git a/examples/unityplugin/simple_peer_connection.h b/examples/unityplugin/simple_peer_connection.h index 5b30778711..e4d8a1b6cc 100644 --- a/examples/unityplugin/simple_peer_connection.h +++ b/examples/unityplugin/simple_peer_connection.h @@ -66,7 +66,6 @@ class SimplePeerConnection : public webrtc::PeerConnectionObserver, const char* username, const char* credential); void CloseDataChannel(); - std::unique_ptr OpenVideoCaptureDevice(); void SetAudioControl(); // PeerConnectionObserver implementation.