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

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

Powered by Google App Engine
This is Rietveld 408576698