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

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

Issue 1419503004: Set send times in send time history via OnSentPacket. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed Created 5 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 <assert.h> 11 #include <assert.h>
12 12
13 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" 13 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
14 14
15 namespace webrtc { 15 namespace webrtc {
16 16
17 SendTimeHistory::SendTimeHistory(int64_t packet_age_limit) 17 SendTimeHistory::SendTimeHistory(Clock* clock, int64_t packet_age_limit)
18 : packet_age_limit_(packet_age_limit), oldest_sequence_number_(0) { 18 : clock_(clock),
19 } 19 packet_age_limit_(packet_age_limit),
20 oldest_sequence_number_(0) {}
20 21
21 SendTimeHistory::~SendTimeHistory() { 22 SendTimeHistory::~SendTimeHistory() {
22 } 23 }
23 24
24 void SendTimeHistory::Clear() { 25 void SendTimeHistory::Clear() {
25 history_.clear(); 26 history_.clear();
26 } 27 }
27 28
28 void SendTimeHistory::AddAndRemoveOld(const PacketInfo& packet) { 29 void SendTimeHistory::AddAndRemoveOld(uint16_t sequence_number,
29 EraseOld(packet.send_time_ms - packet_age_limit_); 30 size_t length,
31 bool was_paced) {
32 EraseOld();
30 33
31 if (history_.empty()) 34 if (history_.empty())
32 oldest_sequence_number_ = packet.sequence_number; 35 oldest_sequence_number_ = sequence_number;
33 36
34 history_.insert( 37 history_.insert(std::pair<uint16_t, PacketInfo>(
35 std::pair<uint16_t, PacketInfo>(packet.sequence_number, packet)); 38 sequence_number, PacketInfo(clock_->TimeInMilliseconds(), 0, -1,
39 sequence_number, length, was_paced)));
36 } 40 }
37 41
38 bool SendTimeHistory::UpdateSendTime(uint16_t sequence_number, 42 bool SendTimeHistory::OnSentPacket(uint16_t sequence_number,
39 int64_t send_time_ms) { 43 int64_t send_time_ms) {
40 auto it = history_.find(sequence_number); 44 auto it = history_.find(sequence_number);
41 if (it == history_.end()) 45 if (it == history_.end())
42 return false; 46 return false;
43 it->second.send_time_ms = send_time_ms; 47 it->second.send_time_ms = send_time_ms;
44 return true; 48 return true;
45 } 49 }
46 50
47 void SendTimeHistory::EraseOld(int64_t limit) { 51 void SendTimeHistory::EraseOld() {
48 while (!history_.empty()) { 52 while (!history_.empty()) {
49 auto it = history_.find(oldest_sequence_number_); 53 auto it = history_.find(oldest_sequence_number_);
50 assert(it != history_.end()); 54 assert(it != history_.end());
51 55
52 if (it->second.send_time_ms > limit) 56 if (clock_->TimeInMilliseconds() - it->second.creation_time_ms <=
57 packet_age_limit_) {
53 return; // Oldest packet within age limit, return. 58 return; // Oldest packet within age limit, return.
59 }
54 60
55 // TODO(sprang): Warn if erasing (too many) old items? 61 // TODO(sprang): Warn if erasing (too many) old items?
56 history_.erase(it); 62 history_.erase(it);
57 UpdateOldestSequenceNumber(); 63 UpdateOldestSequenceNumber();
58 } 64 }
59 } 65 }
60 66
61 void SendTimeHistory::UpdateOldestSequenceNumber() { 67 void SendTimeHistory::UpdateOldestSequenceNumber() {
62 // After removing an element from the map, update oldest_sequence_number_ to 68 // After removing an element from the map, update oldest_sequence_number_ to
63 // the element with the lowest sequence number higher than the previous 69 // the element with the lowest sequence number higher than the previous
(...skipping 22 matching lines...) Expand all
86 packet->arrival_time_ms = receive_time; 92 packet->arrival_time_ms = receive_time;
87 if (remove) { 93 if (remove) {
88 history_.erase(it); 94 history_.erase(it);
89 if (packet->sequence_number == oldest_sequence_number_) 95 if (packet->sequence_number == oldest_sequence_number_)
90 UpdateOldestSequenceNumber(); 96 UpdateOldestSequenceNumber();
91 } 97 }
92 return true; 98 return true;
93 } 99 }
94 100
95 } // namespace webrtc 101 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698