| 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_ -= (time_last_updated_ - packet.enqueue_time_ms); |
| 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 int64_t delta = now - time_last_updated_; |
| 141 queue_time_sum_ += delta * prio_queue_.size(); |
| 142 time_last_updated_ = now; |
| 143 return queue_time_sum_ / prio_queue_.size(); |
| 144 } |
| 145 |
| 133 private: | 146 private: |
| 134 // Try to add a packet to the set of ssrc/seqno identifiers currently in the | 147 // 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. | 148 // queue. Return true if inserted, false if this is a duplicate. |
| 136 bool AddToDupeSet(const Packet& packet) { | 149 bool AddToDupeSet(const Packet& packet) { |
| 137 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); | 150 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); |
| 138 if (it == dupe_map_.end()) { | 151 if (it == dupe_map_.end()) { |
| 139 // First for this ssrc, just insert. | 152 // First for this ssrc, just insert. |
| 140 dupe_map_[packet.ssrc].insert(packet.sequence_number); | 153 dupe_map_[packet.ssrc].insert(packet.sequence_number); |
| 141 return true; | 154 return true; |
| 142 } | 155 } |
| 143 | 156 |
| 144 // Insert returns a pair, where second is a bool set to true if new element. | 157 // Insert returns a pair, where second is a bool set to true if new element. |
| 145 return it->second.insert(packet.sequence_number).second; | 158 return it->second.insert(packet.sequence_number).second; |
| 146 } | 159 } |
| 147 | 160 |
| 148 void RemoveFromDupeSet(const Packet& packet) { | 161 void RemoveFromDupeSet(const Packet& packet) { |
| 149 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); | 162 SsrcSeqNoMap::iterator it = dupe_map_.find(packet.ssrc); |
| 150 assert(it != dupe_map_.end()); | 163 RTC_DCHECK(it != dupe_map_.end()); |
| 151 it->second.erase(packet.sequence_number); | 164 it->second.erase(packet.sequence_number); |
| 152 if (it->second.empty()) { | 165 if (it->second.empty()) { |
| 153 dupe_map_.erase(it); | 166 dupe_map_.erase(it); |
| 154 } | 167 } |
| 155 } | 168 } |
| 156 | 169 |
| 157 // List of packets, in the order the were enqueued. Since dequeueing may | 170 // List of packets, in the order the were enqueued. Since dequeueing may |
| 158 // occur out of order, use list instead of vector. | 171 // occur out of order, use list instead of vector. |
| 159 std::list<Packet> packet_list_; | 172 std::list<Packet> packet_list_; |
| 160 // Priority queue of the packets, sorted according to Comparator. | 173 // Priority queue of the packets, sorted according to Comparator. |
| 161 // Use pointers into list, to avoid moving whole struct within heap. | 174 // Use pointers into list, to avoid moving whole struct within heap. |
| 162 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; | 175 std::priority_queue<Packet*, std::vector<Packet*>, Comparator> prio_queue_; |
| 163 // Total number of bytes in the queue. | 176 // Total number of bytes in the queue. |
| 164 uint64_t bytes_; | 177 uint64_t bytes_; |
| 165 // Map<ssrc, set<seq_no> >, for checking duplicates. | 178 // Map<ssrc, set<seq_no> >, for checking duplicates. |
| 166 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; | 179 typedef std::map<uint32_t, std::set<uint16_t> > SsrcSeqNoMap; |
| 167 SsrcSeqNoMap dupe_map_; | 180 SsrcSeqNoMap dupe_map_; |
| 181 Clock* const clock_; |
| 182 int64_t queue_time_sum_; |
| 183 int64_t time_last_updated_; |
| 168 }; | 184 }; |
| 169 | 185 |
| 170 class IntervalBudget { | 186 class IntervalBudget { |
| 171 public: | 187 public: |
| 172 explicit IntervalBudget(int initial_target_rate_kbps) | 188 explicit IntervalBudget(int initial_target_rate_kbps) |
| 173 : target_rate_kbps_(initial_target_rate_kbps), | 189 : target_rate_kbps_(initial_target_rate_kbps), |
| 174 bytes_remaining_(0) {} | 190 bytes_remaining_(0) {} |
| 175 | 191 |
| 176 void set_target_rate_kbps(int target_rate_kbps) { | 192 void set_target_rate_kbps(int target_rate_kbps) { |
| 177 target_rate_kbps_ = target_rate_kbps; | 193 target_rate_kbps_ = target_rate_kbps; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 202 int target_rate_kbps() const { return target_rate_kbps_; } | 218 int target_rate_kbps() const { return target_rate_kbps_; } |
| 203 | 219 |
| 204 private: | 220 private: |
| 205 static const int kWindowMs = 500; | 221 static const int kWindowMs = 500; |
| 206 | 222 |
| 207 int target_rate_kbps_; | 223 int target_rate_kbps_; |
| 208 int bytes_remaining_; | 224 int bytes_remaining_; |
| 209 }; | 225 }; |
| 210 } // namespace paced_sender | 226 } // namespace paced_sender |
| 211 | 227 |
| 228 const int64_t PacedSender::kMaxQueueLengthMs = 2000; |
| 212 const float PacedSender::kDefaultPaceMultiplier = 2.5f; | 229 const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
| 213 | 230 |
| 214 PacedSender::PacedSender(Clock* clock, | 231 PacedSender::PacedSender(Clock* clock, |
| 215 Callback* callback, | 232 Callback* callback, |
| 216 int bitrate_kbps, | 233 int bitrate_kbps, |
| 217 int max_bitrate_kbps, | 234 int max_bitrate_kbps, |
| 218 int min_bitrate_kbps) | 235 int min_bitrate_kbps) |
| 219 : clock_(clock), | 236 : clock_(clock), |
| 220 callback_(callback), | 237 callback_(callback), |
| 221 critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 238 critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 222 paused_(false), | 239 paused_(false), |
| 223 probing_enabled_(true), | 240 probing_enabled_(true), |
| 224 media_budget_(new paced_sender::IntervalBudget(max_bitrate_kbps)), | 241 media_budget_(new paced_sender::IntervalBudget(max_bitrate_kbps)), |
| 225 padding_budget_(new paced_sender::IntervalBudget(min_bitrate_kbps)), | 242 padding_budget_(new paced_sender::IntervalBudget(min_bitrate_kbps)), |
| 226 prober_(new BitrateProber()), | 243 prober_(new BitrateProber()), |
| 227 bitrate_bps_(1000 * bitrate_kbps), | 244 bitrate_bps_(1000 * bitrate_kbps), |
| 245 max_bitrate_kbps_(max_bitrate_kbps), |
| 228 time_last_update_us_(clock->TimeInMicroseconds()), | 246 time_last_update_us_(clock->TimeInMicroseconds()), |
| 229 packets_(new paced_sender::PacketQueue()), | 247 packets_(new paced_sender::PacketQueue(clock)), |
| 230 packet_counter_(0) { | 248 packet_counter_(0) { |
| 231 UpdateBytesPerInterval(kMinPacketLimitMs); | 249 UpdateBytesPerInterval(kMinPacketLimitMs); |
| 232 } | 250 } |
| 233 | 251 |
| 234 PacedSender::~PacedSender() {} | 252 PacedSender::~PacedSender() {} |
| 235 | 253 |
| 236 void PacedSender::Pause() { | 254 void PacedSender::Pause() { |
| 237 CriticalSectionScoped cs(critsect_.get()); | 255 CriticalSectionScoped cs(critsect_.get()); |
| 238 paused_ = true; | 256 paused_ = true; |
| 239 } | 257 } |
| 240 | 258 |
| 241 void PacedSender::Resume() { | 259 void PacedSender::Resume() { |
| 242 CriticalSectionScoped cs(critsect_.get()); | 260 CriticalSectionScoped cs(critsect_.get()); |
| 243 paused_ = false; | 261 paused_ = false; |
| 244 } | 262 } |
| 245 | 263 |
| 246 void PacedSender::SetProbingEnabled(bool enabled) { | 264 void PacedSender::SetProbingEnabled(bool enabled) { |
| 247 assert(packet_counter_ == 0); | 265 RTC_CHECK_EQ(0u, packet_counter_); |
| 248 probing_enabled_ = enabled; | 266 probing_enabled_ = enabled; |
| 249 } | 267 } |
| 250 | 268 |
| 251 void PacedSender::UpdateBitrate(int bitrate_kbps, | 269 void PacedSender::UpdateBitrate(int bitrate_kbps, |
| 252 int max_bitrate_kbps, | 270 int max_bitrate_kbps, |
| 253 int min_bitrate_kbps) { | 271 int min_bitrate_kbps) { |
| 254 CriticalSectionScoped cs(critsect_.get()); | 272 CriticalSectionScoped cs(critsect_.get()); |
| 255 media_budget_->set_target_rate_kbps(max_bitrate_kbps); | 273 // Don't set media bitrate here as it may be boosted in order to meet max |
| 274 // queue time constraint. Just update max_bitrate_kbps_ and let media_budget_ |
| 275 // be updated in Process(). |
| 256 padding_budget_->set_target_rate_kbps(min_bitrate_kbps); | 276 padding_budget_->set_target_rate_kbps(min_bitrate_kbps); |
| 257 bitrate_bps_ = 1000 * bitrate_kbps; | 277 bitrate_bps_ = 1000 * bitrate_kbps; |
| 278 max_bitrate_kbps_ = max_bitrate_kbps; |
| 258 } | 279 } |
| 259 | 280 |
| 260 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, | 281 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, |
| 261 uint32_t ssrc, | 282 uint32_t ssrc, |
| 262 uint16_t sequence_number, | 283 uint16_t sequence_number, |
| 263 int64_t capture_time_ms, | 284 int64_t capture_time_ms, |
| 264 size_t bytes, | 285 size_t bytes, |
| 265 bool retransmission) { | 286 bool retransmission) { |
| 266 CriticalSectionScoped cs(critsect_.get()); | 287 CriticalSectionScoped cs(critsect_.get()); |
| 267 | 288 |
| 268 if (probing_enabled_ && !prober_->IsProbing()) { | 289 if (probing_enabled_ && !prober_->IsProbing()) |
| 269 prober_->SetEnabled(true); | 290 prober_->SetEnabled(true); |
| 270 } | |
| 271 prober_->MaybeInitializeProbe(bitrate_bps_); | 291 prober_->MaybeInitializeProbe(bitrate_bps_); |
| 272 | 292 |
| 273 if (capture_time_ms < 0) { | 293 if (capture_time_ms < 0) |
| 274 capture_time_ms = clock_->TimeInMilliseconds(); | 294 capture_time_ms = clock_->TimeInMilliseconds(); |
| 275 } | |
| 276 | 295 |
| 277 packets_->Push(paced_sender::Packet( | 296 packets_->Push(paced_sender::Packet( |
| 278 priority, ssrc, sequence_number, capture_time_ms, | 297 priority, ssrc, sequence_number, capture_time_ms, |
| 279 clock_->TimeInMilliseconds(), bytes, retransmission, packet_counter_++)); | 298 clock_->TimeInMilliseconds(), bytes, retransmission, packet_counter_++)); |
| 280 } | 299 } |
| 281 | 300 |
| 282 int64_t PacedSender::ExpectedQueueTimeMs() const { | 301 int64_t PacedSender::ExpectedQueueTimeMs() const { |
| 283 CriticalSectionScoped cs(critsect_.get()); | 302 CriticalSectionScoped cs(critsect_.get()); |
| 284 int target_rate = media_budget_->target_rate_kbps(); | 303 RTC_DCHECK_GT(max_bitrate_kbps_, 0); |
| 285 assert(target_rate > 0); | 304 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / max_bitrate_kbps_); |
| 286 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / target_rate); | |
| 287 } | 305 } |
| 288 | 306 |
| 289 size_t PacedSender::QueueSizePackets() const { | 307 size_t PacedSender::QueueSizePackets() const { |
| 290 CriticalSectionScoped cs(critsect_.get()); | 308 CriticalSectionScoped cs(critsect_.get()); |
| 291 return packets_->SizeInPackets(); | 309 return packets_->SizeInPackets(); |
| 292 } | 310 } |
| 293 | 311 |
| 294 int64_t PacedSender::QueueInMs() const { | 312 int64_t PacedSender::QueueInMs() const { |
| 295 CriticalSectionScoped cs(critsect_.get()); | 313 CriticalSectionScoped cs(critsect_.get()); |
| 296 | 314 |
| 297 int64_t oldest_packet = packets_->OldestEnqueueTime(); | 315 int64_t oldest_packet = packets_->OldestEnqueueTimeMs(); |
| 298 if (oldest_packet == 0) | 316 if (oldest_packet == 0) |
| 299 return 0; | 317 return 0; |
| 300 | 318 |
| 301 return clock_->TimeInMilliseconds() - oldest_packet; | 319 return clock_->TimeInMilliseconds() - oldest_packet; |
| 302 } | 320 } |
| 303 | 321 |
| 304 int64_t PacedSender::TimeUntilNextProcess() { | 322 int64_t PacedSender::TimeUntilNextProcess() { |
| 305 CriticalSectionScoped cs(critsect_.get()); | 323 CriticalSectionScoped cs(critsect_.get()); |
| 306 if (prober_->IsProbing()) { | 324 if (prober_->IsProbing()) { |
| 307 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); | 325 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); |
| 308 if (ret >= 0) { | 326 if (ret >= 0) |
| 309 return ret; | 327 return ret; |
| 310 } | |
| 311 } | 328 } |
| 312 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 329 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
| 313 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 330 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
| 314 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 331 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
| 315 } | 332 } |
| 316 | 333 |
| 317 int32_t PacedSender::Process() { | 334 int32_t PacedSender::Process() { |
| 318 int64_t now_us = clock_->TimeInMicroseconds(); | 335 int64_t now_us = clock_->TimeInMicroseconds(); |
| 319 CriticalSectionScoped cs(critsect_.get()); | 336 CriticalSectionScoped cs(critsect_.get()); |
| 320 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 337 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
| 321 time_last_update_us_ = now_us; | 338 time_last_update_us_ = now_us; |
| 322 if (paused_) | 339 if (paused_) |
| 323 return 0; | 340 return 0; |
| 341 int target_bitrate_kbps = max_bitrate_kbps_; |
| 324 if (elapsed_time_ms > 0) { | 342 if (elapsed_time_ms > 0) { |
| 343 size_t queue_size_bytes = packets_->SizeInBytes(); |
| 344 if (queue_size_bytes > 0) { |
| 345 // Assuming equal size packets and input/output rate, the average packet |
| 346 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if |
| 347 // time constraint shall be met. Determine bitrate needed for that. |
| 348 int64_t avg_time_left_ms = std::max<int64_t>( |
| 349 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); |
| 350 int min_bitrate_needed_kbps = |
| 351 static_cast<int>(queue_size_bytes * 8 / avg_time_left_ms); |
| 352 if (min_bitrate_needed_kbps > target_bitrate_kbps) |
| 353 target_bitrate_kbps = min_bitrate_needed_kbps; |
| 354 } |
| 355 |
| 356 media_budget_->set_target_rate_kbps(target_bitrate_kbps); |
| 357 |
| 325 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 358 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
| 326 UpdateBytesPerInterval(delta_time_ms); | 359 UpdateBytesPerInterval(delta_time_ms); |
| 327 } | 360 } |
| 328 while (!packets_->Empty()) { | 361 while (!packets_->Empty()) { |
| 329 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) { | 362 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
| 330 return 0; | 363 return 0; |
| 331 } | |
| 332 | 364 |
| 333 // Since we need to release the lock in order to send, we first pop the | 365 // 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 | 366 // element from the priority queue but keep it in storage, so that we can |
| 335 // reinsert it if send fails. | 367 // reinsert it if send fails. |
| 336 const paced_sender::Packet& packet = packets_->BeginPop(); | 368 const paced_sender::Packet& packet = packets_->BeginPop(); |
| 337 if (SendPacket(packet)) { | 369 if (SendPacket(packet)) { |
| 338 // Send succeeded, remove it from the queue. | 370 // Send succeeded, remove it from the queue. |
| 339 packets_->FinalizePop(packet); | 371 packets_->FinalizePop(packet); |
| 340 if (prober_->IsProbing()) { | 372 if (prober_->IsProbing()) |
| 341 return 0; | 373 return 0; |
| 342 } | |
| 343 } else { | 374 } else { |
| 344 // Send failed, put it back into the queue. | 375 // Send failed, put it back into the queue. |
| 345 packets_->CancelPop(packet); | 376 packets_->CancelPop(packet); |
| 346 return 0; | 377 return 0; |
| 347 } | 378 } |
| 348 } | 379 } |
| 349 | 380 |
| 350 if (!packets_->Empty()) | 381 if (!packets_->Empty()) |
| 351 return 0; | 382 return 0; |
| 352 | 383 |
| 353 size_t padding_needed; | 384 size_t padding_needed; |
| 354 if (prober_->IsProbing()) | 385 if (prober_->IsProbing()) { |
| 355 padding_needed = prober_->RecommendedPacketSize(); | 386 padding_needed = prober_->RecommendedPacketSize(); |
| 356 else | 387 } else { |
| 357 padding_needed = padding_budget_->bytes_remaining(); | 388 padding_needed = padding_budget_->bytes_remaining(); |
| 389 } |
| 358 | 390 |
| 359 if (padding_needed > 0) | 391 if (padding_needed > 0) |
| 360 SendPadding(static_cast<size_t>(padding_needed)); | 392 SendPadding(static_cast<size_t>(padding_needed)); |
| 361 return 0; | 393 return 0; |
| 362 } | 394 } |
| 363 | 395 |
| 364 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { | 396 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { |
| 365 critsect_->Leave(); | 397 critsect_->Leave(); |
| 366 const bool success = callback_->TimeToSendPacket(packet.ssrc, | 398 const bool success = callback_->TimeToSendPacket(packet.ssrc, |
| 367 packet.sequence_number, | 399 packet.sequence_number, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 389 media_budget_->UseBudget(bytes_sent); | 421 media_budget_->UseBudget(bytes_sent); |
| 390 padding_budget_->UseBudget(bytes_sent); | 422 padding_budget_->UseBudget(bytes_sent); |
| 391 } | 423 } |
| 392 } | 424 } |
| 393 | 425 |
| 394 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 426 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
| 395 media_budget_->IncreaseBudget(delta_time_ms); | 427 media_budget_->IncreaseBudget(delta_time_ms); |
| 396 padding_budget_->IncreaseBudget(delta_time_ms); | 428 padding_budget_->IncreaseBudget(delta_time_ms); |
| 397 } | 429 } |
| 398 } // namespace webrtc | 430 } // namespace webrtc |
| OLD | NEW |