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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // DTLS-SRTP when |writable_| becomes true again. | 293 // DTLS-SRTP when |writable_| becomes true again. |
294 writable_ = false; | 294 writable_ = false; |
295 srtp_filter_.ResetParams(); | 295 srtp_filter_.ResetParams(); |
296 } | 296 } |
297 | 297 |
298 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, | 298 // If this BaseChannel uses RTCP and we haven't fully negotiated RTCP mux, |
299 // we need an RTCP channel. | 299 // we need an RTCP channel. |
300 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) { | 300 if (rtcp_enabled_ && !rtcp_mux_filter_.IsFullyActive()) { |
301 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() | 301 LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name() |
302 << " on " << transport_name << " transport "; | 302 << " on " << transport_name << " transport "; |
303 // TODO(deadbeef): Remove this grossness when we remove non-muxed RTCP. | 303 SetTransportChannel_n( |
304 SetRtcpTransportChannel_n( | 304 true, transport_controller_->CreateTransportChannel_n( |
305 transport_controller_->CreateTransportChannel_n( | 305 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP)); |
306 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP), | |
307 false /* update_writablity */); | |
308 if (!rtcp_transport_channel_) { | 306 if (!rtcp_transport_channel_) { |
309 return false; | 307 return false; |
310 } | 308 } |
311 } | 309 } |
312 | 310 |
313 // We're not updating the writablity during the transition state. | 311 LOG(LS_INFO) << "Create non-RTCP TransportChannel for " << content_name() |
314 SetTransportChannel_n(transport_controller_->CreateTransportChannel_n( | 312 << " on " << transport_name << " transport "; |
315 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 313 SetTransportChannel_n( |
| 314 false, transport_controller_->CreateTransportChannel_n( |
| 315 transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
316 if (!transport_channel_) { | 316 if (!transport_channel_) { |
317 return false; | 317 return false; |
318 } | 318 } |
319 | 319 |
320 // TODO(deadbeef): Remove this grossness when we remove non-muxed RTCP. | |
321 if (rtcp_transport_channel_) { | |
322 // We can only update the RTCP ready to send after set_transport_channel has | |
323 // handled channel writability. | |
324 SetTransportChannelReadyToSend(true, rtcp_transport_channel_->writable()); | |
325 } | |
326 transport_name_ = transport_name; | 320 transport_name_ = transport_name; |
327 return true; | |
328 } | |
329 | |
330 void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) { | |
331 RTC_DCHECK(network_thread_->IsCurrent()); | |
332 | |
333 TransportChannel* old_tc = transport_channel_; | |
334 if (!old_tc && !new_tc) { | |
335 // Nothing to do. | |
336 return; | |
337 } | |
338 RTC_DCHECK(old_tc != new_tc); | |
339 | |
340 if (old_tc) { | |
341 DisconnectFromTransportChannel(old_tc); | |
342 transport_controller_->DestroyTransportChannel_n( | |
343 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP); | |
344 } | |
345 | |
346 transport_channel_ = new_tc; | |
347 | |
348 if (new_tc) { | |
349 ConnectToTransportChannel(new_tc); | |
350 for (const auto& pair : socket_options_) { | |
351 new_tc->SetOption(pair.first, pair.second); | |
352 } | |
353 } | |
354 | 321 |
355 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 322 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
356 // setting new transport channels. | 323 // setting new transport channels. |
357 UpdateWritableState_n(); | 324 UpdateWritableState_n(); |
| 325 // We can only update ready-to-send after updating writability. |
| 326 // |
358 // On setting a new channel, assume it's ready to send if it's writable, | 327 // On setting a new channel, assume it's ready to send if it's writable, |
359 // because we have no way of knowing otherwise (the channel doesn't give us | 328 // because we have no way of knowing otherwise (the channel doesn't give us |
360 // "was last send successful?"). | 329 // "was last send successful?"). |
361 // | 330 // |
362 // This won't always be accurate (the last SendPacket call from another | 331 // This won't always be accurate (the last SendPacket call from another |
363 // BaseChannel could have resulted in an error), but even so, we'll just | 332 // BaseChannel could have resulted in an error), but even so, we'll just |
364 // encounter the error again and update "ready to send" accordingly. | 333 // encounter the error again and update "ready to send" accordingly. |
365 SetTransportChannelReadyToSend(false, new_tc && new_tc->writable()); | 334 SetTransportChannelReadyToSend( |
| 335 false, transport_channel_ && transport_channel_->writable()); |
| 336 SetTransportChannelReadyToSend( |
| 337 true, rtcp_transport_channel_ && rtcp_transport_channel_->writable()); |
| 338 return true; |
366 } | 339 } |
367 | 340 |
368 void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc, | 341 void BaseChannel::SetTransportChannel_n(bool rtcp, |
369 bool update_writablity) { | 342 TransportChannel* new_channel) { |
370 RTC_DCHECK(network_thread_->IsCurrent()); | 343 RTC_DCHECK(network_thread_->IsCurrent()); |
| 344 TransportChannel*& old_channel = |
| 345 rtcp ? rtcp_transport_channel_ : transport_channel_; |
371 | 346 |
372 TransportChannel* old_tc = rtcp_transport_channel_; | 347 if (!old_channel && !new_channel) { |
373 if (!old_tc && !new_tc) { | |
374 // Nothing to do. | 348 // Nothing to do. |
375 return; | 349 return; |
376 } | 350 } |
377 RTC_DCHECK(old_tc != new_tc); | 351 RTC_DCHECK(old_channel != new_channel); |
378 | 352 |
379 if (old_tc) { | 353 if (old_channel) { |
380 DisconnectFromTransportChannel(old_tc); | 354 DisconnectFromTransportChannel(old_channel); |
381 transport_controller_->DestroyTransportChannel_n( | 355 transport_controller_->DestroyTransportChannel_n( |
382 transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP); | 356 transport_name_, rtcp ? cricket::ICE_CANDIDATE_COMPONENT_RTCP |
| 357 : cricket::ICE_CANDIDATE_COMPONENT_RTP); |
383 } | 358 } |
384 | 359 |
385 rtcp_transport_channel_ = new_tc; | 360 old_channel = new_channel; |
386 | 361 |
387 if (new_tc) { | 362 if (new_channel) { |
388 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 363 if (rtcp) { |
389 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 364 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) |
390 << "should never happen."; | 365 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
391 ConnectToTransportChannel(new_tc); | 366 << "should never happen."; |
392 for (const auto& pair : rtcp_socket_options_) { | |
393 new_tc->SetOption(pair.first, pair.second); | |
394 } | 367 } |
395 } | 368 ConnectToTransportChannel(new_channel); |
396 | 369 auto& socket_options = rtcp ? rtcp_socket_options_ : socket_options_; |
397 if (update_writablity) { | 370 for (const auto& pair : socket_options) { |
398 // Update aggregate writable/ready-to-send state between RTP and RTCP upon | 371 new_channel->SetOption(pair.first, pair.second); |
399 // setting new channel | 372 } |
400 UpdateWritableState_n(); | |
401 // On setting a new channel, assume it's ready to send if it's writable, | |
402 // because we have no way of knowing otherwise (the channel doesn't give us | |
403 // "was last send successful?"). | |
404 // | |
405 // This won't always be accurate (the last SendPacket call from another | |
406 // BaseChannel could have resulted in an error), but even so, we'll just | |
407 // encounter the error again and update "ready to send" accordingly. | |
408 SetTransportChannelReadyToSend(true, new_tc && new_tc->writable()); | |
409 } | 373 } |
410 } | 374 } |
411 | 375 |
412 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { | 376 void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) { |
413 RTC_DCHECK(network_thread_->IsCurrent()); | 377 RTC_DCHECK(network_thread_->IsCurrent()); |
414 | 378 |
415 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 379 tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
416 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); | 380 tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead); |
417 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); | 381 tc->SignalReadyToSend.connect(this, &BaseChannel::OnReadyToSend); |
418 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 382 tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 } | 1169 } |
1206 | 1170 |
1207 void BaseChannel::ActivateRtcpMux() { | 1171 void BaseChannel::ActivateRtcpMux() { |
1208 network_thread_->Invoke<void>(RTC_FROM_HERE, | 1172 network_thread_->Invoke<void>(RTC_FROM_HERE, |
1209 Bind(&BaseChannel::ActivateRtcpMux_n, this)); | 1173 Bind(&BaseChannel::ActivateRtcpMux_n, this)); |
1210 } | 1174 } |
1211 | 1175 |
1212 void BaseChannel::ActivateRtcpMux_n() { | 1176 void BaseChannel::ActivateRtcpMux_n() { |
1213 if (!rtcp_mux_filter_.IsActive()) { | 1177 if (!rtcp_mux_filter_.IsActive()) { |
1214 rtcp_mux_filter_.SetActive(); | 1178 rtcp_mux_filter_.SetActive(); |
1215 SetRtcpTransportChannel_n(nullptr, true); | 1179 SetTransportChannel_n(true, nullptr); |
| 1180 // Update aggregate writable/ready-to-send state between RTP and RTCP upon |
| 1181 // removing channel. |
| 1182 UpdateWritableState_n(); |
| 1183 SetTransportChannelReadyToSend(true, false); |
1216 } | 1184 } |
1217 } | 1185 } |
1218 | 1186 |
1219 bool BaseChannel::SetRtcpMux_n(bool enable, | 1187 bool BaseChannel::SetRtcpMux_n(bool enable, |
1220 ContentAction action, | 1188 ContentAction action, |
1221 ContentSource src, | 1189 ContentSource src, |
1222 std::string* error_desc) { | 1190 std::string* error_desc) { |
1223 bool ret = false; | 1191 bool ret = false; |
1224 switch (action) { | 1192 switch (action) { |
1225 case CA_OFFER: | 1193 case CA_OFFER: |
1226 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1194 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1227 break; | 1195 break; |
1228 case CA_PRANSWER: | 1196 case CA_PRANSWER: |
1229 // This may activate RTCP muxing, but we don't yet destroy the channel | 1197 // This may activate RTCP muxing, but we don't yet destroy the channel |
1230 // because the final answer may deactivate it. | 1198 // because the final answer may deactivate it. |
1231 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1199 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1232 break; | 1200 break; |
1233 case CA_ANSWER: | 1201 case CA_ANSWER: |
1234 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1202 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1235 if (ret && rtcp_mux_filter_.IsActive()) { | 1203 if (ret && rtcp_mux_filter_.IsActive()) { |
1236 // We activated RTCP mux, close down the RTCP transport. | 1204 // We activated RTCP mux, close down the RTCP transport. |
1237 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1205 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
1238 << " by destroying RTCP transport channel for " | 1206 << " by destroying RTCP transport channel for " |
1239 << transport_name(); | 1207 << transport_name(); |
1240 SetRtcpTransportChannel_n(nullptr, true); | 1208 SetTransportChannel_n(true, nullptr); |
| 1209 UpdateWritableState_n(); |
| 1210 SetTransportChannelReadyToSend(true, false); |
1241 } | 1211 } |
1242 break; | 1212 break; |
1243 case CA_UPDATE: | 1213 case CA_UPDATE: |
1244 // No RTCP mux info. | 1214 // No RTCP mux info. |
1245 ret = true; | 1215 ret = true; |
1246 break; | 1216 break; |
1247 default: | 1217 default: |
1248 break; | 1218 break; |
1249 } | 1219 } |
1250 if (!ret) { | 1220 if (!ret) { |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 } | 2410 } |
2441 | 2411 |
2442 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { | 2412 void DataChannel::OnStreamClosedRemotely(uint32_t sid) { |
2443 rtc::TypedMessageData<uint32_t>* message = | 2413 rtc::TypedMessageData<uint32_t>* message = |
2444 new rtc::TypedMessageData<uint32_t>(sid); | 2414 new rtc::TypedMessageData<uint32_t>(sid); |
2445 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, | 2415 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_STREAMCLOSEDREMOTELY, |
2446 message); | 2416 message); |
2447 } | 2417 } |
2448 | 2418 |
2449 } // namespace cricket | 2419 } // namespace cricket |
OLD | NEW |