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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 rtc::Thread* network_thread, | 160 rtc::Thread* network_thread, |
161 rtc::Thread* signaling_thread, | 161 rtc::Thread* signaling_thread, |
162 MediaChannel* media_channel, | 162 MediaChannel* media_channel, |
163 const std::string& content_name, | 163 const std::string& content_name, |
164 bool rtcp_mux_required, | 164 bool rtcp_mux_required, |
165 bool srtp_required) | 165 bool srtp_required) |
166 : worker_thread_(worker_thread), | 166 : worker_thread_(worker_thread), |
167 network_thread_(network_thread), | 167 network_thread_(network_thread), |
168 signaling_thread_(signaling_thread), | 168 signaling_thread_(signaling_thread), |
169 content_name_(content_name), | 169 content_name_(content_name), |
170 rtcp_mux_required_(rtcp_mux_required), | 170 rtp_transport_(rtcp_mux_required), |
171 srtp_required_(srtp_required), | 171 srtp_required_(srtp_required), |
172 media_channel_(media_channel), | 172 media_channel_(media_channel), |
173 selected_candidate_pair_(nullptr) { | 173 selected_candidate_pair_(nullptr) { |
174 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 174 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
175 #if defined(ENABLE_EXTERNAL_AUTH) | 175 #if defined(ENABLE_EXTERNAL_AUTH) |
176 srtp_filter_.EnableExternalAuth(); | 176 srtp_filter_.EnableExternalAuth(); |
177 #endif | 177 #endif |
178 LOG(LS_INFO) << "Created channel for " << content_name; | 178 LOG(LS_INFO) << "Created channel for " << content_name; |
179 } | 179 } |
180 | 180 |
(...skipping 13 matching lines...) Expand all Loading... |
194 } | 194 } |
195 | 195 |
196 void BaseChannel::DisconnectTransportChannels_n() { | 196 void BaseChannel::DisconnectTransportChannels_n() { |
197 // Send any outstanding RTCP packets. | 197 // Send any outstanding RTCP packets. |
198 FlushRtcpMessages_n(); | 198 FlushRtcpMessages_n(); |
199 | 199 |
200 // Stop signals from transport channels, but keep them alive because | 200 // Stop signals from transport channels, but keep them alive because |
201 // media_channel may use them from a different thread. | 201 // media_channel may use them from a different thread. |
202 if (rtp_dtls_transport_) { | 202 if (rtp_dtls_transport_) { |
203 DisconnectFromDtlsTransport(rtp_dtls_transport_); | 203 DisconnectFromDtlsTransport(rtp_dtls_transport_); |
204 } else if (rtp_packet_transport_) { | 204 } else if (rtp_transport_.rtp_packet_transport()) { |
205 DisconnectFromPacketTransport(rtp_packet_transport_); | 205 DisconnectFromPacketTransport(rtp_transport_.rtp_packet_transport()); |
206 } | 206 } |
207 if (rtcp_dtls_transport_) { | 207 if (rtcp_dtls_transport_) { |
208 DisconnectFromDtlsTransport(rtcp_dtls_transport_); | 208 DisconnectFromDtlsTransport(rtcp_dtls_transport_); |
209 } else if (rtcp_packet_transport_) { | 209 } else if (rtp_transport_.rtcp_packet_transport()) { |
210 DisconnectFromPacketTransport(rtcp_packet_transport_); | 210 DisconnectFromPacketTransport(rtp_transport_.rtcp_packet_transport()); |
211 } | 211 } |
212 | 212 |
213 // Clear pending read packets/messages. | 213 // Clear pending read packets/messages. |
214 network_thread_->Clear(&invoker_); | 214 network_thread_->Clear(&invoker_); |
215 network_thread_->Clear(this); | 215 network_thread_->Clear(this); |
216 } | 216 } |
217 | 217 |
218 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 218 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, |
219 DtlsTransportInternal* rtcp_dtls_transport, | 219 DtlsTransportInternal* rtcp_dtls_transport, |
220 rtc::PacketTransportInternal* rtp_packet_transport, | 220 rtc::PacketTransportInternal* rtp_packet_transport, |
(...skipping 21 matching lines...) Expand all Loading... |
242 rtcp_packet_transport); | 242 rtcp_packet_transport); |
243 | 243 |
244 if (rtp_dtls_transport_ && | 244 if (rtp_dtls_transport_ && |
245 !SetDtlsSrtpCryptoSuites_n(rtp_dtls_transport_, false)) { | 245 !SetDtlsSrtpCryptoSuites_n(rtp_dtls_transport_, false)) { |
246 return false; | 246 return false; |
247 } | 247 } |
248 if (rtcp_dtls_transport_ && | 248 if (rtcp_dtls_transport_ && |
249 !SetDtlsSrtpCryptoSuites_n(rtcp_dtls_transport_, true)) { | 249 !SetDtlsSrtpCryptoSuites_n(rtcp_dtls_transport_, true)) { |
250 return false; | 250 return false; |
251 } | 251 } |
252 if (rtcp_mux_required_) { | 252 if (rtp_transport_.rtcp_mux_required()) { |
253 rtcp_mux_filter_.SetActive(); | 253 rtcp_mux_filter_.SetActive(); |
254 } | 254 } |
255 return true; | 255 return true; |
256 } | 256 } |
257 | 257 |
258 void BaseChannel::Deinit() { | 258 void BaseChannel::Deinit() { |
259 RTC_DCHECK(worker_thread_->IsCurrent()); | 259 RTC_DCHECK(worker_thread_->IsCurrent()); |
260 media_channel_->SetInterface(NULL); | 260 media_channel_->SetInterface(NULL); |
261 // Packets arrive on the network thread, processing packets calls virtual | 261 // Packets arrive on the network thread, processing packets calls virtual |
262 // functions, so need to stop this process in Deinit that is called in | 262 // functions, so need to stop this process in Deinit that is called in |
(...skipping 25 matching lines...) Expand all Loading... |
288 rtc::PacketTransportInternal* rtcp_packet_transport) { | 288 rtc::PacketTransportInternal* rtcp_packet_transport) { |
289 RTC_DCHECK(network_thread_->IsCurrent()); | 289 RTC_DCHECK(network_thread_->IsCurrent()); |
290 // Validate some assertions about the input. | 290 // Validate some assertions about the input. |
291 RTC_DCHECK(rtp_packet_transport); | 291 RTC_DCHECK(rtp_packet_transport); |
292 RTC_DCHECK_EQ(NeedsRtcpTransport(), rtcp_packet_transport != nullptr); | 292 RTC_DCHECK_EQ(NeedsRtcpTransport(), rtcp_packet_transport != nullptr); |
293 if (rtp_dtls_transport || rtcp_dtls_transport) { | 293 if (rtp_dtls_transport || rtcp_dtls_transport) { |
294 // DTLS/non-DTLS pointers should be to the same object. | 294 // DTLS/non-DTLS pointers should be to the same object. |
295 RTC_DCHECK(rtp_dtls_transport == rtp_packet_transport); | 295 RTC_DCHECK(rtp_dtls_transport == rtp_packet_transport); |
296 RTC_DCHECK(rtcp_dtls_transport == rtcp_packet_transport); | 296 RTC_DCHECK(rtcp_dtls_transport == rtcp_packet_transport); |
297 // Can't go from non-DTLS to DTLS. | 297 // Can't go from non-DTLS to DTLS. |
298 RTC_DCHECK(!rtp_packet_transport_ || rtp_dtls_transport_); | 298 RTC_DCHECK(!rtp_transport_.rtp_packet_transport() || rtp_dtls_transport_); |
299 } else { | 299 } else { |
300 // Can't go from DTLS to non-DTLS. | 300 // Can't go from DTLS to non-DTLS. |
301 RTC_DCHECK(!rtp_dtls_transport_); | 301 RTC_DCHECK(!rtp_dtls_transport_); |
302 } | 302 } |
303 // Transport names should be the same. | 303 // Transport names should be the same. |
304 if (rtp_dtls_transport && rtcp_dtls_transport) { | 304 if (rtp_dtls_transport && rtcp_dtls_transport) { |
305 RTC_DCHECK(rtp_dtls_transport->transport_name() == | 305 RTC_DCHECK(rtp_dtls_transport->transport_name() == |
306 rtcp_dtls_transport->transport_name()); | 306 rtcp_dtls_transport->transport_name()); |
307 } | 307 } |
308 std::string debug_name; | 308 std::string debug_name; |
309 if (rtp_dtls_transport) { | 309 if (rtp_dtls_transport) { |
310 transport_name_ = rtp_dtls_transport->transport_name(); | 310 transport_name_ = rtp_dtls_transport->transport_name(); |
311 debug_name = transport_name_; | 311 debug_name = transport_name_; |
312 } else { | 312 } else { |
313 debug_name = rtp_packet_transport->debug_name(); | 313 debug_name = rtp_packet_transport->debug_name(); |
314 } | 314 } |
315 if (rtp_packet_transport == rtp_packet_transport_) { | 315 if (rtp_packet_transport == rtp_transport_.rtp_packet_transport()) { |
316 // Nothing to do if transport isn't changing. | 316 // Nothing to do if transport isn't changing. |
317 return; | 317 return; |
318 } | 318 } |
319 | 319 |
320 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport | 320 // When using DTLS-SRTP, we must reset the SrtpFilter every time the transport |
321 // changes and wait until the DTLS handshake is complete to set the newly | 321 // changes and wait until the DTLS handshake is complete to set the newly |
322 // negotiated parameters. | 322 // negotiated parameters. |
323 if (ShouldSetupDtlsSrtp_n()) { | 323 if (ShouldSetupDtlsSrtp_n()) { |
324 // Set |writable_| to false such that UpdateWritableState_w can set up | 324 // Set |writable_| to false such that UpdateWritableState_w can set up |
325 // DTLS-SRTP when |writable_| becomes true again. | 325 // DTLS-SRTP when |writable_| becomes true again. |
(...skipping 19 matching lines...) Expand all Loading... |
345 // We can only update ready-to-send after updating writability. | 345 // We can only update ready-to-send after updating writability. |
346 // | 346 // |
347 // On setting a new channel, assume it's ready to send if it's writable, | 347 // On setting a new channel, assume it's ready to send if it's writable, |
348 // because we have no way of knowing otherwise (the channel doesn't give us | 348 // because we have no way of knowing otherwise (the channel doesn't give us |
349 // "was last send successful?"). | 349 // "was last send successful?"). |
350 // | 350 // |
351 // This won't always be accurate (the last SendPacket call from another | 351 // This won't always be accurate (the last SendPacket call from another |
352 // BaseChannel could have resulted in an error), but even so, we'll just | 352 // BaseChannel could have resulted in an error), but even so, we'll just |
353 // encounter the error again and update "ready to send" accordingly. | 353 // encounter the error again and update "ready to send" accordingly. |
354 SetTransportChannelReadyToSend( | 354 SetTransportChannelReadyToSend( |
355 false, rtp_packet_transport_ && rtp_packet_transport_->writable()); | 355 false, rtp_packet_transport && rtp_packet_transport->writable()); |
356 SetTransportChannelReadyToSend( | 356 SetTransportChannelReadyToSend( |
357 true, rtcp_packet_transport_ && rtcp_packet_transport_->writable()); | 357 true, rtcp_packet_transport && rtcp_packet_transport->writable()); |
358 } | 358 } |
359 | 359 |
360 void BaseChannel::SetTransport_n( | 360 void BaseChannel::SetTransport_n( |
361 bool rtcp, | 361 bool rtcp, |
362 DtlsTransportInternal* new_dtls_transport, | 362 DtlsTransportInternal* new_dtls_transport, |
363 rtc::PacketTransportInternal* new_packet_transport) { | 363 rtc::PacketTransportInternal* new_packet_transport) { |
364 RTC_DCHECK(network_thread_->IsCurrent()); | 364 RTC_DCHECK(network_thread_->IsCurrent()); |
365 DtlsTransportInternal*& old_dtls_transport = | 365 DtlsTransportInternal*& old_dtls_transport = |
366 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; | 366 rtcp ? rtcp_dtls_transport_ : rtp_dtls_transport_; |
367 rtc::PacketTransportInternal*& old_packet_transport = | 367 rtc::PacketTransportInternal* old_packet_transport = |
368 rtcp ? rtcp_packet_transport_ : rtp_packet_transport_; | 368 rtcp ? rtp_transport_.rtcp_packet_transport() |
| 369 : rtp_transport_.rtp_packet_transport(); |
369 | 370 |
370 if (!old_packet_transport && !new_packet_transport) { | 371 if (!old_packet_transport && !new_packet_transport) { |
371 // Nothing to do. | 372 // Nothing to do. |
372 return; | 373 return; |
373 } | 374 } |
374 | 375 |
375 RTC_DCHECK(old_packet_transport != new_packet_transport); | 376 RTC_DCHECK(old_packet_transport != new_packet_transport); |
376 if (old_dtls_transport) { | 377 if (old_dtls_transport) { |
377 DisconnectFromDtlsTransport(old_dtls_transport); | 378 DisconnectFromDtlsTransport(old_dtls_transport); |
378 } else if (old_packet_transport) { | 379 } else if (old_packet_transport) { |
379 DisconnectFromPacketTransport(old_packet_transport); | 380 DisconnectFromPacketTransport(old_packet_transport); |
380 } | 381 } |
381 | 382 |
382 old_packet_transport = new_packet_transport; | 383 if (rtcp) { |
| 384 rtp_transport_.set_rtcp_packet_transport(new_packet_transport); |
| 385 } else { |
| 386 rtp_transport_.set_rtp_packet_transport(new_packet_transport); |
| 387 } |
383 old_dtls_transport = new_dtls_transport; | 388 old_dtls_transport = new_dtls_transport; |
384 | 389 |
385 // If there's no new transport, we're done after disconnecting from old one. | 390 // If there's no new transport, we're done after disconnecting from old one. |
386 if (!new_packet_transport) { | 391 if (!new_packet_transport) { |
387 return; | 392 return; |
388 } | 393 } |
389 | 394 |
390 if (rtcp && new_dtls_transport) { | 395 if (rtcp && new_dtls_transport) { |
391 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) | 396 RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive())) |
392 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " | 397 << "Setting RTCP for DTLS/SRTP after SrtpFilter is active " |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 RTC_DCHECK(network_thread_->IsCurrent()); | 522 RTC_DCHECK(network_thread_->IsCurrent()); |
518 if (!rtp_dtls_transport_) { | 523 if (!rtp_dtls_transport_) { |
519 return false; | 524 return false; |
520 } | 525 } |
521 return rtp_dtls_transport_->ice_transport()->GetStats(infos); | 526 return rtp_dtls_transport_->ice_transport()->GetStats(infos); |
522 } | 527 } |
523 | 528 |
524 bool BaseChannel::NeedsRtcpTransport() { | 529 bool BaseChannel::NeedsRtcpTransport() { |
525 // If this BaseChannel doesn't require RTCP mux and we haven't fully | 530 // If this BaseChannel doesn't require RTCP mux and we haven't fully |
526 // negotiated RTCP mux, we need an RTCP transport. | 531 // negotiated RTCP mux, we need an RTCP transport. |
527 return !rtcp_mux_required_ && !rtcp_mux_filter_.IsFullyActive(); | 532 return !rtp_transport_.rtcp_mux_required() && |
| 533 !rtcp_mux_filter_.IsFullyActive(); |
528 } | 534 } |
529 | 535 |
530 bool BaseChannel::IsReadyToReceiveMedia_w() const { | 536 bool BaseChannel::IsReadyToReceiveMedia_w() const { |
531 // Receive data if we are enabled and have local content, | 537 // Receive data if we are enabled and have local content, |
532 return enabled() && IsReceiveContentDirection(local_content_direction_); | 538 return enabled() && IsReceiveContentDirection(local_content_direction_); |
533 } | 539 } |
534 | 540 |
535 bool BaseChannel::IsReadyToSendMedia_w() const { | 541 bool BaseChannel::IsReadyToSendMedia_w() const { |
536 // Need to access some state updated on the network thread. | 542 // Need to access some state updated on the network thread. |
537 return network_thread_->Invoke<bool>( | 543 return network_thread_->Invoke<bool>( |
(...skipping 25 matching lines...) Expand all Loading... |
563 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); | 569 RTC_FROM_HERE, Bind(&BaseChannel::SetOption_n, this, type, opt, value)); |
564 } | 570 } |
565 | 571 |
566 int BaseChannel::SetOption_n(SocketType type, | 572 int BaseChannel::SetOption_n(SocketType type, |
567 rtc::Socket::Option opt, | 573 rtc::Socket::Option opt, |
568 int value) { | 574 int value) { |
569 RTC_DCHECK(network_thread_->IsCurrent()); | 575 RTC_DCHECK(network_thread_->IsCurrent()); |
570 rtc::PacketTransportInternal* transport = nullptr; | 576 rtc::PacketTransportInternal* transport = nullptr; |
571 switch (type) { | 577 switch (type) { |
572 case ST_RTP: | 578 case ST_RTP: |
573 transport = rtp_packet_transport_; | 579 transport = rtp_transport_.rtp_packet_transport(); |
574 socket_options_.push_back( | 580 socket_options_.push_back( |
575 std::pair<rtc::Socket::Option, int>(opt, value)); | 581 std::pair<rtc::Socket::Option, int>(opt, value)); |
576 break; | 582 break; |
577 case ST_RTCP: | 583 case ST_RTCP: |
578 transport = rtcp_packet_transport_; | 584 transport = rtp_transport_.rtcp_packet_transport(); |
579 rtcp_socket_options_.push_back( | 585 rtcp_socket_options_.push_back( |
580 std::pair<rtc::Socket::Option, int>(opt, value)); | 586 std::pair<rtc::Socket::Option, int>(opt, value)); |
581 break; | 587 break; |
582 } | 588 } |
583 return transport ? transport->SetOption(opt, value) : -1; | 589 return transport ? transport->SetOption(opt, value) : -1; |
584 } | 590 } |
585 | 591 |
586 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { | 592 bool BaseChannel::SetCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
587 crypto_options_ = crypto_options; | 593 crypto_options_ = crypto_options; |
588 return true; | 594 return true; |
589 } | 595 } |
590 | 596 |
591 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) { | 597 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) { |
592 RTC_DCHECK(transport == rtp_packet_transport_ || | 598 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || |
593 transport == rtcp_packet_transport_); | 599 transport == rtp_transport_.rtcp_packet_transport()); |
594 RTC_DCHECK(network_thread_->IsCurrent()); | 600 RTC_DCHECK(network_thread_->IsCurrent()); |
595 UpdateWritableState_n(); | 601 UpdateWritableState_n(); |
596 } | 602 } |
597 | 603 |
598 void BaseChannel::OnPacketRead(rtc::PacketTransportInternal* transport, | 604 void BaseChannel::OnPacketRead(rtc::PacketTransportInternal* transport, |
599 const char* data, | 605 const char* data, |
600 size_t len, | 606 size_t len, |
601 const rtc::PacketTime& packet_time, | 607 const rtc::PacketTime& packet_time, |
602 int flags) { | 608 int flags) { |
603 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); | 609 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); |
604 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine | 610 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine |
605 RTC_DCHECK(network_thread_->IsCurrent()); | 611 RTC_DCHECK(network_thread_->IsCurrent()); |
606 | 612 |
607 // When using RTCP multiplexing we might get RTCP packets on the RTP | 613 // When using RTCP multiplexing we might get RTCP packets on the RTP |
608 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | 614 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. |
609 bool rtcp = PacketIsRtcp(transport, data, len); | 615 bool rtcp = PacketIsRtcp(transport, data, len); |
610 rtc::CopyOnWriteBuffer packet(data, len); | 616 rtc::CopyOnWriteBuffer packet(data, len); |
611 HandlePacket(rtcp, &packet, packet_time); | 617 HandlePacket(rtcp, &packet, packet_time); |
612 } | 618 } |
613 | 619 |
614 void BaseChannel::OnReadyToSend(rtc::PacketTransportInternal* transport) { | 620 void BaseChannel::OnReadyToSend(rtc::PacketTransportInternal* transport) { |
615 RTC_DCHECK(transport == rtp_packet_transport_ || | 621 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || |
616 transport == rtcp_packet_transport_); | 622 transport == rtp_transport_.rtcp_packet_transport()); |
617 SetTransportChannelReadyToSend(transport == rtcp_packet_transport_, true); | 623 SetTransportChannelReadyToSend( |
| 624 transport == rtp_transport_.rtcp_packet_transport(), true); |
618 } | 625 } |
619 | 626 |
620 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, | 627 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, |
621 DtlsTransportState state) { | 628 DtlsTransportState state) { |
622 if (!ShouldSetupDtlsSrtp_n()) { | 629 if (!ShouldSetupDtlsSrtp_n()) { |
623 return; | 630 return; |
624 } | 631 } |
625 | 632 |
626 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 633 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
627 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 634 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 RTC_DCHECK(network_thread_->IsCurrent()); | 671 RTC_DCHECK(network_thread_->IsCurrent()); |
665 if (rtcp) { | 672 if (rtcp) { |
666 rtcp_ready_to_send_ = ready; | 673 rtcp_ready_to_send_ = ready; |
667 } else { | 674 } else { |
668 rtp_ready_to_send_ = ready; | 675 rtp_ready_to_send_ = ready; |
669 } | 676 } |
670 | 677 |
671 bool ready_to_send = | 678 bool ready_to_send = |
672 (rtp_ready_to_send_ && | 679 (rtp_ready_to_send_ && |
673 // In the case of rtcp mux |rtcp_packet_transport_| will be null. | 680 // In the case of rtcp mux |rtcp_packet_transport_| will be null. |
674 (rtcp_ready_to_send_ || !rtcp_packet_transport_)); | 681 (rtcp_ready_to_send_ || !rtp_transport_.rtcp_packet_transport())); |
675 | 682 |
676 invoker_.AsyncInvoke<void>( | 683 invoker_.AsyncInvoke<void>( |
677 RTC_FROM_HERE, worker_thread_, | 684 RTC_FROM_HERE, worker_thread_, |
678 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); | 685 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send)); |
679 } | 686 } |
680 | 687 |
681 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInternal* transport, | 688 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInternal* transport, |
682 const char* data, | 689 const char* data, |
683 size_t len) { | 690 size_t len) { |
684 return (transport == rtcp_packet_transport_ || | 691 return (transport == rtp_transport_.rtcp_packet_transport() || |
685 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | 692 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); |
686 } | 693 } |
687 | 694 |
688 bool BaseChannel::SendPacket(bool rtcp, | 695 bool BaseChannel::SendPacket(bool rtcp, |
689 rtc::CopyOnWriteBuffer* packet, | 696 rtc::CopyOnWriteBuffer* packet, |
690 const rtc::PacketOptions& options) { | 697 const rtc::PacketOptions& options) { |
691 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 698 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. |
692 // If the thread is not our network thread, we will post to our network | 699 // If the thread is not our network thread, we will post to our network |
693 // so that the real work happens on our network. This avoids us having to | 700 // so that the real work happens on our network. This avoids us having to |
694 // synchronize access to all the pieces of the send path, including | 701 // synchronize access to all the pieces of the send path, including |
695 // SRTP and the inner workings of the transport channels. | 702 // SRTP and the inner workings of the transport channels. |
696 // The only downside is that we can't return a proper failure code if | 703 // The only downside is that we can't return a proper failure code if |
697 // needed. Since UDP is unreliable anyway, this should be a non-issue. | 704 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
698 if (!network_thread_->IsCurrent()) { | 705 if (!network_thread_->IsCurrent()) { |
699 // Avoid a copy by transferring the ownership of the packet data. | 706 // Avoid a copy by transferring the ownership of the packet data. |
700 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; | 707 int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET; |
701 SendPacketMessageData* data = new SendPacketMessageData; | 708 SendPacketMessageData* data = new SendPacketMessageData; |
702 data->packet = std::move(*packet); | 709 data->packet = std::move(*packet); |
703 data->options = options; | 710 data->options = options; |
704 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); | 711 network_thread_->Post(RTC_FROM_HERE, this, message_id, data); |
705 return true; | 712 return true; |
706 } | 713 } |
707 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); | 714 TRACE_EVENT0("webrtc", "BaseChannel::SendPacket"); |
708 | 715 |
709 // Now that we are on the correct thread, ensure we have a place to send this | 716 // Now that we are on the correct thread, ensure we have a place to send this |
710 // packet before doing anything. (We might get RTCP packets that we don't | 717 // packet before doing anything. (We might get RTCP packets that we don't |
711 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 718 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
712 // transport. | 719 // transport. |
713 rtc::PacketTransportInternal* transport = | 720 rtc::PacketTransportInternal* transport = |
714 (!rtcp || rtcp_mux_filter_.IsActive()) ? rtp_packet_transport_ | 721 (!rtcp || rtcp_mux_filter_.IsActive()) |
715 : rtcp_packet_transport_; | 722 ? rtp_transport_.rtp_packet_transport() |
| 723 : rtp_transport_.rtcp_packet_transport(); |
716 if (!transport || !transport->writable()) { | 724 if (!transport || !transport->writable()) { |
717 return false; | 725 return false; |
718 } | 726 } |
719 | 727 |
720 // Protect ourselves against crazy data. | 728 // Protect ourselves against crazy data. |
721 if (!ValidPacket(rtcp, packet)) { | 729 if (!ValidPacket(rtcp, packet)) { |
722 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 730 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
723 << PacketType(rtcp) | 731 << PacketType(rtcp) |
724 << " packet: wrong size=" << packet->size(); | 732 << " packet: wrong size=" << packet->size(); |
725 return false; | 733 return false; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 967 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
960 if (!enabled_) | 968 if (!enabled_) |
961 return; | 969 return; |
962 | 970 |
963 LOG(LS_INFO) << "Channel disabled"; | 971 LOG(LS_INFO) << "Channel disabled"; |
964 enabled_ = false; | 972 enabled_ = false; |
965 UpdateMediaSendRecvState_w(); | 973 UpdateMediaSendRecvState_w(); |
966 } | 974 } |
967 | 975 |
968 void BaseChannel::UpdateWritableState_n() { | 976 void BaseChannel::UpdateWritableState_n() { |
969 if (rtp_packet_transport_ && rtp_packet_transport_->writable() && | 977 rtc::PacketTransportInternal* rtp_packet_transport = |
970 (!rtcp_packet_transport_ || rtcp_packet_transport_->writable())) { | 978 rtp_transport_.rtp_packet_transport(); |
| 979 rtc::PacketTransportInternal* rtcp_packet_transport = |
| 980 rtp_transport_.rtcp_packet_transport(); |
| 981 if (rtp_packet_transport && rtp_packet_transport->writable() && |
| 982 (!rtcp_packet_transport || rtcp_packet_transport->writable())) { |
971 ChannelWritable_n(); | 983 ChannelWritable_n(); |
972 } else { | 984 } else { |
973 ChannelNotWritable_n(); | 985 ChannelNotWritable_n(); |
974 } | 986 } |
975 } | 987 } |
976 | 988 |
977 void BaseChannel::ChannelWritable_n() { | 989 void BaseChannel::ChannelWritable_n() { |
978 RTC_DCHECK(network_thread_->IsCurrent()); | 990 RTC_DCHECK(network_thread_->IsCurrent()); |
979 if (writable_) { | 991 if (writable_) { |
980 return; | 992 return; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 } | 1251 } |
1240 return true; | 1252 return true; |
1241 } | 1253 } |
1242 | 1254 |
1243 bool BaseChannel::SetRtcpMux_n(bool enable, | 1255 bool BaseChannel::SetRtcpMux_n(bool enable, |
1244 ContentAction action, | 1256 ContentAction action, |
1245 ContentSource src, | 1257 ContentSource src, |
1246 std::string* error_desc) { | 1258 std::string* error_desc) { |
1247 // Provide a more specific error message for the RTCP mux "require" policy | 1259 // Provide a more specific error message for the RTCP mux "require" policy |
1248 // case. | 1260 // case. |
1249 if (rtcp_mux_required_ && !enable) { | 1261 if (rtp_transport_.rtcp_mux_required() && !enable) { |
1250 SafeSetError( | 1262 SafeSetError( |
1251 "rtcpMuxPolicy is 'require', but media description does not " | 1263 "rtcpMuxPolicy is 'require', but media description does not " |
1252 "contain 'a=rtcp-mux'.", | 1264 "contain 'a=rtcp-mux'.", |
1253 error_desc); | 1265 error_desc); |
1254 return false; | 1266 return false; |
1255 } | 1267 } |
1256 bool ret = false; | 1268 bool ret = false; |
1257 switch (action) { | 1269 switch (action) { |
1258 case CA_OFFER: | 1270 case CA_OFFER: |
1259 ret = rtcp_mux_filter_.SetOffer(enable, src); | 1271 ret = rtcp_mux_filter_.SetOffer(enable, src); |
1260 break; | 1272 break; |
1261 case CA_PRANSWER: | 1273 case CA_PRANSWER: |
1262 // This may activate RTCP muxing, but we don't yet destroy the transport | 1274 // This may activate RTCP muxing, but we don't yet destroy the transport |
1263 // because the final answer may deactivate it. | 1275 // because the final answer may deactivate it. |
1264 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); | 1276 ret = rtcp_mux_filter_.SetProvisionalAnswer(enable, src); |
1265 break; | 1277 break; |
1266 case CA_ANSWER: | 1278 case CA_ANSWER: |
1267 ret = rtcp_mux_filter_.SetAnswer(enable, src); | 1279 ret = rtcp_mux_filter_.SetAnswer(enable, src); |
1268 if (ret && rtcp_mux_filter_.IsActive()) { | 1280 if (ret && rtcp_mux_filter_.IsActive()) { |
1269 // We permanently activated RTCP muxing; signal that we no longer need | 1281 // We permanently activated RTCP muxing; signal that we no longer need |
1270 // the RTCP transport. | 1282 // the RTCP transport. |
1271 std::string debug_name = transport_name_.empty() | 1283 std::string debug_name = |
1272 ? rtp_packet_transport_->debug_name() | 1284 transport_name_.empty() |
1273 : transport_name_; | 1285 ? rtp_transport_.rtp_packet_transport()->debug_name() |
| 1286 : transport_name_; |
1274 ; | 1287 ; |
1275 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() | 1288 LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name() |
1276 << "; no longer need RTCP transport for " << debug_name; | 1289 << "; no longer need RTCP transport for " << debug_name; |
1277 if (rtcp_packet_transport_) { | 1290 if (rtp_transport_.rtcp_packet_transport()) { |
1278 SetTransport_n(true, nullptr, nullptr); | 1291 SetTransport_n(true, nullptr, nullptr); |
1279 SignalRtcpMuxFullyActive(transport_name_); | 1292 SignalRtcpMuxFullyActive(transport_name_); |
1280 } | 1293 } |
1281 UpdateWritableState_n(); | 1294 UpdateWritableState_n(); |
1282 SetTransportChannelReadyToSend(true, false); | 1295 SetTransportChannelReadyToSend(true, false); |
1283 } | 1296 } |
1284 break; | 1297 break; |
1285 case CA_UPDATE: | 1298 case CA_UPDATE: |
1286 // No RTCP mux info. | 1299 // No RTCP mux info. |
1287 ret = true; | 1300 ret = true; |
1288 break; | 1301 break; |
1289 default: | 1302 default: |
1290 break; | 1303 break; |
1291 } | 1304 } |
1292 if (!ret) { | 1305 if (!ret) { |
1293 SafeSetError("Failed to setup RTCP mux filter.", error_desc); | 1306 SafeSetError("Failed to setup RTCP mux filter.", error_desc); |
1294 return false; | 1307 return false; |
1295 } | 1308 } |
1296 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or | 1309 // |rtcp_mux_filter_| can be active if |action| is CA_PRANSWER or |
1297 // CA_ANSWER, but we only want to tear down the RTCP transport if we received | 1310 // CA_ANSWER, but we only want to tear down the RTCP transport if we received |
1298 // a final answer. | 1311 // a final answer. |
1299 if (rtcp_mux_filter_.IsActive()) { | 1312 if (rtcp_mux_filter_.IsActive()) { |
1300 // If the RTP transport is already writable, then so are we. | 1313 // If the RTP transport is already writable, then so are we. |
1301 if (rtp_packet_transport_->writable()) { | 1314 if (rtp_transport_.rtp_packet_transport()->writable()) { |
1302 ChannelWritable_n(); | 1315 ChannelWritable_n(); |
1303 } | 1316 } |
1304 } | 1317 } |
1305 | 1318 |
1306 return true; | 1319 return true; |
1307 } | 1320 } |
1308 | 1321 |
1309 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { | 1322 bool BaseChannel::AddRecvStream_w(const StreamParams& sp) { |
1310 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); | 1323 RTC_DCHECK(worker_thread() == rtc::Thread::Current()); |
1311 return media_channel()->AddRecvStream(sp); | 1324 return media_channel()->AddRecvStream(sp); |
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2465 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2478 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2466 new DataChannelReadyToSendMessageData(writable)); | 2479 new DataChannelReadyToSendMessageData(writable)); |
2467 } | 2480 } |
2468 | 2481 |
2469 void RtpDataChannel::GetSrtpCryptoSuites_n( | 2482 void RtpDataChannel::GetSrtpCryptoSuites_n( |
2470 std::vector<int>* crypto_suites) const { | 2483 std::vector<int>* crypto_suites) const { |
2471 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); | 2484 GetSupportedDataCryptoSuites(crypto_options(), crypto_suites); |
2472 } | 2485 } |
2473 | 2486 |
2474 } // namespace cricket | 2487 } // namespace cricket |
OLD | NEW |