Switching some interfaces to use std::unique_ptr<>.

This helps show where ownership is transfered between objects.

Specifically, this CL wraps cricket::VideoCapturer, MediaEngineInterface
and DataEngineInterface in unique_ptr.

BUG=None
TBR=magjed@webrtc.org

Review-Url: https://codereview.webrtc.org/2685093002
Cr-Commit-Position: refs/heads/master@{#16548}
This commit is contained in:
deadbeef 2017-02-10 20:13:37 -08:00 committed by Commit bot
parent 2c87d9991b
commit 112b2e99d8
25 changed files with 169 additions and 114 deletions

View File

@ -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<PeerConnectionInterface>,
CreatePeerConnection,
@ -48,11 +53,11 @@ BEGIN_SIGNALING_PROXY_MAP(PeerConnectionFactory)
const cricket::AudioOptions&)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackSourceInterface>,
CreateVideoSource,
cricket::VideoCapturer*,
std::unique_ptr<cricket::VideoCapturer>,
const MediaConstraintsInterface*)
PROXY_METHOD1(rtc::scoped_refptr<VideoTrackSourceInterface>,
CreateVideoSource,
cricket::VideoCapturer*)
std::unique_ptr<cricket::VideoCapturer>)
PROXY_METHOD2(rtc::scoped_refptr<VideoTrackInterface>,
CreateVideoTrack,
const std::string&,

View File

@ -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<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) = 0;
std::unique_ptr<cricket::VideoCapturer> 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<VideoTrackSourceInterface> CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> 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<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) {
return CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(capturer));
}
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer,
const MediaConstraintsInterface* constraints) = 0;
const MediaConstraintsInterface* constraints) {
return CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(capturer),
constraints);
}
// Creates a new local VideoTrack. The same |source| can be used in several
// tracks.

View File

@ -366,7 +366,7 @@ void Conductor::ConnectToPeer(int peer_id) {
}
}
cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() {
std::unique_ptr<cricket::VideoCapturer> Conductor::OpenVideoCaptureDevice() {
std::vector<std::string> device_names;
{
std::unique_ptr<webrtc::VideoCaptureModule::DeviceInfo> info(
@ -386,7 +386,7 @@ cricket::VideoCapturer* Conductor::OpenVideoCaptureDevice() {
}
cricket::WebRtcVideoDeviceCapturerFactory factory;
cricket::VideoCapturer* capturer = nullptr;
std::unique_ptr<cricket::VideoCapturer> capturer;
for (const auto& name : device_names) {
capturer = factory.Create(cricket::Device(name, 0));
if (capturer) {

View File

@ -14,6 +14,7 @@
#include <deque>
#include <map>
#include <memory>
#include <set>
#include <string>
@ -58,7 +59,7 @@ class Conductor
void DeletePeerConnection();
void EnsureStreamingUI();
void AddStreams();
cricket::VideoCapturer* OpenVideoCaptureDevice();
std::unique_ptr<cricket::VideoCapturer> OpenVideoCaptureDevice();
//
// PeerConnectionObserver implementation.

View File

@ -11,6 +11,8 @@
#ifndef WEBRTC_MEDIA_BASE_VIDEOCAPTURERFACTORY_H_
#define WEBRTC_MEDIA_BASE_VIDEOCAPTURERFACTORY_H_
#include <memory>
#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<VideoCapturer> Create(const Device& device) = 0;
};
} // namespace cricket

View File

@ -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<webrtc::AudioDecoderFactory>&

View File

@ -15,16 +15,17 @@
namespace cricket {
VideoCapturer* WebRtcVideoDeviceCapturerFactory::Create(const Device& device) {
std::unique_ptr<VideoCapturer> WebRtcVideoDeviceCapturerFactory::Create(
const Device& device) {
#ifdef HAVE_WEBRTC_VIDEO
std::unique_ptr<WebRtcVideoCapturer> capturer(
new WebRtcVideoCapturer());
if (!capturer->Init(device)) {
return nullptr;
return std::unique_ptr<VideoCapturer>();
}
return capturer.release();
return std::move(capturer);
#else
return nullptr;
return std::unique_ptr<VideoCapturer>();
#endif
}

View File

@ -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<VideoCapturer> Create(const Device& device) override;
};
} // namespace cricket

View File

@ -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<MediaEngineInterface> me,
std::unique_ptr<DataEngineInterface> 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<MediaEngineInterface> me,
rtc::Thread* worker_thread,
rtc::Thread* network_thread) {
Construct(me, ConstructDataEngine(), worker_thread, network_thread);
Construct(std::move(me),
std::unique_ptr<DataEngineInterface>(new RtpDataEngine()),
worker_thread, network_thread);
}
void ChannelManager::Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
void ChannelManager::Construct(std::unique_ptr<MediaEngineInterface> me,
std::unique_ptr<DataEngineInterface> 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;

View File

@ -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<MediaEngineInterface> me,
std::unique_ptr<DataEngineInterface> dme,
rtc::Thread* worker_and_network);
// Same as above, but gives an easier default DataEngine.
ChannelManager(MediaEngineInterface* me,
ChannelManager(std::unique_ptr<MediaEngineInterface> me,
rtc::Thread* worker,
rtc::Thread* network);
~ChannelManager();
@ -157,8 +156,8 @@ class ChannelManager {
typedef std::vector<VideoChannel*> VideoChannels;
typedef std::vector<RtpDataChannel*> RtpDataChannels;
void Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
void Construct(std::unique_ptr<MediaEngineInterface> me,
std::unique_ptr<DataEngineInterface> dme,
rtc::Thread* worker_thread,
rtc::Thread* network_thread);
bool InitMediaEngine_w();

View File

@ -8,6 +8,8 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#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<MediaEngineInterface>(fme_),
std::unique_ptr<DataEngineInterface>(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<cricket::ChannelManager> cm_;
cricket::FakeCall fake_call_;
cricket::FakeMediaController fake_mc_;
cricket::FakeTransportController* transport_controller_;
std::unique_ptr<cricket::FakeTransportController> 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);

View File

@ -588,8 +588,9 @@ class PeerConnectionTestClient : public webrtc::PeerConnectionObserver,
fake_capturer->SetRotation(capture_rotation_);
video_capturers_.push_back(fake_capturer);
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
peer_connection_factory_->CreateVideoSource(fake_capturer,
&source_constraints);
peer_connection_factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(fake_capturer),
&source_constraints);
std::string label = stream_label + kVideoTrackLabelBase;
rtc::scoped_refptr<webrtc::VideoTrackInterface> track(

View File

@ -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<cricket::MediaEngineInterface*>(
std::unique_ptr<cricket::MediaEngineInterface> media_engine =
worker_thread_->Invoke<std::unique_ptr<cricket::MediaEngineInterface>>(
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<VideoTrackSourceInterface>
PeerConnectionFactory::CreateVideoSource(
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> capturer,
const MediaConstraintsInterface* constraints) {
RTC_DCHECK(signaling_thread_->IsCurrent());
rtc::scoped_refptr<VideoTrackSourceInterface> 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<VideoTrackSourceInterface>
PeerConnectionFactory::CreateVideoSource(cricket::VideoCapturer* capturer) {
PeerConnectionFactory::CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer> capturer) {
RTC_DCHECK(signaling_thread_->IsCurrent());
rtc::scoped_refptr<VideoTrackSourceInterface> 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<cricket::MediaEngineInterface>
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::MediaEngineInterface>(
cricket::WebRtcMediaEngineFactory::Create(
default_adm_.get(), audio_decoder_factory_,
video_encoder_factory_.get(), video_decoder_factory_.get(),
external_audio_mixer_));
}
} // namespace webrtc

View File

@ -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<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) override;
std::unique_ptr<cricket::VideoCapturer> 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<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> capturer,
const MediaConstraintsInterface* constraints) override;
rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
@ -118,7 +124,7 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
virtual ~PeerConnectionFactory();
private:
cricket::MediaEngineInterface* CreateMediaEngine_w();
std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w();
bool owns_ptrs_;
bool wraps_current_thread_;

View File

@ -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<VideoTrackSourceInterface> source(
factory_->CreateVideoSource(capturer, NULL));
factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(capturer), NULL));
ASSERT_TRUE(source.get() != NULL);
rtc::scoped_refptr<VideoTrackInterface> track(
factory_->CreateVideoTrack("testlabel", source));

View File

@ -801,7 +801,9 @@ class PeerConnectionInterfaceTest : public testing::Test {
rtc::scoped_refptr<MediaStreamInterface> stream(
pc_factory_->CreateLocalMediaStream(label));
rtc::scoped_refptr<VideoTrackSourceInterface> video_source(
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL));
pc_factory_->CreateVideoSource(std::unique_ptr<cricket::VideoCapturer>(
new cricket::FakeVideoCapturer()),
NULL));
rtc::scoped_refptr<VideoTrackInterface> 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<VideoTrackInterface> video_track(
pc_factory_->CreateVideoTrack(
video_track_label,
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
video_track_label, pc_factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(
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<VideoTrackInterface> video_track(
pc_factory_->CreateVideoTrack(
"video_track",
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
"video_track", pc_factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(
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<VideoTrackInterface> video_track(
pc_factory_->CreateVideoTrack(
"video_track",
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
"video_track", pc_factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(
new cricket::FakeVideoCapturer()))));
auto audio_sender =
pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
auto video_sender =
@ -1618,8 +1623,9 @@ TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
// Add video track to the audio-only stream.
rtc::scoped_refptr<VideoTrackInterface> video_track(
pc_factory_->CreateVideoTrack(
"video_label",
pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
"video_label", pc_factory_->CreateVideoSource(
std::unique_ptr<cricket::VideoCapturer>(
new cricket::FakeVideoCapturer()))));
stream->AddTrack(video_track.get());
std::unique_ptr<SessionDescriptionInterface> offer;

View File

@ -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<cricket::MediaEngineInterface>(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<cricket::ChannelManager> channel_manager_;
std::unique_ptr<MediaControllerInterface> media_controller_;

View File

@ -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<cricket::MediaEngineInterface>(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_;

View File

@ -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<cricket::MediaEngineInterface>(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<cricket::ChannelManager> channel_manager_;
std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;

View File

@ -269,7 +269,9 @@ rtc::scoped_refptr<webrtc::MediaStreamInterface>
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
peer_connection_factory_->CreateVideoSource(
new webrtc::FakePeriodicVideoCapturer(), &constraints);
std::unique_ptr<cricket::VideoCapturer>(
new webrtc::FakePeriodicVideoCapturer()),
&constraints);
std::string videotrack_label = label + kVideoTrackLabelBase;
rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
peer_connection_factory_->CreateVideoTrack(videotrack_label, source));

View File

@ -258,39 +258,39 @@ namespace webrtc {
rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
rtc::Thread* worker_thread,
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> capturer,
const webrtc::MediaConstraintsInterface* constraints,
bool remote) {
RTC_DCHECK(worker_thread != NULL);
RTC_DCHECK(capturer != NULL);
rtc::scoped_refptr<VideoCapturerTrackSource> source(
new rtc::RefCountedObject<VideoCapturerTrackSource>(worker_thread,
capturer, remote));
new rtc::RefCountedObject<VideoCapturerTrackSource>(
worker_thread, std::move(capturer), remote));
source->Initialize(constraints);
return source;
}
rtc::scoped_refptr<VideoTrackSourceInterface> VideoCapturerTrackSource::Create(
rtc::Thread* worker_thread,
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> capturer,
bool remote) {
RTC_DCHECK(worker_thread != NULL);
RTC_DCHECK(capturer != NULL);
rtc::scoped_refptr<VideoCapturerTrackSource> source(
new rtc::RefCountedObject<VideoCapturerTrackSource>(worker_thread,
capturer, remote));
new rtc::RefCountedObject<VideoCapturerTrackSource>(
worker_thread, std::move(capturer), remote));
source->Initialize(nullptr);
return source;
}
VideoCapturerTrackSource::VideoCapturerTrackSource(
rtc::Thread* worker_thread,
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> 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);

View File

@ -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<VideoTrackSourceInterface> Create(
rtc::Thread* worker_thread,
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> capturer,
const webrtc::MediaConstraintsInterface* constraints,
bool remote);
static rtc::scoped_refptr<VideoTrackSourceInterface> Create(
rtc::Thread* worker_thread,
cricket::VideoCapturer* capturer,
std::unique_ptr<cricket::VideoCapturer> 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<cricket::VideoCapturer> capturer,
bool remote);
virtual ~VideoCapturerTrackSource();
void Initialize(const webrtc::MediaConstraintsInterface* constraints);

View File

@ -109,9 +109,8 @@ class VideoCapturerTrackSourceTest : public testing::Test {
protected:
VideoCapturerTrackSourceTest() { InitCapturer(false); }
void InitCapturer(bool is_screencast) {
capturer_cleanup_ = std::unique_ptr<TestVideoCapturer>(
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<TestVideoCapturer> capturer_cleanup_;
std::unique_ptr<cricket::VideoCapturer> capturer_cleanup_;
TestVideoCapturer* capturer_;
cricket::FakeVideoRenderer renderer_;
std::unique_ptr<StateObserver> state_observer_;

View File

@ -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<cricket::MediaEngineInterface>(media_engine_),
std::unique_ptr<cricket::DataEngineInterface>(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_.

View File

@ -27,7 +27,8 @@
_capturer = new webrtc::AVFoundationVideoCapturer();
rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
factory.nativeFactory->CreateVideoSource(
_capturer, constraints.nativeConstraints.get());
std::unique_ptr<cricket::VideoCapturer>(_capturer),
constraints.nativeConstraints.get());
return [super initWithNativeVideoSource:source];
}