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 kFlexfecPacketsToStoreBeforePacing = 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, kFlexfecPacketsToStoreBeforePacing); | |
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 std::unique_ptr<RtpPacketToSend> packet; |
693 packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | 704 if (ssrc == SSRC()) { |
694 retransmission); | 705 packet = packet_history_.GetPacketAndSetSendTime(sequence_number, 0, |
695 if (!packet) { | 706 retransmission); |
696 // Packet cannot be found. Allow sending to continue. | 707 } else if (ssrc == FlexfecSsrc()) { |
708 packet = flexfec_packet_history_.GetPacketAndSetSendTime(sequence_number, 0, | |
709 retransmission); | |
710 } else { | |
711 // Incorrect SSRC. Allow sending to continue. | |
danilchap
2016/11/11 15:26:06
because of if (!packet) return true; this block ca
brandtr
2016/11/14 09:48:09
Right. Removing block.
| |
697 return true; | 712 return true; |
698 } | 713 } |
699 | 714 |
715 if (!packet) { | |
716 // Packet cannot be found. | |
stefan-webrtc
2016/11/13 13:38:18
Should we log a warning?
brandtr
2016/11/14 09:48:09
That's already done within the packet history itse
| |
717 return true; | |
718 } | |
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, |
707 bool send_over_rtx, | 727 bool send_over_rtx, |
708 bool is_retransmit, | 728 bool is_retransmit, |
709 int probe_cluster_id) { | 729 int probe_cluster_id) { |
(...skipping 119 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 // There is no need to store FlexFEC packets in the history here, since we |
883 // packet here should be treated as any other packet drop so we should be | 910 // will never retransmit those. |
911 if (ssrc == flexfec_ssrc) | |
danilchap
2016/11/11 15:26:06
comment hint that instead you should check:
if (st
brandtr
2016/11/14 09:48:09
This would change how we store the packets in the
danilchap
2016/11/14 11:20:33
I think it is reasonable (no point to store someth
| |
912 return sent; | |
913 | |
914 // Mark the media packet as sent in the history even if send failed. Dropping | |
915 // a packet here should be treated as any other packet drop so we should be | |
884 // ready for a retransmission. | 916 // ready for a retransmission. |
885 packet_history_.PutRtpPacket(std::move(packet), storage, true); | 917 packet_history_.PutRtpPacket(std::move(packet), storage, true); |
886 | 918 |
887 return sent; | 919 return sent; |
888 } | 920 } |
889 | 921 |
890 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { | 922 void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { |
891 if (!send_side_delay_observer_ || capture_time_ms <= 0) | 923 if (!send_side_delay_observer_ || capture_time_ms <= 0) |
892 return; | 924 return; |
893 | 925 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 if (!sequence_number_forced_) { | 1114 if (!sequence_number_forced_) { |
1083 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); | 1115 sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber); |
1084 } | 1116 } |
1085 } | 1117 } |
1086 | 1118 |
1087 uint32_t RTPSender::SSRC() const { | 1119 uint32_t RTPSender::SSRC() const { |
1088 rtc::CritScope lock(&send_critsect_); | 1120 rtc::CritScope lock(&send_critsect_); |
1089 return ssrc_; | 1121 return ssrc_; |
1090 } | 1122 } |
1091 | 1123 |
1124 rtc::Optional<uint32_t> RTPSender::FlexfecSsrc() const { | |
1125 if (video_) { | |
1126 return video_->FlexfecSsrc(); | |
1127 } | |
1128 return rtc::Optional<uint32_t>(); | |
1129 } | |
1130 | |
1092 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { | 1131 void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) { |
1093 assert(csrcs.size() <= kRtpCsrcSize); | 1132 assert(csrcs.size() <= kRtpCsrcSize); |
1094 rtc::CritScope lock(&send_critsect_); | 1133 rtc::CritScope lock(&send_critsect_); |
1095 csrcs_ = csrcs; | 1134 csrcs_ = csrcs; |
1096 } | 1135 } |
1097 | 1136 |
1098 void RTPSender::SetSequenceNumber(uint16_t seq) { | 1137 void RTPSender::SetSequenceNumber(uint16_t seq) { |
1099 rtc::CritScope lock(&send_critsect_); | 1138 rtc::CritScope lock(&send_critsect_); |
1100 sequence_number_forced_ = true; | 1139 sequence_number_forced_ = true; |
1101 sequence_number_ = seq; | 1140 sequence_number_ = seq; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1238 rtc::CritScope lock(&send_critsect_); | 1277 rtc::CritScope lock(&send_critsect_); |
1239 | 1278 |
1240 RtpState state; | 1279 RtpState state; |
1241 state.sequence_number = sequence_number_rtx_; | 1280 state.sequence_number = sequence_number_rtx_; |
1242 state.start_timestamp = timestamp_offset_; | 1281 state.start_timestamp = timestamp_offset_; |
1243 | 1282 |
1244 return state; | 1283 return state; |
1245 } | 1284 } |
1246 | 1285 |
1247 } // namespace webrtc | 1286 } // namespace webrtc |
OLD | NEW |