Make PeerConnectionFactory constructor taking dependency the only constructor

Bug: None
Change-Id: I19e9fab1ecec3799cc7b8573ab3fd6b258114cce
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128601
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27194}
This commit is contained in:
Danil Chapovalov
2019-03-19 17:45:24 +01:00
committed by Commit Bot
parent d26a916a80
commit f5258be6f4
5 changed files with 50 additions and 114 deletions

View File

@ -101,41 +101,19 @@ CreateModularPeerConnectionFactory(
} }
PeerConnectionFactory::PeerConnectionFactory( PeerConnectionFactory::PeerConnectionFactory(
rtc::Thread* network_thread, PeerConnectionFactoryDependencies dependencies)
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<cricket::MediaEngineInterface> media_engine,
std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
: PeerConnectionFactory(network_thread,
worker_thread,
signaling_thread,
std::move(media_engine),
std::move(call_factory),
std::move(event_log_factory),
nullptr,
nullptr) {}
PeerConnectionFactory::PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<cricket::MediaEngineInterface> media_engine,
std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory)
: wraps_current_thread_(false), : wraps_current_thread_(false),
network_thread_(network_thread), network_thread_(dependencies.network_thread),
worker_thread_(worker_thread), worker_thread_(dependencies.worker_thread),
signaling_thread_(signaling_thread), signaling_thread_(dependencies.signaling_thread),
media_engine_(std::move(media_engine)), media_engine_(std::move(dependencies.media_engine)),
call_factory_(std::move(call_factory)), call_factory_(std::move(dependencies.call_factory)),
event_log_factory_(std::move(event_log_factory)), event_log_factory_(std::move(dependencies.event_log_factory)),
fec_controller_factory_(std::move(fec_controller_factory)), fec_controller_factory_(std::move(dependencies.fec_controller_factory)),
injected_network_controller_factory_( injected_network_controller_factory_(
std::move(network_controller_factory)) { std::move(dependencies.network_controller_factory)),
media_transport_factory_(
std::move(dependencies.media_transport_factory)) {
if (!network_thread_) { if (!network_thread_) {
owned_network_thread_ = rtc::Thread::CreateWithSocketServer(); owned_network_thread_ = rtc::Thread::CreateWithSocketServer();
owned_network_thread_->SetName("pc_network_thread", nullptr); owned_network_thread_->SetName("pc_network_thread", nullptr);
@ -159,24 +137,6 @@ PeerConnectionFactory::PeerConnectionFactory(
wraps_current_thread_ = true; wraps_current_thread_ = true;
} }
} }
// TODO(deadbeef): Currently there is no way to create an external adm in
// libjingle source tree. So we can 't currently assert if this is NULL.
// RTC_DCHECK(default_adm != NULL);
}
PeerConnectionFactory::PeerConnectionFactory(
PeerConnectionFactoryDependencies dependencies)
: PeerConnectionFactory(
dependencies.network_thread,
dependencies.worker_thread,
dependencies.signaling_thread,
std::move(dependencies.media_engine),
std::move(dependencies.call_factory),
std::move(dependencies.event_log_factory),
std::move(dependencies.fec_controller_factory),
std::move(dependencies.network_controller_factory)) {
media_transport_factory_ = std::move(dependencies.media_transport_factory);
} }
PeerConnectionFactory::~PeerConnectionFactory() { PeerConnectionFactory::~PeerConnectionFactory() {

View File

@ -92,26 +92,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
} }
protected: protected:
PeerConnectionFactory( // This structure allows simple management of all new dependencies being added
rtc::Thread* network_thread, // to the PeerConnectionFactory.
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<cricket::MediaEngineInterface> media_engine,
std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
PeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<cricket::MediaEngineInterface> media_engine,
std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
std::unique_ptr<NetworkControllerFactoryInterface>
network_controller_factory);
// Use this implementation for all future use. This structure allows simple
// management of all new dependencies being added to the
// PeerConnectionFactory.
explicit PeerConnectionFactory( explicit PeerConnectionFactory(
PeerConnectionFactoryDependencies dependencies); PeerConnectionFactoryDependencies dependencies);

View File

@ -64,13 +64,16 @@ class PeerConnectionFactoryForUsageHistogramTest
: public rtc::RefCountedObject<PeerConnectionFactory> { : public rtc::RefCountedObject<PeerConnectionFactory> {
public: public:
PeerConnectionFactoryForUsageHistogramTest() PeerConnectionFactoryForUsageHistogramTest()
: rtc::RefCountedObject<PeerConnectionFactory>( : rtc::RefCountedObject<PeerConnectionFactory>([] {
rtc::Thread::Current(), PeerConnectionFactoryDependencies dependencies;
rtc::Thread::Current(), dependencies.network_thread = rtc::Thread::Current();
rtc::Thread::Current(), dependencies.worker_thread = rtc::Thread::Current();
absl::make_unique<cricket::FakeMediaEngine>(), dependencies.signaling_thread = rtc::Thread::Current();
CreateCallFactory(), dependencies.media_engine =
nullptr) {} absl::make_unique<cricket::FakeMediaEngine>();
dependencies.call_factory = CreateCallFactory();
return dependencies;
}()) {}
void ActionsBeforeInitializeForTesting(PeerConnectionInterface* pc) override { void ActionsBeforeInitializeForTesting(PeerConnectionInterface* pc) override {
PeerConnection* internal_pc = static_cast<PeerConnection*>(pc); PeerConnection* internal_pc = static_cast<PeerConnection*>(pc);

View File

@ -639,41 +639,30 @@ class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory(); auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory(); auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
PeerConnectionFactoryDependencies dependencies;
dependencies.worker_thread = rtc::Thread::Current();
dependencies.network_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
// Use fake audio device module since we're only testing the interface // Use fake audio device module since we're only testing the interface
// level, and using a real one could make tests flaky when run in parallel. // level, and using a real one could make tests flaky when run in parallel.
auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>( dependencies.media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
cricket::WebRtcMediaEngineFactory::Create( cricket::WebRtcMediaEngineFactory::Create(
FakeAudioCaptureModule::Create(), audio_encoder_factory, FakeAudioCaptureModule::Create(), audio_encoder_factory,
audio_decoder_factory, std::move(video_encoder_factory), audio_decoder_factory, std::move(video_encoder_factory),
std::move(video_decoder_factory), nullptr, std::move(video_decoder_factory), nullptr,
webrtc::AudioProcessingBuilder().Create())); webrtc::AudioProcessingBuilder().Create()));
std::unique_ptr<webrtc::CallFactoryInterface> call_factory = dependencies.call_factory = webrtc::CreateCallFactory();
webrtc::CreateCallFactory(); dependencies.event_log_factory = webrtc::CreateRtcEventLogFactory();
std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
webrtc::CreateRtcEventLogFactory();
return new rtc::RefCountedObject<PeerConnectionFactoryForTest>( return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), std::move(dependencies));
std::move(media_engine), std::move(call_factory),
std::move(event_log_factory));
} }
PeerConnectionFactoryForTest( using PeerConnectionFactory::PeerConnectionFactory;
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
std::unique_ptr<cricket::MediaEngineInterface> media_engine,
std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
: webrtc::PeerConnectionFactory(network_thread,
worker_thread,
signaling_thread,
std::move(media_engine),
std::move(call_factory),
std::move(event_log_factory)) {}
private:
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
}; };

View File

@ -46,20 +46,22 @@ using ::testing::UnorderedElementsAre;
class PeerConnectionFactoryForJsepTest : public PeerConnectionFactory { class PeerConnectionFactoryForJsepTest : public PeerConnectionFactory {
public: public:
PeerConnectionFactoryForJsepTest() PeerConnectionFactoryForJsepTest()
: PeerConnectionFactory(rtc::Thread::Current(), : PeerConnectionFactory([] {
rtc::Thread::Current(), PeerConnectionFactoryDependencies dependencies;
rtc::Thread::Current(), dependencies.worker_thread = rtc::Thread::Current();
cricket::WebRtcMediaEngineFactory::Create( dependencies.network_thread = rtc::Thread::Current();
rtc::scoped_refptr<AudioDeviceModule>( dependencies.signaling_thread = rtc::Thread::Current();
FakeAudioCaptureModule::Create()), dependencies.media_engine = cricket::WebRtcMediaEngineFactory::Create(
CreateBuiltinAudioEncoderFactory(), rtc::scoped_refptr<AudioDeviceModule>(
CreateBuiltinAudioDecoderFactory(), FakeAudioCaptureModule::Create()),
CreateBuiltinVideoEncoderFactory(), CreateBuiltinAudioEncoderFactory(),
CreateBuiltinVideoDecoderFactory(), CreateBuiltinAudioDecoderFactory(),
nullptr, CreateBuiltinVideoEncoderFactory(),
AudioProcessingBuilder().Create()), CreateBuiltinVideoDecoderFactory(), nullptr,
CreateCallFactory(), AudioProcessingBuilder().Create());
nullptr) {} dependencies.call_factory = CreateCallFactory();
return dependencies;
}()) {}
std::unique_ptr<cricket::SctpTransportInternalFactory> std::unique_ptr<cricket::SctpTransportInternalFactory>
CreateSctpTransportInternalFactory() { CreateSctpTransportInternalFactory() {