diff --git a/webrtc/api/peerconnectionfactoryproxy.h b/webrtc/api/peerconnectionfactoryproxy.h index e829cca649..dd784f5025 100644 --- a/webrtc/api/peerconnectionfactoryproxy.h +++ b/webrtc/api/peerconnectionfactoryproxy.h @@ -25,6 +25,11 @@ namespace webrtc { // are called on is an implementation detail. BEGIN_SIGNALING_PROXY_MAP(PeerConnectionFactory) PROXY_SIGNALING_THREAD_DESTRUCTOR() + // Use the overloads of CreateVideoSource that take raw VideoCapturer + // pointers from PeerConnectionFactoryInterface. + // TODO(deadbeef): Remove this using statement once those overloads are + // removed. + using PeerConnectionFactoryInterface::CreateVideoSource; PROXY_METHOD1(void, SetOptions, const Options&) PROXY_METHOD5(rtc::scoped_refptr, CreatePeerConnection, @@ -48,11 +53,11 @@ BEGIN_SIGNALING_PROXY_MAP(PeerConnectionFactory) const cricket::AudioOptions&) PROXY_METHOD2(rtc::scoped_refptr, CreateVideoSource, - cricket::VideoCapturer*, + std::unique_ptr, const MediaConstraintsInterface*) PROXY_METHOD1(rtc::scoped_refptr, CreateVideoSource, - cricket::VideoCapturer*) + std::unique_ptr) PROXY_METHOD2(rtc::scoped_refptr, CreateVideoTrack, const std::string&, diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index 2a22258a0a..0c9198cd01 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -90,6 +90,7 @@ #include "webrtc/base/socketaddress.h" #include "webrtc/base/sslstreamadapter.h" #include "webrtc/media/base/mediachannel.h" +#include "webrtc/media/base/videocapturer.h" #include "webrtc/p2p/base/portallocator.h" namespace rtc { @@ -966,16 +967,37 @@ class PeerConnectionFactoryInterface : public rtc::RefCountInterface { // Creates a VideoTrackSourceInterface. The new source takes ownership of // |capturer|. - // TODO(deadbeef): Switch to std::unique_ptr<>, to make this transfership of - // ownership more clear. + // TODO(deadbeef): Make pure virtual once downstream mock PC factory classes + // are updated. virtual rtc::scoped_refptr CreateVideoSource( - cricket::VideoCapturer* capturer) = 0; + std::unique_ptr capturer) { + return nullptr; + } + // A video source creator that allows selection of resolution and frame rate. // |constraints| decides video resolution and frame rate but can be NULL. // In the NULL case, use the version above. + // + // |constraints| is only used for the invocation of this method, and can + // safely be destroyed afterwards. + virtual rtc::scoped_refptr CreateVideoSource( + std::unique_ptr capturer, + const MediaConstraintsInterface* constraints) { + return nullptr; + } + + // Deprecated; please use the versions that take unique_ptrs above. + // TODO(deadbeef): Remove these once safe to do so. + virtual rtc::scoped_refptr CreateVideoSource( + cricket::VideoCapturer* capturer) { + return CreateVideoSource(std::unique_ptr(capturer)); + } virtual rtc::scoped_refptr CreateVideoSource( cricket::VideoCapturer* capturer, - const MediaConstraintsInterface* constraints) = 0; + const MediaConstraintsInterface* constraints) { + return CreateVideoSource(std::unique_ptr(capturer), + constraints); + } // Creates a new local VideoTrack. The same |source| can be used in several // tracks. diff --git a/webrtc/examples/peerconnection/client/conductor.cc b/webrtc/examples/peerconnection/client/conductor.cc index 8c288ebf26..7c41027474 100644 --- a/webrtc/examples/peerconnection/client/conductor.cc +++ b/webrtc/examples/peerconnection/client/conductor.cc @@ -366,7 +366,7 @@ void Conductor::ConnectToPeer(int peer_id) { } } -cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { +std::unique_ptr Conductor::OpenVideoCaptureDevice() { std::vector device_names; { std::unique_ptr info( @@ -386,7 +386,7 @@ cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() { } cricket::WebRtcVideoDeviceCapturerFactory factory; - cricket::VideoCapturer* capturer = nullptr; + std::unique_ptr capturer; for (const auto& name : device_names) { capturer = factory.Create(cricket::Device(name, 0)); if (capturer) { diff --git a/webrtc/examples/peerconnection/client/conductor.h b/webrtc/examples/peerconnection/client/conductor.h index ba3e271e51..726534b941 100644 --- a/webrtc/examples/peerconnection/client/conductor.h +++ b/webrtc/examples/peerconnection/client/conductor.h @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -58,7 +59,7 @@ class Conductor void DeletePeerConnection(); void EnsureStreamingUI(); void AddStreams(); - cricket::VideoCapturer* OpenVideoCaptureDevice(); + std::unique_ptr OpenVideoCaptureDevice(); // // PeerConnectionObserver implementation. diff --git a/webrtc/media/base/videocapturerfactory.h b/webrtc/media/base/videocapturerfactory.h index 012c4a469b..b6f886b6cf 100644 --- a/webrtc/media/base/videocapturerfactory.h +++ b/webrtc/media/base/videocapturerfactory.h @@ -11,6 +11,8 @@ #ifndef WEBRTC_MEDIA_BASE_VIDEOCAPTURERFACTORY_H_ #define WEBRTC_MEDIA_BASE_VIDEOCAPTURERFACTORY_H_ +#include + #include "webrtc/media/base/device.h" namespace cricket { @@ -22,7 +24,7 @@ class VideoDeviceCapturerFactory { VideoDeviceCapturerFactory() {} virtual ~VideoDeviceCapturerFactory() {} - virtual VideoCapturer* Create(const Device& device) = 0; + virtual std::unique_ptr Create(const Device& device) = 0; }; } // namespace cricket diff --git a/webrtc/media/engine/webrtcmediaengine.h b/webrtc/media/engine/webrtcmediaengine.h index 17e79c6cc1..b539b5856b 100644 --- a/webrtc/media/engine/webrtcmediaengine.h +++ b/webrtc/media/engine/webrtcmediaengine.h @@ -40,6 +40,8 @@ class WebRtcMediaEngineFactory { WebRtcVideoEncoderFactory* video_encoder_factory, WebRtcVideoDecoderFactory* video_decoder_factory); + // TODO(deadbeef): Change these to return an std::unique_ptr<>, to indicate + // that the caller owns the returned object. static MediaEngineInterface* Create( webrtc::AudioDeviceModule* adm, const rtc::scoped_refptr& diff --git a/webrtc/media/engine/webrtcvideocapturerfactory.cc b/webrtc/media/engine/webrtcvideocapturerfactory.cc index 3cf360953b..6ee361a0df 100644 --- a/webrtc/media/engine/webrtcvideocapturerfactory.cc +++ b/webrtc/media/engine/webrtcvideocapturerfactory.cc @@ -15,16 +15,17 @@ namespace cricket { -VideoCapturer* WebRtcVideoDeviceCapturerFactory::Create(const Device& device) { +std::unique_ptr WebRtcVideoDeviceCapturerFactory::Create( + const Device& device) { #ifdef HAVE_WEBRTC_VIDEO std::unique_ptr capturer( new WebRtcVideoCapturer()); if (!capturer->Init(device)) { - return nullptr; + return std::unique_ptr(); } - return capturer.release(); + return std::move(capturer); #else - return nullptr; + return std::unique_ptr(); #endif } diff --git a/webrtc/media/engine/webrtcvideocapturerfactory.h b/webrtc/media/engine/webrtcvideocapturerfactory.h index 128ef9d80d..c1f91b70f6 100644 --- a/webrtc/media/engine/webrtcvideocapturerfactory.h +++ b/webrtc/media/engine/webrtcvideocapturerfactory.h @@ -19,7 +19,7 @@ namespace cricket { // Creates instances of cricket::WebRtcVideoCapturer. class WebRtcVideoDeviceCapturerFactory : public VideoDeviceCapturerFactory { public: - virtual VideoCapturer* Create(const Device& device); + std::unique_ptr Create(const Device& device) override; }; } // namespace cricket diff --git a/webrtc/pc/channelmanager.cc b/webrtc/pc/channelmanager.cc index d0957a7b55..d8ecc9a7d8 100644 --- a/webrtc/pc/channelmanager.cc +++ b/webrtc/pc/channelmanager.cc @@ -28,28 +28,26 @@ namespace cricket { using rtc::Bind; -static DataEngineInterface* ConstructDataEngine() { - return new RtpDataEngine(); -} - -ChannelManager::ChannelManager(MediaEngineInterface* me, - DataEngineInterface* dme, +ChannelManager::ChannelManager(std::unique_ptr me, + std::unique_ptr dme, rtc::Thread* thread) { - Construct(me, dme, thread, thread); + Construct(std::move(me), std::move(dme), thread, thread); } -ChannelManager::ChannelManager(MediaEngineInterface* me, +ChannelManager::ChannelManager(std::unique_ptr me, rtc::Thread* worker_thread, rtc::Thread* network_thread) { - Construct(me, ConstructDataEngine(), worker_thread, network_thread); + Construct(std::move(me), + std::unique_ptr(new RtpDataEngine()), + worker_thread, network_thread); } -void ChannelManager::Construct(MediaEngineInterface* me, - DataEngineInterface* dme, +void ChannelManager::Construct(std::unique_ptr me, + std::unique_ptr dme, rtc::Thread* worker_thread, rtc::Thread* network_thread) { - media_engine_.reset(me); - data_media_engine_.reset(dme); + media_engine_ = std::move(me); + data_media_engine_ = std::move(dme); initialized_ = false; main_thread_ = rtc::Thread::Current(); worker_thread_ = worker_thread; diff --git a/webrtc/pc/channelmanager.h b/webrtc/pc/channelmanager.h index 879ea4d39b..052c363486 100644 --- a/webrtc/pc/channelmanager.h +++ b/webrtc/pc/channelmanager.h @@ -38,13 +38,12 @@ class VoiceChannel; class ChannelManager { public: // For testing purposes. Allows the media engine and data media - // engine and dev manager to be mocks. The ChannelManager takes - // ownership of these objects. - ChannelManager(MediaEngineInterface* me, - DataEngineInterface* dme, + // engine and dev manager to be mocks. + ChannelManager(std::unique_ptr me, + std::unique_ptr dme, rtc::Thread* worker_and_network); // Same as above, but gives an easier default DataEngine. - ChannelManager(MediaEngineInterface* me, + ChannelManager(std::unique_ptr me, rtc::Thread* worker, rtc::Thread* network); ~ChannelManager(); @@ -157,8 +156,8 @@ class ChannelManager { typedef std::vector VideoChannels; typedef std::vector RtpDataChannels; - void Construct(MediaEngineInterface* me, - DataEngineInterface* dme, + void Construct(std::unique_ptr me, + std::unique_ptr dme, rtc::Thread* worker_thread, rtc::Thread* network_thread); bool InitMediaEngine_w(); diff --git a/webrtc/pc/channelmanager_unittest.cc b/webrtc/pc/channelmanager_unittest.cc index 74c359012c..deba6a1155 100644 --- a/webrtc/pc/channelmanager_unittest.cc +++ b/webrtc/pc/channelmanager_unittest.cc @@ -8,6 +8,8 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include + #include "webrtc/base/gunit.h" #include "webrtc/base/logging.h" #include "webrtc/base/thread.h" @@ -40,34 +42,28 @@ class ChannelManagerTest : public testing::Test { ChannelManagerTest() : fme_(new cricket::FakeMediaEngine()), fdme_(new cricket::FakeDataEngine()), - cm_(new cricket::ChannelManager(fme_, fdme_, rtc::Thread::Current())), + cm_(new cricket::ChannelManager( + std::unique_ptr(fme_), + std::unique_ptr(fdme_), + rtc::Thread::Current())), fake_call_(webrtc::Call::Config(&event_log_)), - fake_mc_(cm_, &fake_call_), + fake_mc_(cm_.get(), &fake_call_), transport_controller_( - new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {} - - virtual void SetUp() { + new cricket::FakeTransportController(ICEROLE_CONTROLLING)) { fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); } - virtual void TearDown() { - delete transport_controller_; - delete cm_; - cm_ = NULL; - fdme_ = NULL; - fme_ = NULL; - } - webrtc::RtcEventLogNullImpl event_log_; rtc::Thread network_; rtc::Thread worker_; + // |fme_| and |fdme_| are actually owned by |cm_|. cricket::FakeMediaEngine* fme_; cricket::FakeDataEngine* fdme_; - cricket::ChannelManager* cm_; + std::unique_ptr cm_; cricket::FakeCall fake_call_; cricket::FakeMediaController fake_mc_; - cricket::FakeTransportController* transport_controller_; + std::unique_ptr transport_controller_; }; // Test that we startup/shutdown properly. @@ -133,9 +129,8 @@ TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { EXPECT_TRUE(cm_->set_worker_thread(&worker_)); EXPECT_TRUE(cm_->set_network_thread(&network_)); EXPECT_TRUE(cm_->Init()); - delete transport_controller_; - transport_controller_ = - new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING); + transport_controller_.reset( + new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING)); cricket::DtlsTransportInternal* rtp_transport = transport_controller_->CreateDtlsTransport( cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); diff --git a/webrtc/pc/peerconnection_unittest.cc b/webrtc/pc/peerconnection_unittest.cc index b7ddc24e03..df871356db 100644 --- a/webrtc/pc/peerconnection_unittest.cc +++ b/webrtc/pc/peerconnection_unittest.cc @@ -588,8 +588,9 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver, fake_capturer->SetRotation(capture_rotation_); video_capturers_.push_back(fake_capturer); rtc::scoped_refptr source = - peer_connection_factory_->CreateVideoSource(fake_capturer, - &source_constraints); + peer_connection_factory_->CreateVideoSource( + std::unique_ptr(fake_capturer), + &source_constraints); std::string label = stream_label + kVideoTrackLabelBase; rtc::scoped_refptr track( diff --git a/webrtc/pc/peerconnectionfactory.cc b/webrtc/pc/peerconnectionfactory.cc index 4adee15758..1de7284cfe 100644 --- a/webrtc/pc/peerconnectionfactory.cc +++ b/webrtc/pc/peerconnectionfactory.cc @@ -211,13 +211,13 @@ bool PeerConnectionFactory::Initialize() { // TODO: Need to make sure only one VoE is created inside // WebRtcMediaEngine. - cricket::MediaEngineInterface* media_engine = - worker_thread_->Invoke( + std::unique_ptr media_engine = + worker_thread_->Invoke>( RTC_FROM_HERE, rtc::Bind(&PeerConnectionFactory::CreateMediaEngine_w, this)); channel_manager_.reset(new cricket::ChannelManager( - media_engine, worker_thread_, network_thread_)); + std::move(media_engine), worker_thread_, network_thread_)); channel_manager_->SetVideoRtxEnabled(true); channel_manager_->SetCryptoOptions(options_.crypto_options); @@ -254,21 +254,23 @@ PeerConnectionFactory::CreateAudioSource(const cricket::AudioOptions& options) { rtc::scoped_refptr PeerConnectionFactory::CreateVideoSource( - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, const MediaConstraintsInterface* constraints) { RTC_DCHECK(signaling_thread_->IsCurrent()); rtc::scoped_refptr source( - VideoCapturerTrackSource::Create(worker_thread_, capturer, constraints, - false)); + VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), + constraints, false)); return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, source); } rtc::scoped_refptr -PeerConnectionFactory::CreateVideoSource(cricket::VideoCapturer* capturer) { +PeerConnectionFactory::CreateVideoSource( + std::unique_ptr capturer) { RTC_DCHECK(signaling_thread_->IsCurrent()); rtc::scoped_refptr source( - VideoCapturerTrackSource::Create(worker_thread_, capturer, false)); + VideoCapturerTrackSource::Create(worker_thread_, std::move(capturer), + false)); return VideoTrackSourceProxy::Create(signaling_thread_, worker_thread_, source); } @@ -389,11 +391,14 @@ rtc::Thread* PeerConnectionFactory::network_thread() { return network_thread_; } -cricket::MediaEngineInterface* PeerConnectionFactory::CreateMediaEngine_w() { +std::unique_ptr +PeerConnectionFactory::CreateMediaEngine_w() { RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); - return cricket::WebRtcMediaEngineFactory::Create( - default_adm_.get(), audio_decoder_factory_, video_encoder_factory_.get(), - video_decoder_factory_.get(), external_audio_mixer_); + return std::unique_ptr( + cricket::WebRtcMediaEngineFactory::Create( + default_adm_.get(), audio_decoder_factory_, + video_encoder_factory_.get(), video_decoder_factory_.get(), + external_audio_mixer_)); } } // namespace webrtc diff --git a/webrtc/pc/peerconnectionfactory.h b/webrtc/pc/peerconnectionfactory.h index 932821f640..53c6745ba9 100644 --- a/webrtc/pc/peerconnectionfactory.h +++ b/webrtc/pc/peerconnectionfactory.h @@ -33,6 +33,12 @@ class RtcEventLog; class PeerConnectionFactory : public PeerConnectionFactoryInterface { public: + // Use the overloads of CreateVideoSource that take raw VideoCapturer + // pointers from PeerConnectionFactoryInterface. + // TODO(deadbeef): Remove this using statement once those overloads are + // removed. + using PeerConnectionFactoryInterface::CreateVideoSource; + void SetOptions(const Options& options) override; // Deprecated, use version without constraints. @@ -61,13 +67,13 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { const MediaConstraintsInterface* constraints) override; virtual rtc::scoped_refptr CreateVideoSource( - cricket::VideoCapturer* capturer) override; + std::unique_ptr capturer) override; // This version supports filtering on width, height and frame rate. // For the "constraints=null" case, use the version without constraints. // TODO(hta): Design a version without MediaConstraintsInterface. // https://bugs.chromium.org/p/webrtc/issues/detail?id=5617 rtc::scoped_refptr CreateVideoSource( - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, const MediaConstraintsInterface* constraints) override; rtc::scoped_refptr CreateVideoTrack( @@ -118,7 +124,7 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface { virtual ~PeerConnectionFactory(); private: - cricket::MediaEngineInterface* CreateMediaEngine_w(); + std::unique_ptr CreateMediaEngine_w(); bool owns_ptrs_; bool wraps_current_thread_; diff --git a/webrtc/pc/peerconnectionfactory_unittest.cc b/webrtc/pc/peerconnectionfactory_unittest.cc index 3fa523e3e7..9a6e543105 100644 --- a/webrtc/pc/peerconnectionfactory_unittest.cc +++ b/webrtc/pc/peerconnectionfactory_unittest.cc @@ -336,9 +336,11 @@ TEST_F(PeerConnectionFactoryTest, CreatePCUsingIPLiteralAddress) { // local video track. TEST_F(PeerConnectionFactoryTest, LocalRendering) { cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer(); - // The source take ownership of |capturer|. + // The source takes ownership of |capturer|, but we keep a raw pointer to + // inject fake frames. rtc::scoped_refptr source( - factory_->CreateVideoSource(capturer, NULL)); + factory_->CreateVideoSource( + std::unique_ptr(capturer), NULL)); ASSERT_TRUE(source.get() != NULL); rtc::scoped_refptr track( factory_->CreateVideoTrack("testlabel", source)); diff --git a/webrtc/pc/peerconnectioninterface_unittest.cc b/webrtc/pc/peerconnectioninterface_unittest.cc index 84bfa3abf5..7f73db8432 100644 --- a/webrtc/pc/peerconnectioninterface_unittest.cc +++ b/webrtc/pc/peerconnectioninterface_unittest.cc @@ -801,7 +801,9 @@ class PeerConnectionInterfaceTest : public testing::Test { rtc::scoped_refptr stream( pc_factory_->CreateLocalMediaStream(label)); rtc::scoped_refptr video_source( - pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); + pc_factory_->CreateVideoSource(std::unique_ptr( + new cricket::FakeVideoCapturer()), + NULL)); rtc::scoped_refptr video_track( pc_factory_->CreateVideoTrack(label + "v0", video_source)); stream->AddTrack(video_track.get()); @@ -834,8 +836,9 @@ class PeerConnectionInterfaceTest : public testing::Test { stream->AddTrack(audio_track.get()); rtc::scoped_refptr video_track( pc_factory_->CreateVideoTrack( - video_track_label, - pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); + video_track_label, pc_factory_->CreateVideoSource( + std::unique_ptr( + new cricket::FakeVideoCapturer())))); stream->AddTrack(video_track.get()); EXPECT_TRUE(pc_->AddStream(stream)); EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); @@ -1385,8 +1388,9 @@ TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) { pc_factory_->CreateAudioTrack("audio_track", nullptr)); rtc::scoped_refptr video_track( pc_factory_->CreateVideoTrack( - "video_track", - pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); + "video_track", pc_factory_->CreateVideoSource( + std::unique_ptr( + new cricket::FakeVideoCapturer())))); auto audio_sender = pc_->AddTrack(audio_track, stream_list); auto video_sender = pc_->AddTrack(video_track, stream_list); EXPECT_EQ(1UL, audio_sender->stream_ids().size()); @@ -1456,8 +1460,9 @@ TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) { pc_factory_->CreateAudioTrack("audio_track", nullptr)); rtc::scoped_refptr video_track( pc_factory_->CreateVideoTrack( - "video_track", - pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); + "video_track", pc_factory_->CreateVideoSource( + std::unique_ptr( + new cricket::FakeVideoCapturer())))); auto audio_sender = pc_->AddTrack(audio_track, std::vector()); auto video_sender = @@ -1618,8 +1623,9 @@ TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) { // Add video track to the audio-only stream. rtc::scoped_refptr video_track( pc_factory_->CreateVideoTrack( - "video_label", - pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); + "video_label", pc_factory_->CreateVideoSource( + std::unique_ptr( + new cricket::FakeVideoCapturer())))); stream->AddTrack(video_track.get()); std::unique_ptr offer; diff --git a/webrtc/pc/rtcstatscollector_unittest.cc b/webrtc/pc/rtcstatscollector_unittest.cc index 715da567ab..adace3f4dd 100644 --- a/webrtc/pc/rtcstatscollector_unittest.cc +++ b/webrtc/pc/rtcstatscollector_unittest.cc @@ -277,9 +277,10 @@ class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { network_thread_(rtc::Thread::Current()), signaling_thread_(rtc::Thread::Current()), media_engine_(new cricket::FakeMediaEngine()), - channel_manager_(new cricket::ChannelManager(media_engine_, - worker_thread_, - network_thread_)), + channel_manager_(new cricket::ChannelManager( + std::unique_ptr(media_engine_), + worker_thread_, + network_thread_)), media_controller_( MediaControllerInterface::Create(cricket::MediaConfig(), worker_thread_, @@ -489,6 +490,7 @@ class RTCStatsCollectorTestHelper : public SetSessionDescriptionObserver { rtc::Thread* const worker_thread_; rtc::Thread* const network_thread_; rtc::Thread* const signaling_thread_; + // |media_engine_| is actually owned by |channel_manager_|. cricket::FakeMediaEngine* media_engine_; std::unique_ptr channel_manager_; std::unique_ptr media_controller_; diff --git a/webrtc/pc/rtpsenderreceiver_unittest.cc b/webrtc/pc/rtpsenderreceiver_unittest.cc index c02da587b0..99380e9220 100644 --- a/webrtc/pc/rtpsenderreceiver_unittest.cc +++ b/webrtc/pc/rtpsenderreceiver_unittest.cc @@ -61,9 +61,10 @@ class RtpSenderReceiverTest : public testing::Test, : // Create fake media engine/etc. so we can create channels to use to // test RtpSenders/RtpReceivers. media_engine_(new cricket::FakeMediaEngine()), - channel_manager_(media_engine_, - rtc::Thread::Current(), - rtc::Thread::Current()), + channel_manager_( + std::unique_ptr(media_engine_), + rtc::Thread::Current(), + rtc::Thread::Current()), fake_call_(Call::Config(&event_log_)), fake_media_controller_(&channel_manager_, &fake_call_), stream_(MediaStream::Create(kStreamLabel1)) { @@ -251,6 +252,7 @@ class RtpSenderReceiverTest : public testing::Test, protected: webrtc::RtcEventLogNullImpl event_log_; + // |media_engine_| is actually owned by |channel_manager_|. cricket::FakeMediaEngine* media_engine_; cricket::FakeTransportController fake_transport_controller_; cricket::ChannelManager channel_manager_; diff --git a/webrtc/pc/statscollector_unittest.cc b/webrtc/pc/statscollector_unittest.cc index 1bb6d1de4c..c9affa187e 100644 --- a/webrtc/pc/statscollector_unittest.cc +++ b/webrtc/pc/statscollector_unittest.cc @@ -504,9 +504,10 @@ class StatsCollectorTest : public testing::Test { : worker_thread_(rtc::Thread::Current()), network_thread_(rtc::Thread::Current()), media_engine_(new cricket::FakeMediaEngine()), - channel_manager_(new cricket::ChannelManager(media_engine_, - worker_thread_, - network_thread_)), + channel_manager_(new cricket::ChannelManager( + std::unique_ptr(media_engine_), + worker_thread_, + network_thread_)), media_controller_( webrtc::MediaControllerInterface::Create(cricket::MediaConfig(), worker_thread_, @@ -780,6 +781,7 @@ class StatsCollectorTest : public testing::Test { webrtc::RtcEventLogNullImpl event_log_; rtc::Thread* const worker_thread_; rtc::Thread* const network_thread_; + // |media_engine_| is actually owned by |channel_manager_|. cricket::FakeMediaEngine* media_engine_; std::unique_ptr channel_manager_; std::unique_ptr media_controller_; diff --git a/webrtc/pc/test/peerconnectiontestwrapper.cc b/webrtc/pc/test/peerconnectiontestwrapper.cc index c433699652..e5ead481b8 100644 --- a/webrtc/pc/test/peerconnectiontestwrapper.cc +++ b/webrtc/pc/test/peerconnectiontestwrapper.cc @@ -269,7 +269,9 @@ rtc::scoped_refptr rtc::scoped_refptr source = peer_connection_factory_->CreateVideoSource( - new webrtc::FakePeriodicVideoCapturer(), &constraints); + std::unique_ptr( + new webrtc::FakePeriodicVideoCapturer()), + &constraints); std::string videotrack_label = label + kVideoTrackLabelBase; rtc::scoped_refptr video_track( peer_connection_factory_->CreateVideoTrack(videotrack_label, source)); diff --git a/webrtc/pc/videocapturertracksource.cc b/webrtc/pc/videocapturertracksource.cc index 771429aecd..2bb29da114 100644 --- a/webrtc/pc/videocapturertracksource.cc +++ b/webrtc/pc/videocapturertracksource.cc @@ -258,39 +258,39 @@ namespace webrtc { rtc::scoped_refptr VideoCapturerTrackSource::Create( rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, const webrtc::MediaConstraintsInterface* constraints, bool remote) { RTC_DCHECK(worker_thread != NULL); RTC_DCHECK(capturer != NULL); rtc::scoped_refptr source( - new rtc::RefCountedObject(worker_thread, - capturer, remote)); + new rtc::RefCountedObject( + worker_thread, std::move(capturer), remote)); source->Initialize(constraints); return source; } rtc::scoped_refptr VideoCapturerTrackSource::Create( rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, bool remote) { RTC_DCHECK(worker_thread != NULL); RTC_DCHECK(capturer != NULL); rtc::scoped_refptr source( - new rtc::RefCountedObject(worker_thread, - capturer, remote)); + new rtc::RefCountedObject( + worker_thread, std::move(capturer), remote)); source->Initialize(nullptr); return source; } VideoCapturerTrackSource::VideoCapturerTrackSource( rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, bool remote) - : VideoTrackSource(capturer, remote), + : VideoTrackSource(capturer.get(), remote), signaling_thread_(rtc::Thread::Current()), worker_thread_(worker_thread), - video_capturer_(capturer), + video_capturer_(std::move(capturer)), started_(false) { video_capturer_->SignalStateChange.connect( this, &VideoCapturerTrackSource::OnStateChange); diff --git a/webrtc/pc/videocapturertracksource.h b/webrtc/pc/videocapturertracksource.h index 30991a11ac..af87cc9b82 100644 --- a/webrtc/pc/videocapturertracksource.h +++ b/webrtc/pc/videocapturertracksource.h @@ -34,18 +34,18 @@ class VideoCapturerTrackSource : public VideoTrackSource, public sigslot::has_slots<> { public: // Creates an instance of VideoCapturerTrackSource. - // VideoCapturerTrackSource take ownership of |capturer|. + // VideoCapturerTrackSource takes ownership of |capturer|. // |constraints| can be NULL and in that case the camera is opened using a // default resolution. static rtc::scoped_refptr Create( rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, const webrtc::MediaConstraintsInterface* constraints, bool remote); static rtc::scoped_refptr Create( rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, bool remote); bool is_screencast() const override { @@ -59,7 +59,7 @@ class VideoCapturerTrackSource : public VideoTrackSource, protected: VideoCapturerTrackSource(rtc::Thread* worker_thread, - cricket::VideoCapturer* capturer, + std::unique_ptr capturer, bool remote); virtual ~VideoCapturerTrackSource(); void Initialize(const webrtc::MediaConstraintsInterface* constraints); diff --git a/webrtc/pc/videocapturertracksource_unittest.cc b/webrtc/pc/videocapturertracksource_unittest.cc index 144d4b4b79..3fe726a49a 100644 --- a/webrtc/pc/videocapturertracksource_unittest.cc +++ b/webrtc/pc/videocapturertracksource_unittest.cc @@ -109,9 +109,8 @@ class VideoCapturerTrackSourceTest : public testing::Test { protected: VideoCapturerTrackSourceTest() { InitCapturer(false); } void InitCapturer(bool is_screencast) { - capturer_cleanup_ = std::unique_ptr( - new TestVideoCapturer(is_screencast)); - capturer_ = capturer_cleanup_.get(); + capturer_ = new TestVideoCapturer(is_screencast); + capturer_cleanup_.reset(capturer_); } void InitScreencast() { InitCapturer(true); } @@ -120,9 +119,8 @@ class VideoCapturerTrackSourceTest : public testing::Test { void CreateVideoCapturerSource( const webrtc::MediaConstraintsInterface* constraints) { - // VideoSource take ownership of |capturer_| source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(), - capturer_cleanup_.release(), + std::move(capturer_cleanup_), constraints, false); ASSERT_TRUE(source_.get() != NULL); @@ -132,7 +130,7 @@ class VideoCapturerTrackSourceTest : public testing::Test { source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); } - std::unique_ptr capturer_cleanup_; + std::unique_ptr capturer_cleanup_; TestVideoCapturer* capturer_; cricket::FakeVideoRenderer renderer_; std::unique_ptr state_observer_; diff --git a/webrtc/pc/webrtcsession_unittest.cc b/webrtc/pc/webrtcsession_unittest.cc index e9017d429c..f785151d18 100644 --- a/webrtc/pc/webrtcsession_unittest.cc +++ b/webrtc/pc/webrtcsession_unittest.cc @@ -369,9 +369,10 @@ class WebRtcSessionTest WebRtcSessionTest() : media_engine_(new cricket::FakeMediaEngine()), data_engine_(new cricket::FakeDataEngine()), - channel_manager_(new cricket::ChannelManager(media_engine_, - data_engine_, - rtc::Thread::Current())), + channel_manager_(new cricket::ChannelManager( + std::unique_ptr(media_engine_), + std::unique_ptr(data_engine_), + rtc::Thread::Current())), fake_call_(webrtc::Call::Config(&event_log_)), media_controller_( webrtc::MediaControllerInterface::Create(cricket::MediaConfig(), @@ -1504,6 +1505,8 @@ class WebRtcSessionTest } webrtc::RtcEventLogNullImpl event_log_; + // |media_engine_| and |data_engine_| are actually owned by + // |channel_manager_|. cricket::FakeMediaEngine* media_engine_; cricket::FakeDataEngine* data_engine_; // Actually owned by session_. diff --git a/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm b/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm index 96c5c3649a..b004191f8b 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCAVFoundationVideoSource.mm @@ -27,7 +27,8 @@ _capturer = new webrtc::AVFoundationVideoCapturer(); rtc::scoped_refptr source = factory.nativeFactory->CreateVideoSource( - _capturer, constraints.nativeConstraints.get()); + std::unique_ptr(_capturer), + constraints.nativeConstraints.get()); return [super initWithNativeVideoSource:source]; }