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 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 static const int kWindowMs = 500; | 238 static const int kWindowMs = 500; |
239 | 239 |
240 int target_rate_kbps_; | 240 int target_rate_kbps_; |
241 int bytes_remaining_; | 241 int bytes_remaining_; |
242 }; | 242 }; |
243 } // namespace paced_sender | 243 } // namespace paced_sender |
244 | 244 |
245 const int64_t PacedSender::kMaxQueueLengthMs = 2000; | 245 const int64_t PacedSender::kMaxQueueLengthMs = 2000; |
246 const float PacedSender::kDefaultPaceMultiplier = 2.5f; | 246 const float PacedSender::kDefaultPaceMultiplier = 2.5f; |
247 | 247 |
248 PacedSender::PacedSender(Clock* clock, | 248 PacedSender::PacedSender(Clock* clock, PacketSender* packet_sender) |
249 PacketSender* packet_sender) | |
250 : clock_(clock), | 249 : clock_(clock), |
251 packet_sender_(packet_sender), | 250 packet_sender_(packet_sender), |
252 critsect_(CriticalSectionWrapper::CreateCriticalSection()), | 251 critsect_(CriticalSectionWrapper::CreateCriticalSection()), |
253 paused_(false), | 252 paused_(false), |
254 probing_enabled_(true), | 253 probing_enabled_(true), |
255 media_budget_(new paced_sender::IntervalBudget(0)), | 254 media_budget_(new paced_sender::IntervalBudget(0)), |
256 padding_budget_(new paced_sender::IntervalBudget(0)), | 255 padding_budget_(new paced_sender::IntervalBudget(0)), |
257 prober_(new BitrateProber()), | 256 prober_(new BitrateProber()), |
258 estimated_bitrate_bps_(0), | 257 estimated_bitrate_bps_(0), |
259 min_send_bitrate_kbps_(0u), | 258 min_send_bitrate_kbps_(0u), |
259 max_padding_bitrate_kbps_(0u), | |
260 pacing_bitrate_kbps_(0), | 260 pacing_bitrate_kbps_(0), |
261 time_last_update_us_(clock->TimeInMicroseconds()), | 261 time_last_update_us_(clock->TimeInMicroseconds()), |
262 packets_(new paced_sender::PacketQueue(clock)), | 262 packets_(new paced_sender::PacketQueue(clock)), |
263 packet_counter_(0) { | 263 packet_counter_(0) { |
264 UpdateBytesPerInterval(kMinPacketLimitMs); | 264 UpdateBytesPerInterval(kMinPacketLimitMs); |
265 } | 265 } |
266 | 266 |
267 PacedSender::~PacedSender() {} | 267 PacedSender::~PacedSender() {} |
268 | 268 |
269 void PacedSender::Pause() { | 269 void PacedSender::Pause() { |
(...skipping 19 matching lines...) Expand all Loading... | |
289 kDefaultPaceMultiplier; | 289 kDefaultPaceMultiplier; |
290 } | 290 } |
291 | 291 |
292 void PacedSender::SetAllocatedSendBitrate(int allocated_bitrate, | 292 void PacedSender::SetAllocatedSendBitrate(int allocated_bitrate, |
293 int padding_bitrate) { | 293 int padding_bitrate) { |
294 CriticalSectionScoped cs(critsect_.get()); | 294 CriticalSectionScoped cs(critsect_.get()); |
295 min_send_bitrate_kbps_ = allocated_bitrate / 1000; | 295 min_send_bitrate_kbps_ = allocated_bitrate / 1000; |
296 pacing_bitrate_kbps_ = | 296 pacing_bitrate_kbps_ = |
297 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * | 297 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * |
298 kDefaultPaceMultiplier; | 298 kDefaultPaceMultiplier; |
299 padding_budget_->set_target_rate_kbps(padding_bitrate / 1000); | 299 max_padding_bitrate_kbps_ = padding_bitrate / 1000; |
300 } | 300 } |
301 | 301 |
302 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, | 302 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, |
303 uint32_t ssrc, | 303 uint32_t ssrc, |
304 uint16_t sequence_number, | 304 uint16_t sequence_number, |
305 int64_t capture_time_ms, | 305 int64_t capture_time_ms, |
306 size_t bytes, | 306 size_t bytes, |
307 bool retransmission) { | 307 bool retransmission) { |
308 CriticalSectionScoped cs(critsect_.get()); | 308 CriticalSectionScoped cs(critsect_.get()); |
309 RTC_DCHECK(estimated_bitrate_bps_ > 0) | 309 RTC_DCHECK(estimated_bitrate_bps_ > 0) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 361 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
362 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 362 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
363 } | 363 } |
364 | 364 |
365 void PacedSender::Process() { | 365 void PacedSender::Process() { |
366 int64_t now_us = clock_->TimeInMicroseconds(); | 366 int64_t now_us = clock_->TimeInMicroseconds(); |
367 CriticalSectionScoped cs(critsect_.get()); | 367 CriticalSectionScoped cs(critsect_.get()); |
368 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 368 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
369 time_last_update_us_ = now_us; | 369 time_last_update_us_ = now_us; |
370 int target_bitrate_kbps = pacing_bitrate_kbps_; | 370 int target_bitrate_kbps = pacing_bitrate_kbps_; |
371 padding_budget_->set_target_rate_kbps( | |
372 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); | |
stefan-webrtc
2016/06/08 09:25:13
Why was this change needed? Seems like we're setti
perkj_webrtc
2016/06/08 15:35:27
Done.
| |
371 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. | 373 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. |
372 if (!paused_ && elapsed_time_ms > 0) { | 374 if (!paused_ && elapsed_time_ms > 0) { |
373 size_t queue_size_bytes = packets_->SizeInBytes(); | 375 size_t queue_size_bytes = packets_->SizeInBytes(); |
374 if (queue_size_bytes > 0) { | 376 if (queue_size_bytes > 0) { |
375 // Assuming equal size packets and input/output rate, the average packet | 377 // Assuming equal size packets and input/output rate, the average packet |
376 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if | 378 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if |
377 // time constraint shall be met. Determine bitrate needed for that. | 379 // time constraint shall be met. Determine bitrate needed for that. |
378 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); | 380 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); |
379 int64_t avg_time_left_ms = std::max<int64_t>( | 381 int64_t avg_time_left_ms = std::max<int64_t>( |
380 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); | 382 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); |
(...skipping 30 matching lines...) Expand all Loading... | |
411 // Send failed, put it back into the queue. | 413 // Send failed, put it back into the queue. |
412 packets_->CancelPop(packet); | 414 packets_->CancelPop(packet); |
413 return; | 415 return; |
414 } | 416 } |
415 } | 417 } |
416 | 418 |
417 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. | 419 // TODO(holmer): Remove the paused_ check when issue 5307 has been fixed. |
418 if (paused_ || !packets_->Empty()) | 420 if (paused_ || !packets_->Empty()) |
419 return; | 421 return; |
420 | 422 |
421 size_t padding_needed; | 423 // We can not send padding unless a normal packet has first been sent. If we |
422 if (is_probing) { | 424 // do, time stamps gets messed up. |
stefan-webrtc
2016/06/08 09:25:13
"timestamps get messsed up"
perkj_webrtc
2016/06/08 15:35:27
Done.
stefan-webrtc
2016/06/10 13:54:13
I was referring to that "gets" should be "get" :)
perkj_webrtc
2016/06/14 10:58:02
oops
| |
423 padding_needed = prober_->RecommendedPacketSize(); | 425 if (packet_counter_ > 0) { |
424 } else { | 426 size_t padding_needed = is_probing |
425 padding_needed = padding_budget_->bytes_remaining(); | 427 ? prober_->RecommendedPacketSize() |
428 : padding_budget_->bytes_remaining(); | |
429 | |
430 if (padding_needed > 0) | |
431 SendPadding(padding_needed, probe_cluster_id); | |
426 } | 432 } |
427 | |
428 if (padding_needed > 0) | |
429 SendPadding(padding_needed, probe_cluster_id); | |
430 } | 433 } |
431 | 434 |
432 bool PacedSender::SendPacket(const paced_sender::Packet& packet, | 435 bool PacedSender::SendPacket(const paced_sender::Packet& packet, |
433 int probe_cluster_id) { | 436 int probe_cluster_id) { |
434 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 437 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
435 // packets even when the pacer is paused. Here we assume audio packets are | 438 // packets even when the pacer is paused. Here we assume audio packets are |
436 // always high priority and that they are the only high priority packets. | 439 // always high priority and that they are the only high priority packets. |
437 if (paused_ && packet.priority != kHighPriority) | 440 if (paused_ && packet.priority != kHighPriority) |
438 return false; | 441 return false; |
439 critsect_->Leave(); | 442 critsect_->Leave(); |
(...skipping 27 matching lines...) Expand all Loading... | |
467 media_budget_->UseBudget(bytes_sent); | 470 media_budget_->UseBudget(bytes_sent); |
468 padding_budget_->UseBudget(bytes_sent); | 471 padding_budget_->UseBudget(bytes_sent); |
469 } | 472 } |
470 } | 473 } |
471 | 474 |
472 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 475 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
473 media_budget_->IncreaseBudget(delta_time_ms); | 476 media_budget_->IncreaseBudget(delta_time_ms); |
474 padding_budget_->IncreaseBudget(delta_time_ms); | 477 padding_budget_->IncreaseBudget(delta_time_ms); |
475 } | 478 } |
476 } // namespace webrtc | 479 } // namespace webrtc |
OLD | NEW |