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 |
11 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_impl.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <algorithm> | |
15 #include <set> | 16 #include <set> |
16 #include <string> | 17 #include <string> |
17 | 18 |
18 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
20 #include "webrtc/common_types.h" | 21 #include "webrtc/common_types.h" |
21 #include "webrtc/config.h" | 22 #include "webrtc/config.h" |
22 | 23 |
23 #ifdef _WIN32 | 24 #ifdef _WIN32 |
24 // Disable warning C4355: 'this' : used in base member initializer list. | 25 // Disable warning C4355: 'this' : used in base member initializer list. |
25 #pragma warning(disable : 4355) | 26 #pragma warning(disable : 4355) |
26 #endif | 27 #endif |
27 | 28 |
28 namespace webrtc { | 29 namespace webrtc { |
30 namespace { | |
31 const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; | |
32 const int64_t kRtpRtcpRttProcessTimeMs = 1000; | |
33 const int64_t kRtpRtcpBitrateProcessTimeMs = 10; | |
34 } // namespace | |
29 | 35 |
30 RTPExtensionType StringToRtpExtensionType(const std::string& extension) { | 36 RTPExtensionType StringToRtpExtensionType(const std::string& extension) { |
31 if (extension == RtpExtension::kTimestampOffsetUri) | 37 if (extension == RtpExtension::kTimestampOffsetUri) |
32 return kRtpExtensionTransmissionTimeOffset; | 38 return kRtpExtensionTransmissionTimeOffset; |
33 if (extension == RtpExtension::kAudioLevelUri) | 39 if (extension == RtpExtension::kAudioLevelUri) |
34 return kRtpExtensionAudioLevel; | 40 return kRtpExtensionAudioLevel; |
35 if (extension == RtpExtension::kAbsSendTimeUri) | 41 if (extension == RtpExtension::kAbsSendTimeUri) |
36 return kRtpExtensionAbsoluteSendTime; | 42 return kRtpExtensionAbsoluteSendTime; |
37 if (extension == RtpExtension::kVideoRotationUri) | 43 if (extension == RtpExtension::kVideoRotationUri) |
38 return kRtpExtensionVideoRotation; | 44 return kRtpExtensionVideoRotation; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 rtcp_receiver_(configuration.clock, | 88 rtcp_receiver_(configuration.clock, |
83 configuration.receiver_only, | 89 configuration.receiver_only, |
84 configuration.rtcp_packet_type_counter_observer, | 90 configuration.rtcp_packet_type_counter_observer, |
85 configuration.bandwidth_callback, | 91 configuration.bandwidth_callback, |
86 configuration.intra_frame_callback, | 92 configuration.intra_frame_callback, |
87 configuration.transport_feedback_callback, | 93 configuration.transport_feedback_callback, |
88 configuration.bitrate_allocation_observer, | 94 configuration.bitrate_allocation_observer, |
89 this), | 95 this), |
90 clock_(configuration.clock), | 96 clock_(configuration.clock), |
91 audio_(configuration.audio), | 97 audio_(configuration.audio), |
92 last_process_time_(configuration.clock->TimeInMilliseconds()), | 98 keepalive_config_(configuration.keepalive_config), |
93 last_bitrate_process_time_(configuration.clock->TimeInMilliseconds()), | 99 last_process_time_(clock_->TimeInMilliseconds()), |
94 last_rtt_process_time_(configuration.clock->TimeInMilliseconds()), | 100 last_bitrate_process_time_(clock_->TimeInMilliseconds()), |
101 last_rtt_process_time_(clock_->TimeInMilliseconds()), | |
102 next_process_time_(clock_->TimeInMilliseconds() + | |
103 kRtpRtcpMaxIdleTimeProcessMs), | |
104 next_keepalive_time_(-1), | |
95 packet_overhead_(28), // IPV4 UDP. | 105 packet_overhead_(28), // IPV4 UDP. |
96 nack_last_time_sent_full_(0), | 106 nack_last_time_sent_full_(0), |
97 nack_last_time_sent_full_prev_(0), | 107 nack_last_time_sent_full_prev_(0), |
98 nack_last_seq_number_sent_(0), | 108 nack_last_seq_number_sent_(0), |
99 key_frame_req_method_(kKeyFrameReqPliRtcp), | 109 key_frame_req_method_(kKeyFrameReqPliRtcp), |
100 remote_bitrate_(configuration.remote_bitrate_estimator), | 110 remote_bitrate_(configuration.remote_bitrate_estimator), |
101 rtt_stats_(configuration.rtt_stats), | 111 rtt_stats_(configuration.rtt_stats), |
102 rtt_ms_(0) { | 112 rtt_ms_(0) { |
103 if (!configuration.receiver_only) { | 113 if (!configuration.receiver_only) { |
104 rtp_sender_.reset(new RTPSender( | 114 rtp_sender_.reset(new RTPSender( |
105 configuration.audio, | 115 configuration.audio, |
106 configuration.clock, | 116 configuration.clock, |
107 configuration.outgoing_transport, | 117 configuration.outgoing_transport, |
108 configuration.paced_sender, | 118 configuration.paced_sender, |
109 configuration.flexfec_sender, | 119 configuration.flexfec_sender, |
110 configuration.transport_sequence_number_allocator, | 120 configuration.transport_sequence_number_allocator, |
111 configuration.transport_feedback_callback, | 121 configuration.transport_feedback_callback, |
112 configuration.send_bitrate_observer, | 122 configuration.send_bitrate_observer, |
113 configuration.send_frame_count_observer, | 123 configuration.send_frame_count_observer, |
114 configuration.send_side_delay_observer, | 124 configuration.send_side_delay_observer, |
115 configuration.event_log, | 125 configuration.event_log, |
116 configuration.send_packet_observer, | 126 configuration.send_packet_observer, |
117 configuration.retransmission_rate_limiter, | 127 configuration.retransmission_rate_limiter, |
118 configuration.overhead_observer)); | 128 configuration.overhead_observer)); |
119 // Make sure rtcp sender use same timestamp offset as rtp sender. | 129 // Make sure rtcp sender use same timestamp offset as rtp sender. |
120 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset()); | 130 rtcp_sender_.SetTimestampOffset(rtp_sender_->TimestampOffset()); |
131 | |
132 if (keepalive_config_.timeout_interval_ms != -1) { | |
133 next_keepalive_time_ = | |
134 clock_->TimeInMilliseconds() + keepalive_config_.timeout_interval_ms; | |
135 } | |
121 } | 136 } |
122 | 137 |
123 // Set default packet size limit. | 138 // Set default packet size limit. |
124 // TODO(nisse): Kind-of duplicates | 139 // TODO(nisse): Kind-of duplicates |
125 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize. | 140 // webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize. |
126 const size_t kTcpOverIpv4HeaderSize = 40; | 141 const size_t kTcpOverIpv4HeaderSize = 40; |
127 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); | 142 SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize); |
128 } | 143 } |
129 | 144 |
130 // Returns the number of milliseconds until the module want a worker thread | 145 // Returns the number of milliseconds until the module want a worker thread |
131 // to call Process. | 146 // to call Process. |
132 int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { | 147 int64_t ModuleRtpRtcpImpl::TimeUntilNextProcess() { |
133 const int64_t now = clock_->TimeInMilliseconds(); | 148 return std::max<int64_t>(0, |
134 const int64_t kRtpRtcpMaxIdleTimeProcessMs = 5; | 149 next_process_time_ - clock_->TimeInMilliseconds()); |
135 return kRtpRtcpMaxIdleTimeProcessMs - (now - last_process_time_); | |
136 } | 150 } |
137 | 151 |
138 // Process any pending tasks such as timeouts (non time critical events). | 152 // Process any pending tasks such as timeouts (non time critical events). |
139 void ModuleRtpRtcpImpl::Process() { | 153 void ModuleRtpRtcpImpl::Process() { |
140 const int64_t now = clock_->TimeInMilliseconds(); | 154 const int64_t now = clock_->TimeInMilliseconds(); |
141 last_process_time_ = now; | 155 last_process_time_ = now; |
åsapersson
2017/06/30 15:09:13
is last_process_time_ still needed?
sprang_webrtc
2017/06/30 16:20:59
No, cleaned up.
| |
156 next_process_time_ = last_process_time_ + kRtpRtcpMaxIdleTimeProcessMs; | |
142 | 157 |
143 if (rtp_sender_) { | 158 if (rtp_sender_) { |
144 const int64_t kRtpRtcpBitrateProcessTimeMs = 10; | |
145 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { | 159 if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) { |
146 rtp_sender_->ProcessBitrate(); | 160 rtp_sender_->ProcessBitrate(); |
147 last_bitrate_process_time_ = now; | 161 last_bitrate_process_time_ = now; |
162 next_process_time_ = | |
163 std::min(next_process_time_, now + kRtpRtcpBitrateProcessTimeMs); | |
164 } | |
165 if (keepalive_config_.timeout_interval_ms > 0 && | |
166 now >= next_keepalive_time_) { | |
167 int64_t last_send_time_ms = rtp_sender_->LastTimestampTimeMs(); | |
åsapersson
2017/06/30 15:09:13
check if last_send_time_ms is set?
sprang_webrtc
2017/06/30 16:20:59
There's no need, since if it's not set it will ret
| |
168 if (now >= last_send_time_ms + keepalive_config_.timeout_interval_ms) { | |
169 rtp_sender_->SendKeepAlive(keepalive_config_.payload_type); | |
170 next_keepalive_time_ = now + keepalive_config_.timeout_interval_ms; | |
171 } else { | |
172 next_keepalive_time_ = | |
173 last_send_time_ms + keepalive_config_.timeout_interval_ms; | |
174 } | |
175 next_process_time_ = std::min(next_process_time_, next_keepalive_time_); | |
148 } | 176 } |
149 } | 177 } |
150 const int64_t kRtpRtcpRttProcessTimeMs = 1000; | 178 |
151 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; | 179 bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs; |
152 if (rtcp_sender_.Sending()) { | 180 if (rtcp_sender_.Sending()) { |
153 // Process RTT if we have received a receiver report and we haven't | 181 // Process RTT if we have received a receiver report and we haven't |
154 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. | 182 // processed RTT for at least |kRtpRtcpRttProcessTimeMs| milliseconds. |
155 if (rtcp_receiver_.LastReceivedReceiverReport() > | 183 if (rtcp_receiver_.LastReceivedReceiverReport() > |
156 last_rtt_process_time_ && process_rtt) { | 184 last_rtt_process_time_ && process_rtt) { |
157 std::vector<RTCPReportBlock> receive_blocks; | 185 std::vector<RTCPReportBlock> receive_blocks; |
158 rtcp_receiver_.StatisticsReceived(&receive_blocks); | 186 rtcp_receiver_.StatisticsReceived(&receive_blocks); |
159 int64_t max_rtt = 0; | 187 int64_t max_rtt = 0; |
160 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin(); | 188 for (std::vector<RTCPReportBlock>::iterator it = receive_blocks.begin(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 int64_t rtt_ms; | 222 int64_t rtt_ms; |
195 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { | 223 if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) { |
196 rtt_stats_->OnRttUpdate(rtt_ms); | 224 rtt_stats_->OnRttUpdate(rtt_ms); |
197 } | 225 } |
198 } | 226 } |
199 } | 227 } |
200 | 228 |
201 // Get processed rtt. | 229 // Get processed rtt. |
202 if (process_rtt) { | 230 if (process_rtt) { |
203 last_rtt_process_time_ = now; | 231 last_rtt_process_time_ = now; |
232 next_process_time_ = std::min( | |
233 next_process_time_, last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs); | |
204 if (rtt_stats_) { | 234 if (rtt_stats_) { |
205 // Make sure we have a valid RTT before setting. | 235 // Make sure we have a valid RTT before setting. |
206 int64_t last_rtt = rtt_stats_->LastProcessedRtt(); | 236 int64_t last_rtt = rtt_stats_->LastProcessedRtt(); |
207 if (last_rtt >= 0) | 237 if (last_rtt >= 0) |
208 set_rtt_ms(last_rtt); | 238 set_rtt_ms(last_rtt); |
209 } | 239 } |
210 } | 240 } |
211 | 241 |
212 if (rtcp_sender_.TimeToSendRTCPReport()) | 242 if (rtcp_sender_.TimeToSendRTCPReport()) |
213 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); | 243 rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 StreamDataCountersCallback* | 916 StreamDataCountersCallback* |
887 ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { | 917 ModuleRtpRtcpImpl::GetSendChannelRtpStatisticsCallback() const { |
888 return rtp_sender_->GetRtpStatisticsCallback(); | 918 return rtp_sender_->GetRtpStatisticsCallback(); |
889 } | 919 } |
890 | 920 |
891 void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( | 921 void ModuleRtpRtcpImpl::SetVideoBitrateAllocation( |
892 const BitrateAllocation& bitrate) { | 922 const BitrateAllocation& bitrate) { |
893 rtcp_sender_.SetVideoBitrateAllocation(bitrate); | 923 rtcp_sender_.SetVideoBitrateAllocation(bitrate); |
894 } | 924 } |
895 } // namespace webrtc | 925 } // namespace webrtc |
OLD | NEW |