OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 if (transport_name == transport_name_) { | 259 if (transport_name == transport_name_) { |
260 // Nothing to do if transport name isn't changing | 260 // Nothing to do if transport name isn't changing |
261 return true; | 261 return true; |
262 } | 262 } |
263 | 263 |
264 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 264 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
265 // changes and wait until the DTLS handshake is complete to set the newly | 265 // changes and wait until the DTLS handshake is complete to set the newly |
266 // negotiated parameters. | 266 // negotiated parameters. |
267 if (ShouldSetupDtlsSrtp()) { | 267 if (ShouldSetupDtlsSrtp()) { |
| 268 // Setting to non-writable will send RTCP BYE so we can only clean up the |
| 269 // srtp filter parameters after this. |
| 270 ChannelNotWritable_w(); |
268 srtp_filter_.ResetParams(); | 271 srtp_filter_.ResetParams(); |
269 } | 272 } |
270 | 273 |
271 set_transport_channel(transport_controller_->CreateTransportChannel_w( | 274 // We're not updating the writablity during the transition state. |
272 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 275 set_transport_channel( |
| 276 transport_controller_->CreateTransportChannel_w( |
| 277 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP), |
| 278 false /* update_writablity */); |
273 if (!transport_channel()) { | 279 if (!transport_channel()) { |
274 return false; | 280 return false; |
275 } | 281 } |
276 if (rtcp_transport_enabled()) { | 282 if (rtcp_transport_enabled()) { |
277 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() | 283 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
278 << " on " << transport_name << " transport "; | 284 << " on " << transport_name << " transport "; |
279 set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w( | 285 set_rtcp_transport_channel( |
280 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); | 286 transport_controller_->CreateTransportChannel_w( |
| 287 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP), |
| 288 false /* update_writablity */); |
281 if (!rtcp_transport_channel()) { | 289 if (!rtcp_transport_channel()) { |
282 return false; | 290 return false; |
283 } | 291 } |
284 } | 292 } |
285 | 293 |
| 294 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 295 // setting new channel |
| 296 UpdateWritableState_w(); |
| 297 SetReadyToSend(false, transport_channel() && transport_channel()->writable()); |
| 298 SetReadyToSend( |
| 299 true, rtcp_transport_channel() && rtcp_transport_channel()->writable()); |
| 300 |
286 transport_name_ = transport_name; | 301 transport_name_ = transport_name; |
287 return true; | 302 return true; |
288 } | 303 } |
289 | 304 |
290 void BaseChannel::set_transport_channel(TransportChannel* new_tc) { | 305 void BaseChannel::set_transport_channel(TransportChannel* new_tc, |
| 306 bool update_writablity) { |
291 ASSERT(worker_thread_ == rtc::Thread::Current()); | 307 ASSERT(worker_thread_ == rtc::Thread::Current()); |
292 | 308 |
293 TransportChannel* old_tc = transport_channel_; | 309 TransportChannel* old_tc = transport_channel_; |
294 if (!old_tc && !new_tc) { | 310 if (!old_tc && !new_tc) { |
295 // Nothing to do | 311 // Nothing to do |
296 return; | 312 return; |
297 } | 313 } |
298 ASSERT(old_tc != new_tc); | 314 ASSERT(old_tc != new_tc); |
299 | 315 |
300 if (old_tc) { | 316 if (old_tc) { |
301 DisconnectFromTransportChannel(old_tc); | 317 DisconnectFromTransportChannel(old_tc); |
302 transport_controller_->DestroyTransportChannel_w( | 318 transport_controller_->DestroyTransportChannel_w( |
303 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 319 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
304 } | 320 } |
305 | 321 |
306 transport_channel_ = new_tc; | 322 transport_channel_ = new_tc; |
307 | 323 |
308 if (new_tc) { | 324 if (new_tc) { |
309 ConnectToTransportChannel(new_tc); | 325 ConnectToTransportChannel(new_tc); |
310 for (const auto& pair : socket_options_) { | 326 for (const auto& pair : socket_options_) { |
311 new_tc->SetOption(pair.first, pair.second); | 327 new_tc->SetOption(pair.first, pair.second); |
312 } | 328 } |
313 } | 329 } |
314 | 330 |
315 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 331 if (update_writablity) { |
316 // setting new channel | 332 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
317 UpdateWritableState_w(); | 333 // setting new channel |
318 SetReadyToSend(false, new_tc && new_tc->writable()); | 334 UpdateWritableState_w(); |
| 335 SetReadyToSend(false, new_tc && new_tc->writable()); |
| 336 } |
319 } | 337 } |
320 | 338 |
321 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) { | 339 void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc, |
| 340 bool update_writablity) { |
322 ASSERT(worker_thread_ == rtc::Thread::Current()); | 341 ASSERT(worker_thread_ == rtc::Thread::Current()); |
323 | 342 |
324 TransportChannel* old_tc = rtcp_transport_channel_; | 343 TransportChannel* old_tc = rtcp_transport_channel_; |
325 if (!old_tc && !new_tc) { | 344 if (!old_tc && !new_tc) { |
326 // Nothing to do | 345 // Nothing to do |
327 return; | 346 return; |
328 } | 347 } |
329 ASSERT(old_tc != new_tc); | 348 ASSERT(old_tc != new_tc); |
330 | 349 |
331 if (old_tc) { | 350 if (old_tc) { |
332 DisconnectFromTransportChannel(old_tc); | 351 DisconnectFromTransportChannel(old_tc); |
333 transport_controller_->DestroyTransportChannel_w( | 352 transport_controller_->DestroyTransportChannel_w( |
334 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 353 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); |
335 } | 354 } |
336 | 355 |
337 rtcp_transport_channel_ = new_tc; | 356 rtcp_transport_channel_ = new_tc; |
338 | 357 |
339 if (new_tc) { | 358 if (new_tc) { |
340 RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) | 359 RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive())) |
341 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 360 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
342 << "should never happen."; | 361 << "should never happen."; |
343 ConnectToTransportChannel(new_tc); | 362 ConnectToTransportChannel(new_tc); |
344 for (const auto& pair : rtcp_socket_options_) { | 363 for (const auto& pair : rtcp_socket_options_) { |
345 new_tc->SetOption(pair.first, pair.second); | 364 new_tc->SetOption(pair.first, pair.second); |
346 } | 365 } |
347 } | 366 } |
348 | 367 |
349 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 368 if (update_writablity) { |
350 // setting new channel | 369 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
351 UpdateWritableState_w(); | 370 // setting new channel |
352 SetReadyToSend(true, new_tc && new_tc->writable()); | 371 UpdateWritableState_w(); |
| 372 SetReadyToSend(true, new_tc && new_tc->writable()); |
| 373 } |
353 } | 374 } |
354 | 375 |
355 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 376 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
356 ASSERT(worker_thread_ == rtc::Thread::Current()); | 377 ASSERT(worker_thread_ == rtc::Thread::Current()); |
357 | 378 |
358 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 379 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
359 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 380 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
360 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 381 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
361 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 382 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
362 } | 383 } |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 } | 1084 } |
1064 | 1085 |
1065 void BaseChannel::ActivateRtcpMux() { | 1086 void BaseChannel::ActivateRtcpMux() { |
1066 worker_thread_->Invoke<void>(Bind( | 1087 worker_thread_->Invoke<void>(Bind( |
1067 &BaseChannel::ActivateRtcpMux_w, this)); | 1088 &BaseChannel::ActivateRtcpMux_w, this)); |
1068 } | 1089 } |
1069 | 1090 |
1070 void BaseChannel::ActivateRtcpMux_w() { | 1091 void BaseChannel::ActivateRtcpMux_w() { |
1071 if (!rtcp_mux_filter_.IsActive()) { | 1092 if (!rtcp_mux_filter_.IsActive()) { |
1072 rtcp_mux_filter_.SetActive(); | 1093 rtcp_mux_filter_.SetActive(); |
1073 set_rtcp_transport_channel(nullptr); | 1094 set_rtcp_transport_channel(nullptr, true); |
1074 rtcp_transport_enabled_ = false; | 1095 rtcp_transport_enabled_ = false; |
1075 } | 1096 } |
1076 } | 1097 } |
1077 | 1098 |
1078 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, | 1099 bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action, |
1079 ContentSource src, | 1100 ContentSource src, |
1080 std::string* error_desc) { | 1101 std::string* error_desc) { |
1081 bool ret = false; | 1102 bool ret = false; |
1082 switch (action) { | 1103 switch (action) { |
1083 case CA_OFFER: | 1104 case CA_OFFER: |
1084 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1105 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1085 break; | 1106 break; |
1086 case CA_PRANSWER: | 1107 case CA_PRANSWER: |
1087 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1108 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1088 break; | 1109 break; |
1089 case CA_ANSWER: | 1110 case CA_ANSWER: |
1090 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1111 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1091 if (ret && rtcp_mux_filter_.IsActive()) { | 1112 if (ret && rtcp_mux_filter_.IsActive()) { |
1092 // We activated RTCP mux, close down the RTCP transport. | 1113 // We activated RTCP mux, close down the RTCP transport. |
1093 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1114 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
1094 << " by destroying RTCP transport channel for " | 1115 << " by destroying RTCP transport channel for " |
1095 << transport_name(); | 1116 << transport_name(); |
1096 set_rtcp_transport_channel(nullptr); | 1117 set_rtcp_transport_channel(nullptr, true); |
1097 rtcp_transport_enabled_ = false; | 1118 rtcp_transport_enabled_ = false; |
1098 } | 1119 } |
1099 break; | 1120 break; |
1100 case CA_UPDATE: | 1121 case CA_UPDATE: |
1101 // No RTCP mux info. | 1122 // No RTCP mux info. |
1102 ret = true; | 1123 ret = true; |
1103 break; | 1124 break; |
1104 default: | 1125 default: |
1105 break; | 1126 break; |
1106 } | 1127 } |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2333 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); | 2354 return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp(); |
2334 } | 2355 } |
2335 | 2356 |
2336 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2357 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2337 rtc::TypedMessageData<uint32_t>* message = | 2358 rtc::TypedMessageData<uint32_t>* message = |
2338 new rtc::TypedMessageData<uint32_t>(sid); | 2359 new rtc::TypedMessageData<uint32_t>(sid); |
2339 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); | 2360 signaling_thread()->Post(this, MSG_STREAMCLOSEDREMOTELY, message); |
2340 } | 2361 } |
2341 | 2362 |
2342 } // namespace cricket | 2363 } // namespace cricket |
OLD | NEW |