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

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: Response to comments 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),
(...skipping 24 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 int send_interval_ms = kDefaultSendIntervalMs;
75 time_until_next = (last_process_time_ms_ + kDefaultProcessIntervalMs - now); 78 if (bitrate_bps_) {
79 // TwccReportSize = Ipv4(20B) + UDP(8B) + SRTP(10B) +
80 // AverageTwccReport(30B)
81 // TwccReport size at 50ms interval is 24 byte.
82 // TwccReport size at 250ms interval is 36 byte.
83 // AverageTwccReport = (TwccReport(50ms) + TwccReport(250ms)) / 2
84 constexpr int kTwccReportSize = 20 + 8 + 10 + 30;
85 send_interval_ms = static_cast<int>(
86 kTwccReportSize * 8.0 * 1000.0 / (0.05 * *bitrate_bps_) + 0.5);
87 send_interval_ms = std::min(
88 std::max(send_interval_ms, kMinSendIntervalMs), kMaxSendIntervalMs);
89 }
90 int64_t now = clock_->TimeInMilliseconds();
91 if (now - last_process_time_ms_ < send_interval_ms)
92 time_until_next = (last_process_time_ms_ + send_interval_ms - now);
76 } 93 }
77 return time_until_next; 94 return time_until_next;
78 } 95 }
79 96
80 void RemoteEstimatorProxy::Process() { 97 void RemoteEstimatorProxy::Process() {
81 last_process_time_ms_ = clock_->TimeInMilliseconds(); 98 last_process_time_ms_ = clock_->TimeInMilliseconds();
82 99
83 bool more_to_build = true; 100 bool more_to_build = true;
84 while (more_to_build) { 101 while (more_to_build) {
85 rtcp::TransportFeedback feedback_packet; 102 rtcp::TransportFeedback feedback_packet;
86 if (BuildFeedbackPacket(&feedback_packet)) { 103 if (BuildFeedbackPacket(&feedback_packet)) {
87 RTC_DCHECK(packet_router_ != nullptr); 104 RTC_DCHECK(packet_router_ != nullptr);
88 packet_router_->SendFeedback(&feedback_packet); 105 packet_router_->SendFeedback(&feedback_packet);
89 } else { 106 } else {
90 more_to_build = false; 107 more_to_build = false;
91 } 108 }
92 } 109 }
93 } 110 }
94 111
112 void RemoteEstimatorProxy::OnBitrateChanged(int bitrate_bps) {
113 bitrate_bps_ = rtc::Optional<int>(bitrate_bps);
stefan-webrtc 2016/11/02 13:10:24 Is this accessed on the same thread as TimeUntilNe
michaelt 2016/11/02 14:28:02 Done.
114 }
115
95 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number, 116 void RemoteEstimatorProxy::OnPacketArrival(uint16_t sequence_number,
96 int64_t arrival_time) { 117 int64_t arrival_time) {
97 if (arrival_time < 0 || arrival_time > kMaxTimeMs) { 118 if (arrival_time < 0 || arrival_time > kMaxTimeMs) {
98 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time; 119 LOG(LS_WARNING) << "Arrival time out of bounds: " << arrival_time;
99 return; 120 return;
100 } 121 }
101 122
102 // TODO(holmer): We should handle a backwards wrap here if the first 123 // 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 124 // sequence number was small and the new sequence number is large. The
104 // SequenceNumberUnwrapper doesn't do this, so we should replace this with 125 // 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 195 // 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 196 // they need to be re-sent after a reordering. Removal will be handled
176 // by OnPacketArrival once packets are too old. 197 // by OnPacketArrival once packets are too old.
177 window_start_seq_ = it->first + 1; 198 window_start_seq_ = it->first + 1;
178 } 199 }
179 200
180 return true; 201 return true;
181 } 202 }
182 203
183 } // namespace webrtc 204 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698