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 <algorithm> | 13 #include <algorithm> |
14 #include <map> | 14 #include <map> |
15 #include <queue> | 15 #include <queue> |
16 #include <set> | 16 #include <set> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
| 19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
19 #include "webrtc/modules/include/module_common_types.h" | 20 #include "webrtc/modules/include/module_common_types.h" |
20 #include "webrtc/modules/pacing/alr_detector.h" | 21 #include "webrtc/modules/pacing/alr_detector.h" |
21 #include "webrtc/modules/pacing/bitrate_prober.h" | 22 #include "webrtc/modules/pacing/bitrate_prober.h" |
22 #include "webrtc/modules/pacing/interval_budget.h" | 23 #include "webrtc/modules/pacing/interval_budget.h" |
23 #include "webrtc/modules/utility/include/process_thread.h" | 24 #include "webrtc/modules/utility/include/process_thread.h" |
24 #include "webrtc/rtc_base/checks.h" | 25 #include "webrtc/rtc_base/checks.h" |
25 #include "webrtc/rtc_base/logging.h" | 26 #include "webrtc/rtc_base/logging.h" |
26 #include "webrtc/system_wrappers/include/clock.h" | 27 #include "webrtc/system_wrappers/include/clock.h" |
27 #include "webrtc/system_wrappers/include/field_trial.h" | 28 #include "webrtc/system_wrappers/include/field_trial.h" |
28 | 29 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 if (first->capture_time_ms != second->capture_time_ms) | 89 if (first->capture_time_ms != second->capture_time_ms) |
89 return first->capture_time_ms > second->capture_time_ms; | 90 return first->capture_time_ms > second->capture_time_ms; |
90 | 91 |
91 return first->enqueue_order > second->enqueue_order; | 92 return first->enqueue_order > second->enqueue_order; |
92 } | 93 } |
93 }; | 94 }; |
94 | 95 |
95 // Class encapsulating a priority queue with some extensions. | 96 // Class encapsulating a priority queue with some extensions. |
96 class PacketQueue { | 97 class PacketQueue { |
97 public: | 98 public: |
98 explicit PacketQueue(const Clock* clock) | 99 explicit PacketQueue(const Clock* clock, RtcEventLog* event_log = nullptr) |
99 : bytes_(0), | 100 : bytes_(0), |
100 clock_(clock), | 101 clock_(clock), |
101 queue_time_sum_(0), | 102 queue_time_sum_(0), |
102 time_last_updated_(clock_->TimeInMilliseconds()), | 103 time_last_updated_(clock_->TimeInMilliseconds()), |
103 paused_(false) {} | 104 paused_(false), |
| 105 event_log_(event_log) {} |
104 virtual ~PacketQueue() {} | 106 virtual ~PacketQueue() {} |
105 | 107 |
106 void Push(const Packet& packet) { | 108 void Push(const Packet& packet) { |
107 if (!AddToDupeSet(packet)) | 109 if (!AddToDupeSet(packet)) |
108 return; | 110 return; |
109 | 111 |
110 UpdateQueueTime(packet.enqueue_time_ms); | 112 UpdateQueueTime(packet.enqueue_time_ms); |
111 | 113 |
112 // Store packet in list, use pointers in priority queue for cheaper moves. | 114 // Store packet in list, use pointers in priority queue for cheaper moves. |
113 // Packets have a handle to its own iterator in the list, for easy removal | 115 // Packets have a handle to its own iterator in the list, for easy removal |
(...skipping 18 matching lines...) Expand all Loading... |
132 bytes_ -= packet.bytes; | 134 bytes_ -= packet.bytes; |
133 int64_t packet_queue_time_ms = time_last_updated_ - packet.enqueue_time_ms; | 135 int64_t packet_queue_time_ms = time_last_updated_ - packet.enqueue_time_ms; |
134 RTC_DCHECK_LE(packet.sum_paused_ms, packet_queue_time_ms); | 136 RTC_DCHECK_LE(packet.sum_paused_ms, packet_queue_time_ms); |
135 packet_queue_time_ms -= packet.sum_paused_ms; | 137 packet_queue_time_ms -= packet.sum_paused_ms; |
136 RTC_DCHECK_LE(packet_queue_time_ms, queue_time_sum_); | 138 RTC_DCHECK_LE(packet_queue_time_ms, queue_time_sum_); |
137 queue_time_sum_ -= packet_queue_time_ms; | 139 queue_time_sum_ -= packet_queue_time_ms; |
138 packet_list_.erase(packet.this_it); | 140 packet_list_.erase(packet.this_it); |
139 RTC_DCHECK_EQ(packet_list_.size(), prio_queue_.size()); | 141 RTC_DCHECK_EQ(packet_list_.size(), prio_queue_.size()); |
140 if (packet_list_.empty()) | 142 if (packet_list_.empty()) |
141 RTC_DCHECK_EQ(0, queue_time_sum_); | 143 RTC_DCHECK_EQ(0, queue_time_sum_); |
| 144 if (event_log_ && !packet.retransmission) |
| 145 event_log_->LogPacketQueueTime(packet.ssrc, packet_queue_time_ms); |
142 } | 146 } |
143 | 147 |
144 bool Empty() const { return prio_queue_.empty(); } | 148 bool Empty() const { return prio_queue_.empty(); } |
145 | 149 |
146 size_t SizeInPackets() const { return prio_queue_.size(); } | 150 size_t SizeInPackets() const { return prio_queue_.size(); } |
147 | 151 |
148 uint64_t SizeInBytes() const { return bytes_; } | 152 uint64_t SizeInBytes() const { return bytes_; } |
149 | 153 |
150 int64_t OldestEnqueueTimeMs() const { | 154 int64_t OldestEnqueueTimeMs() const { |
151 auto it = packet_list_.rbegin(); | 155 auto it = packet_list_.rbegin(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; | 226 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; |
223 // Total number of bytes in the queue. | 227 // Total number of bytes in the queue. |
224 uint64_t bytes_; | 228 uint64_t bytes_; |
225 // Map<ssrc, std::set<seq_no> >, for checking duplicates. | 229 // Map<ssrc, std::set<seq_no> >, for checking duplicates. |
226 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; | 230 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; |
227 SsrcSeqNoMap dupe_map_; | 231 SsrcSeqNoMap dupe_map_; |
228 const Clock* const clock_; | 232 const Clock* const clock_; |
229 int64_t queue_time_sum_; | 233 int64_t queue_time_sum_; |
230 int64_t time_last_updated_; | 234 int64_t time_last_updated_; |
231 bool paused_; | 235 bool paused_; |
| 236 RtcEventLog* event_log_; |
232 }; | 237 }; |
233 | 238 |
234 } // namespace paced_sender | 239 } // namespace paced_sender |
235 | 240 |
236 const int64_t PacedSender::kMaxQueueLengthMs = 2000; | 241 const int64_t PacedSender::kMaxQueueLengthMs = 2000; |
237 const float PacedSender::kDefaultPaceMultiplier = 2.5f; | 242 const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
238 | 243 |
239 PacedSender::PacedSender(const Clock* clock, | 244 PacedSender::PacedSender(const Clock* clock, |
240 PacketSender* packet_sender, | 245 PacketSender* packet_sender, |
241 RtcEventLog* event_log) | 246 RtcEventLog* event_log) |
242 : clock_(clock), | 247 : clock_(clock), |
243 packet_sender_(packet_sender), | 248 packet_sender_(packet_sender), |
244 alr_detector_(new AlrDetector()), | 249 alr_detector_(new AlrDetector(event_log)), |
245 paused_(false), | 250 paused_(false), |
246 media_budget_(new IntervalBudget(0)), | 251 media_budget_(new IntervalBudget(0)), |
247 padding_budget_(new IntervalBudget(0)), | 252 padding_budget_(new IntervalBudget(0)), |
248 prober_(new BitrateProber(event_log)), | 253 prober_(new BitrateProber(event_log)), |
249 probing_send_failure_(false), | 254 probing_send_failure_(false), |
250 estimated_bitrate_bps_(0), | 255 estimated_bitrate_bps_(0), |
251 min_send_bitrate_kbps_(0u), | 256 min_send_bitrate_kbps_(0u), |
252 max_padding_bitrate_kbps_(0u), | 257 max_padding_bitrate_kbps_(0u), |
253 pacing_bitrate_kbps_(0), | 258 pacing_bitrate_kbps_(0), |
254 time_last_update_us_(clock->TimeInMicroseconds()), | 259 time_last_update_us_(clock->TimeInMicroseconds()), |
255 first_sent_packet_ms_(-1), | 260 first_sent_packet_ms_(-1), |
256 packets_(new paced_sender::PacketQueue(clock)), | 261 packets_(new paced_sender::PacketQueue(clock, event_log)), |
257 packet_counter_(0), | 262 packet_counter_(0), |
258 pacing_factor_(kDefaultPaceMultiplier), | 263 pacing_factor_(kDefaultPaceMultiplier), |
259 queue_time_limit(kMaxQueueLengthMs) { | 264 queue_time_limit(kMaxQueueLengthMs) { |
260 UpdateBudgetWithElapsedTime(kMinPacketLimitMs); | 265 UpdateBudgetWithElapsedTime(kMinPacketLimitMs); |
261 } | 266 } |
262 | 267 |
263 PacedSender::~PacedSender() {} | 268 PacedSender::~PacedSender() {} |
264 | 269 |
265 void PacedSender::CreateProbeCluster(int bitrate_bps) { | 270 void PacedSender::CreateProbeCluster(int bitrate_bps) { |
266 rtc::CritScope cs(&critsect_); | 271 rtc::CritScope cs(&critsect_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 alr_detector_->SetEstimatedBitrate(bitrate_bps); | 319 alr_detector_->SetEstimatedBitrate(bitrate_bps); |
315 } | 320 } |
316 | 321 |
317 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, | 322 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, |
318 int padding_bitrate) { | 323 int padding_bitrate) { |
319 rtc::CritScope cs(&critsect_); | 324 rtc::CritScope cs(&critsect_); |
320 min_send_bitrate_kbps_ = min_send_bitrate_bps / 1000; | 325 min_send_bitrate_kbps_ = min_send_bitrate_bps / 1000; |
321 pacing_bitrate_kbps_ = | 326 pacing_bitrate_kbps_ = |
322 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * | 327 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * |
323 pacing_factor_; | 328 pacing_factor_; |
324 max_padding_bitrate_kbps_ = padding_bitrate / 1000; | 329 max_padding_bitrate_kbps_ = 0; // padding_bitrate / 1000; |
325 padding_budget_->set_target_rate_kbps( | 330 padding_budget_->set_target_rate_kbps( |
326 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); | 331 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); |
327 } | 332 } |
328 | 333 |
329 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, | 334 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, |
330 uint32_t ssrc, | 335 uint32_t ssrc, |
331 uint16_t sequence_number, | 336 uint16_t sequence_number, |
332 int64_t capture_time_ms, | 337 int64_t capture_time_ms, |
333 size_t bytes, | 338 size_t bytes, |
334 bool retransmission) { | 339 bool retransmission) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // time constraint shall be met. Determine bitrate needed for that. | 435 // time constraint shall be met. Determine bitrate needed for that. |
431 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 436 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
432 int64_t avg_time_left_ms = std::max<int64_t>( | 437 int64_t avg_time_left_ms = std::max<int64_t>( |
433 1, queue_time_limit - packets_->AverageQueueTimeMs()); | 438 1, queue_time_limit - packets_->AverageQueueTimeMs()); |
434 int min_bitrate_needed_kbps = | 439 int min_bitrate_needed_kbps = |
435 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); | 440 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); |
436 if (min_bitrate_needed_kbps > target_bitrate_kbps) | 441 if (min_bitrate_needed_kbps > target_bitrate_kbps) |
437 target_bitrate_kbps = min_bitrate_needed_kbps; | 442 target_bitrate_kbps = min_bitrate_needed_kbps; |
438 } | 443 } |
439 | 444 |
440 media_budget_->set_target_rate_kbps(target_bitrate_kbps); | 445 media_budget_->set_target_rate_kbps(pacing_bitrate_kbps_); |
| 446 // media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
441 UpdateBudgetWithElapsedTime(elapsed_time_ms); | 447 UpdateBudgetWithElapsedTime(elapsed_time_ms); |
442 } | 448 } |
443 | 449 |
444 time_last_update_us_ = now_us; | 450 time_last_update_us_ = now_us; |
445 | 451 |
446 bool is_probing = prober_->IsProbing(); | 452 bool is_probing = prober_->IsProbing(); |
447 PacedPacketInfo pacing_info; | 453 PacedPacketInfo pacing_info; |
448 size_t bytes_sent = 0; | 454 size_t bytes_sent = 0; |
449 size_t recommended_probe_size = 0; | 455 size_t recommended_probe_size = 0; |
450 if (is_probing) { | 456 if (is_probing) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 rtc::CritScope cs(&critsect_); | 560 rtc::CritScope cs(&critsect_); |
555 pacing_factor_ = pacing_factor; | 561 pacing_factor_ = pacing_factor; |
556 } | 562 } |
557 | 563 |
558 void PacedSender::SetQueueTimeLimit(int limit_ms) { | 564 void PacedSender::SetQueueTimeLimit(int limit_ms) { |
559 rtc::CritScope cs(&critsect_); | 565 rtc::CritScope cs(&critsect_); |
560 queue_time_limit = limit_ms; | 566 queue_time_limit = limit_ms; |
561 } | 567 } |
562 | 568 |
563 } // namespace webrtc | 569 } // namespace webrtc |
OLD | NEW |