Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webrtc/pc/channel.cc

Issue 2890263003: Move RTP/RTCP demuxing logic from BaseChannel to RtpTransport. (Closed)
Patch Set: Disconnect transport channels in method called from Deinit to prevent races during object destructi… Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 15 matching lines...) Expand all
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 }
216 215
216 rtp_transport_.SetRtpPacketTransport(nullptr);
217 rtp_transport_.SetRtcpPacketTransport(nullptr);
218
217 // Clear pending read packets/messages. 219 // Clear pending read packets/messages.
218 network_thread_->Clear(&invoker_); 220 network_thread_->Clear(&invoker_);
219 network_thread_->Clear(this); 221 network_thread_->Clear(this);
220 } 222 }
221 223
222 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport, 224 bool BaseChannel::Init_w(DtlsTransportInternal* rtp_dtls_transport,
223 DtlsTransportInternal* rtcp_dtls_transport, 225 DtlsTransportInternal* rtcp_dtls_transport,
224 rtc::PacketTransportInternal* rtp_packet_transport, 226 rtc::PacketTransportInternal* rtp_packet_transport,
225 rtc::PacketTransportInternal* rtcp_packet_transport) { 227 rtc::PacketTransportInternal* rtcp_packet_transport) {
226 if (!network_thread_->Invoke<bool>( 228 if (!network_thread_->Invoke<bool>(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 for (const auto& pair : socket_options) { 392 for (const auto& pair : socket_options) {
391 new_packet_transport->SetOption(pair.first, pair.second); 393 new_packet_transport->SetOption(pair.first, pair.second);
392 } 394 }
393 } 395 }
394 396
395 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) { 397 void BaseChannel::ConnectToDtlsTransport(DtlsTransportInternal* transport) {
396 RTC_DCHECK(network_thread_->IsCurrent()); 398 RTC_DCHECK(network_thread_->IsCurrent());
397 399
398 // TODO(zstein): de-dup with ConnectToPacketTransport 400 // TODO(zstein): de-dup with ConnectToPacketTransport
399 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 401 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
400 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead);
401 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState); 402 transport->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState);
402 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); 403 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
403 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect( 404 transport->ice_transport()->SignalSelectedCandidatePairChanged.connect(
404 this, &BaseChannel::OnSelectedCandidatePairChanged); 405 this, &BaseChannel::OnSelectedCandidatePairChanged);
405 } 406 }
406 407
407 void BaseChannel::DisconnectFromDtlsTransport( 408 void BaseChannel::DisconnectFromDtlsTransport(
408 DtlsTransportInternal* transport) { 409 DtlsTransportInternal* transport) {
409 RTC_DCHECK(network_thread_->IsCurrent()); 410 RTC_DCHECK(network_thread_->IsCurrent());
410 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1, 411 OnSelectedCandidatePairChanged(transport->ice_transport(), nullptr, -1,
411 false); 412 false);
412 413
413 transport->SignalWritableState.disconnect(this); 414 transport->SignalWritableState.disconnect(this);
414 transport->SignalReadPacket.disconnect(this);
415 transport->SignalDtlsState.disconnect(this); 415 transport->SignalDtlsState.disconnect(this);
416 transport->SignalSentPacket.disconnect(this); 416 transport->SignalSentPacket.disconnect(this);
417 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect( 417 transport->ice_transport()->SignalSelectedCandidatePairChanged.disconnect(
418 this); 418 this);
419 } 419 }
420 420
421 void BaseChannel::ConnectToPacketTransport( 421 void BaseChannel::ConnectToPacketTransport(
422 rtc::PacketTransportInternal* transport) { 422 rtc::PacketTransportInternal* transport) {
423 RTC_DCHECK_RUN_ON(network_thread_); 423 RTC_DCHECK_RUN_ON(network_thread_);
424 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState); 424 transport->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
425 transport->SignalReadPacket.connect(this, &BaseChannel::OnPacketRead);
426 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n); 425 transport->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
427 } 426 }
428 427
429 void BaseChannel::DisconnectFromPacketTransport( 428 void BaseChannel::DisconnectFromPacketTransport(
430 rtc::PacketTransportInternal* transport) { 429 rtc::PacketTransportInternal* transport) {
431 RTC_DCHECK_RUN_ON(network_thread_); 430 RTC_DCHECK_RUN_ON(network_thread_);
432 transport->SignalWritableState.disconnect(this); 431 transport->SignalWritableState.disconnect(this);
433 transport->SignalReadPacket.disconnect(this);
434 transport->SignalSentPacket.disconnect(this); 432 transport->SignalSentPacket.disconnect(this);
435 } 433 }
436 434
437 bool BaseChannel::Enable(bool enable) { 435 bool BaseChannel::Enable(bool enable) {
438 worker_thread_->Invoke<void>( 436 worker_thread_->Invoke<void>(
439 RTC_FROM_HERE, 437 RTC_FROM_HERE,
440 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w, 438 Bind(enable ? &BaseChannel::EnableMedia_w : &BaseChannel::DisableMedia_w,
441 this)); 439 this));
442 return true; 440 return true;
443 } 441 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return transport ? transport->SetOption(opt, value) : -1; 567 return transport ? transport->SetOption(opt, value) : -1;
570 } 568 }
571 569
572 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) { 570 void BaseChannel::OnWritableState(rtc::PacketTransportInternal* transport) {
573 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() || 571 RTC_DCHECK(transport == rtp_transport_.rtp_packet_transport() ||
574 transport == rtp_transport_.rtcp_packet_transport()); 572 transport == rtp_transport_.rtcp_packet_transport());
575 RTC_DCHECK(network_thread_->IsCurrent()); 573 RTC_DCHECK(network_thread_->IsCurrent());
576 UpdateWritableState_n(); 574 UpdateWritableState_n();
577 } 575 }
578 576
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, 577 void BaseChannel::OnDtlsState(DtlsTransportInternal* transport,
596 DtlsTransportState state) { 578 DtlsTransportState state) {
597 if (!ShouldSetupDtlsSrtp_n()) { 579 if (!ShouldSetupDtlsSrtp_n()) {
598 return; 580 return;
599 } 581 }
600 582
601 // Reset the srtp filter if it's not the CONNECTED state. For the CONNECTED 583 // 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 584 // 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 585 // cover other scenarios like the whole transport is writable (not just this
604 // TransportChannel) or when TransportChannel is attached after DTLS is 586 // TransportChannel) or when TransportChannel is attached after DTLS is
(...skipping 29 matching lines...) Expand all
634 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name, 616 Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_, transport_name,
635 network_route)); 617 network_route));
636 } 618 }
637 619
638 void BaseChannel::OnTransportReadyToSend(bool ready) { 620 void BaseChannel::OnTransportReadyToSend(bool ready) {
639 invoker_.AsyncInvoke<void>( 621 invoker_.AsyncInvoke<void>(
640 RTC_FROM_HERE, worker_thread_, 622 RTC_FROM_HERE, worker_thread_,
641 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready)); 623 Bind(&MediaChannel::OnReadyToSend, media_channel_, ready));
642 } 624 }
643 625
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, 626 bool BaseChannel::SendPacket(bool rtcp,
652 rtc::CopyOnWriteBuffer* packet, 627 rtc::CopyOnWriteBuffer* packet,
653 const rtc::PacketOptions& options) { 628 const rtc::PacketOptions& options) {
654 // SendPacket gets called from MediaEngine, on a pacer or an encoder thread. 629 // 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 630 // 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 631 // 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 632 // synchronize access to all the pieces of the send path, including
658 // SRTP and the inner workings of the transport channels. 633 // SRTP and the inner workings of the transport channels.
659 // The only downside is that we can't return a proper failure code if 634 // 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. 635 // needed. Since UDP is unreliable anyway, this should be a non-issue.
(...skipping 12 matching lines...) Expand all
673 // packet before doing anything. (We might get RTCP packets that we don't 648 // 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 649 // intend to send.) If we've negotiated RTCP mux, send RTCP over the RTP
675 // transport. 650 // transport.
676 if (!rtp_transport_.IsWritable(rtcp)) { 651 if (!rtp_transport_.IsWritable(rtcp)) {
677 return false; 652 return false;
678 } 653 }
679 654
680 // Protect ourselves against crazy data. 655 // Protect ourselves against crazy data.
681 if (!ValidPacket(rtcp, packet)) { 656 if (!ValidPacket(rtcp, packet)) {
682 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " " 657 LOG(LS_ERROR) << "Dropping outgoing " << content_name_ << " "
683 << PacketType(rtcp) 658 << RtpRtcpStringLiteral(rtcp)
684 << " packet: wrong size=" << packet->size(); 659 << " packet: wrong size=" << packet->size();
685 return false; 660 return false;
686 } 661 }
687 662
688 rtc::PacketOptions updated_options; 663 rtc::PacketOptions updated_options;
689 updated_options = options; 664 updated_options = options;
690 // Protect if needed. 665 // Protect if needed.
691 if (srtp_filter_.IsActive()) { 666 if (srtp_filter_.IsActive()) {
692 TRACE_EVENT0("webrtc", "SRTP Encode"); 667 TRACE_EVENT0("webrtc", "SRTP Encode");
693 bool res; 668 bool res;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 << " and crypto is required"; 740 << " and crypto is required";
766 RTC_NOTREACHED(); 741 RTC_NOTREACHED();
767 return false; 742 return false;
768 } 743 }
769 744
770 // Bon voyage. 745 // Bon voyage.
771 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL; 746 int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL;
772 return rtp_transport_.SendPacket(rtcp, packet, updated_options, flags); 747 return rtp_transport_.SendPacket(rtcp, packet, updated_options, flags);
773 } 748 }
774 749
775 bool BaseChannel::WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) { 750 bool BaseChannel::HandlesPayloadType(int packet_type) const {
776 // Protect ourselves against crazy data. 751 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 } 752 }
790 753
791 void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet, 754 void BaseChannel::OnPacketReceived(bool rtcp,
792 const rtc::PacketTime& packet_time) { 755 rtc::CopyOnWriteBuffer& packet,
793 RTC_DCHECK(network_thread_->IsCurrent()); 756 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) { 757 if (!has_received_packet_ && !rtcp) {
801 has_received_packet_ = true; 758 has_received_packet_ = true;
802 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); 759 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED);
803 } 760 }
804 761
805 // Unprotect the packet, if needed. 762 // Unprotect the packet, if needed.
806 if (srtp_filter_.IsActive()) { 763 if (srtp_filter_.IsActive()) {
807 TRACE_EVENT0("webrtc", "SRTP Decode"); 764 TRACE_EVENT0("webrtc", "SRTP Decode");
808 char* data = packet->data<char>(); 765 char* data = packet.data<char>();
809 int len = static_cast<int>(packet->size()); 766 int len = static_cast<int>(packet.size());
810 bool res; 767 bool res;
811 if (!rtcp) { 768 if (!rtcp) {
812 res = srtp_filter_.UnprotectRtp(data, len, &len); 769 res = srtp_filter_.UnprotectRtp(data, len, &len);
813 if (!res) { 770 if (!res) {
814 int seq_num = -1; 771 int seq_num = -1;
815 uint32_t ssrc = 0; 772 uint32_t ssrc = 0;
816 GetRtpSeqNum(data, len, &seq_num); 773 GetRtpSeqNum(data, len, &seq_num);
817 GetRtpSsrc(data, len, &ssrc); 774 GetRtpSsrc(data, len, &ssrc);
818 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ 775 LOG(LS_ERROR) << "Failed to unprotect " << content_name_
819 << " RTP packet: size=" << len 776 << " RTP packet: size=" << len << ", seqnum=" << seq_num
820 << ", seqnum=" << seq_num << ", SSRC=" << ssrc; 777 << ", SSRC=" << ssrc;
821 return; 778 return;
822 } 779 }
823 } else { 780 } else {
824 res = srtp_filter_.UnprotectRtcp(data, len, &len); 781 res = srtp_filter_.UnprotectRtcp(data, len, &len);
825 if (!res) { 782 if (!res) {
826 int type = -1; 783 int type = -1;
827 GetRtcpType(data, len, &type); 784 GetRtcpType(data, len, &type);
828 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ 785 LOG(LS_ERROR) << "Failed to unprotect " << content_name_
829 << " RTCP packet: size=" << len << ", type=" << type; 786 << " RTCP packet: size=" << len << ", type=" << type;
830 return; 787 return;
831 } 788 }
832 } 789 }
833 790
834 packet->SetSize(len); 791 packet.SetSize(len);
835 } else if (srtp_required_) { 792 } else if (srtp_required_) {
836 // Our session description indicates that SRTP is required, but we got a 793 // Our session description indicates that SRTP is required, but we got a
837 // packet before our SRTP filter is active. This means either that 794 // 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 795 // a) we got SRTP packets before we received the SDES keys, in which case
839 // we can't decrypt it anyway, or 796 // we can't decrypt it anyway, or
840 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP 797 // 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 798 // 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 799 // 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 800 // 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 801 // 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 802 // for us to just eat packets here. This is all sidestepped if RTCP mux
846 // is used anyway. 803 // is used anyway.
847 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) 804 LOG(LS_WARNING) << "Can't process incoming " << RtpRtcpStringLiteral(rtcp)
848 << " packet when SRTP is inactive and crypto is required"; 805 << " packet when SRTP is inactive and crypto is required";
849 return; 806 return;
850 } 807 }
851 808
852 invoker_.AsyncInvoke<void>( 809 invoker_.AsyncInvoke<void>(
853 RTC_FROM_HERE, worker_thread_, 810 RTC_FROM_HERE, worker_thread_,
854 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); 811 Bind(&BaseChannel::ProcessPacket, this, rtcp, packet, packet_time));
855 } 812 }
856 813
857 void BaseChannel::OnPacketReceived(bool rtcp, 814 void BaseChannel::ProcessPacket(bool rtcp,
858 const rtc::CopyOnWriteBuffer& packet, 815 const rtc::CopyOnWriteBuffer& packet,
859 const rtc::PacketTime& packet_time) { 816 const rtc::PacketTime& packet_time) {
860 RTC_DCHECK(worker_thread_->IsCurrent()); 817 RTC_DCHECK(worker_thread_->IsCurrent());
818
861 // Need to copy variable because OnRtcpReceived/OnPacketReceived 819 // Need to copy variable because OnRtcpReceived/OnPacketReceived
862 // requires non-const pointer to buffer. This doesn't memcpy the actual data. 820 // requires non-const pointer to buffer. This doesn't memcpy the actual data.
863 rtc::CopyOnWriteBuffer data(packet); 821 rtc::CopyOnWriteBuffer data(packet);
864 if (rtcp) { 822 if (rtcp) {
865 media_channel_->OnRtcpReceived(&data, packet_time); 823 media_channel_->OnRtcpReceived(&data, packet_time);
866 } else { 824 } else {
867 media_channel_->OnPacketReceived(&data, packet_time); 825 media_channel_->OnPacketReceived(&data, packet_time);
868 } 826 }
869 } 827 }
870 828
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 RTC_DCHECK(transport->IsDtlsActive()); 938 RTC_DCHECK(transport->IsDtlsActive());
981 939
982 int selected_crypto_suite; 940 int selected_crypto_suite;
983 941
984 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) { 942 if (!transport->GetSrtpCryptoSuite(&selected_crypto_suite)) {
985 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite"; 943 LOG(LS_ERROR) << "No DTLS-SRTP selected crypto suite";
986 return false; 944 return false;
987 } 945 }
988 946
989 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " " 947 LOG(LS_INFO) << "Installing keys from DTLS-SRTP on " << content_name() << " "
990 << PacketType(rtcp); 948 << RtpRtcpStringLiteral(rtcp);
991 949
992 int key_len; 950 int key_len;
993 int salt_len; 951 int salt_len;
994 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len, 952 if (!rtc::GetSrtpKeyAndSaltLengths(selected_crypto_suite, &key_len,
995 &salt_len)) { 953 &salt_len)) {
996 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite; 954 LOG(LS_ERROR) << "Unknown DTLS-SRTP crypto suite" << selected_crypto_suite;
997 return false; 955 return false;
998 } 956 }
999 957
1000 // OK, we're now doing DTLS (RFC 5764) 958 // OK, we're now doing DTLS (RFC 5764)
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 delete data; 1399 delete data;
1442 break; 1400 break;
1443 } 1401 }
1444 case MSG_FIRSTPACKETRECEIVED: { 1402 case MSG_FIRSTPACKETRECEIVED: {
1445 SignalFirstPacketReceived(this); 1403 SignalFirstPacketReceived(this);
1446 break; 1404 break;
1447 } 1405 }
1448 } 1406 }
1449 } 1407 }
1450 1408
1409 void BaseChannel::AddHandledPayloadType(int payload_type) {
1410 rtp_transport_.AddHandledPayloadType(payload_type);
1411 }
1412
1451 void BaseChannel::FlushRtcpMessages_n() { 1413 void BaseChannel::FlushRtcpMessages_n() {
1452 // Flush all remaining RTCP messages. This should only be called in 1414 // Flush all remaining RTCP messages. This should only be called in
1453 // destructor. 1415 // destructor.
1454 RTC_DCHECK(network_thread_->IsCurrent()); 1416 RTC_DCHECK(network_thread_->IsCurrent());
1455 rtc::MessageList rtcp_messages; 1417 rtc::MessageList rtcp_messages;
1456 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); 1418 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages);
1457 for (const auto& message : rtcp_messages) { 1419 for (const auto& message : rtcp_messages) {
1458 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, 1420 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET,
1459 message.pdata); 1421 message.pdata);
1460 } 1422 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1614 }
1653 1615
1654 int VoiceChannel::GetOutputLevel_w() { 1616 int VoiceChannel::GetOutputLevel_w() {
1655 return media_channel()->GetOutputLevel(); 1617 return media_channel()->GetOutputLevel();
1656 } 1618 }
1657 1619
1658 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { 1620 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) {
1659 media_channel()->GetActiveStreams(actives); 1621 media_channel()->GetActiveStreams(actives);
1660 } 1622 }
1661 1623
1662 void VoiceChannel::OnPacketRead(rtc::PacketTransportInternal* transport, 1624 void VoiceChannel::OnPacketReceived(bool rtcp,
1663 const char* data, 1625 rtc::CopyOnWriteBuffer& packet,
1664 size_t len, 1626 const rtc::PacketTime& packet_time) {
1665 const rtc::PacketTime& packet_time, 1627 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 1628 // Set a flag when we've received an RTP packet. If we're waiting for early
1669 // media, this will disable the timeout. 1629 // media, this will disable the timeout.
1670 if (!received_media_ && !PacketIsRtcp(transport, data, len)) { 1630 if (!received_media_ && !rtcp) {
1671 received_media_ = true; 1631 received_media_ = true;
1672 } 1632 }
1673 } 1633 }
1674 1634
1675 void BaseChannel::UpdateMediaSendRecvState() { 1635 void BaseChannel::UpdateMediaSendRecvState() {
1676 RTC_DCHECK(network_thread_->IsCurrent()); 1636 RTC_DCHECK(network_thread_->IsCurrent());
1677 invoker_.AsyncInvoke<void>( 1637 invoker_.AsyncInvoke<void>(
1678 RTC_FROM_HERE, worker_thread_, 1638 RTC_FROM_HERE, worker_thread_,
1679 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); 1639 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this));
1680 } 1640 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 } 1719 }
1760 1720
1761 AudioRecvParameters recv_params = last_recv_params_; 1721 AudioRecvParameters recv_params = last_recv_params_;
1762 RtpParametersFromMediaDescription(audio, &recv_params); 1722 RtpParametersFromMediaDescription(audio, &recv_params);
1763 if (!media_channel()->SetRecvParameters(recv_params)) { 1723 if (!media_channel()->SetRecvParameters(recv_params)) {
1764 SafeSetError("Failed to set local audio description recv parameters.", 1724 SafeSetError("Failed to set local audio description recv parameters.",
1765 error_desc); 1725 error_desc);
1766 return false; 1726 return false;
1767 } 1727 }
1768 for (const AudioCodec& codec : audio->codecs()) { 1728 for (const AudioCodec& codec : audio->codecs()) {
1769 bundle_filter()->AddPayloadType(codec.id); 1729 AddHandledPayloadType(codec.id);
1770 } 1730 }
1771 last_recv_params_ = recv_params; 1731 last_recv_params_ = recv_params;
1772 1732
1773 // TODO(pthatcher): Move local streams into AudioSendParameters, and 1733 // TODO(pthatcher): Move local streams into AudioSendParameters, and
1774 // only give it to the media channel once we have a remote 1734 // only give it to the media channel once we have a remote
1775 // description too (without a remote description, we won't be able 1735 // description too (without a remote description, we won't be able
1776 // to send them anyway). 1736 // to send them anyway).
1777 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { 1737 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) {
1778 SafeSetError("Failed to set local audio description streams.", error_desc); 1738 SafeSetError("Failed to set local audio description streams.", error_desc);
1779 return false; 1739 return false;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } 1992 }
2033 1993
2034 VideoRecvParameters recv_params = last_recv_params_; 1994 VideoRecvParameters recv_params = last_recv_params_;
2035 RtpParametersFromMediaDescription(video, &recv_params); 1995 RtpParametersFromMediaDescription(video, &recv_params);
2036 if (!media_channel()->SetRecvParameters(recv_params)) { 1996 if (!media_channel()->SetRecvParameters(recv_params)) {
2037 SafeSetError("Failed to set local video description recv parameters.", 1997 SafeSetError("Failed to set local video description recv parameters.",
2038 error_desc); 1998 error_desc);
2039 return false; 1999 return false;
2040 } 2000 }
2041 for (const VideoCodec& codec : video->codecs()) { 2001 for (const VideoCodec& codec : video->codecs()) {
2042 bundle_filter()->AddPayloadType(codec.id); 2002 AddHandledPayloadType(codec.id);
2043 } 2003 }
2044 last_recv_params_ = recv_params; 2004 last_recv_params_ = recv_params;
2045 2005
2046 // TODO(pthatcher): Move local streams into VideoSendParameters, and 2006 // TODO(pthatcher): Move local streams into VideoSendParameters, and
2047 // only give it to the media channel once we have a remote 2007 // only give it to the media channel once we have a remote
2048 // description too (without a remote description, we won't be able 2008 // description too (without a remote description, we won't be able
2049 // to send them anyway). 2009 // to send them anyway).
2050 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { 2010 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) {
2051 SafeSetError("Failed to set local video description streams.", error_desc); 2011 SafeSetError("Failed to set local video description streams.", error_desc);
2052 return false; 2012 return false;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 } 2187 }
2228 2188
2229 DataRecvParameters recv_params = last_recv_params_; 2189 DataRecvParameters recv_params = last_recv_params_;
2230 RtpParametersFromMediaDescription(data, &recv_params); 2190 RtpParametersFromMediaDescription(data, &recv_params);
2231 if (!media_channel()->SetRecvParameters(recv_params)) { 2191 if (!media_channel()->SetRecvParameters(recv_params)) {
2232 SafeSetError("Failed to set remote data description recv parameters.", 2192 SafeSetError("Failed to set remote data description recv parameters.",
2233 error_desc); 2193 error_desc);
2234 return false; 2194 return false;
2235 } 2195 }
2236 for (const DataCodec& codec : data->codecs()) { 2196 for (const DataCodec& codec : data->codecs()) {
2237 bundle_filter()->AddPayloadType(codec.id); 2197 AddHandledPayloadType(codec.id);
2238 } 2198 }
2239 last_recv_params_ = recv_params; 2199 last_recv_params_ = recv_params;
2240 2200
2241 // TODO(pthatcher): Move local streams into DataSendParameters, and 2201 // TODO(pthatcher): Move local streams into DataSendParameters, and
2242 // only give it to the media channel once we have a remote 2202 // only give it to the media channel once we have a remote
2243 // description too (without a remote description, we won't be able 2203 // description too (without a remote description, we won't be able
2244 // to send them anyway). 2204 // to send them anyway).
2245 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { 2205 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) {
2246 SafeSetError("Failed to set local data description streams.", error_desc); 2206 SafeSetError("Failed to set local data description streams.", error_desc);
2247 return false; 2207 return false;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 2360
2401 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { 2361 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) {
2402 // This is usded for congestion control to indicate that the stream is ready 2362 // 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 2363 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates
2404 // that the transport channel is ready. 2364 // that the transport channel is ready.
2405 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, 2365 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA,
2406 new DataChannelReadyToSendMessageData(writable)); 2366 new DataChannelReadyToSendMessageData(writable));
2407 } 2367 }
2408 2368
2409 } // namespace cricket 2369 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/pc/channel.h ('k') | webrtc/pc/channel_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698