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

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

Issue 2918323002: Add functionality which limits the number of bytes on the network. (Closed)
Patch Set: . Created 3 years, 5 months 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/include/send_time_history.h" 11 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
12 12
13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
14 #include "webrtc/rtc_base/checks.h" 14 #include "webrtc/rtc_base/checks.h"
15 #include "webrtc/system_wrappers/include/clock.h" 15 #include "webrtc/system_wrappers/include/clock.h"
16 16
17 namespace webrtc { 17 namespace webrtc {
18 18
19 SendTimeHistory::SendTimeHistory(const Clock* clock, 19 SendTimeHistory::SendTimeHistory(const Clock* clock,
20 int64_t packet_age_limit_ms) 20 int64_t packet_age_limit_ms)
21 : clock_(clock), packet_age_limit_ms_(packet_age_limit_ms) {} 21 : clock_(clock),
22 packet_age_limit_ms_(packet_age_limit_ms),
23 latest_acked_seq_num_(-1) {}
22 24
23 SendTimeHistory::~SendTimeHistory() {} 25 SendTimeHistory::~SendTimeHistory() {}
24 26
25 void SendTimeHistory::AddAndRemoveOld(const PacketFeedback& packet) { 27 void SendTimeHistory::AddAndRemoveOld(const PacketFeedback& packet) {
26 int64_t now_ms = clock_->TimeInMilliseconds(); 28 int64_t now_ms = clock_->TimeInMilliseconds();
27 // Remove old. 29 // Remove old.
28 while (!history_.empty() && 30 while (!history_.empty() &&
29 now_ms - history_.begin()->second.creation_time_ms > 31 now_ms - history_.begin()->second.creation_time_ms >
30 packet_age_limit_ms_) { 32 packet_age_limit_ms_) {
31 // TODO(sprang): Warn if erasing (too many) old items? 33 // TODO(sprang): Warn if erasing (too many) old items?
(...skipping 13 matching lines...) Expand all
45 return false; 47 return false;
46 it->second.send_time_ms = send_time_ms; 48 it->second.send_time_ms = send_time_ms;
47 return true; 49 return true;
48 } 50 }
49 51
50 bool SendTimeHistory::GetFeedback(PacketFeedback* packet_feedback, 52 bool SendTimeHistory::GetFeedback(PacketFeedback* packet_feedback,
51 bool remove) { 53 bool remove) {
52 RTC_DCHECK(packet_feedback); 54 RTC_DCHECK(packet_feedback);
53 int64_t unwrapped_seq_num = 55 int64_t unwrapped_seq_num =
54 seq_num_unwrapper_.Unwrap(packet_feedback->sequence_number); 56 seq_num_unwrapper_.Unwrap(packet_feedback->sequence_number);
57 latest_acked_seq_num_ = std::max(unwrapped_seq_num, latest_acked_seq_num_);
58 RTC_DCHECK_GE(latest_acked_seq_num_, 0);
55 auto it = history_.find(unwrapped_seq_num); 59 auto it = history_.find(unwrapped_seq_num);
56 if (it == history_.end()) 60 if (it == history_.end())
57 return false; 61 return false;
58 62
59 // Save arrival_time not to overwrite it. 63 // Save arrival_time not to overwrite it.
60 int64_t arrival_time_ms = packet_feedback->arrival_time_ms; 64 int64_t arrival_time_ms = packet_feedback->arrival_time_ms;
61 *packet_feedback = it->second; 65 *packet_feedback = it->second;
62 packet_feedback->arrival_time_ms = arrival_time_ms; 66 packet_feedback->arrival_time_ms = arrival_time_ms;
63 67
64 if (remove) 68 if (remove)
65 history_.erase(it); 69 history_.erase(it);
66 return true; 70 return true;
67 } 71 }
68 72
73 size_t SendTimeHistory::GetOutstandingBytes(uint16_t local_net_id,
74 uint16_t remote_net_id) const {
75 size_t outstanding_bytes = 0;
76 auto unacked_it = history_.begin();
77 if (latest_acked_seq_num_ >= 0) {
78 unacked_it = history_.lower_bound(latest_acked_seq_num_);
79 }
80 for (; unacked_it != history_.end(); ++unacked_it) {
81 if (unacked_it->second.local_net_id == local_net_id &&
82 unacked_it->second.remote_net_id == remote_net_id &&
83 unacked_it->second.send_time_ms >= 0) {
84 outstanding_bytes += unacked_it->second.payload_size;
85 }
86 }
87 return outstanding_bytes;
88 }
89
69 } // namespace webrtc 90 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698