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(
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)
: 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)
PeerConnectionFactoryDependencies dependencies)
: wraps_current_thread_(false),
network_thread_(network_thread),
worker_thread_(worker_thread),
signaling_thread_(signaling_thread),
media_engine_(std::move(media_engine)),
call_factory_(std::move(call_factory)),
event_log_factory_(std::move(event_log_factory)),
fec_controller_factory_(std::move(fec_controller_factory)),
network_thread_(dependencies.network_thread),
worker_thread_(dependencies.worker_thread),
signaling_thread_(dependencies.signaling_thread),
media_engine_(std::move(dependencies.media_engine)),
call_factory_(std::move(dependencies.call_factory)),
event_log_factory_(std::move(dependencies.event_log_factory)),
fec_controller_factory_(std::move(dependencies.fec_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_) {
owned_network_thread_ = rtc::Thread::CreateWithSocketServer();
owned_network_thread_->SetName("pc_network_thread", nullptr);
@ -159,24 +137,6 @@ PeerConnectionFactory::PeerConnectionFactory(
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() {

View File

@ -92,26 +92,8 @@ class PeerConnectionFactory : public PeerConnectionFactoryInterface {
}
protected:
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);
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.
// This structure allows simple management of all new dependencies being added
// to the PeerConnectionFactory.
explicit PeerConnectionFactory(
PeerConnectionFactoryDependencies dependencies);

View File

@ -64,13 +64,16 @@ class PeerConnectionFactoryForUsageHistogramTest
: public rtc::RefCountedObject<PeerConnectionFactory> {
public:
PeerConnectionFactoryForUsageHistogramTest()
: rtc::RefCountedObject<PeerConnectionFactory>(
rtc::Thread::Current(),
rtc::Thread::Current(),
rtc::Thread::Current(),
absl::make_unique<cricket::FakeMediaEngine>(),
CreateCallFactory(),
nullptr) {}
: rtc::RefCountedObject<PeerConnectionFactory>([] {
PeerConnectionFactoryDependencies dependencies;
dependencies.network_thread = rtc::Thread::Current();
dependencies.worker_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
dependencies.media_engine =
absl::make_unique<cricket::FakeMediaEngine>();
dependencies.call_factory = CreateCallFactory();
return dependencies;
}()) {}
void ActionsBeforeInitializeForTesting(PeerConnectionInterface* pc) override {
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_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
// 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(
FakeAudioCaptureModule::Create(), audio_encoder_factory,
audio_decoder_factory, std::move(video_encoder_factory),
std::move(video_decoder_factory), nullptr,
webrtc::AudioProcessingBuilder().Create()));
std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
webrtc::CreateCallFactory();
std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
webrtc::CreateRtcEventLogFactory();
dependencies.call_factory = webrtc::CreateCallFactory();
dependencies.event_log_factory = webrtc::CreateRtcEventLogFactory();
return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
std::move(media_engine), std::move(call_factory),
std::move(event_log_factory));
std::move(dependencies));
}
PeerConnectionFactoryForTest(
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)) {}
using PeerConnectionFactory::PeerConnectionFactory;
private:
rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
};

View File

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