OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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/remote_bitrate_estimator/remote_estimator_proxy.h" | 11 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <algorithm> | 14 #include <algorithm> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/safe_minmax.h" |
| 19 #include "webrtc/modules/pacing/packet_router.h" |
| 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
18 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
19 #include "webrtc/modules/pacing/packet_router.h" | |
20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | |
21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 | 25 |
25 // TODO(sprang): Tune these! | 26 // TODO(sprang): Tune these! |
26 const int RemoteEstimatorProxy::kBackWindowMs = 500; | 27 const int RemoteEstimatorProxy::kBackWindowMs = 500; |
27 const int RemoteEstimatorProxy::kMinSendIntervalMs = 50; | 28 const int RemoteEstimatorProxy::kMinSendIntervalMs = 50; |
28 const int RemoteEstimatorProxy::kMaxSendIntervalMs = 250; | 29 const int RemoteEstimatorProxy::kMaxSendIntervalMs = 250; |
29 const int RemoteEstimatorProxy::kDefaultSendIntervalMs = 100; | 30 const int RemoteEstimatorProxy::kDefaultSendIntervalMs = 100; |
30 | 31 |
31 // The maximum allowed value for a timestamp in milliseconds. This is lower | 32 // The maximum allowed value for a timestamp in milliseconds. This is lower |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // TwccReport size at 250ms interval is 36 byte. | 98 // TwccReport size at 250ms interval is 36 byte. |
98 // AverageTwccReport = (TwccReport(50ms) + TwccReport(250ms)) / 2 | 99 // AverageTwccReport = (TwccReport(50ms) + TwccReport(250ms)) / 2 |
99 constexpr int kTwccReportSize = 20 + 8 + 10 + 30; | 100 constexpr int kTwccReportSize = 20 + 8 + 10 + 30; |
100 constexpr double kMinTwccRate = | 101 constexpr double kMinTwccRate = |
101 kTwccReportSize * 8.0 * 1000.0 / kMaxSendIntervalMs; | 102 kTwccReportSize * 8.0 * 1000.0 / kMaxSendIntervalMs; |
102 constexpr double kMaxTwccRate = | 103 constexpr double kMaxTwccRate = |
103 kTwccReportSize * 8.0 * 1000.0 / kMinSendIntervalMs; | 104 kTwccReportSize * 8.0 * 1000.0 / kMinSendIntervalMs; |
104 | 105 |
105 // Let TWCC reports occupy 5% of total bandwidth. | 106 // Let TWCC reports occupy 5% of total bandwidth. |
106 rtc::CritScope cs(&lock_); | 107 rtc::CritScope cs(&lock_); |
107 send_interval_ms_ = static_cast<int>(0.5 + kTwccReportSize * 8.0 * 1000.0 / | 108 send_interval_ms_ = static_cast<int>( |
108 (std::max(std::min(0.05 * bitrate_bps, kMaxTwccRate), kMinTwccRate))); | 109 0.5 + kTwccReportSize * 8.0 * 1000.0 / |
| 110 rtc::SafeClamp(0.05 * bitrate_bps, kMinTwccRate, kMaxTwccRate)); |
109 } | 111 } |
110 | 112 |
111 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, | 113 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, |
112 int64_t arrival_time) { | 114 int64_t arrival_time) { |
113 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { | 115 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { |
114 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; | 116 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; |
115 return; | 117 return; |
116 } | 118 } |
117 | 119 |
118 // TODO(holmer): We should handle a backwards wrap here if the first | 120 // TODO(holmer): We should handle a backwards wrap here if the first |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // Note: Don't erase items from packet_arrival_times_ after sending, in case | 192 // Note: Don't erase items from packet_arrival_times_ after sending, in case |
191 // they need to be re-sent after a reordering. Removal will be handled | 193 // they need to be re-sent after a reordering. Removal will be handled |
192 // by OnPacketArrival once packets are too old. | 194 // by OnPacketArrival once packets are too old. |
193 window_start_seq_ = it->first + 1; | 195 window_start_seq_ = it->first + 1; |
194 } | 196 } |
195 | 197 |
196 return true; | 198 return true; |
197 } | 199 } |
198 | 200 |
199 } // namespace webrtc | 201 } // namespace webrtc |
OLD | NEW |