Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: webrtc/pc/peerconnectionfactory.cc

Issue 2854123003: Build WebRTC with data channel only. (Closed)
Patch Set: Revert the android changes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/pc/peerconnectionfactory.cc
diff --git a/webrtc/pc/peerconnectionfactory.cc b/webrtc/pc/peerconnectionfactory.cc
index 777bac1eb59aadd49bcc9af1d44ac66e9d02276f..509d963065102ecc6db794aebcde97f026ca7d3e 100644
--- a/webrtc/pc/peerconnectionfactory.cc
+++ b/webrtc/pc/peerconnectionfactory.cc
@@ -12,8 +12,6 @@
#include <utility>
-#include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
-#include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
#include "webrtc/api/mediaconstraintsinterface.h"
#include "webrtc/api/mediastreamproxy.h"
#include "webrtc/api/mediastreamtrackproxy.h"
@@ -22,10 +20,13 @@
#include "webrtc/api/videosourceproxy.h"
#include "webrtc/base/bind.h"
#include "webrtc/base/checks.h"
-#include "webrtc/media/engine/webrtcmediaengine.h"
-#include "webrtc/media/engine/webrtcvideodecoderfactory.h"
-#include "webrtc/media/engine/webrtcvideoencoderfactory.h"
-#include "webrtc/modules/audio_device/include/audio_device.h"
+#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
+// Adding 'nogncheck' to disable the gn include headers check to support modular
+// WebRTC build targets.
Taylor Brandstetter 2017/06/14 01:54:16 Really, the solution here is to put the interface
Zhi Huang 2017/06/14 06:57:01 Done.
+#include "webrtc/media/engine/webrtcmediaengine.h" // nogncheck
+#include "webrtc/media/engine/webrtcvideodecoderfactory.h" // nogncheck
+#include "webrtc/media/engine/webrtcvideoencoderfactory.h" // nogncheck
+#include "webrtc/modules/audio_device/include/audio_device.h" // nogncheck
#include "webrtc/p2p/base/basicpacketsocketfactory.h"
#include "webrtc/p2p/client/basicportallocator.h"
#include "webrtc/pc/audiotrack.h"
@@ -37,58 +38,8 @@
namespace webrtc {
-rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
- rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
- rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
- rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
- new rtc::RefCountedObject<PeerConnectionFactory>(audio_encoder_factory,
- audio_decoder_factory));
-
- RTC_CHECK(rtc::Thread::Current() == pc_factory->signaling_thread());
- // The signaling thread is the current thread so we can
- // safely call Initialize directly.
- if (!pc_factory->Initialize()) {
- return nullptr;
- }
- return PeerConnectionFactoryProxy::Create(pc_factory->signaling_thread(),
- pc_factory);
-}
-
-rtc::scoped_refptr<PeerConnectionFactoryInterface>
-CreatePeerConnectionFactory() {
- return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(),
- CreateBuiltinAudioDecoderFactory());
-}
-
-rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
- rtc::Thread* network_thread,
- rtc::Thread* worker_thread,
- rtc::Thread* signaling_thread,
- AudioDeviceModule* default_adm,
- rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
- rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
- cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
- cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
- return CreatePeerConnectionFactoryWithAudioMixer(
- network_thread, worker_thread, signaling_thread, default_adm,
- audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
- video_decoder_factory, nullptr);
-}
-
-rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
- rtc::Thread* network_thread,
- rtc::Thread* worker_thread,
- rtc::Thread* signaling_thread,
- AudioDeviceModule* default_adm,
- cricket::WebRtcVideoEncoderFactory* encoder_factory,
- cricket::WebRtcVideoDecoderFactory* decoder_factory) {
- return CreatePeerConnectionFactoryWithAudioMixer(
- network_thread, worker_thread, signaling_thread, default_adm,
- encoder_factory, decoder_factory, nullptr);
-}
-
rtc::scoped_refptr<PeerConnectionFactoryInterface>
-CreatePeerConnectionFactoryWithAudioMixer(
+CreateModularPeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
@@ -97,12 +48,16 @@ CreatePeerConnectionFactoryWithAudioMixer(
rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
- rtc::scoped_refptr<AudioMixer> audio_mixer) {
+ rtc::scoped_refptr<AudioMixer> audio_mixer,
+ std::unique_ptr<cricket::MediaEngineInterface> media_engine,
+ std::unique_ptr<CallFactoryInterface> call_factory,
+ std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory) {
rtc::scoped_refptr<PeerConnectionFactory> pc_factory(
new rtc::RefCountedObject<PeerConnectionFactory>(
network_thread, worker_thread, signaling_thread, default_adm,
audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
- video_decoder_factory, audio_mixer));
+ video_decoder_factory, audio_mixer, std::move(media_engine),
+ std::move(call_factory), std::move(event_log_factory)));
// Call Initialize synchronously but make sure it is executed on
// |signaling_thread|.
@@ -116,36 +71,21 @@ CreatePeerConnectionFactoryWithAudioMixer(
return PeerConnectionFactoryProxy::Create(signaling_thread, pc_factory);
}
-rtc::scoped_refptr<PeerConnectionFactoryInterface>
-CreatePeerConnectionFactoryWithAudioMixer(
- rtc::Thread* network_thread,
- rtc::Thread* worker_thread,
- rtc::Thread* signaling_thread,
- AudioDeviceModule* default_adm,
- cricket::WebRtcVideoEncoderFactory* encoder_factory,
- cricket::WebRtcVideoDecoderFactory* decoder_factory,
- rtc::scoped_refptr<AudioMixer> audio_mixer) {
- return CreatePeerConnectionFactoryWithAudioMixer(
- network_thread, worker_thread, signaling_thread, default_adm,
- CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
- encoder_factory, decoder_factory, audio_mixer);
-}
-
PeerConnectionFactory::PeerConnectionFactory(
rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory)
- : owns_ptrs_(true),
- wraps_current_thread_(false),
- network_thread_(rtc::Thread::CreateWithSocketServer().release()),
- worker_thread_(rtc::Thread::Create().release()),
- signaling_thread_(rtc::Thread::Current()),
- audio_encoder_factory_(audio_encoder_factory),
- audio_decoder_factory_(audio_decoder_factory) {
- if (!signaling_thread_) {
- signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
- wraps_current_thread_ = true;
- }
- network_thread_->Start();
+ : PeerConnectionFactory(nullptr /*network_thread*/,
+ rtc::Thread::Create().release(),
+ nullptr /*signaling_thread*/,
+ nullptr /*default_adm */,
+ audio_encoder_factory,
+ audio_decoder_factory,
+ nullptr /*video_encoder_factory*/,
+ nullptr /*video_decoder_factory*/,
+ nullptr /*audio_mixer*/,
+ std::unique_ptr<cricket::MediaEngineInterface>(),
+ std::unique_ptr<webrtc::CallFactoryInterface>(),
+ std::unique_ptr<RtcEventLogFactoryInterface>()) {
worker_thread_->Start();
}
@@ -159,6 +99,32 @@ PeerConnectionFactory::PeerConnectionFactory(
cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer)
+ : PeerConnectionFactory(network_thread,
+ worker_thread,
+ signaling_thread,
+ default_adm,
+ audio_encoder_factory,
+ audio_decoder_factory,
+ video_encoder_factory,
+ video_decoder_factory,
+ audio_mixer,
+ std::unique_ptr<cricket::MediaEngineInterface>(),
+ std::unique_ptr<webrtc::CallFactoryInterface>(),
+ std::unique_ptr<RtcEventLogFactoryInterface>()) {}
+
+PeerConnectionFactory::PeerConnectionFactory(
+ rtc::Thread* network_thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* signaling_thread,
+ AudioDeviceModule* default_adm,
+ rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory,
+ rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory,
+ cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
+ cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
+ rtc::scoped_refptr<AudioMixer> audio_mixer,
+ std::unique_ptr<cricket::MediaEngineInterface> media_engine,
+ std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
+ std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory)
: owns_ptrs_(false),
wraps_current_thread_(false),
network_thread_(network_thread),
@@ -169,10 +135,25 @@ PeerConnectionFactory::PeerConnectionFactory(
audio_decoder_factory_(audio_decoder_factory),
video_encoder_factory_(video_encoder_factory),
video_decoder_factory_(video_decoder_factory),
- external_audio_mixer_(audio_mixer) {
- RTC_DCHECK(network_thread);
+ external_audio_mixer_(audio_mixer),
+ media_engine_(std::move(media_engine)),
+ call_factory_(std::move(call_factory)),
+ event_log_factory_(std::move(event_log_factory)) {
RTC_DCHECK(worker_thread);
- RTC_DCHECK(signaling_thread);
+
+ // Create the threads internally and own them.
+ if (!network_thread || !signaling_thread) {
+ owns_ptrs_ = true;
+ network_thread_ = rtc::Thread::CreateWithSocketServer().release();
+ signaling_thread_ = rtc::Thread::Current();
+
+ if (!signaling_thread_) {
+ signaling_thread_ = rtc::ThreadManager::Instance()->WrapCurrentThread();
+ wraps_current_thread_ = true;
+ }
+ network_thread_->Start();
+ }
+
// TODO: Currently there is no way creating an external adm in
// libjingle source tree. So we can 't currently assert if this is NULL.
// RTC_DCHECK(default_adm != NULL);
@@ -210,13 +191,8 @@ bool PeerConnectionFactory::Initialize() {
return false;
}
- 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(
- std::move(media_engine), worker_thread_, network_thread_));
+ std::move(media_engine_), worker_thread_, network_thread_));
channel_manager_->SetVideoRtxEnabled(true);
if (!channel_manager_->Init()) {
@@ -320,8 +296,18 @@ PeerConnectionFactory::CreatePeerConnection(
RTC_FROM_HERE, rtc::Bind(&cricket::PortAllocator::SetNetworkIgnoreMask,
allocator.get(), options_.network_ignore_mask));
+ std::unique_ptr<RtcEventLog> event_log(new RtcEventLogNullImpl());
+ if (event_log_factory_) {
+ event_log = event_log_factory_->CreateRtcEventLog();
+ }
+
+ std::unique_ptr<Call> call = worker_thread_->Invoke<std::unique_ptr<Call>>(
+ RTC_FROM_HERE,
+ rtc::Bind(&PeerConnectionFactory::CreateCall_w, this, event_log.get()));
+
rtc::scoped_refptr<PeerConnection> pc(
- new rtc::RefCountedObject<PeerConnection>(this));
+ new rtc::RefCountedObject<PeerConnection>(this, std::move(event_log),
+ std::move(call)));
if (!pc->Initialize(configuration, std::move(allocator),
std::move(cert_generator), observer)) {
@@ -382,15 +368,22 @@ rtc::Thread* PeerConnectionFactory::network_thread() {
return network_thread_;
}
-std::unique_ptr<cricket::MediaEngineInterface>
-PeerConnectionFactory::CreateMediaEngine_w() {
- RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
- return std::unique_ptr<cricket::MediaEngineInterface>(
- cricket::WebRtcMediaEngineFactory::Create(
- default_adm_.get(), audio_encoder_factory_,
- audio_decoder_factory_,
- video_encoder_factory_.get(), video_decoder_factory_.get(),
- external_audio_mixer_));
+std::unique_ptr<Call> PeerConnectionFactory::CreateCall_w(
+ RtcEventLog* event_log) {
+ const int kMinBandwidthBps = 30000;
+ const int kStartBandwidthBps = 300000;
+ const int kMaxBandwidthBps = 2000000;
+
+ webrtc::Call::Config call_config(event_log);
+ if (!channel_manager_->media_engine() || !call_factory_) {
+ return nullptr;
+ }
+ call_config.audio_state = channel_manager_->media_engine()->GetAudioState();
+ call_config.bitrate_config.min_bitrate_bps = kMinBandwidthBps;
+ call_config.bitrate_config.start_bitrate_bps = kStartBandwidthBps;
+ call_config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps;
+
+ return std::unique_ptr<Call>(call_factory_->CreateCall(call_config));
}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698