OLD | NEW |
---|---|
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 |
11 #include "webrtc/modules/pacing/paced_sender.h" | 11 #include "webrtc/modules/pacing/paced_sender.h" |
12 | 12 |
13 #include <assert.h> | |
14 | |
15 #include <map> | 13 #include <map> |
16 #include <queue> | 14 #include <queue> |
17 #include <set> | 15 #include <set> |
18 | 16 |
17 #include "webrtc/base/checks.h" | |
19 #include "webrtc/modules/include/module_common_types.h" | 18 #include "webrtc/modules/include/module_common_types.h" |
20 #include "webrtc/modules/pacing/bitrate_prober.h" | 19 #include "webrtc/modules/pacing/bitrate_prober.h" |
21 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
23 #include "webrtc/system_wrappers/include/field_trial.h" | 22 #include "webrtc/system_wrappers/include/field_trial.h" |
24 #include "webrtc/system_wrappers/include/logging.h" | 23 #include "webrtc/system_wrappers/include/logging.h" |
25 | 24 |
26 namespace { | 25 namespace { |
27 // Time limit in milliseconds between packet bursts. | 26 // Time limit in milliseconds between packet bursts. |
28 const int64_t kMinPacketLimitMs = 5; | 27 const int64_t kMinPacketLimitMs = 5; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 if (first->capture_time_ms != second->capture_time_ms) | 78 if (first->capture_time_ms != second->capture_time_ms) |
80 return first->capture_time_ms > second->capture_time_ms; | 79 return first->capture_time_ms > second->capture_time_ms; |
81 | 80 |
82 return first->enqueue_order > second->enqueue_order; | 81 return first->enqueue_order > second->enqueue_order; |
83 } | 82 } |
84 }; | 83 }; |
85 | 84 |
86 // Class encapsulating a priority queue with some extensions. | 85 // Class encapsulating a priority queue with some extensions. |
87 class PacketQueue { | 86 class PacketQueue { |
88 public: | 87 public: |
89 PacketQueue() : bytes_(0) {} | 88 explicit PacketQueue(Clock* clock) |
89 : bytes_(0), | |
90 clock_(clock), | |
91 queue_time_sum_(0), | |
92 time_last_updated_(clock_->TimeInMilliseconds()) {} | |
90 virtual ~PacketQueue() {} | 93 virtual ~PacketQueue() {} |
91 | 94 |
92 void Push(const Packet& packet) { | 95 void Push(const Packet& packet) { |
93 if (!AddToDupeSet(packet)) { | 96 if (!AddToDupeSet(packet)) { |
94 return; | 97 return; |
95 } | 98 } |
96 // 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. |
97 // 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 |
98 // when popping from queue. | 101 // when popping from queue. |
99 packet_list_.push_front(packet); | 102 packet_list_.push_front(packet); |
100 std::list<Packet>::iterator it = packet_list_.begin(); | 103 std::list<Packet>::iterator it = packet_list_.begin(); |
101 it->this_it = it; // Handle for direct removal from list. | 104 it->this_it = it; // Handle for direct removal from list. |
102 prio_queue_.push(&(*it)); // Pointer into list. | 105 prio_queue_.push(&(*it)); // Pointer into list. |
103 bytes_ += packet.bytes; | 106 bytes_ += packet.bytes; |
104 } | 107 } |
105 | 108 |
106 const Packet& BeginPop() { | 109 const Packet& BeginPop() { |
107 const Packet& packet = *prio_queue_.top(); | 110 const Packet& packet = *prio_queue_.top(); |
108 prio_queue_.pop(); | 111 prio_queue_.pop(); |
109 return packet; | 112 return packet; |
110 } | 113 } |
111 | 114 |
112 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); } | 115 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); } |
113 | 116 |
114 void FinalizePop(const Packet& packet) { | 117 void FinalizePop(const Packet& packet) { |
115 RemoveFromDupeSet(packet); | 118 RemoveFromDupeSet(packet); |
116 bytes_ -= packet.bytes; | 119 bytes_ -= packet.bytes; |
120 queue_time_sum_ -= (clock_->TimeInMilliseconds() - packet.enqueue_time_ms); | |
stefan-webrtc
2015/11/19 18:55:04
Can this cause queue_time_sum_ to become negative?
mflodman
2015/11/19 18:58:55
I'm not sure clock_->TimeInMilliseconds() is the r
sprang_webrtc
2015/11/20 11:07:52
Done.
| |
117 packet_list_.erase(packet.this_it); | 121 packet_list_.erase(packet.this_it); |
118 } | 122 } |
119 | 123 |
120 bool Empty() const { return prio_queue_.empty(); } | 124 bool Empty() const { return prio_queue_.empty(); } |
121 | 125 |
122 size_t SizeInPackets() const { return prio_queue_.size(); } | 126 size_t SizeInPackets() const { return prio_queue_.size(); } |
123 | 127 |
124 uint64_t SizeInBytes() const { return bytes_; } | 128 uint64_t SizeInBytes() const { return bytes_; } |
125 | 129 |
126 int64_t OldestEnqueueTime() const { | 130 int64_t OldestEnqueueTimeMs() const { |
127 std::list<Packet>::const_reverse_iterator it = packet_list_.rbegin(); | 131 auto it = packet_list_.rbegin(); |
128 if (it == packet_list_.rend()) | 132 if (it == packet_list_.rend()) |
129 return 0; | 133 return 0; |
130 return it->enqueue_time_ms; | 134 return it->enqueue_time_ms; |
131 } | 135 } |
132 | 136 |
137 int64_t AverageQueueTimeMs() { | |
138 int64_t now = clock_->TimeInMilliseconds(); | |
139 RTC_DCHECK_GE(now, time_last_updated_); | |
140 if (now > time_last_updated_) { | |
stefan-webrtc
2015/11/19 17:13:46
If these are equal the delta will be zero and the
mflodman
2015/11/19 18:58:56
There is also already a check in Process() prevent
sprang_webrtc
2015/11/20 11:07:52
It was mostly to avoid unnecessary execution. But
| |
141 int64_t delta = now - time_last_updated_; | |
142 queue_time_sum_ += delta * prio_queue_.size(); | |
143 time_last_updated_ = now; | |
144 } | |
145 return queue_time_sum_ / prio_queue_.size(); | |
146 } | |
147 | |
133 private: | 148 private: |
134 // Try to add a packet to the set of ssrc/seqno identifiers currently in the | 149 // Try to add a packet to the set of ssrc/seqno identifiers currently in the |
135 // queue. Return true if inserted, false if this is a duplicate. | 150 // queue. Return true if inserted, false if this is a duplicate. |
136 bool AddToDupeSet(const Packet& packet) { | 151 bool AddToDupeSet(const Packet& packet) { |
137 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); | 152 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); |
138 if (it == dupe_map_.end()) { | 153 if (it == dupe_map_.end()) { |
139 // First for this ssrc, just insert. | 154 // First for this ssrc, just insert. |
140 dupe_map_[packet.ssrc].insert(packet.sequence_number); | 155 dupe_map_[packet.ssrc].insert(packet.sequence_number); |
141 return true; | 156 return true; |
142 } | 157 } |
143 | 158 |
144 // Insert returns a pair, where second is a bool set to true if new element. | 159 // Insert returns a pair, where second is a bool set to true if new element. |
145 return it->second.insert(packet.sequence_number).second; | 160 return it->second.insert(packet.sequence_number).second; |
146 } | 161 } |
147 | 162 |
148 void RemoveFromDupeSet(const Packet& packet) { | 163 void RemoveFromDupeSet(const Packet& packet) { |
149 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); | 164 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); |
150 assert(it != dupe_map_.end()); | 165 RTC_DCHECK(it != dupe_map_.end()); |
151 it->second.erase(packet.sequence_number); | 166 it->second.erase(packet.sequence_number); |
152 if (it->second.empty()) { | 167 if (it->second.empty()) { |
153 dupe_map_.erase(it); | 168 dupe_map_.erase(it); |
154 } | 169 } |
155 } | 170 } |
156 | 171 |
157 // List of packets, in the order the were enqueued. Since dequeueing may | 172 // List of packets, in the order the were enqueued. Since dequeueing may |
158 // occur out of order, use list instead of vector. | 173 // occur out of order, use list instead of vector. |
159 std::list<Packet> packet_list_; | 174 std::list<Packet> packet_list_; |
160 // Priority queue of the packets, sorted according to Comparator. | 175 // Priority queue of the packets, sorted according to Comparator. |
161 // Use pointers into list, to avoid moving whole struct within heap. | 176 // Use pointers into list, to avoid moving whole struct within heap. |
162 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; | 177 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; |
163 // Total number of bytes in the queue. | 178 // Total number of bytes in the queue. |
164 uint64_t bytes_; | 179 uint64_t bytes_; |
165 // Map<ssrc, set<seq_no> >, for checking duplicates. | 180 // Map<ssrc, set<seq_no> >, for checking duplicates. |
166 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; | 181 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; |
167 SsrcSeqNoMap dupe_map_; | 182 SsrcSeqNoMap dupe_map_; |
183 Clock* const clock_; | |
184 int64_t queue_time_sum_; | |
185 int64_t time_last_updated_; | |
168 }; | 186 }; |
169 | 187 |
170 class IntervalBudget { | 188 class IntervalBudget { |
171 public: | 189 public: |
172 explicit IntervalBudget(int initial_target_rate_kbps) | 190 explicit IntervalBudget(int initial_target_rate_kbps) |
173 : target_rate_kbps_(initial_target_rate_kbps), | 191 : target_rate_kbps_(initial_target_rate_kbps), |
174 bytes_remaining_(0) {} | 192 bytes_remaining_(0) {} |
175 | 193 |
176 void set_target_rate_kbps(int target_rate_kbps) { | 194 void set_target_rate_kbps(int target_rate_kbps) { |
177 target_rate_kbps_ = target_rate_kbps; | 195 target_rate_kbps_ = target_rate_kbps; |
(...skipping 24 matching lines...) Expand all Loading... | |
202 int target_rate_kbps() const { return target_rate_kbps_; } | 220 int target_rate_kbps() const { return target_rate_kbps_; } |
203 | 221 |
204 private: | 222 private: |
205 static const int kWindowMs = 500; | 223 static const int kWindowMs = 500; |
206 | 224 |
207 int target_rate_kbps_; | 225 int target_rate_kbps_; |
208 int bytes_remaining_; | 226 int bytes_remaining_; |
209 }; | 227 }; |
210 } // namespace paced_sender | 228 } // namespace paced_sender |
211 | 229 |
230 const int64_t PacedSender::kMaxQueueLengthMs = 2000; | |
212 const float PacedSender::kDefaultPaceMultiplier = 2.5f; | 231 const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
213 | 232 |
214 PacedSender::PacedSender(Clock* clock, | 233 PacedSender::PacedSender(Clock* clock, |
215 Callback* callback, | 234 Callback* callback, |
216 int bitrate_kbps, | 235 int bitrate_kbps, |
217 int max_bitrate_kbps, | 236 int max_bitrate_kbps, |
218 int min_bitrate_kbps) | 237 int min_bitrate_kbps) |
219 : clock_(clock), | 238 : clock_(clock), |
220 callback_(callback), | 239 callback_(callback), |
221 critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 240 critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
222 paused_(false), | 241 paused_(false), |
223 probing_enabled_(true), | 242 probing_enabled_(true), |
224 media_budget_(new paced_sender::IntervalBudget(max_bitrate_kbps)), | 243 media_budget_(new paced_sender::IntervalBudget(max_bitrate_kbps)), |
225 padding_budget_(new paced_sender::IntervalBudget(min_bitrate_kbps)), | 244 padding_budget_(new paced_sender::IntervalBudget(min_bitrate_kbps)), |
226 prober_(new BitrateProber()), | 245 prober_(new BitrateProber()), |
227 bitrate_bps_(1000 * bitrate_kbps), | 246 bitrate_bps_(1000 * bitrate_kbps), |
247 max_bitrate_kbps_(max_bitrate_kbps), | |
228 time_last_update_us_(clock->TimeInMicroseconds()), | 248 time_last_update_us_(clock->TimeInMicroseconds()), |
229 packets_(new paced_sender::PacketQueue()), | 249 packets_(new paced_sender::PacketQueue(clock)), |
230 packet_counter_(0) { | 250 packet_counter_(0) { |
231 UpdateBytesPerInterval(kMinPacketLimitMs); | 251 UpdateBytesPerInterval(kMinPacketLimitMs); |
232 } | 252 } |
233 | 253 |
234 PacedSender::~PacedSender() {} | 254 PacedSender::~PacedSender() {} |
235 | 255 |
236 void PacedSender::Pause() { | 256 void PacedSender::Pause() { |
237 CriticalSectionScoped cs(critsect_.get()); | 257 CriticalSectionScoped cs(critsect_.get()); |
238 paused_ = true; | 258 paused_ = true; |
239 } | 259 } |
240 | 260 |
241 void PacedSender::Resume() { | 261 void PacedSender::Resume() { |
242 CriticalSectionScoped cs(critsect_.get()); | 262 CriticalSectionScoped cs(critsect_.get()); |
243 paused_ = false; | 263 paused_ = false; |
244 } | 264 } |
245 | 265 |
246 void PacedSender::SetProbingEnabled(bool enabled) { | 266 void PacedSender::SetProbingEnabled(bool enabled) { |
247 assert(packet_counter_ == 0); | 267 RTC_CHECK_EQ(0u, packet_counter_); |
248 probing_enabled_ = enabled; | 268 probing_enabled_ = enabled; |
249 } | 269 } |
250 | 270 |
251 void PacedSender::UpdateBitrate(int bitrate_kbps, | 271 void PacedSender::UpdateBitrate(int bitrate_kbps, |
252 int max_bitrate_kbps, | 272 int max_bitrate_kbps, |
253 int min_bitrate_kbps) { | 273 int min_bitrate_kbps) { |
254 CriticalSectionScoped cs(critsect_.get()); | 274 CriticalSectionScoped cs(critsect_.get()); |
255 media_budget_->set_target_rate_kbps(max_bitrate_kbps); | 275 // Don't set media bitrate here as it may be boosted in order to meet max |
276 // queue time constraint. Just update max_bitrate_kbps_ and let media_budget_ | |
277 // be updated in Process(). | |
256 padding_budget_->set_target_rate_kbps(min_bitrate_kbps); | 278 padding_budget_->set_target_rate_kbps(min_bitrate_kbps); |
257 bitrate_bps_ = 1000 * bitrate_kbps; | 279 bitrate_bps_ = 1000 * bitrate_kbps; |
280 max_bitrate_kbps_ = max_bitrate_kbps; | |
258 } | 281 } |
259 | 282 |
260 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, | 283 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, |
261 uint32_t ssrc, | 284 uint32_t ssrc, |
262 uint16_t sequence_number, | 285 uint16_t sequence_number, |
263 int64_t capture_time_ms, | 286 int64_t capture_time_ms, |
264 size_t bytes, | 287 size_t bytes, |
265 bool retransmission) { | 288 bool retransmission) { |
266 CriticalSectionScoped cs(critsect_.get()); | 289 CriticalSectionScoped cs(critsect_.get()); |
267 | 290 |
268 if (probing_enabled_ && !prober_->IsProbing()) { | 291 if (probing_enabled_ && !prober_->IsProbing()) |
269 prober_->SetEnabled(true); | 292 prober_->SetEnabled(true); |
270 } | |
271 prober_->MaybeInitializeProbe(bitrate_bps_); | 293 prober_->MaybeInitializeProbe(bitrate_bps_); |
272 | 294 |
273 if (capture_time_ms < 0) { | 295 if (capture_time_ms < 0) |
274 capture_time_ms = clock_->TimeInMilliseconds(); | 296 capture_time_ms = clock_->TimeInMilliseconds(); |
275 } | |
276 | 297 |
277 packets_->Push(paced_sender::Packet( | 298 packets_->Push(paced_sender::Packet( |
278 priority, ssrc, sequence_number, capture_time_ms, | 299 priority, ssrc, sequence_number, capture_time_ms, |
279 clock_->TimeInMilliseconds(), bytes, retransmission, packet_counter_++)); | 300 clock_->TimeInMilliseconds(), bytes, retransmission, packet_counter_++)); |
280 } | 301 } |
281 | 302 |
282 int64_t PacedSender::ExpectedQueueTimeMs() const { | 303 int64_t PacedSender::ExpectedQueueTimeMs() const { |
283 CriticalSectionScoped cs(critsect_.get()); | 304 CriticalSectionScoped cs(critsect_.get()); |
284 int target_rate = media_budget_->target_rate_kbps(); | 305 RTC_DCHECK_GT(max_bitrate_kbps_, 0); |
285 assert(target_rate > 0); | 306 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / max_bitrate_kbps_); |
286 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / target_rate); | |
287 } | 307 } |
288 | 308 |
289 size_t PacedSender::QueueSizePackets() const { | 309 size_t PacedSender::QueueSizePackets() const { |
290 CriticalSectionScoped cs(critsect_.get()); | 310 CriticalSectionScoped cs(critsect_.get()); |
291 return packets_->SizeInPackets(); | 311 return packets_->SizeInPackets(); |
292 } | 312 } |
293 | 313 |
294 int64_t PacedSender::QueueInMs() const { | 314 int64_t PacedSender::QueueInMs() const { |
295 CriticalSectionScoped cs(critsect_.get()); | 315 CriticalSectionScoped cs(critsect_.get()); |
296 | 316 |
297 int64_t oldest_packet = packets_->OldestEnqueueTime(); | 317 int64_t oldest_packet = packets_->OldestEnqueueTimeMs(); |
298 if (oldest_packet == 0) | 318 if (oldest_packet == 0) |
299 return 0; | 319 return 0; |
300 | 320 |
301 return clock_->TimeInMilliseconds() - oldest_packet; | 321 return clock_->TimeInMilliseconds() - oldest_packet; |
302 } | 322 } |
303 | 323 |
304 int64_t PacedSender::TimeUntilNextProcess() { | 324 int64_t PacedSender::TimeUntilNextProcess() { |
305 CriticalSectionScoped cs(critsect_.get()); | 325 CriticalSectionScoped cs(critsect_.get()); |
306 if (prober_->IsProbing()) { | 326 if (prober_->IsProbing()) { |
307 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); | 327 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); |
308 if (ret >= 0) { | 328 if (ret >= 0) |
309 return ret; | 329 return ret; |
310 } | |
311 } | 330 } |
312 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 331 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
313 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 332 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
314 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 333 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
315 } | 334 } |
316 | 335 |
317 int32_t PacedSender::Process() { | 336 int32_t PacedSender::Process() { |
318 int64_t now_us = clock_->TimeInMicroseconds(); | 337 int64_t now_us = clock_->TimeInMicroseconds(); |
319 CriticalSectionScoped cs(critsect_.get()); | 338 CriticalSectionScoped cs(critsect_.get()); |
320 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 339 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
321 time_last_update_us_ = now_us; | 340 time_last_update_us_ = now_us; |
322 if (paused_) | 341 if (paused_) |
323 return 0; | 342 return 0; |
343 int target_bitrate_kbps = max_bitrate_kbps_; | |
324 if (elapsed_time_ms > 0) { | 344 if (elapsed_time_ms > 0) { |
345 size_t queue_size_bytes = packets_->SizeInBytes(); | |
346 if (queue_size_bytes > 0) { | |
347 // Assuming equal size packets and input/output rate, the average packet | |
348 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if | |
349 // time constraint shall be met. Determine bitrate needed for that. | |
350 int64_t avg_time_left_ms = | |
351 std::max(1L, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); | |
352 int min_bitrate_needed_kbps = queue_size_bytes * 8 / avg_time_left_ms; | |
353 if (min_bitrate_needed_kbps > target_bitrate_kbps) | |
354 target_bitrate_kbps = min_bitrate_needed_kbps; | |
355 } | |
356 | |
357 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | |
358 | |
325 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 359 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
326 UpdateBytesPerInterval(delta_time_ms); | 360 UpdateBytesPerInterval(delta_time_ms); |
327 } | 361 } |
328 while (!packets_->Empty()) { | 362 while (!packets_->Empty()) { |
329 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) { | 363 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
330 return 0; | 364 return 0; |
331 } | |
332 | 365 |
333 // Since we need to release the lock in order to send, we first pop the | 366 // Since we need to release the lock in order to send, we first pop the |
334 // element from the priority queue but keep it in storage, so that we can | 367 // element from the priority queue but keep it in storage, so that we can |
335 // reinsert it if send fails. | 368 // reinsert it if send fails. |
336 const paced_sender::Packet& packet = packets_->BeginPop(); | 369 const paced_sender::Packet& packet = packets_->BeginPop(); |
337 if (SendPacket(packet)) { | 370 if (SendPacket(packet)) { |
338 // Send succeeded, remove it from the queue. | 371 // Send succeeded, remove it from the queue. |
339 packets_->FinalizePop(packet); | 372 packets_->FinalizePop(packet); |
340 if (prober_->IsProbing()) { | 373 if (prober_->IsProbing()) |
341 return 0; | 374 return 0; |
342 } | |
343 } else { | 375 } else { |
344 // Send failed, put it back into the queue. | 376 // Send failed, put it back into the queue. |
345 packets_->CancelPop(packet); | 377 packets_->CancelPop(packet); |
346 return 0; | 378 return 0; |
347 } | 379 } |
348 } | 380 } |
349 | 381 |
350 if (!packets_->Empty()) | 382 if (!packets_->Empty()) |
351 return 0; | 383 return 0; |
352 | 384 |
353 size_t padding_needed; | 385 size_t padding_needed; |
354 if (prober_->IsProbing()) | 386 if (prober_->IsProbing()) { |
355 padding_needed = prober_->RecommendedPacketSize(); | 387 padding_needed = prober_->RecommendedPacketSize(); |
356 else | 388 } else { |
357 padding_needed = padding_budget_->bytes_remaining(); | 389 padding_needed = padding_budget_->bytes_remaining(); |
390 } | |
358 | 391 |
359 if (padding_needed > 0) | 392 if (padding_needed > 0) |
360 SendPadding(static_cast<size_t>(padding_needed)); | 393 SendPadding(static_cast<size_t>(padding_needed)); |
361 return 0; | 394 return 0; |
362 } | 395 } |
363 | 396 |
364 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { | 397 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { |
365 critsect_->Leave(); | 398 critsect_->Leave(); |
366 const bool success = callback_->TimeToSendPacket(packet.ssrc, | 399 const bool success = callback_->TimeToSendPacket(packet.ssrc, |
367 packet.sequence_number, | 400 packet.sequence_number, |
(...skipping 21 matching lines...) Expand all Loading... | |
389 media_budget_->UseBudget(bytes_sent); | 422 media_budget_->UseBudget(bytes_sent); |
390 padding_budget_->UseBudget(bytes_sent); | 423 padding_budget_->UseBudget(bytes_sent); |
391 } | 424 } |
392 } | 425 } |
393 | 426 |
394 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 427 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
395 media_budget_->IncreaseBudget(delta_time_ms); | 428 media_budget_->IncreaseBudget(delta_time_ms); |
396 padding_budget_->IncreaseBudget(delta_time_ms); | 429 padding_budget_->IncreaseBudget(delta_time_ms); |
397 } | 430 } |
398 } // namespace webrtc | 431 } // namespace webrtc |
OLD | NEW |