Chromium Code Reviews| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 struct DataChannelErrorMessageData : public rtc::MessageData { | 100 struct DataChannelErrorMessageData : public rtc::MessageData { |
| 101 DataChannelErrorMessageData(uint32_t in_ssrc, | 101 DataChannelErrorMessageData(uint32_t in_ssrc, |
| 102 DataMediaChannel::Error in_error) | 102 DataMediaChannel::Error in_error) |
| 103 : ssrc(in_ssrc), error(in_error) {} | 103 : ssrc(in_ssrc), error(in_error) {} |
| 104 uint32_t ssrc; | 104 uint32_t ssrc; |
| 105 DataMediaChannel::Error error; | 105 DataMediaChannel::Error error; |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 static const char* PacketType(bool rtcp) { | |
| 109 return (!rtcp) ? "RTP" : "RTCP"; | |
| 110 } | |
| 111 | |
| 112 static bool ValidPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { | 108 static bool ValidPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { |
| 113 // Check the packet size. We could check the header too if needed. | 109 // Check the packet size. We could check the header too if needed. |
| 114 return (packet && | 110 return packet && IsValidRtpRtcpPacketSize(rtcp, packet->size()); |
| 115 packet->size() >= (!rtcp ? kMinRtpPacketLen : kMinRtcpPacketLen) && | |
| 116 packet->size() <= kMaxRtpPacketLen); | |
| 117 } | 111 } |
| 118 | 112 |
| 119 static bool IsReceiveContentDirection(MediaContentDirection direction) { | 113 static bool IsReceiveContentDirection(MediaContentDirection direction) { |
| 120 return direction == MD_SENDRECV || direction == MD_RECVONLY; | 114 return direction == MD_SENDRECV || direction == MD_RECVONLY; |
| 121 } | 115 } |
| 122 | 116 |
| 123 static bool IsSendContentDirection(MediaContentDirection direction) { | 117 static bool IsSendContentDirection(MediaContentDirection direction) { |
| 124 return direction == MD_SENDRECV || direction == MD_SENDONLY; | 118 return direction == MD_SENDRECV || direction == MD_SENDONLY; |
| 125 } | 119 } |
| 126 | 120 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 rtp_transport_(rtcp_mux_required), | 166 rtp_transport_(rtcp_mux_required), |
| 173 srtp_required_(srtp_required), | 167 srtp_required_(srtp_required), |
| 174 media_channel_(media_channel), | 168 media_channel_(media_channel), |
| 175 selected_candidate_pair_(nullptr) { | 169 selected_candidate_pair_(nullptr) { |
| 176 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 170 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 177 #if defined(ENABLE_EXTERNAL_AUTH) | 171 #if defined(ENABLE_EXTERNAL_AUTH) |
| 178 srtp_filter_.EnableExternalAuth(); | 172 srtp_filter_.EnableExternalAuth(); |
| 179 #endif | 173 #endif |
| 180 rtp_transport_.SignalReadyToSend.connect( | 174 rtp_transport_.SignalReadyToSend.connect( |
| 181 this, &BaseChannel::OnTransportReadyToSend); | 175 this, &BaseChannel::OnTransportReadyToSend); |
| 176 // TODO(zstein): RtpTransport::SignalPacketReceived will probably be replaced | |
| 177 // with a callback interface later so that the demuxer can select which | |
| 178 // channel to signal. | |
| 179 rtp_transport_.SignalPacketReceived.connect(this, | |
| 180 &BaseChannel::OnPacketReceived); | |
| 182 LOG(LS_INFO) << "Created channel for " << content_name; | 181 LOG(LS_INFO) << "Created channel for " << content_name; |
| 183 } | 182 } |
| 184 | 183 |
| 185 BaseChannel::~BaseChannel() { | 184 BaseChannel::~BaseChannel() { |
| 186 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 185 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
| 187 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 186 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
| 188 Deinit(); | 187 Deinit(); |
| 189 StopConnectionMonitor(); | 188 StopConnectionMonitor(); |
| 190 // Eats any outstanding messages or packets. | 189 // Eats any outstanding messages or packets. |
| 191 worker_thread_->Clear(&invoker_); | 190 worker_thread_->Clear(&invoker_); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 205 // media_channel may use them from a different thread. | 204 // media_channel may use them from a different thread. |
| 206 if (rtp_dtls_transport_) { | 205 if (rtp_dtls_transport_) { |
| 207 DisconnectFromDtlsTransport(rtp_dtls_transport_); | 206 DisconnectFromDtlsTransport(rtp_dtls_transport_); |
| 208 } else if (rtp_transport_.rtp_packet_transport()) { | 207 } else if (rtp_transport_.rtp_packet_transport()) { |
| 209 DisconnectFromPacketTransport(rtp_transport_.rtp_packet_transport()); | 208 DisconnectFromPacketTransport(rtp_transport_.rtp_packet_transport()); |
| 210 } | 209 } |
| 211 if (rtcp_dtls_transport_) { | 210 if (rtcp_dtls_transport_) { |
| 212 DisconnectFromDtlsTransport(rtcp_dtls_transport_); | 211 DisconnectFromDtlsTransport(rtcp_dtls_transport_); |
| 213 } else if (rtp_transport_.rtcp_packet_transport()) { | 212 } else if (rtp_transport_.rtcp_packet_transport()) { |
| 214 DisconnectFromPacketTransport(rtp_transport_.rtcp_packet_transport()); | 213 DisconnectFromPacketTransport(rtp_transport_.rtcp_packet_transport()); |
| 215 } | 214 } |
|
pthatcher1
2017/06/01 18:49:17
I think you need rtp_transport_->SetRtpPacketTrans
Zach Stein
2017/06/01 19:56:54
Done. Thanks for helping me track this down.
This
| |
| 216 | 215 |
| 217 // Clear pending read packets/messages. | 216 // Clear pending read packets/messages. |
| 218 network_thread_->Clear(&invoker_); | 217 network_thread_->Clear(&invoker_); |
| 219 network_thread_->Clear(this); | 218 network_thread_->Clear(this); |
| 220 } | 219 } |
| 221 | 220 |
| 222 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, | 221 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, |
| 223 DtlsTransportInternal* rtcp_dtls_transport, | 222 DtlsTransportInternal* rtcp_dtls_transport, |
| 224 rtc::PacketTransportInternal* rtp_packet_transport, | 223 rtc::PacketTransportInternal* rtp_packet_transport, |
| 225 rtc::PacketTransportInternal* rtcp_packet_transport) { | 224 rtc::PacketTransportInternal* rtcp_packet_transport) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 for (const auto& pair : socket_options) { | 389 for (const auto& pair : socket_options) { |
| 391 new_packet_transport->SetOption(pair.first, pair.second); | 390 new_packet_transport->SetOption(pair.first, pair.second); |
| 392 } | 391 } |
| 393 } | 392 } |
| 394 | 393 |
| 395 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) { | 394 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) { |
| 396 RTC_DCHECK(network_thread_->IsCurrent()); | 395 RTC_DCHECK(network_thread_->IsCurrent()); |
| 397 | 396 |
| 398 // TODO(zstein): de-dup with ConnectToPacketTransport | 397 // TODO(zstein): de-dup with ConnectToPacketTransport |
| 399 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 398 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 400 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | |
| 401 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); | 399 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); |
| 402 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 400 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 403 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( | 401 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( |
| 404 this, &BaseChannel::OnSelectedCandidatePairChanged); | 402 this, &BaseChannel::OnSelectedCandidatePairChanged); |
| 405 } | 403 } |
| 406 | 404 |
| 407 void BaseChannel::DisconnectFromDtlsTransport( | 405 void BaseChannel::DisconnectFromDtlsTransport( |
| 408 DtlsTransportInternal* transport) { | 406 DtlsTransportInternal* transport) { |
| 409 RTC_DCHECK(network_thread_->IsCurrent()); | 407 RTC_DCHECK(network_thread_->IsCurrent()); |
| 410 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, | 408 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, |
| 411 false); | 409 false); |
| 412 | 410 |
| 413 transport->SignalWritableState.disconnect(this); | 411 transport->SignalWritableState.disconnect(this); |
| 414 transport->SignalReadPacket.disconnect(this); | |
| 415 transport->SignalDtlsState.disconnect(this); | 412 transport->SignalDtlsState.disconnect(this); |
| 416 transport->SignalSentPacket.disconnect(this); | 413 transport->SignalSentPacket.disconnect(this); |
| 417 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( | 414 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( |
| 418 this); | 415 this); |
| 419 } | 416 } |
| 420 | 417 |
| 421 void BaseChannel::ConnectToPacketTransport( | 418 void BaseChannel::ConnectToPacketTransport( |
| 422 rtc::PacketTransportInternal* transport) { | 419 rtc::PacketTransportInternal* transport) { |
| 423 RTC_DCHECK_RUN_ON(network_thread_); | 420 RTC_DCHECK_RUN_ON(network_thread_); |
| 424 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); | 421 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); |
| 425 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead); | |
| 426 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); | 422 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); |
| 427 } | 423 } |
| 428 | 424 |
| 429 void BaseChannel::DisconnectFromPacketTransport( | 425 void BaseChannel::DisconnectFromPacketTransport( |
| 430 rtc::PacketTransportInternal* transport) { | 426 rtc::PacketTransportInternal* transport) { |
| 431 RTC_DCHECK_RUN_ON(network_thread_); | 427 RTC_DCHECK_RUN_ON(network_thread_); |
| 432 transport->SignalWritableState.disconnect(this); | 428 transport->SignalWritableState.disconnect(this); |
| 433 transport->SignalReadPacket.disconnect(this); | |
| 434 transport->SignalSentPacket.disconnect(this); | 429 transport->SignalSentPacket.disconnect(this); |
| 435 } | 430 } |
| 436 | 431 |
| 437 bool BaseChannel::Enable(bool enable) { | 432 bool BaseChannel::Enable(bool enable) { |
| 438 worker_thread_->Invoke<void>( | 433 worker_thread_->Invoke<void>( |
| 439 RTC_FROM_HERE, | 434 RTC_FROM_HERE, |
| 440 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, | 435 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, |
| 441 this)); | 436 this)); |
| 442 return true; | 437 return true; |
| 443 } | 438 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 return transport ? transport->SetOption(opt, value) : -1; | 564 return transport ? transport->SetOption(opt, value) : -1; |
| 570 } | 565 } |
| 571 | 566 |
| 572 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) { | 567 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) { |
| 573 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || | 568 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || |
| 574 transport == rtp_transport_.rtcp_packet_transport()); | 569 transport == rtp_transport_.rtcp_packet_transport()); |
| 575 RTC_DCHECK(network_thread_->IsCurrent()); | 570 RTC_DCHECK(network_thread_->IsCurrent()); |
| 576 UpdateWritableState_n(); | 571 UpdateWritableState_n(); |
| 577 } | 572 } |
| 578 | 573 |
| 579 void BaseChannel::OnPacketRead(rtc::PacketTransportInternal* transport, | |
| 580 const char* data, | |
| 581 size_t len, | |
| 582 const rtc::PacketTime& packet_time, | |
| 583 int flags) { | |
| 584 TRACE_EVENT0("webrtc", "BaseChannel::OnPacketRead"); | |
| 585 // OnPacketRead gets called from P2PSocket; now pass data to MediaEngine | |
| 586 RTC_DCHECK(network_thread_->IsCurrent()); | |
| 587 | |
| 588 // When using RTCP multiplexing we might get RTCP packets on the RTP | |
| 589 // transport. We feed RTP traffic into the demuxer to determine if it is RTCP. | |
| 590 bool rtcp = PacketIsRtcp(transport, data, len); | |
| 591 rtc::CopyOnWriteBuffer packet(data, len); | |
| 592 HandlePacket(rtcp, &packet, packet_time); | |
| 593 } | |
| 594 | |
| 595 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, | 574 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport, |
| 596 DtlsTransportState state) { | 575 DtlsTransportState state) { |
| 597 if (!ShouldSetupDtlsSrtp_n()) { | 576 if (!ShouldSetupDtlsSrtp_n()) { |
| 598 return; | 577 return; |
| 599 } | 578 } |
| 600 | 579 |
| 601 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED | 580 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED |
| 602 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to | 581 // state, setting up DTLS-SRTP context is deferred to ChannelWritable_w to |
| 603 // cover other scenarios like the whole transport is writable (not just this | 582 // cover other scenarios like the whole transport is writable (not just this |
| 604 // TransportChannel) or when TransportChannel is attached after DTLS is | 583 // TransportChannel) or when TransportChannel is attached after DTLS is |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 634 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, | 613 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, |
| 635 network_route)); | 614 network_route)); |
| 636 } | 615 } |
| 637 | 616 |
| 638 void BaseChannel::OnTransportReadyToSend(bool ready) { | 617 void BaseChannel::OnTransportReadyToSend(bool ready) { |
| 639 invoker_.AsyncInvoke<void>( | 618 invoker_.AsyncInvoke<void>( |
| 640 RTC_FROM_HERE, worker_thread_, | 619 RTC_FROM_HERE, worker_thread_, |
| 641 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready)); | 620 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready)); |
| 642 } | 621 } |
| 643 | 622 |
| 644 bool BaseChannel::PacketIsRtcp(const rtc::PacketTransportInternal* transport, | |
| 645 const char* data, | |
| 646 size_t len) { | |
| 647 return (transport == rtp_transport_.rtcp_packet_transport() || | |
| 648 rtcp_mux_filter_.DemuxRtcp(data, static_cast<int>(len))); | |
| 649 } | |
| 650 | |
| 651 bool BaseChannel::SendPacket(bool rtcp, | 623 bool BaseChannel::SendPacket(bool rtcp, |
| 652 rtc::CopyOnWriteBuffer* packet, | 624 rtc::CopyOnWriteBuffer* packet, |
| 653 const rtc::PacketOptions& options) { | 625 const rtc::PacketOptions& options) { |
| 654 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. | 626 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. |
| 655 // If the thread is not our network thread, we will post to our network | 627 // If the thread is not our network thread, we will post to our network |
| 656 // so that the real work happens on our network. This avoids us having to | 628 // so that the real work happens on our network. This avoids us having to |
| 657 // synchronize access to all the pieces of the send path, including | 629 // synchronize access to all the pieces of the send path, including |
| 658 // SRTP and the inner workings of the transport channels. | 630 // SRTP and the inner workings of the transport channels. |
| 659 // The only downside is that we can't return a proper failure code if | 631 // The only downside is that we can't return a proper failure code if |
| 660 // needed. Since UDP is unreliable anyway, this should be a non-issue. | 632 // needed. Since UDP is unreliable anyway, this should be a non-issue. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 673 // packet before doing anything. (We might get RTCP packets that we don't | 645 // packet before doing anything. (We might get RTCP packets that we don't |
| 674 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP | 646 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP |
| 675 // transport. | 647 // transport. |
| 676 if (!rtp_transport_.IsWritable(rtcp)) { | 648 if (!rtp_transport_.IsWritable(rtcp)) { |
| 677 return false; | 649 return false; |
| 678 } | 650 } |
| 679 | 651 |
| 680 // Protect ourselves against crazy data. | 652 // Protect ourselves against crazy data. |
| 681 if (!ValidPacket(rtcp, packet)) { | 653 if (!ValidPacket(rtcp, packet)) { |
| 682 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " | 654 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " |
| 683 << PacketType(rtcp) | 655 << RtpRtcpStringLiteral(rtcp) |
| 684 << " packet: wrong size=" << packet->size(); | 656 << " packet: wrong size=" << packet->size(); |
| 685 return false; | 657 return false; |
| 686 } | 658 } |
| 687 | 659 |
| 688 rtc::PacketOptions updated_options; | 660 rtc::PacketOptions updated_options; |
| 689 updated_options = options; | 661 updated_options = options; |
| 690 // Protect if needed. | 662 // Protect if needed. |
| 691 if (srtp_filter_.IsActive()) { | 663 if (srtp_filter_.IsActive()) { |
| 692 TRACE_EVENT0("webrtc", "SRTP Encode"); | 664 TRACE_EVENT0("webrtc", "SRTP Encode"); |
| 693 bool res; | 665 bool res; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 << " and crypto is required"; | 737 << " and crypto is required"; |
| 766 RTC_NOTREACHED(); | 738 RTC_NOTREACHED(); |
| 767 return false; | 739 return false; |
| 768 } | 740 } |
| 769 | 741 |
| 770 // Bon voyage. | 742 // Bon voyage. |
| 771 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; | 743 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; |
| 772 return rtp_transport_.SendPacket(rtcp, packet, updated_options, flags); | 744 return rtp_transport_.SendPacket(rtcp, packet, updated_options, flags); |
| 773 } | 745 } |
| 774 | 746 |
| 775 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { | 747 bool BaseChannel::HandlesPayloadType(int packet_type) const { |
| 776 // Protect ourselves against crazy data. | 748 return rtp_transport_.HandlesPayloadType(packet_type); |
| 777 if (!ValidPacket(rtcp, packet)) { | |
| 778 LOG(LS_ERROR) << "Dropping incoming " << content_name_ << " " | |
| 779 << PacketType(rtcp) | |
| 780 << " packet: wrong size=" << packet->size(); | |
| 781 return false; | |
| 782 } | |
| 783 if (rtcp) { | |
| 784 // Permit all (seemingly valid) RTCP packets. | |
| 785 return true; | |
| 786 } | |
| 787 // Check whether we handle this payload. | |
| 788 return bundle_filter_.DemuxPacket(packet->data(), packet->size()); | |
| 789 } | 749 } |
| 790 | 750 |
| 791 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, | 751 void BaseChannel::OnPacketReceived(bool rtcp, |
| 792 const rtc::PacketTime& packet_time) { | 752 rtc::CopyOnWriteBuffer& packet, |
| 793 RTC_DCHECK(network_thread_->IsCurrent()); | 753 const rtc::PacketTime& packet_time) { |
| 794 if (!WantsPacket(rtcp, packet)) { | |
| 795 return; | |
| 796 } | |
| 797 | |
| 798 // We are only interested in the first rtp packet because that | |
| 799 // indicates the media has started flowing. | |
| 800 if (!has_received_packet_ && !rtcp) { | 754 if (!has_received_packet_ && !rtcp) { |
| 801 has_received_packet_ = true; | 755 has_received_packet_ = true; |
| 802 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); | 756 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); |
| 803 } | 757 } |
| 804 | 758 |
| 805 // Unprotect the packet, if needed. | 759 // Unprotect the packet, if needed. |
| 806 if (srtp_filter_.IsActive()) { | 760 if (srtp_filter_.IsActive()) { |
| 807 TRACE_EVENT0("webrtc", "SRTP Decode"); | 761 TRACE_EVENT0("webrtc", "SRTP Decode"); |
| 808 char* data = packet->data<char>(); | 762 char* data = packet.data<char>(); |
| 809 int len = static_cast<int>(packet->size()); | 763 int len = static_cast<int>(packet.size()); |
| 810 bool res; | 764 bool res; |
| 811 if (!rtcp) { | 765 if (!rtcp) { |
| 812 res = srtp_filter_.UnprotectRtp(data, len, &len); | 766 res = srtp_filter_.UnprotectRtp(data, len, &len); |
| 813 if (!res) { | 767 if (!res) { |
| 814 int seq_num = -1; | 768 int seq_num = -1; |
| 815 uint32_t ssrc = 0; | 769 uint32_t ssrc = 0; |
| 816 GetRtpSeqNum(data, len, &seq_num); | 770 GetRtpSeqNum(data, len, &seq_num); |
| 817 GetRtpSsrc(data, len, &ssrc); | 771 GetRtpSsrc(data, len, &ssrc); |
| 818 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ | 772 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
| 819 << " RTP packet: size=" << len | 773 << " RTP packet: size=" << len << ", seqnum=" << seq_num |
| 820 << ", seqnum=" << seq_num << ", SSRC=" << ssrc; | 774 << ", SSRC=" << ssrc; |
| 821 return; | 775 return; |
| 822 } | 776 } |
| 823 } else { | 777 } else { |
| 824 res = srtp_filter_.UnprotectRtcp(data, len, &len); | 778 res = srtp_filter_.UnprotectRtcp(data, len, &len); |
| 825 if (!res) { | 779 if (!res) { |
| 826 int type = -1; | 780 int type = -1; |
| 827 GetRtcpType(data, len, &type); | 781 GetRtcpType(data, len, &type); |
| 828 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ | 782 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
| 829 << " RTCP packet: size=" << len << ", type=" << type; | 783 << " RTCP packet: size=" << len << ", type=" << type; |
| 830 return; | 784 return; |
| 831 } | 785 } |
| 832 } | 786 } |
| 833 | 787 |
| 834 packet->SetSize(len); | 788 packet.SetSize(len); |
| 835 } else if (srtp_required_) { | 789 } else if (srtp_required_) { |
| 836 // Our session description indicates that SRTP is required, but we got a | 790 // Our session description indicates that SRTP is required, but we got a |
| 837 // packet before our SRTP filter is active. This means either that | 791 // packet before our SRTP filter is active. This means either that |
| 838 // a) we got SRTP packets before we received the SDES keys, in which case | 792 // a) we got SRTP packets before we received the SDES keys, in which case |
| 839 // we can't decrypt it anyway, or | 793 // we can't decrypt it anyway, or |
| 840 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP | 794 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP |
| 841 // transports, so we haven't yet extracted keys, even if DTLS did | 795 // transports, so we haven't yet extracted keys, even if DTLS did |
| 842 // complete on the transport that the packets are being sent on. It's | 796 // complete on the transport that the packets are being sent on. It's |
| 843 // really good practice to wait for both RTP and RTCP to be good to go | 797 // really good practice to wait for both RTP and RTCP to be good to go |
| 844 // before sending media, to prevent weird failure modes, so it's fine | 798 // before sending media, to prevent weird failure modes, so it's fine |
| 845 // for us to just eat packets here. This is all sidestepped if RTCP mux | 799 // for us to just eat packets here. This is all sidestepped if RTCP mux |
| 846 // is used anyway. | 800 // is used anyway. |
| 847 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) | 801 LOG(LS_WARNING) << "Can't process incoming " << RtpRtcpStringLiteral(rtcp) |
| 848 << " packet when SRTP is inactive and crypto is required"; | 802 << " packet when SRTP is inactive and crypto is required"; |
| 849 return; | 803 return; |
| 850 } | 804 } |
| 851 | 805 |
| 852 invoker_.AsyncInvoke<void>( | 806 invoker_.AsyncInvoke<void>( |
| 853 RTC_FROM_HERE, worker_thread_, | 807 RTC_FROM_HERE, worker_thread_, |
| 854 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); | 808 Bind(&BaseChannel::ProcessPacket, this, rtcp, packet, packet_time)); |
| 855 } | 809 } |
| 856 | 810 |
| 857 void BaseChannel::OnPacketReceived(bool rtcp, | 811 void BaseChannel::ProcessPacket(bool rtcp, |
| 858 const rtc::CopyOnWriteBuffer& packet, | 812 const rtc::CopyOnWriteBuffer& packet, |
| 859 const rtc::PacketTime& packet_time) { | 813 const rtc::PacketTime& packet_time) { |
| 860 RTC_DCHECK(worker_thread_->IsCurrent()); | 814 RTC_DCHECK(worker_thread_->IsCurrent()); |
| 815 | |
| 861 // Need to copy variable because OnRtcpReceived/OnPacketReceived | 816 // Need to copy variable because OnRtcpReceived/OnPacketReceived |
| 862 // requires non-const pointer to buffer. This doesn't memcpy the actual data. | 817 // requires non-const pointer to buffer. This doesn't memcpy the actual data. |
| 863 rtc::CopyOnWriteBuffer data(packet); | 818 rtc::CopyOnWriteBuffer data(packet); |
| 864 if (rtcp) { | 819 if (rtcp) { |
| 865 media_channel_->OnRtcpReceived(&data, packet_time); | 820 media_channel_->OnRtcpReceived(&data, packet_time); |
| 866 } else { | 821 } else { |
| 867 media_channel_->OnPacketReceived(&data, packet_time); | 822 media_channel_->OnPacketReceived(&data, packet_time); |
| 868 } | 823 } |
| 869 } | 824 } |
| 870 | 825 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 RTC_DCHECK(transport->IsDtlsActive()); | 935 RTC_DCHECK(transport->IsDtlsActive()); |
| 981 | 936 |
| 982 int selected_crypto_suite; | 937 int selected_crypto_suite; |
| 983 | 938 |
| 984 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) { | 939 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) { |
| 985 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; | 940 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; |
| 986 return false; | 941 return false; |
| 987 } | 942 } |
| 988 | 943 |
| 989 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " " | 944 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " " |
| 990 << PacketType(rtcp); | 945 << RtpRtcpStringLiteral(rtcp); |
| 991 | 946 |
| 992 int key_len; | 947 int key_len; |
| 993 int salt_len; | 948 int salt_len; |
| 994 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, | 949 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, |
| 995 &salt_len)) { | 950 &salt_len)) { |
| 996 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; | 951 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; |
| 997 return false; | 952 return false; |
| 998 } | 953 } |
| 999 | 954 |
| 1000 // OK, we're now doing DTLS (RFC 5764) | 955 // OK, we're now doing DTLS (RFC 5764) |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1441 delete data; | 1396 delete data; |
| 1442 break; | 1397 break; |
| 1443 } | 1398 } |
| 1444 case MSG_FIRSTPACKETRECEIVED: { | 1399 case MSG_FIRSTPACKETRECEIVED: { |
| 1445 SignalFirstPacketReceived(this); | 1400 SignalFirstPacketReceived(this); |
| 1446 break; | 1401 break; |
| 1447 } | 1402 } |
| 1448 } | 1403 } |
| 1449 } | 1404 } |
| 1450 | 1405 |
| 1406 void BaseChannel::AddHandledPayloadType(int payload_type) { | |
| 1407 rtp_transport_.AddHandledPayloadType(payload_type); | |
| 1408 } | |
| 1409 | |
| 1451 void BaseChannel::FlushRtcpMessages_n() { | 1410 void BaseChannel::FlushRtcpMessages_n() { |
| 1452 // Flush all remaining RTCP messages. This should only be called in | 1411 // Flush all remaining RTCP messages. This should only be called in |
| 1453 // destructor. | 1412 // destructor. |
| 1454 RTC_DCHECK(network_thread_->IsCurrent()); | 1413 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1455 rtc::MessageList rtcp_messages; | 1414 rtc::MessageList rtcp_messages; |
| 1456 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 1415 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); |
| 1457 for (const auto& message : rtcp_messages) { | 1416 for (const auto& message : rtcp_messages) { |
| 1458 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, | 1417 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, |
| 1459 message.pdata); | 1418 message.pdata); |
| 1460 } | 1419 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 } | 1611 } |
| 1653 | 1612 |
| 1654 int VoiceChannel::GetOutputLevel_w() { | 1613 int VoiceChannel::GetOutputLevel_w() { |
| 1655 return media_channel()->GetOutputLevel(); | 1614 return media_channel()->GetOutputLevel(); |
| 1656 } | 1615 } |
| 1657 | 1616 |
| 1658 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { | 1617 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
| 1659 media_channel()->GetActiveStreams(actives); | 1618 media_channel()->GetActiveStreams(actives); |
| 1660 } | 1619 } |
| 1661 | 1620 |
| 1662 void VoiceChannel::OnPacketRead(rtc::PacketTransportInternal* transport, | 1621 void VoiceChannel::OnPacketReceived(bool rtcp, |
| 1663 const char* data, | 1622 rtc::CopyOnWriteBuffer& packet, |
| 1664 size_t len, | 1623 const rtc::PacketTime& packet_time) { |
| 1665 const rtc::PacketTime& packet_time, | 1624 BaseChannel::OnPacketReceived(rtcp, packet, packet_time); |
| 1666 int flags) { | |
| 1667 BaseChannel::OnPacketRead(transport, data, len, packet_time, flags); | |
| 1668 // Set a flag when we've received an RTP packet. If we're waiting for early | 1625 // Set a flag when we've received an RTP packet. If we're waiting for early |
| 1669 // media, this will disable the timeout. | 1626 // media, this will disable the timeout. |
| 1670 if (!received_media_ && !PacketIsRtcp(transport, data, len)) { | 1627 if (!received_media_ && !rtcp) { |
| 1671 received_media_ = true; | 1628 received_media_ = true; |
| 1672 } | 1629 } |
| 1673 } | 1630 } |
| 1674 | 1631 |
| 1675 void BaseChannel::UpdateMediaSendRecvState() { | 1632 void BaseChannel::UpdateMediaSendRecvState() { |
| 1676 RTC_DCHECK(network_thread_->IsCurrent()); | 1633 RTC_DCHECK(network_thread_->IsCurrent()); |
| 1677 invoker_.AsyncInvoke<void>( | 1634 invoker_.AsyncInvoke<void>( |
| 1678 RTC_FROM_HERE, worker_thread_, | 1635 RTC_FROM_HERE, worker_thread_, |
| 1679 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); | 1636 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); |
| 1680 } | 1637 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 } | 1716 } |
| 1760 | 1717 |
| 1761 AudioRecvParameters recv_params = last_recv_params_; | 1718 AudioRecvParameters recv_params = last_recv_params_; |
| 1762 RtpParametersFromMediaDescription(audio, &recv_params); | 1719 RtpParametersFromMediaDescription(audio, &recv_params); |
| 1763 if (!media_channel()->SetRecvParameters(recv_params)) { | 1720 if (!media_channel()->SetRecvParameters(recv_params)) { |
| 1764 SafeSetError("Failed to set local audio description recv parameters.", | 1721 SafeSetError("Failed to set local audio description recv parameters.", |
| 1765 error_desc); | 1722 error_desc); |
| 1766 return false; | 1723 return false; |
| 1767 } | 1724 } |
| 1768 for (const AudioCodec& codec : audio->codecs()) { | 1725 for (const AudioCodec& codec : audio->codecs()) { |
| 1769 bundle_filter()->AddPayloadType(codec.id); | 1726 AddHandledPayloadType(codec.id); |
| 1770 } | 1727 } |
| 1771 last_recv_params_ = recv_params; | 1728 last_recv_params_ = recv_params; |
| 1772 | 1729 |
| 1773 // TODO(pthatcher): Move local streams into AudioSendParameters, and | 1730 // TODO(pthatcher): Move local streams into AudioSendParameters, and |
| 1774 // only give it to the media channel once we have a remote | 1731 // only give it to the media channel once we have a remote |
| 1775 // description too (without a remote description, we won't be able | 1732 // description too (without a remote description, we won't be able |
| 1776 // to send them anyway). | 1733 // to send them anyway). |
| 1777 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { | 1734 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { |
| 1778 SafeSetError("Failed to set local audio description streams.", error_desc); | 1735 SafeSetError("Failed to set local audio description streams.", error_desc); |
| 1779 return false; | 1736 return false; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2032 } | 1989 } |
| 2033 | 1990 |
| 2034 VideoRecvParameters recv_params = last_recv_params_; | 1991 VideoRecvParameters recv_params = last_recv_params_; |
| 2035 RtpParametersFromMediaDescription(video, &recv_params); | 1992 RtpParametersFromMediaDescription(video, &recv_params); |
| 2036 if (!media_channel()->SetRecvParameters(recv_params)) { | 1993 if (!media_channel()->SetRecvParameters(recv_params)) { |
| 2037 SafeSetError("Failed to set local video description recv parameters.", | 1994 SafeSetError("Failed to set local video description recv parameters.", |
| 2038 error_desc); | 1995 error_desc); |
| 2039 return false; | 1996 return false; |
| 2040 } | 1997 } |
| 2041 for (const VideoCodec& codec : video->codecs()) { | 1998 for (const VideoCodec& codec : video->codecs()) { |
| 2042 bundle_filter()->AddPayloadType(codec.id); | 1999 AddHandledPayloadType(codec.id); |
| 2043 } | 2000 } |
| 2044 last_recv_params_ = recv_params; | 2001 last_recv_params_ = recv_params; |
| 2045 | 2002 |
| 2046 // TODO(pthatcher): Move local streams into VideoSendParameters, and | 2003 // TODO(pthatcher): Move local streams into VideoSendParameters, and |
| 2047 // only give it to the media channel once we have a remote | 2004 // only give it to the media channel once we have a remote |
| 2048 // description too (without a remote description, we won't be able | 2005 // description too (without a remote description, we won't be able |
| 2049 // to send them anyway). | 2006 // to send them anyway). |
| 2050 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { | 2007 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { |
| 2051 SafeSetError("Failed to set local video description streams.", error_desc); | 2008 SafeSetError("Failed to set local video description streams.", error_desc); |
| 2052 return false; | 2009 return false; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2227 } | 2184 } |
| 2228 | 2185 |
| 2229 DataRecvParameters recv_params = last_recv_params_; | 2186 DataRecvParameters recv_params = last_recv_params_; |
| 2230 RtpParametersFromMediaDescription(data, &recv_params); | 2187 RtpParametersFromMediaDescription(data, &recv_params); |
| 2231 if (!media_channel()->SetRecvParameters(recv_params)) { | 2188 if (!media_channel()->SetRecvParameters(recv_params)) { |
| 2232 SafeSetError("Failed to set remote data description recv parameters.", | 2189 SafeSetError("Failed to set remote data description recv parameters.", |
| 2233 error_desc); | 2190 error_desc); |
| 2234 return false; | 2191 return false; |
| 2235 } | 2192 } |
| 2236 for (const DataCodec& codec : data->codecs()) { | 2193 for (const DataCodec& codec : data->codecs()) { |
| 2237 bundle_filter()->AddPayloadType(codec.id); | 2194 AddHandledPayloadType(codec.id); |
| 2238 } | 2195 } |
| 2239 last_recv_params_ = recv_params; | 2196 last_recv_params_ = recv_params; |
| 2240 | 2197 |
| 2241 // TODO(pthatcher): Move local streams into DataSendParameters, and | 2198 // TODO(pthatcher): Move local streams into DataSendParameters, and |
| 2242 // only give it to the media channel once we have a remote | 2199 // only give it to the media channel once we have a remote |
| 2243 // description too (without a remote description, we won't be able | 2200 // description too (without a remote description, we won't be able |
| 2244 // to send them anyway). | 2201 // to send them anyway). |
| 2245 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | 2202 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |
| 2246 SafeSetError("Failed to set local data description streams.", error_desc); | 2203 SafeSetError("Failed to set local data description streams.", error_desc); |
| 2247 return false; | 2204 return false; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2400 | 2357 |
| 2401 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { | 2358 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { |
| 2402 // This is usded for congestion control to indicate that the stream is ready | 2359 // This is usded for congestion control to indicate that the stream is ready |
| 2403 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates | 2360 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
| 2404 // that the transport channel is ready. | 2361 // that the transport channel is ready. |
| 2405 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2362 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
| 2406 new DataChannelReadyToSendMessageData(writable)); | 2363 new DataChannelReadyToSendMessageData(writable)); |
| 2407 } | 2364 } |
| 2408 | 2365 |
| 2409 } // namespace cricket | 2366 } // namespace cricket |
| OLD | NEW |