Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.cc

Issue 2381833003: Change TWCC send interval to reduce overhead on low BW situations. (Closed)
Patch Set: fix nit's Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15
15 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
16 #include "webrtc/base/logging.h" 17 #include "webrtc/base/logging.h"
17 #include "webrtc/system_wrappers/include/clock.h" 18 #include "webrtc/system_wrappers/include/clock.h"
18 #include "webrtc/modules/pacing/packet_router.h" 19 #include "webrtc/modules/pacing/packet_router.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" 20 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
21 22
22 namespace webrtc { 23 namespace webrtc {
23 24
24 // TODO(sprang): Tune these! 25 // TODO(sprang): Tune these!
25 const int RemoteEstimatorProxy::kDefaultProcessIntervalMs = 50;
26 const int RemoteEstimatorProxy::kBackWindowMs = 500; 26 const int RemoteEstimatorProxy::kBackWindowMs = 500;
27 const int RemoteEstimatorProxy::kMinSendIntervalMs = 50;
28 const int RemoteEstimatorProxy::kMaxSendIntervalMs = 250;
29 const int RemoteEstimatorProxy::kDefaultSendIntervalMs = 100;
27 30
28 // The maximum allowed value for a timestamp in milliseconds. This is lower 31 // The maximum allowed value for a timestamp in milliseconds. This is lower
29 // than the numerical limit since we often convert to microseconds. 32 // than the numerical limit since we often convert to microseconds.
30 static constexpr int64_t kMaxTimeMs = 33 static constexpr int64_t kMaxTimeMs =
31 std::numeric_limits<int64_t>::max() / 1000; 34 std::numeric_limits<int64_t>::max() / 1000;
32 35
33 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock, 36 RemoteEstimatorProxy::RemoteEstimatorProxy(Clock* clock,
34 PacketRouter* packet_router) 37 PacketRouter* packet_router)
35 : clock_(clock), 38 : clock_(clock),
36 packet_router_(packet_router), 39 packet_router_(packet_router),
37 last_process_time_ms_(-1), 40 last_process_time_ms_(-1),
38 media_ssrc_(0), 41 media_ssrc_(0),
39 feedback_sequence_(0), 42 feedback_sequence_(0),
40 window_start_seq_(-1) {} 43 window_start_seq_(-1),
44 send_interval_ms_(kDefaultSendIntervalMs) {}
41 45
42 RemoteEstimatorProxy::~RemoteEstimatorProxy() {} 46 RemoteEstimatorProxy::~RemoteEstimatorProxy() {}
43 47
44 void RemoteEstimatorProxy::IncomingPacketFeedbackVector( 48 void RemoteEstimatorProxy::IncomingPacketFeedbackVector(
45 const std::vector<PacketInfo>& packet_feedback_vector) { 49 const std::vector<PacketInfo>& packet_feedback_vector) {
46 rtc::CritScope cs(&lock_); 50 rtc::CritScope cs(&lock_);
47 for (PacketInfo info : packet_feedback_vector) 51 for (PacketInfo info : packet_feedback_vector)
48 OnPacketArrival(info.sequence_number, info.arrival_time_ms); 52 OnPacketArrival(info.sequence_number, info.arrival_time_ms);
49 } 53 }
50 54
(...skipping 10 matching lines...) Expand all
61 65
62 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms); 66 OnPacketArrival(header.extension.transportSequenceNumber, arrival_time_ms);
63 } 67 }
64 68
65 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs, 69 bool RemoteEstimatorProxy::LatestEstimate(std::vector<unsigned int>* ssrcs,
66 unsigned int* bitrate_bps) const { 70 unsigned int* bitrate_bps) const {
67 return false; 71 return false;
68 } 72 }
69 73
70 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() { 74 int64_t RemoteEstimatorProxy::TimeUntilNextProcess() {
71 int64_t now = clock_->TimeInMilliseconds();
72 int64_t time_until_next = 0; 75 int64_t time_until_next = 0;
73 if (last_process_time_ms_ != -1 && 76 if (last_process_time_ms_ != -1) {
74 now - last_process_time_ms_ < kDefaultProcessIntervalMs) { 77 rtc::CritScope cs(&lock_);
75 time_until_next = (last_process_time_ms_ + kDefaultProcessIntervalMs - now); 78 int64_t now = clock_->TimeInMilliseconds();
79 if (now - last_process_time_ms_ < send_interval_ms_)
80 time_until_next = (last_process_time_ms_ + send_interval_ms_ - now);
76 } 81 }
77 return time_until_next; 82 return time_until_next;
78 } 83 }
79 84
80 void RemoteEstimatorProxy::Process() { 85 void RemoteEstimatorProxy::Process() {
81 last_process_time_ms_ = clock_->TimeInMilliseconds(); 86 last_process_time_ms_ = clock_->TimeInMilliseconds();
82 87
83 bool more_to_build = true; 88 bool more_to_build = true;
84 while (more_to_build) { 89 while (more_to_build) {
85 rtcp::TransportFeedback feedback_packet; 90 rtcp::TransportFeedback feedback_packet;
86 if (BuildFeedbackPacket(&feedback_packet)) { 91 if (BuildFeedbackPacket(&feedback_packet)) {
87 RTC_DCHECK(packet_router_ != nullptr); 92 RTC_DCHECK(packet_router_ != nullptr);
88 packet_router_->SendFeedback(&feedback_packet); 93 packet_router_->SendFeedback(&feedback_packet);
89 } else { 94 } else {
90 more_to_build = false; 95 more_to_build = false;
91 } 96 }
92 } 97 }
93 } 98 }
94 99
100 void RemoteEstimatorProxy::OnBitrateChanged(int bitrate_bps) {
101 // TwccReportSize = Ipv4(20B) + UDP(8B) + SRTP(10B) +
102 // AverageTwccReport(30B)
103 // TwccReport size at 50ms interval is 24 byte.
104 // TwccReport size at 250ms interval is 36 byte.
105 // AverageTwccReport = (TwccReport(50ms) + TwccReport(250ms)) / 2
106 constexpr int kTwccReportSize = 20 + 8 + 10 + 30;
107
108 // Let TWCC reports occupy 5% of total bandwidth.
109 rtc::CritScope cs(&lock_);
110 send_interval_ms_ = std::min(
111 std::max(static_cast<int>(
112 kTwccReportSize * 8.0 * 1000.0 / (0.05 * bitrate_bps) + 0.5),
113 kMinSendIntervalMs),
114 kMaxSendIntervalMs);
115 }
116
95 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, 117 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number,
96 int64_t arrival_time) { 118 int64_t arrival_time) {
97 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { 119 if (arrival_time < 0 || arrival_time > kMaxTimeMs) {
98 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; 120 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time;
99 return; 121 return;
100 } 122 }
101 123
102 // TODO(holmer): We should handle a backwards wrap here if the first 124 // TODO(holmer): We should handle a backwards wrap here if the first
103 // sequence number was small and the new sequence number is large. The 125 // sequence number was small and the new sequence number is large. The
104 // SequenceNumberUnwrapper doesn't do this, so we should replace this with 126 // SequenceNumberUnwrapper doesn't do this, so we should replace this with
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Note: Don't erase items from packet_arrival_times_ after sending, in case 196 // Note: Don't erase items from packet_arrival_times_ after sending, in case
175 // they need to be re-sent after a reordering. Removal will be handled 197 // they need to be re-sent after a reordering. Removal will be handled
176 // by OnPacketArrival once packets are too old. 198 // by OnPacketArrival once packets are too old.
177 window_start_seq_ = it->first + 1; 199 window_start_seq_ = it->first + 1;
178 } 200 }
179 201
180 return true; 202 return true;
181 } 203 }
182 204
183 } // namespace webrtc 205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698