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

Unified Diff: webrtc/api/webrtcsession.cc

Issue 1713043002: Late initialize MediaController, for less resource i.e. ProcessThread, usage by PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Missed one comment Created 4 years, 10 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/api/webrtcsession.cc
diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc
index c693cb1077ee6e1d072bfd9a1308ad1175b6350e..7fa28e7da7c1d17a7f151a23d20a1c900b7e1bfd 100644
--- a/webrtc/api/webrtcsession.cc
+++ b/webrtc/api/webrtcsession.cc
@@ -521,8 +521,7 @@ class IceRestartAnswerLatch {
bool ice_restart_;
};
-WebRtcSession::WebRtcSession(webrtc::MediaControllerInterface* media_controller,
- rtc::Thread* signaling_thread,
+WebRtcSession::WebRtcSession(rtc::Thread* signaling_thread,
rtc::Thread* worker_thread,
cricket::PortAllocator* port_allocator)
: signaling_thread_(signaling_thread),
@@ -535,13 +534,9 @@ WebRtcSession::WebRtcSession(webrtc::MediaControllerInterface* media_controller,
transport_controller_(new cricket::TransportController(signaling_thread,
worker_thread,
port_allocator)),
- media_controller_(media_controller),
- channel_manager_(media_controller_->channel_manager()),
ice_observer_(NULL),
ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
ice_connection_receiving_(true),
- older_version_remote_peer_(false),
- dtls_enabled_(false),
data_channel_type_(cricket::DCT_NONE),
ice_restart_latch_(new IceRestartAnswerLatch),
metrics_observer_(NULL) {
@@ -561,16 +556,22 @@ WebRtcSession::~WebRtcSession() {
// Destroy video_channel_ first since it may have a pointer to the
// voice_channel_.
if (video_channel_) {
+ RTC_DCHECK(media_controller_);
SignalVideoChannelDestroyed();
- channel_manager_->DestroyVideoChannel(video_channel_.release());
+ media_controller_->channel_manager()->DestroyVideoChannel(
+ video_channel_.release());
}
if (voice_channel_) {
+ RTC_DCHECK(media_controller_);
SignalVoiceChannelDestroyed();
- channel_manager_->DestroyVoiceChannel(voice_channel_.release());
+ media_controller_->channel_manager()->DestroyVoiceChannel(
+ voice_channel_.release());
}
if (data_channel_) {
+ RTC_DCHECK(media_controller_);
SignalDataChannelDestroyed();
- channel_manager_->DestroyDataChannel(data_channel_.release());
+ media_controller_->channel_manager()->DestroyDataChannel(
+ data_channel_.release());
}
SignalDestroyed();
@@ -585,14 +586,14 @@ bool WebRtcSession::Initialize(
bundle_policy_ = rtc_configuration.bundle_policy;
rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy;
transport_controller_->SetSslMaxProtocolVersion(options.ssl_max_version);
+ dtls_identity_store_ = std::move(dtls_identity_store);
// Obtain a certificate from RTCConfiguration if any were provided (optional).
- rtc::scoped_refptr<rtc::RTCCertificate> certificate;
if (!rtc_configuration.certificates.empty()) {
// TODO(hbos,torbjorng): Decide on certificate-selection strategy instead of
// just picking the first one. The decision should be made based on the DTLS
// handshake. The DTLS negotiations need to know about all certificates.
- certificate = rtc_configuration.certificates[0];
+ certificate_ = rtc_configuration.certificates[0];
}
SetIceConfig(ParseIceConfig(rtc_configuration));
@@ -604,9 +605,10 @@ bool WebRtcSession::Initialize(
if (options.disable_encryption) {
dtls_enabled_ = false;
+ disable_encryption_ = true;
} else {
// Enable DTLS by default if we have an identity store or a certificate.
- dtls_enabled_ = (dtls_identity_store || certificate);
+ dtls_enabled_ = (dtls_identity_store_ || certificate_);
// |constraints| can override the default |dtls_enabled_| value.
if (FindConstraint(constraints, MediaConstraintsInterface::kEnableDtlsSrtp,
&value, nullptr)) {
@@ -653,35 +655,45 @@ bool WebRtcSession::Initialize(
audio_options_.audio_jitter_buffer_fast_accelerate = rtc::Optional<bool>(
rtc_configuration.audio_jitter_buffer_fast_accelerate);
+ port_allocator()->set_candidate_filter(
+ ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type));
+
+ return true;
+}
+
+void WebRtcSession::LateInitialize(
+ webrtc::MediaControllerInterface* media_controller) {
+ RTC_DCHECK(media_controller);
+ RTC_DCHECK(!media_controller_);
+ media_controller_ = media_controller;
+
if (!dtls_enabled_) {
// Construct with DTLS disabled.
webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
- signaling_thread(), channel_manager_, this, id()));
+ signaling_thread(), media_controller_->channel_manager(), this, id()));
} else {
// Construct with DTLS enabled.
- if (!certificate) {
+ if (!certificate_) {
// Use the |dtls_identity_store| to generate a certificate.
- RTC_DCHECK(dtls_identity_store);
+ RTC_DCHECK(dtls_identity_store_);
webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
- signaling_thread(), channel_manager_, std::move(dtls_identity_store),
- this, id()));
+ signaling_thread(), media_controller_->channel_manager(),
+ std::move(dtls_identity_store_), this, id()));
} else {
// Use the already generated certificate.
webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
- signaling_thread(), channel_manager_, certificate, this, id()));
+ signaling_thread(), media_controller_->channel_manager(),
+ certificate_, this, id()));
+ certificate_ = rtc::scoped_refptr<rtc::RTCCertificate>(nullptr);
}
}
webrtc_session_desc_factory_->SignalCertificateReady.connect(
this, &WebRtcSession::OnCertificateReady);
- if (options.disable_encryption) {
+ if (disable_encryption_) {
webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
}
- port_allocator()->set_candidate_filter(
- ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type));
-
- return true;
}
void WebRtcSession::Close() {
@@ -690,6 +702,7 @@ void WebRtcSession::Close() {
ASSERT(!voice_channel_);
ASSERT(!video_channel_);
ASSERT(!data_channel_);
+ media_controller_ = nullptr;
}
void WebRtcSession::SetSdesPolicy(cricket::SecurePolicy secure_policy) {
@@ -1696,22 +1709,28 @@ void WebRtcSession::RemoveUnusedChannels(const SessionDescription* desc) {
const cricket::ContentInfo* video_info =
cricket::GetFirstVideoContent(desc);
if ((!video_info || video_info->rejected) && video_channel_) {
+ RTC_DCHECK(media_controller_);
SignalVideoChannelDestroyed();
- channel_manager_->DestroyVideoChannel(video_channel_.release());
+ media_controller_->channel_manager()->DestroyVideoChannel(
+ video_channel_.release());
pthatcher1 2016/02/24 23:10:09 Why not just make a channel_manager() method? Cha
}
const cricket::ContentInfo* voice_info =
cricket::GetFirstAudioContent(desc);
if ((!voice_info || voice_info->rejected) && voice_channel_) {
+ RTC_DCHECK(media_controller_);
SignalVoiceChannelDestroyed();
- channel_manager_->DestroyVoiceChannel(voice_channel_.release());
+ media_controller_->channel_manager()->DestroyVoiceChannel(
+ voice_channel_.release());
}
const cricket::ContentInfo* data_info =
cricket::GetFirstDataContent(desc);
if ((!data_info || data_info->rejected) && data_channel_) {
+ RTC_DCHECK(media_controller_);
SignalDataChannelDestroyed();
- channel_manager_->DestroyDataChannel(data_channel_.release());
+ media_controller_->channel_manager()->DestroyDataChannel(
+ data_channel_.release());
}
}
@@ -1774,7 +1793,8 @@ bool WebRtcSession::CreateChannels(const SessionDescription* desc) {
}
bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) {
- voice_channel_.reset(channel_manager_->CreateVoiceChannel(
+ RTC_DCHECK(media_controller_);
+ voice_channel_.reset(media_controller_->channel_manager()->CreateVoiceChannel(
media_controller_, transport_controller_.get(), content->name, true,
audio_options_));
if (!voice_channel_) {
@@ -1791,7 +1811,8 @@ bool WebRtcSession::CreateVoiceChannel(const cricket::ContentInfo* content) {
}
bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) {
- video_channel_.reset(channel_manager_->CreateVideoChannel(
+ RTC_DCHECK(media_controller_);
+ video_channel_.reset(media_controller_->channel_manager()->CreateVideoChannel(
media_controller_, transport_controller_.get(), content->name, true,
video_options_));
if (!video_channel_) {
@@ -1808,8 +1829,9 @@ bool WebRtcSession::CreateVideoChannel(const cricket::ContentInfo* content) {
}
bool WebRtcSession::CreateDataChannel(const cricket::ContentInfo* content) {
+ RTC_DCHECK(media_controller_);
bool sctp = (data_channel_type_ == cricket::DCT_SCTP);
- data_channel_.reset(channel_manager_->CreateDataChannel(
+ data_channel_.reset(media_controller_->channel_manager()->CreateDataChannel(
transport_controller_.get(), content->name, !sctp, data_channel_type_));
if (!data_channel_) {
return false;
@@ -2146,6 +2168,7 @@ void WebRtcSession::ReportNegotiatedCiphers(
void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel,
const rtc::SentPacket& sent_packet) {
RTC_DCHECK(worker_thread()->IsCurrent());
+ RTC_DCHECK(media_controller_);
media_controller_->call_w()->OnSentPacket(sent_packet);
}

Powered by Google App Engine
This is Rietveld 408576698