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::SignalFirstPacketReceived and | |
177 // RtpTransport::SignalPacketReceived will probably be replaced with a | |
178 // callback interface later so that the demuxer can select which chanenl | |
Taylor Brandstetter
2017/05/25 16:14:25
nit: "chanenl"
Zach Stein
2017/05/30 21:50:55
Dnoe.
| |
179 // to signal. | |
180 rtp_transport_.SignalFirstPacketReceived.connect( | |
181 this, &BaseChannel::OnFirstPacketReceived); | |
182 rtp_transport_.SignalPacketReceived.connect(this, | |
183 &BaseChannel::OnPacketReceived); | |
182 LOG(LS_INFO) << "Created channel for " << content_name; | 184 LOG(LS_INFO) << "Created channel for " << content_name; |
183 } | 185 } |
184 | 186 |
185 BaseChannel::~BaseChannel() { | 187 BaseChannel::~BaseChannel() { |
186 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); | 188 TRACE_EVENT0("webrtc", "BaseChannel::~BaseChannel"); |
187 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); | 189 RTC_DCHECK(worker_thread_ == rtc::Thread::Current()); |
188 Deinit(); | 190 Deinit(); |
189 StopConnectionMonitor(); | 191 StopConnectionMonitor(); |
190 // Eats any outstanding messages or packets. | 192 // Eats any outstanding messages or packets. |
191 worker_thread_->Clear(&invoker_); | 193 worker_thread_->Clear(&invoker_); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 Loading... | |
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { | |
801 has_received_packet_ = true; | |
802 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); | |
803 } | |
804 | |
805 // Unprotect the packet, if needed. | 757 // Unprotect the packet, if needed. |
806 if (srtp_filter_.IsActive()) { | 758 if (srtp_filter_.IsActive()) { |
807 TRACE_EVENT0("webrtc", "SRTP Decode"); | 759 TRACE_EVENT0("webrtc", "SRTP Decode"); |
808 char* data = packet->data<char>(); | 760 char* data = packet.data<char>(); |
809 int len = static_cast<int>(packet->size()); | 761 int len = static_cast<int>(packet.size()); |
810 bool res; | 762 bool res; |
811 if (!rtcp) { | 763 if (!rtcp) { |
812 res = srtp_filter_.UnprotectRtp(data, len, &len); | 764 res = srtp_filter_.UnprotectRtp(data, len, &len); |
813 if (!res) { | 765 if (!res) { |
814 int seq_num = -1; | 766 int seq_num = -1; |
815 uint32_t ssrc = 0; | 767 uint32_t ssrc = 0; |
816 GetRtpSeqNum(data, len, &seq_num); | 768 GetRtpSeqNum(data, len, &seq_num); |
817 GetRtpSsrc(data, len, &ssrc); | 769 GetRtpSsrc(data, len, &ssrc); |
818 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ | 770 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
819 << " RTP packet: size=" << len | 771 << " RTP packet: size=" << len << ", seqnum=" << seq_num |
820 << ", seqnum=" << seq_num << ", SSRC=" << ssrc; | 772 << ", SSRC=" << ssrc; |
821 return; | 773 return; |
822 } | 774 } |
823 } else { | 775 } else { |
824 res = srtp_filter_.UnprotectRtcp(data, len, &len); | 776 res = srtp_filter_.UnprotectRtcp(data, len, &len); |
825 if (!res) { | 777 if (!res) { |
826 int type = -1; | 778 int type = -1; |
827 GetRtcpType(data, len, &type); | 779 GetRtcpType(data, len, &type); |
828 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ | 780 LOG(LS_ERROR) << "Failed to unprotect " << content_name_ |
829 << " RTCP packet: size=" << len << ", type=" << type; | 781 << " RTCP packet: size=" << len << ", type=" << type; |
830 return; | 782 return; |
831 } | 783 } |
832 } | 784 } |
833 | 785 |
834 packet->SetSize(len); | 786 packet.SetSize(len); |
835 } else if (srtp_required_) { | 787 } else if (srtp_required_) { |
836 // Our session description indicates that SRTP is required, but we got a | 788 // Our session description indicates that SRTP is required, but we got a |
837 // packet before our SRTP filter is active. This means either that | 789 // 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 | 790 // a) we got SRTP packets before we received the SDES keys, in which case |
839 // we can't decrypt it anyway, or | 791 // we can't decrypt it anyway, or |
840 // b) we got SRTP packets before DTLS completed on both the RTP and RTCP | 792 // 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 | 793 // 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 | 794 // 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 | 795 // 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 | 796 // 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 | 797 // for us to just eat packets here. This is all sidestepped if RTCP mux |
846 // is used anyway. | 798 // is used anyway. |
847 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) | 799 LOG(LS_WARNING) << "Can't process incoming " << PacketType(rtcp) |
848 << " packet when SRTP is inactive and crypto is required"; | 800 << " packet when SRTP is inactive and crypto is required"; |
849 return; | 801 return; |
850 } | 802 } |
851 | 803 |
852 invoker_.AsyncInvoke<void>( | 804 invoker_.AsyncInvoke<void>( |
853 RTC_FROM_HERE, worker_thread_, | 805 RTC_FROM_HERE, worker_thread_, |
854 Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time)); | 806 Bind(&BaseChannel::ProcessPacket, this, rtcp, packet, packet_time)); |
855 } | 807 } |
856 | 808 |
857 void BaseChannel::OnPacketReceived(bool rtcp, | 809 void BaseChannel::ProcessPacket(bool rtcp, |
858 const rtc::CopyOnWriteBuffer& packet, | 810 const rtc::CopyOnWriteBuffer& packet, |
859 const rtc::PacketTime& packet_time) { | 811 const rtc::PacketTime& packet_time) { |
860 RTC_DCHECK(worker_thread_->IsCurrent()); | 812 RTC_DCHECK(worker_thread_->IsCurrent()); |
813 | |
861 // Need to copy variable because OnRtcpReceived/OnPacketReceived | 814 // Need to copy variable because OnRtcpReceived/OnPacketReceived |
862 // requires non-const pointer to buffer. This doesn't memcpy the actual data. | 815 // requires non-const pointer to buffer. This doesn't memcpy the actual data. |
863 rtc::CopyOnWriteBuffer data(packet); | 816 rtc::CopyOnWriteBuffer data(packet); |
864 if (rtcp) { | 817 if (rtcp) { |
865 media_channel_->OnRtcpReceived(&data, packet_time); | 818 media_channel_->OnRtcpReceived(&data, packet_time); |
866 } else { | 819 } else { |
867 media_channel_->OnPacketReceived(&data, packet_time); | 820 media_channel_->OnPacketReceived(&data, packet_time); |
868 } | 821 } |
869 } | 822 } |
870 | 823 |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1441 delete data; | 1394 delete data; |
1442 break; | 1395 break; |
1443 } | 1396 } |
1444 case MSG_FIRSTPACKETRECEIVED: { | 1397 case MSG_FIRSTPACKETRECEIVED: { |
1445 SignalFirstPacketReceived(this); | 1398 SignalFirstPacketReceived(this); |
1446 break; | 1399 break; |
1447 } | 1400 } |
1448 } | 1401 } |
1449 } | 1402 } |
1450 | 1403 |
1404 void BaseChannel::AddHandledPayloadType(int payload_type) { | |
1405 rtp_transport_.AddHandledPayloadType(payload_type); | |
1406 } | |
1407 | |
1451 void BaseChannel::FlushRtcpMessages_n() { | 1408 void BaseChannel::FlushRtcpMessages_n() { |
1452 // Flush all remaining RTCP messages. This should only be called in | 1409 // Flush all remaining RTCP messages. This should only be called in |
1453 // destructor. | 1410 // destructor. |
1454 RTC_DCHECK(network_thread_->IsCurrent()); | 1411 RTC_DCHECK(network_thread_->IsCurrent()); |
1455 rtc::MessageList rtcp_messages; | 1412 rtc::MessageList rtcp_messages; |
1456 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); | 1413 network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages); |
1457 for (const auto& message : rtcp_messages) { | 1414 for (const auto& message : rtcp_messages) { |
1458 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, | 1415 network_thread_->Send(RTC_FROM_HERE, this, MSG_SEND_RTCP_PACKET, |
1459 message.pdata); | 1416 message.pdata); |
1460 } | 1417 } |
(...skipping 21 matching lines...) Expand all Loading... | |
1482 const std::string& content_name, | 1439 const std::string& content_name, |
1483 bool rtcp_mux_required, | 1440 bool rtcp_mux_required, |
1484 bool srtp_required) | 1441 bool srtp_required) |
1485 : BaseChannel(worker_thread, | 1442 : BaseChannel(worker_thread, |
1486 network_thread, | 1443 network_thread, |
1487 signaling_thread, | 1444 signaling_thread, |
1488 media_channel, | 1445 media_channel, |
1489 content_name, | 1446 content_name, |
1490 rtcp_mux_required, | 1447 rtcp_mux_required, |
1491 srtp_required), | 1448 srtp_required), |
1492 media_engine_(media_engine), | 1449 media_engine_(media_engine) {} |
1493 received_media_(false) {} | |
1494 | 1450 |
1495 VoiceChannel::~VoiceChannel() { | 1451 VoiceChannel::~VoiceChannel() { |
1496 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); | 1452 TRACE_EVENT0("webrtc", "VoiceChannel::~VoiceChannel"); |
1497 StopAudioMonitor(); | 1453 StopAudioMonitor(); |
1498 StopMediaMonitor(); | 1454 StopMediaMonitor(); |
1499 // this can't be done in the base class, since it calls a virtual | 1455 // this can't be done in the base class, since it calls a virtual |
1500 DisableMedia_w(); | 1456 DisableMedia_w(); |
1501 Deinit(); | 1457 Deinit(); |
1502 } | 1458 } |
1503 | 1459 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 } | 1608 } |
1653 | 1609 |
1654 int VoiceChannel::GetOutputLevel_w() { | 1610 int VoiceChannel::GetOutputLevel_w() { |
1655 return media_channel()->GetOutputLevel(); | 1611 return media_channel()->GetOutputLevel(); |
1656 } | 1612 } |
1657 | 1613 |
1658 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { | 1614 void VoiceChannel::GetActiveStreams_w(AudioInfo::StreamList* actives) { |
1659 media_channel()->GetActiveStreams(actives); | 1615 media_channel()->GetActiveStreams(actives); |
1660 } | 1616 } |
1661 | 1617 |
1662 void VoiceChannel::OnPacketRead(rtc::PacketTransportInternal* transport, | |
1663 const char* data, | |
1664 size_t len, | |
1665 const rtc::PacketTime& 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 | |
1669 // media, this will disable the timeout. | |
1670 if (!received_media_ && !PacketIsRtcp(transport, data, len)) { | |
1671 received_media_ = true; | |
1672 } | |
1673 } | |
1674 | |
1675 void BaseChannel::UpdateMediaSendRecvState() { | 1618 void BaseChannel::UpdateMediaSendRecvState() { |
1676 RTC_DCHECK(network_thread_->IsCurrent()); | 1619 RTC_DCHECK(network_thread_->IsCurrent()); |
1677 invoker_.AsyncInvoke<void>( | 1620 invoker_.AsyncInvoke<void>( |
1678 RTC_FROM_HERE, worker_thread_, | 1621 RTC_FROM_HERE, worker_thread_, |
1679 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); | 1622 Bind(&BaseChannel::UpdateMediaSendRecvState_w, this)); |
1680 } | 1623 } |
1681 | 1624 |
1682 int BaseChannel::GetTransportOverheadPerPacket() const { | 1625 int BaseChannel::GetTransportOverheadPerPacket() const { |
1683 RTC_DCHECK(network_thread_->IsCurrent()); | 1626 RTC_DCHECK(network_thread_->IsCurrent()); |
1684 | 1627 |
(...skipping 28 matching lines...) Expand all Loading... | |
1713 | 1656 |
1714 void BaseChannel::UpdateTransportOverhead() { | 1657 void BaseChannel::UpdateTransportOverhead() { |
1715 int transport_overhead_per_packet = GetTransportOverheadPerPacket(); | 1658 int transport_overhead_per_packet = GetTransportOverheadPerPacket(); |
1716 if (transport_overhead_per_packet) | 1659 if (transport_overhead_per_packet) |
1717 invoker_.AsyncInvoke<void>( | 1660 invoker_.AsyncInvoke<void>( |
1718 RTC_FROM_HERE, worker_thread_, | 1661 RTC_FROM_HERE, worker_thread_, |
1719 Bind(&MediaChannel::OnTransportOverheadChanged, media_channel_, | 1662 Bind(&MediaChannel::OnTransportOverheadChanged, media_channel_, |
1720 transport_overhead_per_packet)); | 1663 transport_overhead_per_packet)); |
1721 } | 1664 } |
1722 | 1665 |
1666 void BaseChannel::OnFirstPacketReceived() { | |
1667 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_FIRSTPACKETRECEIVED); | |
1668 } | |
1669 | |
1723 void VoiceChannel::UpdateMediaSendRecvState_w() { | 1670 void VoiceChannel::UpdateMediaSendRecvState_w() { |
1724 // Render incoming data if we're the active call, and we have the local | 1671 // Render incoming data if we're the active call, and we have the local |
1725 // content. We receive data on the default channel and multiplexed streams. | 1672 // content. We receive data on the default channel and multiplexed streams. |
1726 bool recv = IsReadyToReceiveMedia_w(); | 1673 bool recv = IsReadyToReceiveMedia_w(); |
1727 media_channel()->SetPlayout(recv); | 1674 media_channel()->SetPlayout(recv); |
1728 | 1675 |
1729 // Send outgoing data if we're the active call, we have the remote content, | 1676 // Send outgoing data if we're the active call, we have the remote content, |
1730 // and we have had some form of connectivity. | 1677 // and we have had some form of connectivity. |
1731 bool send = IsReadyToSendMedia_w(); | 1678 bool send = IsReadyToSendMedia_w(); |
1732 media_channel()->SetSend(send); | 1679 media_channel()->SetSend(send); |
(...skipping 26 matching lines...) Expand all Loading... | |
1759 } | 1706 } |
1760 | 1707 |
1761 AudioRecvParameters recv_params = last_recv_params_; | 1708 AudioRecvParameters recv_params = last_recv_params_; |
1762 RtpParametersFromMediaDescription(audio, &recv_params); | 1709 RtpParametersFromMediaDescription(audio, &recv_params); |
1763 if (!media_channel()->SetRecvParameters(recv_params)) { | 1710 if (!media_channel()->SetRecvParameters(recv_params)) { |
1764 SafeSetError("Failed to set local audio description recv parameters.", | 1711 SafeSetError("Failed to set local audio description recv parameters.", |
1765 error_desc); | 1712 error_desc); |
1766 return false; | 1713 return false; |
1767 } | 1714 } |
1768 for (const AudioCodec& codec : audio->codecs()) { | 1715 for (const AudioCodec& codec : audio->codecs()) { |
1769 bundle_filter()->AddPayloadType(codec.id); | 1716 AddHandledPayloadType(codec.id); |
1770 } | 1717 } |
1771 last_recv_params_ = recv_params; | 1718 last_recv_params_ = recv_params; |
1772 | 1719 |
1773 // TODO(pthatcher): Move local streams into AudioSendParameters, and | 1720 // TODO(pthatcher): Move local streams into AudioSendParameters, and |
1774 // only give it to the media channel once we have a remote | 1721 // only give it to the media channel once we have a remote |
1775 // description too (without a remote description, we won't be able | 1722 // description too (without a remote description, we won't be able |
1776 // to send them anyway). | 1723 // to send them anyway). |
1777 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { | 1724 if (!UpdateLocalStreams_w(audio->streams(), action, error_desc)) { |
1778 SafeSetError("Failed to set local audio description streams.", error_desc); | 1725 SafeSetError("Failed to set local audio description streams.", error_desc); |
1779 return false; | 1726 return false; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1830 MaybeCacheRtpAbsSendTimeHeaderExtension_w(audio->rtp_header_extensions()); | 1777 MaybeCacheRtpAbsSendTimeHeaderExtension_w(audio->rtp_header_extensions()); |
1831 } | 1778 } |
1832 | 1779 |
1833 set_remote_content_direction(content->direction()); | 1780 set_remote_content_direction(content->direction()); |
1834 UpdateMediaSendRecvState_w(); | 1781 UpdateMediaSendRecvState_w(); |
1835 return true; | 1782 return true; |
1836 } | 1783 } |
1837 | 1784 |
1838 void VoiceChannel::HandleEarlyMediaTimeout() { | 1785 void VoiceChannel::HandleEarlyMediaTimeout() { |
1839 // This occurs on the main thread, not the worker thread. | 1786 // This occurs on the main thread, not the worker thread. |
1840 if (!received_media_) { | 1787 if (!received_media()) { |
1841 LOG(LS_INFO) << "No early media received before timeout"; | 1788 LOG(LS_INFO) << "No early media received before timeout"; |
1842 SignalEarlyMediaTimeout(this); | 1789 SignalEarlyMediaTimeout(this); |
1843 } | 1790 } |
1844 } | 1791 } |
1845 | 1792 |
1846 bool VoiceChannel::InsertDtmf_w(uint32_t ssrc, | 1793 bool VoiceChannel::InsertDtmf_w(uint32_t ssrc, |
1847 int event, | 1794 int event, |
1848 int duration) { | 1795 int duration) { |
1849 if (!enabled()) { | 1796 if (!enabled()) { |
1850 return false; | 1797 return false; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2032 } | 1979 } |
2033 | 1980 |
2034 VideoRecvParameters recv_params = last_recv_params_; | 1981 VideoRecvParameters recv_params = last_recv_params_; |
2035 RtpParametersFromMediaDescription(video, &recv_params); | 1982 RtpParametersFromMediaDescription(video, &recv_params); |
2036 if (!media_channel()->SetRecvParameters(recv_params)) { | 1983 if (!media_channel()->SetRecvParameters(recv_params)) { |
2037 SafeSetError("Failed to set local video description recv parameters.", | 1984 SafeSetError("Failed to set local video description recv parameters.", |
2038 error_desc); | 1985 error_desc); |
2039 return false; | 1986 return false; |
2040 } | 1987 } |
2041 for (const VideoCodec& codec : video->codecs()) { | 1988 for (const VideoCodec& codec : video->codecs()) { |
2042 bundle_filter()->AddPayloadType(codec.id); | 1989 AddHandledPayloadType(codec.id); |
2043 } | 1990 } |
2044 last_recv_params_ = recv_params; | 1991 last_recv_params_ = recv_params; |
2045 | 1992 |
2046 // TODO(pthatcher): Move local streams into VideoSendParameters, and | 1993 // TODO(pthatcher): Move local streams into VideoSendParameters, and |
2047 // only give it to the media channel once we have a remote | 1994 // only give it to the media channel once we have a remote |
2048 // description too (without a remote description, we won't be able | 1995 // description too (without a remote description, we won't be able |
2049 // to send them anyway). | 1996 // to send them anyway). |
2050 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { | 1997 if (!UpdateLocalStreams_w(video->streams(), action, error_desc)) { |
2051 SafeSetError("Failed to set local video description streams.", error_desc); | 1998 SafeSetError("Failed to set local video description streams.", error_desc); |
2052 return false; | 1999 return false; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2227 } | 2174 } |
2228 | 2175 |
2229 DataRecvParameters recv_params = last_recv_params_; | 2176 DataRecvParameters recv_params = last_recv_params_; |
2230 RtpParametersFromMediaDescription(data, &recv_params); | 2177 RtpParametersFromMediaDescription(data, &recv_params); |
2231 if (!media_channel()->SetRecvParameters(recv_params)) { | 2178 if (!media_channel()->SetRecvParameters(recv_params)) { |
2232 SafeSetError("Failed to set remote data description recv parameters.", | 2179 SafeSetError("Failed to set remote data description recv parameters.", |
2233 error_desc); | 2180 error_desc); |
2234 return false; | 2181 return false; |
2235 } | 2182 } |
2236 for (const DataCodec& codec : data->codecs()) { | 2183 for (const DataCodec& codec : data->codecs()) { |
2237 bundle_filter()->AddPayloadType(codec.id); | 2184 AddHandledPayloadType(codec.id); |
2238 } | 2185 } |
2239 last_recv_params_ = recv_params; | 2186 last_recv_params_ = recv_params; |
2240 | 2187 |
2241 // TODO(pthatcher): Move local streams into DataSendParameters, and | 2188 // TODO(pthatcher): Move local streams into DataSendParameters, and |
2242 // only give it to the media channel once we have a remote | 2189 // only give it to the media channel once we have a remote |
2243 // description too (without a remote description, we won't be able | 2190 // description too (without a remote description, we won't be able |
2244 // to send them anyway). | 2191 // to send them anyway). |
2245 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { | 2192 if (!UpdateLocalStreams_w(data->streams(), action, error_desc)) { |
2246 SafeSetError("Failed to set local data description streams.", error_desc); | 2193 SafeSetError("Failed to set local data description streams.", error_desc); |
2247 return false; | 2194 return false; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2400 | 2347 |
2401 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { | 2348 void RtpDataChannel::OnDataChannelReadyToSend(bool writable) { |
2402 // This is usded for congestion control to indicate that the stream is ready | 2349 // 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 | 2350 // to send by the MediaChannel, as opposed to OnReadyToSend, which indicates |
2404 // that the transport channel is ready. | 2351 // that the transport channel is ready. |
2405 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, | 2352 signaling_thread()->Post(RTC_FROM_HERE, this, MSG_READYTOSENDDATA, |
2406 new DataChannelReadyToSendMessageData(writable)); | 2353 new DataChannelReadyToSendMessageData(writable)); |
2407 } | 2354 } |
2408 | 2355 |
2409 } // namespace cricket | 2356 } // namespace cricket |
OLD | NEW |