OLD | NEW |
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 Loading... |
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_mux_required, | 166 bool rtcp, |
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_mux_required_(rtcp_mux_required), | 172 rtcp_enabled_(rtcp), |
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 Loading... |
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 } | |
246 return true; | 243 return true; |
247 } | 244 } |
248 | 245 |
249 void BaseChannel::Deinit() { | 246 void BaseChannel::Deinit() { |
250 RTC_DCHECK(worker_thread_->IsCurrent()); | 247 RTC_DCHECK(worker_thread_->IsCurrent()); |
251 media_channel_->SetInterface(NULL); | 248 media_channel_->SetInterface(NULL); |
252 // Packets arrive on the network thread, processing packets calls virtual | 249 // Packets arrive on the network thread, processing packets calls virtual |
253 // functions, so need to stop this process in Deinit that is called in | 250 // functions, so need to stop this process in Deinit that is called in |
254 // derived classes destructor. | 251 // derived classes destructor. |
255 network_thread_->Invoke<void>( | 252 network_thread_->Invoke<void>( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 284 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
288 // changes and wait until the DTLS handshake is complete to set the newly | 285 // changes and wait until the DTLS handshake is complete to set the newly |
289 // negotiated parameters. | 286 // negotiated parameters. |
290 if (ShouldSetupDtlsSrtp_n()) { | 287 if (ShouldSetupDtlsSrtp_n()) { |
291 // Set |writable_| to false such that UpdateWritableState_w can set up | 288 // Set |writable_| to false such that UpdateWritableState_w can set up |
292 // DTLS-SRTP when |writable_| becomes true again. | 289 // DTLS-SRTP when |writable_| becomes true again. |
293 writable_ = false; | 290 writable_ = false; |
294 srtp_filter_.ResetParams(); | 291 srtp_filter_.ResetParams(); |
295 } | 292 } |
296 | 293 |
297 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 294 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, |
298 // negotiated RTCP mux, we need an RTCP transport. | 295 // we need an RTCP channel. |
299 if (NeedsRtcpTransport()) { | 296 if (NeedsRtcpTransport()) { |
300 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " | 297 LOG(LS_INFO) << "Setting RTCP Transport for " << content_name() << " on " |
301 << transport_name() << " transport " << rtcp_transport; | 298 << transport_name() << " transport " << rtcp_transport; |
302 SetTransportChannel_n(true, rtcp_transport); | 299 SetTransportChannel_n(true, rtcp_transport); |
303 if (!rtcp_transport_) { | 300 if (!rtcp_transport_) { |
304 return false; | 301 return false; |
305 } | 302 } |
306 } | 303 } |
307 | 304 |
308 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " | 305 LOG(LS_INFO) << "Setting non-RTCP Transport for " << content_name() << " on " |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 connection_monitor_.reset(); | 445 connection_monitor_.reset(); |
449 } | 446 } |
450 } | 447 } |
451 | 448 |
452 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { | 449 bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) { |
453 RTC_DCHECK(network_thread_->IsCurrent()); | 450 RTC_DCHECK(network_thread_->IsCurrent()); |
454 return rtp_transport_->GetStats(infos); | 451 return rtp_transport_->GetStats(infos); |
455 } | 452 } |
456 | 453 |
457 bool BaseChannel::NeedsRtcpTransport() { | 454 bool BaseChannel::NeedsRtcpTransport() { |
458 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 455 return rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive(); |
459 // negotiated RTCP mux, we need an RTCP transport. | |
460 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); | |
461 } | 456 } |
462 | 457 |
463 bool BaseChannel::IsReadyToReceiveMedia_w() const { | 458 bool BaseChannel::IsReadyToReceiveMedia_w() const { |
464 // Receive data if we are enabled and have local content, | 459 // Receive data if we are enabled and have local content, |
465 return enabled() && IsReceiveContentDirection(local_content_direction_); | 460 return enabled() && IsReceiveContentDirection(local_content_direction_); |
466 } | 461 } |
467 | 462 |
468 bool BaseChannel::IsReadyToSendMedia_w() const { | 463 bool BaseChannel::IsReadyToSendMedia_w() const { |
469 // Need to access some state updated on the network thread. | 464 // Need to access some state updated on the network thread. |
470 return network_thread_->Invoke<bool>( | 465 return network_thread_->Invoke<bool>( |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 default: | 1150 default: |
1156 break; | 1151 break; |
1157 } | 1152 } |
1158 if (!ret) { | 1153 if (!ret) { |
1159 SafeSetError("Failed to setup SRTP filter.", error_desc); | 1154 SafeSetError("Failed to setup SRTP filter.", error_desc); |
1160 return false; | 1155 return false; |
1161 } | 1156 } |
1162 return true; | 1157 return true; |
1163 } | 1158 } |
1164 | 1159 |
| 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 |
1165 bool BaseChannel::SetRtcpMux_n(bool enable, | 1180 bool BaseChannel::SetRtcpMux_n(bool enable, |
1166 ContentAction action, | 1181 ContentAction action, |
1167 ContentSource src, | 1182 ContentSource src, |
1168 std::string* error_desc) { | 1183 std::string* error_desc) { |
1169 bool ret = false; | 1184 bool ret = false; |
1170 switch (action) { | 1185 switch (action) { |
1171 case CA_OFFER: | 1186 case CA_OFFER: |
1172 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1187 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1173 break; | 1188 break; |
1174 case CA_PRANSWER: | 1189 case CA_PRANSWER: |
1175 // This may activate RTCP muxing, but we don't yet destroy the channel | 1190 // This may activate RTCP muxing, but we don't yet destroy the channel |
1176 // because the final answer may deactivate it. | 1191 // because the final answer may deactivate it. |
1177 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1192 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1178 break; | 1193 break; |
1179 case CA_ANSWER: | 1194 case CA_ANSWER: |
1180 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1195 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1181 if (ret && rtcp_mux_filter_.IsActive()) { | 1196 if (ret && rtcp_mux_filter_.IsActive()) { |
1182 // We activated RTCP mux, close down the RTCP transport. | 1197 // We activated RTCP mux, close down the RTCP transport. |
1183 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1198 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
1184 << " by destroying RTCP transport channel for " | 1199 << " by destroying RTCP transport channel for " |
1185 << transport_name(); | 1200 << transport_name(); |
1186 if (rtcp_transport()) { | 1201 bool need_to_delete_rtcp = (rtcp_transport() != nullptr); |
1187 SetTransportChannel_n(true, nullptr); | 1202 SetTransportChannel_n(true, nullptr); |
1188 SignalRtcpMuxFullyActive(rtp_transport()->transport_name()); | 1203 if (need_to_delete_rtcp) { |
| 1204 SignalDestroyRtcpTransport(rtp_transport()->transport_name()); |
1189 } | 1205 } |
1190 UpdateWritableState_n(); | 1206 UpdateWritableState_n(); |
1191 SetTransportChannelReadyToSend(true, false); | 1207 SetTransportChannelReadyToSend(true, false); |
1192 } | 1208 } |
1193 break; | 1209 break; |
1194 case CA_UPDATE: | 1210 case CA_UPDATE: |
1195 // No RTCP mux info. | 1211 // No RTCP mux info. |
1196 ret = true; | 1212 ret = true; |
1197 break; | 1213 break; |
1198 default: | 1214 default: |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 RTC_DCHECK(worker_thread_->IsCurrent()); | 1455 RTC_DCHECK(worker_thread_->IsCurrent()); |
1440 SignalSentPacket(sent_packet); | 1456 SignalSentPacket(sent_packet); |
1441 } | 1457 } |
1442 | 1458 |
1443 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, | 1459 VoiceChannel::VoiceChannel(rtc::Thread* worker_thread, |
1444 rtc::Thread* network_thread, | 1460 rtc::Thread* network_thread, |
1445 rtc::Thread* signaling_thread, | 1461 rtc::Thread* signaling_thread, |
1446 MediaEngineInterface* media_engine, | 1462 MediaEngineInterface* media_engine, |
1447 VoiceMediaChannel* media_channel, | 1463 VoiceMediaChannel* media_channel, |
1448 const std::string& content_name, | 1464 const std::string& content_name, |
1449 bool rtcp_mux_required, | 1465 bool rtcp, |
1450 bool srtp_required) | 1466 bool srtp_required) |
1451 : BaseChannel(worker_thread, | 1467 : BaseChannel(worker_thread, |
1452 network_thread, | 1468 network_thread, |
1453 signaling_thread, | 1469 signaling_thread, |
1454 media_channel, | 1470 media_channel, |
1455 content_name, | 1471 content_name, |
1456 rtcp_mux_required, | 1472 rtcp, |
1457 srtp_required), | 1473 srtp_required), |
1458 media_engine_(media_engine), | 1474 media_engine_(media_engine), |
1459 received_media_(false) {} | 1475 received_media_(false) {} |
1460 | 1476 |
1461 VoiceChannel::~VoiceChannel() { | 1477 VoiceChannel::~VoiceChannel() { |
1462 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 1478 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |
1463 StopAudioMonitor(); | 1479 StopAudioMonitor(); |
1464 StopMediaMonitor(); | 1480 StopMediaMonitor(); |
1465 // this can't be done in the base class, since it calls a virtual | 1481 // this can't be done in the base class, since it calls a virtual |
1466 DisableMedia_w(); | 1482 DisableMedia_w(); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 void VoiceChannel::GetSrtpCryptoSuites_n( | 1868 void VoiceChannel::GetSrtpCryptoSuites_n( |
1853 std::vector<int>* crypto_suites) const { | 1869 std::vector<int>* crypto_suites) const { |
1854 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); | 1870 GetSupportedAudioCryptoSuites(crypto_options(), crypto_suites); |
1855 } | 1871 } |
1856 | 1872 |
1857 VideoChannel::VideoChannel(rtc::Thread* worker_thread, | 1873 VideoChannel::VideoChannel(rtc::Thread* worker_thread, |
1858 rtc::Thread* network_thread, | 1874 rtc::Thread* network_thread, |
1859 rtc::Thread* signaling_thread, | 1875 rtc::Thread* signaling_thread, |
1860 VideoMediaChannel* media_channel, | 1876 VideoMediaChannel* media_channel, |
1861 const std::string& content_name, | 1877 const std::string& content_name, |
1862 bool rtcp_mux_required, | 1878 bool rtcp, |
1863 bool srtp_required) | 1879 bool srtp_required) |
1864 : BaseChannel(worker_thread, | 1880 : BaseChannel(worker_thread, |
1865 network_thread, | 1881 network_thread, |
1866 signaling_thread, | 1882 signaling_thread, |
1867 media_channel, | 1883 media_channel, |
1868 content_name, | 1884 content_name, |
1869 rtcp_mux_required, | 1885 rtcp, |
1870 srtp_required) {} | 1886 srtp_required) {} |
1871 | 1887 |
1872 bool VideoChannel::Init_w(TransportChannel* rtp_transport, | 1888 bool VideoChannel::Init_w(TransportChannel* rtp_transport, |
1873 TransportChannel* rtcp_transport) { | 1889 TransportChannel* rtcp_transport) { |
1874 return BaseChannel::Init_w(rtp_transport, rtcp_transport); | 1890 return BaseChannel::Init_w(rtp_transport, rtcp_transport); |
1875 } | 1891 } |
1876 | 1892 |
1877 VideoChannel::~VideoChannel() { | 1893 VideoChannel::~VideoChannel() { |
1878 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); | 1894 TRACE_EVENT0("webrtc", "VideoChannel::~VideoChannel"); |
1879 StopMediaMonitor(); | 1895 StopMediaMonitor(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 void VideoChannel::GetSrtpCryptoSuites_n( | 2129 void VideoChannel::GetSrtpCryptoSuites_n( |
2114 std::vector<int>* crypto_suites) const { | 2130 std::vector<int>* crypto_suites) const { |
2115 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); | 2131 GetSupportedVideoCryptoSuites(crypto_options(), crypto_suites); |
2116 } | 2132 } |
2117 | 2133 |
2118 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, | 2134 RtpDataChannel::RtpDataChannel(rtc::Thread* worker_thread, |
2119 rtc::Thread* network_thread, | 2135 rtc::Thread* network_thread, |
2120 rtc::Thread* signaling_thread, | 2136 rtc::Thread* signaling_thread, |
2121 DataMediaChannel* media_channel, | 2137 DataMediaChannel* media_channel, |
2122 const std::string& content_name, | 2138 const std::string& content_name, |
2123 bool rtcp_mux_required, | 2139 bool rtcp, |
2124 bool srtp_required) | 2140 bool srtp_required) |
2125 : BaseChannel(worker_thread, | 2141 : BaseChannel(worker_thread, |
2126 network_thread, | 2142 network_thread, |
2127 signaling_thread, | 2143 signaling_thread, |
2128 media_channel, | 2144 media_channel, |
2129 content_name, | 2145 content_name, |
2130 rtcp_mux_required, | 2146 rtcp, |
2131 srtp_required) {} | 2147 srtp_required) {} |
2132 | 2148 |
2133 RtpDataChannel::~RtpDataChannel() { | 2149 RtpDataChannel::~RtpDataChannel() { |
2134 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); | 2150 TRACE_EVENT0("webrtc", "RtpDataChannel::~RtpDataChannel"); |
2135 StopMediaMonitor(); | 2151 StopMediaMonitor(); |
2136 // this can't be done in the base class, since it calls a virtual | 2152 // this can't be done in the base class, since it calls a virtual |
2137 DisableMedia_w(); | 2153 DisableMedia_w(); |
2138 | 2154 |
2139 Deinit(); | 2155 Deinit(); |
2140 } | 2156 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2380 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2396 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2381 new DataChannelReadyToSendMessageData(writable)); | 2397 new DataChannelReadyToSendMessageData(writable)); |
2382 } | 2398 } |
2383 | 2399 |
2384 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2400 void RtpDataChannel::GetSrtpCryptoSuites_n( |
2385 std::vector<int>* crypto_suites) const { | 2401 std::vector<int>* crypto_suites) const { |
2386 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2402 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
2387 } | 2403 } |
2388 | 2404 |
2389 } // namespace cricket | 2405 } // namespace cricket |
OLD | NEW |