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

Side by Side Diff: webrtc/modules/pacing/paced_sender.cc

Issue 1474533006: Fix bug in calculation of averge queue time in paced sender. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 class PacketQueue { 86 class PacketQueue {
87 public: 87 public:
88 explicit PacketQueue(Clock* clock) 88 explicit PacketQueue(Clock* clock)
89 : bytes_(0), 89 : bytes_(0),
90 clock_(clock), 90 clock_(clock),
91 queue_time_sum_(0), 91 queue_time_sum_(0),
92 time_last_updated_(clock_->TimeInMilliseconds()) {} 92 time_last_updated_(clock_->TimeInMilliseconds()) {}
93 virtual ~PacketQueue() {} 93 virtual ~PacketQueue() {}
94 94
95 void Push(const Packet& packet) { 95 void Push(const Packet& packet) {
96 if (!AddToDupeSet(packet)) { 96 if (!AddToDupeSet(packet))
97 return; 97 return;
98 } 98
99 // Store packet in list, use pointers in priority queue for cheaper moves. 99 // Store packet in list, use pointers in priority queue for cheaper moves.
100 // Packets have a handle to its own iterator in the list, for easy removal 100 // Packets have a handle to its own iterator in the list, for easy removal
101 // when popping from queue. 101 // when popping from queue.
102 packet_list_.push_front(packet); 102 packet_list_.push_front(packet);
103 std::list<Packet>::iterator it = packet_list_.begin(); 103 std::list<Packet>::iterator it = packet_list_.begin();
104 it->this_it = it; // Handle for direct removal from list. 104 it->this_it = it; // Handle for direct removal from list.
105 prio_queue_.push(&(*it)); // Pointer into list. 105 prio_queue_.push(&(*it)); // Pointer into list.
106 bytes_ += packet.bytes; 106 bytes_ += packet.bytes;
107 UpdateQueueTime();
stefan-webrtc 2015/11/25 15:28:52 To me it makes more sense to call this before we a
sprang_webrtc 2015/11/25 15:36:00 Yes, I realized this just after uploading...
107 } 108 }
108 109
109 const Packet& BeginPop() { 110 const Packet& BeginPop() {
110 const Packet& packet = *prio_queue_.top(); 111 const Packet& packet = *prio_queue_.top();
111 prio_queue_.pop(); 112 prio_queue_.pop();
112 return packet; 113 return packet;
113 } 114 }
114 115
115 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); } 116 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); }
116 117
117 void FinalizePop(const Packet& packet) { 118 void FinalizePop(const Packet& packet) {
118 RemoveFromDupeSet(packet); 119 RemoveFromDupeSet(packet);
119 bytes_ -= packet.bytes; 120 bytes_ -= packet.bytes;
120 queue_time_sum_ -= (time_last_updated_ - packet.enqueue_time_ms); 121 queue_time_sum_ -= (time_last_updated_ - packet.enqueue_time_ms);
121 packet_list_.erase(packet.this_it); 122 packet_list_.erase(packet.this_it);
123 UpdateQueueTime();
122 } 124 }
123 125
124 bool Empty() const { return prio_queue_.empty(); } 126 bool Empty() const { return prio_queue_.empty(); }
125 127
126 size_t SizeInPackets() const { return prio_queue_.size(); } 128 size_t SizeInPackets() const { return prio_queue_.size(); }
127 129
128 uint64_t SizeInBytes() const { return bytes_; } 130 uint64_t SizeInBytes() const { return bytes_; }
129 131
130 int64_t OldestEnqueueTimeMs() const { 132 int64_t OldestEnqueueTimeMs() const {
131 auto it = packet_list_.rbegin(); 133 auto it = packet_list_.rbegin();
132 if (it == packet_list_.rend()) 134 if (it == packet_list_.rend())
133 return 0; 135 return 0;
134 return it->enqueue_time_ms; 136 return it->enqueue_time_ms;
135 } 137 }
136 138
137 int64_t AverageQueueTimeMs() { 139 void UpdateQueueTime() {
138 int64_t now = clock_->TimeInMilliseconds(); 140 int64_t now = clock_->TimeInMilliseconds();
139 RTC_DCHECK_GE(now, time_last_updated_); 141 RTC_DCHECK_GE(now, time_last_updated_);
140 int64_t delta = now - time_last_updated_; 142 int64_t delta = now - time_last_updated_;
141 queue_time_sum_ += delta * prio_queue_.size(); 143 queue_time_sum_ += delta * prio_queue_.size();
142 time_last_updated_ = now; 144 time_last_updated_ = now;
145 }
146
147 int64_t AverageQueueTimeMs() {
stefan-webrtc 2015/11/25 15:28:52 Make this const...
sprang_webrtc 2015/11/25 15:36:00 Done.
148 UpdateQueueTime();
stefan-webrtc 2015/11/25 15:28:52 ... and call this separately?
sprang_webrtc 2015/11/25 15:36:00 Done.
149 if (prio_queue_.empty())
150 return 0;
143 return queue_time_sum_ / prio_queue_.size(); 151 return queue_time_sum_ / prio_queue_.size();
144 } 152 }
145 153
146 private: 154 private:
147 // Try to add a packet to the set of ssrc/seqno identifiers currently in the 155 // Try to add a packet to the set of ssrc/seqno identifiers currently in the
148 // queue. Return true if inserted, false if this is a duplicate. 156 // queue. Return true if inserted, false if this is a duplicate.
149 bool AddToDupeSet(const Packet& packet) { 157 bool AddToDupeSet(const Packet& packet) {
150 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); 158 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc);
151 if (it == dupe_map_.end()) { 159 if (it == dupe_map_.end()) {
152 // First for this ssrc, just insert. 160 // First for this ssrc, just insert.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 media_budget_->UseBudget(bytes_sent); 429 media_budget_->UseBudget(bytes_sent);
422 padding_budget_->UseBudget(bytes_sent); 430 padding_budget_->UseBudget(bytes_sent);
423 } 431 }
424 } 432 }
425 433
426 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 434 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
427 media_budget_->IncreaseBudget(delta_time_ms); 435 media_budget_->IncreaseBudget(delta_time_ms);
428 padding_budget_->IncreaseBudget(delta_time_ms); 436 padding_budget_->IncreaseBudget(delta_time_ms);
429 } 437 }
430 } // namespace webrtc 438 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/test/fake_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698