Update unityplugin to use VcmCapturer.
Replaces use of WebRtcVideoDeviceCapturerFactory.
Bug: webrtc:6353
Change-Id: I3c1626af46cb56817190739a39842c4c5a51560d
Reviewed-on: https://webrtc-review.googlesource.com/c/115960
Reviewed-by: Kári Helgason <kthelgason@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26117}
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 3fded23..d5aef6a 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -868,7 +868,9 @@
"../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 bf6a682..e1a2552 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 @@
// 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<CapturerTrackSource> Create() {
+ const size_t kWidth = 640;
+ const size_t kHeight = 480;
+ const size_t kFps = 30;
+ const size_t kDeviceIndex = 0;
+ std::unique_ptr<webrtc::test::VcmCapturer> capturer = absl::WrapUnique(
+ webrtc::test::VcmCapturer::Create(kWidth, kHeight, kFps, kDeviceIndex));
+ if (!capturer) {
+ return nullptr;
+ }
+ return new rtc::RefCountedObject<CapturerTrackSource>(std::move(capturer));
+ }
+
+ protected:
+ explicit CapturerTrackSource(
+ std::unique_ptr<webrtc::test::VcmCapturer> capturer)
+ : VideoTrackSource(/*remote=*/false), capturer_(std::move(capturer)) {}
+
+ private:
+ rtc::VideoSourceInterface<webrtc::VideoFrame>* source() override {
+ return capturer_.get();
+ }
+ std::unique_ptr<webrtc::test::VcmCapturer> capturer_;
+};
+
#endif
std::string GetEnvVarOrDefault(const char* env_var_name,
@@ -388,37 +417,6 @@
SetAudioControl();
}
-std::unique_ptr<cricket::VideoCapturer>
-SimplePeerConnection::OpenVideoCaptureDevice() {
- std::vector<std::string> device_names;
- {
- std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> 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<cricket::VideoCapturer> 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 @@
proxy_source.release()));
stream->AddTrack(video_track);
#else
- std::unique_ptr<cricket::VideoCapturer> capture = OpenVideoCaptureDevice();
- if (capture) {
+ rtc::scoped_refptr<CapturerTrackSource> video_device =
+ CapturerTrackSource::Create();
+ if (video_device) {
rtc::scoped_refptr<webrtc::VideoTrackInterface> 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 5b30778..e4d8a1b 100644
--- a/examples/unityplugin/simple_peer_connection.h
+++ b/examples/unityplugin/simple_peer_connection.h
@@ -66,7 +66,6 @@
const char* username,
const char* credential);
void CloseDataChannel();
- std::unique_ptr<cricket::VideoCapturer> OpenVideoCaptureDevice();
void SetAudioControl();
// PeerConnectionObserver implementation.