OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 namespace { | 35 namespace { |
36 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. | 36 // Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP. |
37 constexpr size_t kMaxPaddingLength = 224; | 37 constexpr size_t kMaxPaddingLength = 224; |
38 constexpr int kSendSideDelayWindowMs = 1000; | 38 constexpr int kSendSideDelayWindowMs = 1000; |
39 constexpr size_t kRtpHeaderLength = 12; | 39 constexpr size_t kRtpHeaderLength = 12; |
40 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. | 40 constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1. |
41 constexpr uint32_t kTimestampTicksPerMs = 90; | 41 constexpr uint32_t kTimestampTicksPerMs = 90; |
42 constexpr int kBitrateStatisticsWindowMs = 1000; | 42 constexpr int kBitrateStatisticsWindowMs = 1000; |
43 | 43 |
44 constexpr size_t kMinFlexfecPacketsToStoreForPacing = 50; | |
45 | |
44 const char* FrameTypeToString(FrameType frame_type) { | 46 const char* FrameTypeToString(FrameType frame_type) { |
45 switch (frame_type) { | 47 switch (frame_type) { |
46 case kEmptyFrame: | 48 case kEmptyFrame: |
47 return "empty"; | 49 return "empty"; |
48 case kAudioFrameSpeech: return "audio_speech"; | 50 case kAudioFrameSpeech: return "audio_speech"; |
49 case kAudioFrameCN: return "audio_cn"; | 51 case kAudioFrameCN: return "audio_cn"; |
50 case kVideoFrameKey: return "video_key"; | 52 case kVideoFrameKey: return "video_key"; |
51 case kVideoFrameDelta: return "video_delta"; | 53 case kVideoFrameDelta: return "video_delta"; |
52 } | 54 } |
53 return ""; | 55 return ""; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 transport_sequence_number_allocator_(sequence_number_allocator), | 89 transport_sequence_number_allocator_(sequence_number_allocator), |
88 transport_feedback_observer_(transport_feedback_observer), | 90 transport_feedback_observer_(transport_feedback_observer), |
89 last_capture_time_ms_sent_(0), | 91 last_capture_time_ms_sent_(0), |
90 transport_(transport), | 92 transport_(transport), |
91 sending_media_(true), // Default to sending media. | 93 sending_media_(true), // Default to sending media. |
92 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. | 94 max_payload_length_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP. |
93 payload_type_(-1), | 95 payload_type_(-1), |
94 payload_type_map_(), | 96 payload_type_map_(), |
95 rtp_header_extension_map_(), | 97 rtp_header_extension_map_(), |
96 packet_history_(clock), | 98 packet_history_(clock), |
99 flexfec_packet_history_(clock), | |
97 // Statistics | 100 // Statistics |
98 rtp_stats_callback_(nullptr), | 101 rtp_stats_callback_(nullptr), |
99 total_bitrate_sent_(kBitrateStatisticsWindowMs, | 102 total_bitrate_sent_(kBitrateStatisticsWindowMs, |
100 RateStatistics::kBpsScale), | 103 RateStatistics::kBpsScale), |
101 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), | 104 nack_bitrate_sent_(kBitrateStatisticsWindowMs, RateStatistics::kBpsScale), |
102 frame_count_observer_(frame_count_observer), | 105 frame_count_observer_(frame_count_observer), |
103 send_side_delay_observer_(send_side_delay_observer), | 106 send_side_delay_observer_(send_side_delay_observer), |
104 event_log_(event_log), | 107 event_log_(event_log), |
105 send_packet_observer_(send_packet_observer), | 108 send_packet_observer_(send_packet_observer), |
106 bitrate_callback_(bitrate_callback), | 109 bitrate_callback_(bitrate_callback), |
(...skipping 13 matching lines...) Expand all Loading... | |
120 ssrc_ = ssrc_db_->CreateSSRC(); | 123 ssrc_ = ssrc_db_->CreateSSRC(); |
121 RTC_DCHECK(ssrc_ != 0); | 124 RTC_DCHECK(ssrc_ != 0); |
122 ssrc_rtx_ = ssrc_db_->CreateSSRC(); | 125 ssrc_rtx_ = ssrc_db_->CreateSSRC(); |
123 RTC_DCHECK(ssrc_rtx_ != 0); | 126 RTC_DCHECK(ssrc_rtx_ != 0); |
124 | 127 |
125 // This random initialization is not intended to be cryptographic strong. | 128 // This random initialization is not intended to be cryptographic strong. |
126 timestamp_offset_ = random_.Rand<uint32_t>(); | 129 timestamp_offset_ = random_.Rand<uint32_t>(); |
127 // Random start, 16 bits. Can't be 0. | 130 // Random start, 16 bits. Can't be 0. |
128 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 131 sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
129 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 132 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
133 | |
134 // Store FlexFEC packets in the packet history data structure, so they can | |
135 // be found when paced. | |
136 if (flexfec_sender) { | |
137 flexfec_packet_history_.SetStorePacketsStatus( | |
138 true, kMinFlexfecPacketsToStoreForPacing); | |
139 } | |
130 } | 140 } |
131 | 141 |
132 RTPSender::~RTPSender() { | 142 RTPSender::~RTPSender() { |
133 // TODO(tommi): Use a thread checker to ensure the object is created and | 143 // TODO(tommi): Use a thread checker to ensure the object is created and |
134 // deleted on the same thread. At the moment this isn't possible due to | 144 // deleted on the same thread. At the moment this isn't possible due to |
135 // voe::ChannelOwner in voice engine. To reproduce, run: | 145 // voe::ChannelOwner in voice engine. To reproduce, run: |
136 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus | 146 // voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus |
137 | 147 |
138 // TODO(tommi,holmer): We don't grab locks in the dtor before accessing member | 148 // TODO(tommi,holmer): We don't grab locks in the dtor before accessing member |
139 // variables but we grab them in all other methods. (what's the design?) | 149 // variables but we grab them in all other methods. (what's the design?) |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 } | 688 } |
679 } | 689 } |
680 } | 690 } |
681 | 691 |
682 void RTPSender::OnReceivedRtcpReportBlocks( | 692 void RTPSender::OnReceivedRtcpReportBlocks( |
683 const ReportBlockList& report_blocks) { | 693 const ReportBlockList& report_blocks) { |
684 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); | 694 playout_delay_oracle_.OnReceivedRtcpReportBlocks(report_blocks); |
685 } | 695 } |
686 | 696 |
687 // Called from pacer when we can send the packet. | 697 // Called from pacer when we can send the packet. |
688 bool RTPSender::TimeToSendPacket(uint16_t sequence_number, | 698 bool RTPSender::TimeToSendPacket(uint32_t ssrc, |
699 uint16_t sequence_number, | |
689 int64_t capture_time_ms, | 700 int64_t capture_time_ms, |
690 bool retransmission, | 701 bool retransmission, |
691 int probe_cluster_id) { | 702 int probe_cluster_id) { |
692 std::unique_ptr<RtpPacketToSend> packet = | 703 if (!SendingMedia()) |
693 packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | 704 return true; |
694 retransmission); | 705 |
706 std::unique_ptr<RtpPacketToSend> packet; | |
707 if (ssrc == SSRC()) { | |
708 packet = packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | |
709 retransmission); | |
710 } else if (ssrc == FlexfecSsrc()) { | |
711 packet = flexfec_packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | |
712 retransmission); | |
713 } | |
714 | |
695 if (!packet) { | 715 if (!packet) { |
696 // Packet cannot be found. Allow sending to continue. | 716 // Packet cannot be found. |
697 return true; | 717 return true; |
698 } | 718 } |
699 | 719 |
700 return PrepareAndSendPacket( | 720 return PrepareAndSendPacket( |
701 std::move(packet), | 721 std::move(packet), |
702 retransmission && (RtxStatus() & kRtxRetransmitted) > 0, retransmission, | 722 retransmission && (RtxStatus() & kRtxRetransmitted) > 0, retransmission, |
703 probe_cluster_id); | 723 probe_cluster_id); |
704 } | 724 } |
705 | 725 |
706 bool RTPSender::PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet, | 726 bool RTPSender::PrepareAndSendPacket(std::unique_ptr<RtpPacketToSend> packet, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 FecOverheadRate() / 1000, packet->Ssrc()); | 849 FecOverheadRate() / 1000, packet->Ssrc()); |
830 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoNackBitrate_kbps", now_ms, | 850 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "VideoNackBitrate_kbps", now_ms, |
831 NackOverheadRate() / 1000, packet->Ssrc()); | 851 NackOverheadRate() / 1000, packet->Ssrc()); |
832 } else { | 852 } else { |
833 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioTotBitrate_kbps", now_ms, | 853 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioTotBitrate_kbps", now_ms, |
834 ActualSendBitrateKbit(), packet->Ssrc()); | 854 ActualSendBitrateKbit(), packet->Ssrc()); |
835 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioNackBitrate_kbps", now_ms, | 855 BWE_TEST_LOGGING_PLOT_WITH_SSRC(1, "AudioNackBitrate_kbps", now_ms, |
836 NackOverheadRate() / 1000, packet->Ssrc()); | 856 NackOverheadRate() / 1000, packet->Ssrc()); |
837 } | 857 } |
838 | 858 |
859 uint32_t ssrc = packet->Ssrc(); | |
860 rtc::Optional<uint32_t> flexfec_ssrc = FlexfecSsrc(); | |
839 if (paced_sender_) { | 861 if (paced_sender_) { |
840 uint16_t seq_no = packet->SequenceNumber(); | 862 uint16_t seq_no = packet->SequenceNumber(); |
841 uint32_t ssrc = packet->Ssrc(); | |
842 // Correct offset between implementations of millisecond time stamps in | 863 // Correct offset between implementations of millisecond time stamps in |
843 // TickTime and Clock. | 864 // TickTime and Clock. |
844 int64_t corrected_time_ms = packet->capture_time_ms() + clock_delta_ms_; | 865 int64_t corrected_time_ms = packet->capture_time_ms() + clock_delta_ms_; |
845 size_t payload_length = packet->payload_size(); | 866 size_t payload_length = packet->payload_size(); |
846 packet_history_.PutRtpPacket(std::move(packet), storage, false); | 867 if (ssrc == flexfec_ssrc) { |
868 // Store FlexFEC packets in the history here, so they can be found | |
869 // when the pacer calls TimeToSendPacket. | |
870 flexfec_packet_history_.PutRtpPacket(std::move(packet), storage, false); | |
871 } else { | |
872 packet_history_.PutRtpPacket(std::move(packet), storage, false); | |
873 } | |
847 | 874 |
848 paced_sender_->InsertPacket(priority, ssrc, seq_no, corrected_time_ms, | 875 paced_sender_->InsertPacket(priority, ssrc, seq_no, corrected_time_ms, |
849 payload_length, false); | 876 payload_length, false); |
850 if (last_capture_time_ms_sent_ == 0 || | 877 if (last_capture_time_ms_sent_ == 0 || |
851 corrected_time_ms > last_capture_time_ms_sent_) { | 878 corrected_time_ms > last_capture_time_ms_sent_) { |
852 last_capture_time_ms_sent_ = corrected_time_ms; | 879 last_capture_time_ms_sent_ = corrected_time_ms; |
853 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), | 880 TRACE_EVENT_ASYNC_BEGIN1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
854 "PacedSend", corrected_time_ms, | 881 "PacedSend", corrected_time_ms, |
855 "capture_time_ms", corrected_time_ms); | 882 "capture_time_ms", corrected_time_ms); |
856 } | 883 } |
(...skipping 15 matching lines...) Expand all Loading... | |
872 bool sent = SendPacketToNetwork(*packet, options); | 899 bool sent = SendPacketToNetwork(*packet, options); |
873 | 900 |
874 if (sent) { | 901 if (sent) { |
875 { | 902 { |
876 rtc::CritScope lock(&send_critsect_); | 903 rtc::CritScope lock(&send_critsect_); |
877 media_has_been_sent_ = true; | 904 media_has_been_sent_ = true; |
878 } | 905 } |
879 UpdateRtpStats(*packet, false, false); | 906 UpdateRtpStats(*packet, false, false); |
880 } | 907 } |
881 | 908 |
882 // Mark the packet as sent in the history even if send failed. Dropping a | 909 // To support retransmissions, we store the media packet as sent in the |
883 // packet here should be treated as any other packet drop so we should be | 910 // packet history (even if send failed). |
884 // ready for a retransmission. | 911 if (storage == kAllowRetransmission) { |
brandtr
2016/11/14 12:36:20
I thought it was nice to check the complement (i.e
| |
885 packet_history_.PutRtpPacket(std::move(packet), storage, true); | 912 RTC_DCHECK_EQ(ssrc, SSRC()); |
913 packet_history_.PutRtpPacket(std::move(packet), storage, true); | |
914 } | |
886 | 915 |
887 return sent; | 916 return sent; |
888 } | 917 } |
889 | 918 |
890 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 919 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { |
891 if (!send_side_delay_observer_ || capture_time_ms <= 0) | 920 if (!send_side_delay_observer_ || capture_time_ms <= 0) |
892 return; | 921 return; |
893 | 922 |
894 uint32_t ssrc; | 923 uint32_t ssrc; |
895 int avg_delay_ms = 0; | 924 int avg_delay_ms = 0; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 if (!sequence_number_forced_) { | 1111 if (!sequence_number_forced_) { |
1083 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 1112 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
1084 } | 1113 } |
1085 } | 1114 } |
1086 | 1115 |
1087 uint32_t RTPSender::SSRC() const { | 1116 uint32_t RTPSender::SSRC() const { |
1088 rtc::CritScope lock(&send_critsect_); | 1117 rtc::CritScope lock(&send_critsect_); |
1089 return ssrc_; | 1118 return ssrc_; |
1090 } | 1119 } |
1091 | 1120 |
1121 rtc::Optional<uint32_t> RTPSender::FlexfecSsrc() const { | |
1122 if (video_) { | |
1123 return video_->FlexfecSsrc(); | |
1124 } | |
1125 return rtc::Optional<uint32_t>(); | |
1126 } | |
1127 | |
1092 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 1128 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
1093 assert(csrcs.size() <= kRtpCsrcSize); | 1129 assert(csrcs.size() <= kRtpCsrcSize); |
1094 rtc::CritScope lock(&send_critsect_); | 1130 rtc::CritScope lock(&send_critsect_); |
1095 csrcs_ = csrcs; | 1131 csrcs_ = csrcs; |
1096 } | 1132 } |
1097 | 1133 |
1098 void RTPSender::SetSequenceNumber(uint16_t seq) { | 1134 void RTPSender::SetSequenceNumber(uint16_t seq) { |
1099 rtc::CritScope lock(&send_critsect_); | 1135 rtc::CritScope lock(&send_critsect_); |
1100 sequence_number_forced_ = true; | 1136 sequence_number_forced_ = true; |
1101 sequence_number_ = seq; | 1137 sequence_number_ = seq; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1234 rtc::CritScope lock(&send_critsect_); | 1270 rtc::CritScope lock(&send_critsect_); |
1235 | 1271 |
1236 RtpState state; | 1272 RtpState state; |
1237 state.sequence_number = sequence_number_rtx_; | 1273 state.sequence_number = sequence_number_rtx_; |
1238 state.start_timestamp = timestamp_offset_; | 1274 state.start_timestamp = timestamp_offset_; |
1239 | 1275 |
1240 return state; | 1276 return state; |
1241 } | 1277 } |
1242 | 1278 |
1243 } // namespace webrtc | 1279 } // namespace webrtc |
OLD | NEW |