diff --git a/examples/BUILD.gn b/examples/BUILD.gn index d5aef6a79a..ace85fed8a 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -701,6 +701,7 @@ if (is_linux || is_win) { "../rtc_base/third_party/sigslot", "../system_wrappers:field_trial", "../test:field_trial", + "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/types:optional", ] if (is_win) { @@ -742,9 +743,11 @@ if (is_linux || is_win) { "../modules/audio_processing:audio_processing", "../modules/video_capture:video_capture_module", "../pc:libjingle_peerconnection", + "../pc:peerconnection", "../rtc_base:rtc_base", "../rtc_base:rtc_base_approved", "../rtc_base:rtc_json", + "../test:video_test_common", "//third_party/libyuv", ] } diff --git a/examples/peerconnection/client/conductor.cc b/examples/peerconnection/client/conductor.cc index ff31213117..096ff58d72 100644 --- a/examples/peerconnection/client/conductor.cc +++ b/examples/peerconnection/client/conductor.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/memory/memory.h" #include "absl/types/optional.h" #include "api/audio/audio_mixer.h" #include "api/audio_codecs/audio_decoder_factory.h" @@ -31,18 +32,20 @@ #include "api/video_codecs/video_encoder_factory.h" #include "examples/peerconnection/client/defaults.h" #include "media/base/device.h" -#include "media/engine/webrtcvideocapturerfactory.h" #include "modules/audio_device/include/audio_device.h" #include "modules/audio_processing/include/audio_processing.h" #include "modules/video_capture/video_capture.h" #include "modules/video_capture/video_capture_factory.h" #include "p2p/base/portallocator.h" +#include "pc/videotracksource.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/refcountedobject.h" #include "rtc_base/rtccertificategenerator.h" #include "rtc_base/strings/json.h" +#include "test/vcm_capturer.h" +namespace { // Names used for a IceCandidate JSON object. const char kCandidateSdpMidName[] = "sdpMid"; const char kCandidateSdpMlineIndexName[] = "sdpMLineIndex"; @@ -65,6 +68,35 @@ class DummySetSessionDescriptionObserver } }; +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_; +}; + +} // namespace + Conductor::Conductor(PeerConnectionClient* client, MainWindow* main_wnd) : peer_id_(-1), loopback_(false), client_(client), main_wnd_(main_wnd) { client_->RegisterObserver(this); @@ -387,36 +419,6 @@ void Conductor::ConnectToPeer(int peer_id) { } } -std::unique_ptr Conductor::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 Conductor::AddTracks() { if (!peer_connection_->GetSenders().empty()) { return; // Already added tracks. @@ -432,13 +434,11 @@ void Conductor::AddTracks() { << result_or_error.error().message(); } - std::unique_ptr video_device = - OpenVideoCaptureDevice(); + rtc::scoped_refptr video_device = + CapturerTrackSource::Create(); if (video_device) { rtc::scoped_refptr video_track_( - peer_connection_factory_->CreateVideoTrack( - kVideoLabel, peer_connection_factory_->CreateVideoSource( - std::move(video_device), nullptr))); + peer_connection_factory_->CreateVideoTrack(kVideoLabel, video_device)); main_wnd_->StartLocalRenderer(video_track_); result_or_error = peer_connection_->AddTrack(video_track_, {kStreamId}); diff --git a/examples/peerconnection/client/conductor.h b/examples/peerconnection/client/conductor.h index a038743915..76c1dbecf9 100644 --- a/examples/peerconnection/client/conductor.h +++ b/examples/peerconnection/client/conductor.h @@ -57,7 +57,6 @@ class Conductor : public webrtc::PeerConnectionObserver, void DeletePeerConnection(); void EnsureStreamingUI(); void AddTracks(); - std::unique_ptr OpenVideoCaptureDevice(); // // PeerConnectionObserver implementation.