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

Side by Side Diff: webrtc/pc/channel.cc

Issue 2622613004: Refactoring of RTCP options in BaseChannel. (Closed)
Patch Set: Minor renaming/adding a comment, which makes sense to do after this refactoring. Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 RtpSendParameters<Codec>* send_params) { 156 RtpSendParameters<Codec>* send_params) {
157 RtpParametersFromMediaDescription(desc, send_params); 157 RtpParametersFromMediaDescription(desc, send_params);
158 send_params->max_bandwidth_bps = desc->bandwidth(); 158 send_params->max_bandwidth_bps = desc->bandwidth();
159 } 159 }
160 160
161 BaseChannel::BaseChannel(rtc::Thread* worker_thread, 161 BaseChannel::BaseChannel(rtc::Thread* worker_thread,
162 rtc::Thread* network_thread, 162 rtc::Thread* network_thread,
163 rtc::Thread* signaling_thread, 163 rtc::Thread* signaling_thread,
164 MediaChannel* media_channel, 164 MediaChannel* media_channel,
165 const std::string& content_name, 165 const std::string& content_name,
166 bool rtcp, 166 bool rtcp_mux_required,
167 bool srtp_required) 167 bool srtp_required)
168 : worker_thread_(worker_thread), 168 : worker_thread_(worker_thread),
169 network_thread_(network_thread), 169 network_thread_(network_thread),
170 signaling_thread_(signaling_thread), 170 signaling_thread_(signaling_thread),
171 content_name_(content_name), 171 content_name_(content_name),
172 rtcp_enabled_(rtcp), 172 rtcp_mux_required_(rtcp_mux_required),
173 srtp_required_(srtp_required), 173 srtp_required_(srtp_required),
174 media_channel_(media_channel), 174 media_channel_(media_channel),
175 selected_candidate_pair_(nullptr) { 175 selected_candidate_pair_(nullptr) {
176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
177 LOG(LS_INFO) << "Created channel for " << content_name; 177 LOG(LS_INFO) << "Created channel for " << content_name;
178 } 178 }
179 179
180 BaseChannel::~BaseChannel() { 180 BaseChannel::~BaseChannel() {
181 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); 181 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel");
182 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); 182 RTC_DCHECK(worker_thread_ == rtc::Thread::Current());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 if (!SetTransport_n(rtp_transport, rtcp_transport)) { 233 if (!SetTransport_n(rtp_transport, rtcp_transport)) {
234 return false; 234 return false;
235 } 235 }
236 236
237 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) { 237 if (!SetDtlsSrtpCryptoSuites_n(rtp_transport_, false)) {
238 return false; 238 return false;
239 } 239 }
240 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) { 240 if (rtcp_transport_ && !SetDtlsSrtpCryptoSuites_n(rtcp_transport_, true)) {
241 return false; 241 return false;
242 } 242 }
243 if (rtcp_mux_required_) {
244 rtcp_mux_filter_.SetActive();
245 }
243 return true; 246 return true;
244 } 247 }
245 248
246 void BaseChannel::Deinit() { 249 void BaseChannel::Deinit() {
247 RTC_DCHECK(worker_thread_->IsCurrent()); 250 RTC_DCHECK(worker_thread_->IsCurrent());
248 media_channel_->SetInterface(NULL); 251 media_channel_->SetInterface(NULL);
249 // Packets arrive on the network thread, processing packets calls virtual 252 // Packets arrive on the network thread, processing packets calls virtual
250 // functions, so need to stop this process in Deinit that is called in 253 // functions, so need to stop this process in Deinit that is called in
251 // derived classes destructor. 254 // derived classes destructor.
252 network_thread_->Invoke<void>( 255 network_thread_->Invoke<void>(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport 287 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport
285 // changes and wait until the DTLS handshake is complete to set the newly 288 // changes and wait until the DTLS handshake is complete to set the newly
286 // negotiated parameters. 289 // negotiated parameters.
287 if (ShouldSetupDtlsSrtp_n()) { 290 if (ShouldSetupDtlsSrtp_n()) {
288 // Set |writable_| to false such that UpdateWritableState_w can set up 291 // Set |writable_| to false such that UpdateWritableState_w can set up
289 // DTLS-SRTP when |writable_| becomes true again. 292 // DTLS-SRTP when |writable_| becomes true again.
290 writable_ = false; 293 writable_ = false;
291 srtp_filter_.ResetParams(); 294 srtp_filter_.ResetParams();
292 } 295 }
293 296
294 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, 297 // If this BaseChannel doesn't require RTCP mux and we haven't fully
295 // we need an RTCP channel. 298 // negotiated RTCP mux, we need an RTCP transport.
296 if (NeedsRtcpTransport()) { 299 if (NeedsRtcpTransport()) {
297 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " 300 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on "
298 << transport_name() << " transport " << rtcp_transport; 301 << transport_name() << " transport " << rtcp_transport;
299 SetTransportChannel_n(true, rtcp_transport); 302 SetTransportChannel_n(true, rtcp_transport);
300 if (!rtcp_transport_) { 303 if (!rtcp_transport_) {
301 return false; 304 return false;
302 } 305 }
303 } 306 }
304 307
305 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " 308 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on "
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 connection_monitor_.reset(); 448 connection_monitor_.reset();
446 } 449 }
447 } 450 }
448 451
449 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { 452 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
450 RTC_DCHECK(network_thread_->IsCurrent()); 453 RTC_DCHECK(network_thread_->IsCurrent());
451 return rtp_transport_->GetStats(infos); 454 return rtp_transport_->GetStats(infos);
452 } 455 }
453 456
454 bool BaseChannel::NeedsRtcpTransport() { 457 bool BaseChannel::NeedsRtcpTransport() {
455 return rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive(); 458 // If this BaseChannel doesn't require RTCP mux and we haven't fully
459 // negotiated RTCP mux, we need an RTCP transport.
460 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive();
456 } 461 }
457 462
458 bool BaseChannel::IsReadyToReceiveMedia_w() const { 463 bool BaseChannel::IsReadyToReceiveMedia_w() const {
459 // Receive data if we are enabled and have local content, 464 // Receive data if we are enabled and have local content,
460 return enabled() && IsReceiveContentDirection(local_content_direction_); 465 return enabled() && IsReceiveContentDirection(local_content_direction_);
461 } 466 }
462 467
463 bool BaseChannel::IsReadyToSendMedia_w() const { 468 bool BaseChannel::IsReadyToSendMedia_w() const {
464 // Need to access some state updated on the network thread. 469 // Need to access some state updated on the network thread.
465 return network_thread_->Invoke<bool>( 470 return network_thread_->Invoke<bool>(
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 default: 1155 default:
1151 break; 1156 break;
1152 } 1157 }
1153 if (!ret) { 1158 if (!ret) {
1154 SafeSetError("Failed to setup SRTP filter.", error_desc); 1159 SafeSetError("Failed to setup SRTP filter.", error_desc);
1155 return false; 1160 return false;
1156 } 1161 }
1157 return true; 1162 return true;
1158 } 1163 }
1159 1164
1160 void BaseChannel::ActivateRtcpMux() {
1161 network_thread_->Invoke<void>(RTC_FROM_HERE,
1162 Bind(&BaseChannel::ActivateRtcpMux_n, this));
1163 }
1164
1165 void BaseChannel::ActivateRtcpMux_n() {
1166 if (!rtcp_mux_filter_.IsActive()) {
1167 rtcp_mux_filter_.SetActive();
1168 bool need_to_delete_rtcp = (rtcp_transport() != nullptr);
1169 SetTransportChannel_n(true, nullptr);
1170 if (need_to_delete_rtcp) {
1171 SignalDestroyRtcpTransport(rtp_transport()->transport_name());
1172 }
1173 // Update aggregate writable/ready-to-send state between RTP and RTCP upon
1174 // removing channel.
1175 UpdateWritableState_n();
1176 SetTransportChannelReadyToSend(true, false);
1177 }
1178 }
1179
1180 bool BaseChannel::SetRtcpMux_n(bool enable, 1165 bool BaseChannel::SetRtcpMux_n(bool enable,
1181 ContentAction action, 1166 ContentAction action,
1182 ContentSource src, 1167 ContentSource src,
1183 std::string* error_desc) { 1168 std::string* error_desc) {
1184 bool ret = false; 1169 bool ret = false;
1185 switch (action) { 1170 switch (action) {
1186 case CA_OFFER: 1171 case CA_OFFER:
1187 ret = rtcp_mux_filter_.SetOffer(enable, src); 1172 ret = rtcp_mux_filter_.SetOffer(enable, src);
1188 break; 1173 break;
1189 case CA_PRANSWER: 1174 case CA_PRANSWER:
1190 // This may activate RTCP muxing, but we don't yet destroy the channel 1175 // This may activate RTCP muxing, but we don't yet destroy the channel
1191 // because the final answer may deactivate it. 1176 // because the final answer may deactivate it.
1192 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); 1177 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src);
1193 break; 1178 break;
1194 case CA_ANSWER: 1179 case CA_ANSWER:
1195 ret = rtcp_mux_filter_.SetAnswer(enable, src); 1180 ret = rtcp_mux_filter_.SetAnswer(enable, src);
1196 if (ret && rtcp_mux_filter_.IsActive()) { 1181 if (ret && rtcp_mux_filter_.IsActive()) {
1197 // We activated RTCP mux, close down the RTCP transport. 1182 // We activated RTCP mux, close down the RTCP transport.
1198 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() 1183 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
1199 << " by destroying RTCP transport channel for " 1184 << " by destroying RTCP transport channel for "
1200 << transport_name(); 1185 << transport_name();
1201 bool need_to_delete_rtcp = (rtcp_transport() != nullptr); 1186 if (rtcp_transport()) {
1202 SetTransportChannel_n(true, nullptr); 1187 SetTransportChannel_n(true, nullptr);
1203 if (need_to_delete_rtcp) { 1188 SignalRtcpMuxFullyActive(rtp_transport()->transport_name());
1204 SignalDestroyRtcpTransport(rtp_transport()->transport_name());
1205 } 1189 }
1206 UpdateWritableState_n(); 1190 UpdateWritableState_n();
1207 SetTransportChannelReadyToSend(true, false); 1191 SetTransportChannelReadyToSend(true, false);
1208 } 1192 }
1209 break; 1193 break;
1210 case CA_UPDATE: 1194 case CA_UPDATE:
1211 // No RTCP mux info. 1195 // No RTCP mux info.
1212 ret = true; 1196 ret = true;
1213 break; 1197 break;
1214 default: 1198 default:
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 RTC_DCHECK(worker_thread_->IsCurrent()); 1439 RTC_DCHECK(worker_thread_->IsCurrent());
1456 SignalSentPacket(sent_packet); 1440 SignalSentPacket(sent_packet);
1457 } 1441 }
1458 1442
1459 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, 1443 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread,
1460 rtc::Thread* network_thread, 1444 rtc::Thread* network_thread,
1461 rtc::Thread* signaling_thread, 1445 rtc::Thread* signaling_thread,
1462 MediaEngineInterface* media_engine, 1446 MediaEngineInterface* media_engine,
1463 VoiceMediaChannel* media_channel, 1447 VoiceMediaChannel* media_channel,
1464 const std::string& content_name, 1448 const std::string& content_name,
1465 bool rtcp, 1449 bool rtcp_mux_required,
1466 bool srtp_required) 1450 bool srtp_required)
1467 : BaseChannel(worker_thread, 1451 : BaseChannel(worker_thread,
1468 network_thread, 1452 network_thread,
1469 signaling_thread, 1453 signaling_thread,
1470 media_channel, 1454 media_channel,
1471 content_name, 1455 content_name,
1472 rtcp, 1456 rtcp_mux_required,
1473 srtp_required), 1457 srtp_required),
1474 media_engine_(media_engine), 1458 media_engine_(media_engine),
1475 received_media_(false) {} 1459 received_media_(false) {}
1476 1460
1477 VoiceChannel::~VoiceChannel() { 1461 VoiceChannel::~VoiceChannel() {
1478 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); 1462 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel");
1479 StopAudioMonitor(); 1463 StopAudioMonitor();
1480 StopMediaMonitor(); 1464 StopMediaMonitor();
1481 // this can't be done in the base class, since it calls a virtual 1465 // this can't be done in the base class, since it calls a virtual
1482 DisableMedia_w(); 1466 DisableMedia_w();
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 void VoiceChannel::GetSrtpCryptoSuites_n( 1852 void VoiceChannel::GetSrtpCryptoSuites_n(
1869 std::vector<int>* crypto_suites) const { 1853 std::vector<int>* crypto_suites) const {
1870 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); 1854 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites);
1871 } 1855 }
1872 1856
1873 VideoChannel::VideoChannel(rtc::Thread* worker_thread, 1857 VideoChannel::VideoChannel(rtc::Thread* worker_thread,
1874 rtc::Thread* network_thread, 1858 rtc::Thread* network_thread,
1875 rtc::Thread* signaling_thread, 1859 rtc::Thread* signaling_thread,
1876 VideoMediaChannel* media_channel, 1860 VideoMediaChannel* media_channel,
1877 const std::string& content_name, 1861 const std::string& content_name,
1878 bool rtcp, 1862 bool rtcp_mux_required,
1879 bool srtp_required) 1863 bool srtp_required)
1880 : BaseChannel(worker_thread, 1864 : BaseChannel(worker_thread,
1881 network_thread, 1865 network_thread,
1882 signaling_thread, 1866 signaling_thread,
1883 media_channel, 1867 media_channel,
1884 content_name, 1868 content_name,
1885 rtcp, 1869 rtcp_mux_required,
1886 srtp_required) {} 1870 srtp_required) {}
1887 1871
1888 bool VideoChannel::Init_w(TransportChannel* rtp_transport, 1872 bool VideoChannel::Init_w(TransportChannel* rtp_transport,
1889 TransportChannel* rtcp_transport) { 1873 TransportChannel* rtcp_transport) {
1890 return BaseChannel::Init_w(rtp_transport, rtcp_transport); 1874 return BaseChannel::Init_w(rtp_transport, rtcp_transport);
1891 } 1875 }
1892 1876
1893 VideoChannel::~VideoChannel() { 1877 VideoChannel::~VideoChannel() {
1894 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); 1878 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel");
1895 StopMediaMonitor(); 1879 StopMediaMonitor();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 void VideoChannel::GetSrtpCryptoSuites_n( 2113 void VideoChannel::GetSrtpCryptoSuites_n(
2130 std::vector<int>* crypto_suites) const { 2114 std::vector<int>* crypto_suites) const {
2131 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); 2115 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites);
2132 } 2116 }
2133 2117
2134 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, 2118 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread,
2135 rtc::Thread* network_thread, 2119 rtc::Thread* network_thread,
2136 rtc::Thread* signaling_thread, 2120 rtc::Thread* signaling_thread,
2137 DataMediaChannel* media_channel, 2121 DataMediaChannel* media_channel,
2138 const std::string& content_name, 2122 const std::string& content_name,
2139 bool rtcp, 2123 bool rtcp_mux_required,
2140 bool srtp_required) 2124 bool srtp_required)
2141 : BaseChannel(worker_thread, 2125 : BaseChannel(worker_thread,
2142 network_thread, 2126 network_thread,
2143 signaling_thread, 2127 signaling_thread,
2144 media_channel, 2128 media_channel,
2145 content_name, 2129 content_name,
2146 rtcp, 2130 rtcp_mux_required,
2147 srtp_required) {} 2131 srtp_required) {}
2148 2132
2149 RtpDataChannel::~RtpDataChannel() { 2133 RtpDataChannel::~RtpDataChannel() {
2150 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); 2134 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel");
2151 StopMediaMonitor(); 2135 StopMediaMonitor();
2152 // this can't be done in the base class, since it calls a virtual 2136 // this can't be done in the base class, since it calls a virtual
2153 DisableMedia_w(); 2137 DisableMedia_w();
2154 2138
2155 Deinit(); 2139 Deinit();
2156 } 2140 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, 2380 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
2397 new DataChannelReadyToSendMessageData(writable)); 2381 new DataChannelReadyToSendMessageData(writable));
2398 } 2382 }
2399 2383
2400 void RtpDataChannel::GetSrtpCryptoSuites_n( 2384 void RtpDataChannel::GetSrtpCryptoSuites_n(
2401 std::vector<int>* crypto_suites) const { 2385 std::vector<int>* crypto_suites) const {
2402 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); 2386 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites);
2403 } 2387 }
2404 2388
2405 } // namespace cricket 2389 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698