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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 padding_budget_(new paced_sender::IntervalBudget(0)), | 254 padding_budget_(new paced_sender::IntervalBudget(0)), |
255 prober_(new BitrateProber()), | 255 prober_(new BitrateProber()), |
256 estimated_bitrate_bps_(0), | 256 estimated_bitrate_bps_(0), |
257 min_send_bitrate_kbps_(0u), | 257 min_send_bitrate_kbps_(0u), |
258 max_padding_bitrate_kbps_(0u), | 258 max_padding_bitrate_kbps_(0u), |
259 pacing_bitrate_kbps_(0), | 259 pacing_bitrate_kbps_(0), |
260 time_last_update_us_(clock->TimeInMicroseconds()), | 260 time_last_update_us_(clock->TimeInMicroseconds()), |
261 packets_(new paced_sender::PacketQueue(clock)), | 261 packets_(new paced_sender::PacketQueue(clock)), |
262 packet_counter_(0) { | 262 packet_counter_(0) { |
263 UpdateBytesPerInterval(kMinPacketLimitMs); | 263 UpdateBytesPerInterval(kMinPacketLimitMs); |
264 prober_->ProbeAtBitrate(900000, 6); | |
265 prober_->ProbeAtBitrate(1800000, 5); | |
266 } | 264 } |
267 | 265 |
268 PacedSender::~PacedSender() {} | 266 PacedSender::~PacedSender() {} |
269 | 267 |
270 void PacedSender::Pause() { | 268 void PacedSender::Pause() { |
271 LOG(LS_INFO) << "PacedSender paused."; | 269 LOG(LS_INFO) << "PacedSender paused."; |
272 CriticalSectionScoped cs(critsect_.get()); | 270 CriticalSectionScoped cs(critsect_.get()); |
273 paused_ = true; | 271 paused_ = true; |
274 } | 272 } |
275 | 273 |
276 void PacedSender::Resume() { | 274 void PacedSender::Resume() { |
277 LOG(LS_INFO) << "PacedSender resumed."; | 275 LOG(LS_INFO) << "PacedSender resumed."; |
278 CriticalSectionScoped cs(critsect_.get()); | 276 CriticalSectionScoped cs(critsect_.get()); |
279 paused_ = false; | 277 paused_ = false; |
280 } | 278 } |
281 | 279 |
282 void PacedSender::SetProbingEnabled(bool enabled) { | 280 void PacedSender::SetProbingEnabled(bool enabled) { |
283 RTC_CHECK_EQ(0u, packet_counter_); | 281 RTC_CHECK_EQ(0u, packet_counter_); |
284 CriticalSectionScoped cs(critsect_.get()); | 282 CriticalSectionScoped cs(critsect_.get()); |
285 prober_->SetEnabled(enabled); | 283 prober_->SetEnabled(enabled); |
286 } | 284 } |
287 | 285 |
288 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) { | 286 void PacedSender::SetEstimatedBitrate(int bitrate_bps) { |
289 if (bitrate_bps == 0) | 287 if (bitrate_bps == 0) |
290 LOG(LS_ERROR) << "PacedSender is not designed to handle 0 bitrate."; | 288 LOG(LS_ERROR) << "PacedSender is not designed to handle 0 bitrate."; |
291 CriticalSectionScoped cs(critsect_.get()); | 289 CriticalSectionScoped cs(critsect_.get()); |
292 estimated_bitrate_bps_ = bitrate_bps; | 290 estimated_bitrate_bps_ = bitrate_bps; |
293 padding_budget_->set_target_rate_kbps( | 291 padding_budget_->set_target_rate_kbps( |
294 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); | 292 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); |
295 pacing_bitrate_kbps_ = | 293 pacing_bitrate_kbps_ = |
296 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * | 294 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * |
297 kDefaultPaceMultiplier; | 295 kDefaultPaceMultiplier; |
| 296 prober_->SetEstimatedBitrate(bitrate_bps); |
298 } | 297 } |
299 | 298 |
300 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, | 299 void PacedSender::SetSendBitrateLimits(int min_send_bitrate_bps, |
301 int padding_bitrate) { | 300 int padding_bitrate) { |
302 CriticalSectionScoped cs(critsect_.get()); | 301 CriticalSectionScoped cs(critsect_.get()); |
303 min_send_bitrate_kbps_ = min_send_bitrate_bps / 1000; | 302 min_send_bitrate_kbps_ = min_send_bitrate_bps / 1000; |
304 pacing_bitrate_kbps_ = | 303 pacing_bitrate_kbps_ = |
305 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * | 304 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) * |
306 kDefaultPaceMultiplier; | 305 kDefaultPaceMultiplier; |
307 max_padding_bitrate_kbps_ = padding_bitrate / 1000; | 306 max_padding_bitrate_kbps_ = padding_bitrate / 1000; |
308 padding_budget_->set_target_rate_kbps( | 307 padding_budget_->set_target_rate_kbps( |
309 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); | 308 std::min(estimated_bitrate_bps_ / 1000, max_padding_bitrate_kbps_)); |
310 } | 309 } |
311 | 310 |
312 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, | 311 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, |
313 uint32_t ssrc, | 312 uint32_t ssrc, |
314 uint16_t sequence_number, | 313 uint16_t sequence_number, |
315 int64_t capture_time_ms, | 314 int64_t capture_time_ms, |
316 size_t bytes, | 315 size_t bytes, |
317 bool retransmission) { | 316 bool retransmission) { |
318 CriticalSectionScoped cs(critsect_.get()); | 317 CriticalSectionScoped cs(critsect_.get()); |
319 RTC_DCHECK(estimated_bitrate_bps_ > 0) | 318 RTC_DCHECK(estimated_bitrate_bps_ > 0) |
320 << "SetEstimatedBitrate must be called before InsertPacket."; | 319 << "SetEstimatedBitrate must be called before InsertPacket."; |
321 | 320 |
322 int64_t now_ms = clock_->TimeInMilliseconds(); | 321 int64_t now_ms = clock_->TimeInMilliseconds(); |
323 prober_->OnIncomingPacket(bytes); | 322 prober_->OnIncomingPacket(now_ms, bytes); |
324 | 323 |
325 if (capture_time_ms < 0) | 324 if (capture_time_ms < 0) |
326 capture_time_ms = now_ms; | 325 capture_time_ms = now_ms; |
327 | 326 |
328 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number, | 327 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number, |
329 capture_time_ms, now_ms, bytes, | 328 capture_time_ms, now_ms, bytes, |
330 retransmission, packet_counter_++)); | 329 retransmission, packet_counter_++)); |
331 } | 330 } |
332 | 331 |
333 int64_t PacedSender::ExpectedQueueTimeMs() const { | 332 int64_t PacedSender::ExpectedQueueTimeMs() const { |
334 CriticalSectionScoped cs(critsect_.get()); | 333 CriticalSectionScoped cs(critsect_.get()); |
335 RTC_DCHECK_GT(pacing_bitrate_kbps_, 0u); | 334 RTC_DCHECK_GT(pacing_bitrate_kbps_, 0); |
336 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / | 335 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / |
337 pacing_bitrate_kbps_); | 336 pacing_bitrate_kbps_); |
338 } | 337 } |
339 | 338 |
340 size_t PacedSender::QueueSizePackets() const { | 339 size_t PacedSender::QueueSizePackets() const { |
341 CriticalSectionScoped cs(critsect_.get()); | 340 CriticalSectionScoped cs(critsect_.get()); |
342 return packets_->SizeInPackets(); | 341 return packets_->SizeInPackets(); |
343 } | 342 } |
344 | 343 |
345 int64_t PacedSender::QueueInMs() const { | 344 int64_t PacedSender::QueueInMs() const { |
(...skipping 17 matching lines...) Expand all Loading... |
363 if (prober_->IsProbing()) { | 362 if (prober_->IsProbing()) { |
364 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); | 363 int64_t ret = prober_->TimeUntilNextProbe(clock_->TimeInMilliseconds()); |
365 if (ret >= 0) | 364 if (ret >= 0) |
366 return ret; | 365 return ret; |
367 } | 366 } |
368 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; | 367 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; |
369 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; | 368 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; |
370 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); | 369 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); |
371 } | 370 } |
372 | 371 |
| 372 bool PacedSender::IsExpectingProbingResults() const { |
| 373 CriticalSectionScoped cs(critsect_.get()); |
| 374 return prober_->IsExpectingProbingResults(); |
| 375 } |
| 376 |
373 void PacedSender::Process() { | 377 void PacedSender::Process() { |
374 int64_t now_us = clock_->TimeInMicroseconds(); | 378 int64_t now_us = clock_->TimeInMicroseconds(); |
375 CriticalSectionScoped cs(critsect_.get()); | 379 CriticalSectionScoped cs(critsect_.get()); |
376 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; | 380 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; |
377 time_last_update_us_ = now_us; | 381 time_last_update_us_ = now_us; |
378 int target_bitrate_kbps = pacing_bitrate_kbps_; | 382 int target_bitrate_kbps = pacing_bitrate_kbps_; |
379 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. | 383 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. |
380 if (!paused_ && elapsed_time_ms > 0) { | 384 if (!paused_ && elapsed_time_ms > 0) { |
381 size_t queue_size_bytes = packets_->SizeInBytes(); | 385 size_t queue_size_bytes = packets_->SizeInBytes(); |
382 if (queue_size_bytes > 0) { | 386 if (queue_size_bytes > 0) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 return false; | 452 return false; |
449 } | 453 } |
450 } | 454 } |
451 critsect_->Leave(); | 455 critsect_->Leave(); |
452 const bool success = packet_sender_->TimeToSendPacket( | 456 const bool success = packet_sender_->TimeToSendPacket( |
453 packet.ssrc, packet.sequence_number, packet.capture_time_ms, | 457 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
454 packet.retransmission, probe_cluster_id); | 458 packet.retransmission, probe_cluster_id); |
455 critsect_->Enter(); | 459 critsect_->Enter(); |
456 | 460 |
457 if (success) { | 461 if (success) { |
458 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | 462 // Is this a probe ? |
| 463 if (probe_cluster_id != PacketInfo::kNotAProbe) |
| 464 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); |
459 // TODO(holmer): High priority packets should only be accounted for if we | 465 // TODO(holmer): High priority packets should only be accounted for if we |
460 // are allocating bandwidth for audio. | 466 // are allocating bandwidth for audio. |
461 if (packet.priority != kHighPriority) { | 467 if (packet.priority != kHighPriority) { |
462 // Update media bytes sent. | 468 // Update media bytes sent. |
463 media_budget_->UseBudget(packet.bytes); | 469 media_budget_->UseBudget(packet.bytes); |
464 padding_budget_->UseBudget(packet.bytes); | 470 padding_budget_->UseBudget(packet.bytes); |
465 } | 471 } |
466 } | 472 } |
467 | 473 |
468 return success; | 474 return success; |
469 } | 475 } |
470 | 476 |
471 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { | 477 void PacedSender::SendPadding(size_t padding_needed, int probe_cluster_id) { |
472 critsect_->Leave(); | 478 critsect_->Leave(); |
473 size_t bytes_sent = | 479 size_t bytes_sent = |
474 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); | 480 packet_sender_->TimeToSendPadding(padding_needed, probe_cluster_id); |
475 critsect_->Enter(); | 481 critsect_->Enter(); |
476 | 482 |
477 if (bytes_sent > 0) { | 483 if (bytes_sent > 0) { |
478 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); | 484 // Is this a probe ? |
| 485 if (probe_cluster_id != PacketInfo::kNotAProbe) |
| 486 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); |
479 media_budget_->UseBudget(bytes_sent); | 487 media_budget_->UseBudget(bytes_sent); |
480 padding_budget_->UseBudget(bytes_sent); | 488 padding_budget_->UseBudget(bytes_sent); |
481 } | 489 } |
482 } | 490 } |
483 | 491 |
484 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 492 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
485 media_budget_->IncreaseBudget(delta_time_ms); | 493 media_budget_->IncreaseBudget(delta_time_ms); |
486 padding_budget_->IncreaseBudget(delta_time_ms); | 494 padding_budget_->IncreaseBudget(delta_time_ms); |
487 } | 495 } |
488 } // namespace webrtc | 496 } // namespace webrtc |
OLD | NEW |