Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: webrtc/modules/pacing/paced_sender.cc

Issue 1947873002: Reland of Remove SendPacer from ViEEncoder (patchset #13 id:240001 of https://codereview.we… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed CongestionController backwards compatibility Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/pacing/paced_sender.h ('k') | webrtc/modules/pacing/paced_sender_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
249 Callback* callback, 249 PacketSender* packet_sender,
250 int bitrate_kbps, 250 int estimated_bitrate_bps)
251 int max_bitrate_kbps,
252 int min_bitrate_kbps)
253 : clock_(clock), 251 : clock_(clock),
254 callback_(callback), 252 packet_sender_(packet_sender),
255 critsect_(CriticalSectionWrapper::CreateCriticalSection()), 253 critsect_(CriticalSectionWrapper::CreateCriticalSection()),
256 paused_(false), 254 paused_(false),
257 probing_enabled_(true), 255 probing_enabled_(true),
258 media_budget_(new paced_sender::IntervalBudget(max_bitrate_kbps)), 256 media_budget_(new paced_sender::IntervalBudget(
259 padding_budget_(new paced_sender::IntervalBudget(min_bitrate_kbps)), 257 estimated_bitrate_bps / 1000 * kDefaultPaceMultiplier)),
258 padding_budget_(new paced_sender::IntervalBudget(0)),
260 prober_(new BitrateProber()), 259 prober_(new BitrateProber()),
261 bitrate_bps_(1000 * bitrate_kbps), 260 estimated_bitrate_bps_(estimated_bitrate_bps),
262 max_bitrate_kbps_(max_bitrate_kbps), 261 min_send_bitrate_kbps_(0u),
262 pacing_bitrate_kbps_(estimated_bitrate_bps / 1000 *
263 kDefaultPaceMultiplier),
263 time_last_update_us_(clock->TimeInMicroseconds()), 264 time_last_update_us_(clock->TimeInMicroseconds()),
264 packets_(new paced_sender::PacketQueue(clock)), 265 packets_(new paced_sender::PacketQueue(clock)),
265 packet_counter_(0) { 266 packet_counter_(0) {
266 UpdateBytesPerInterval(kMinPacketLimitMs); 267 UpdateBytesPerInterval(kMinPacketLimitMs);
267 } 268 }
268 269
269 PacedSender::~PacedSender() {} 270 PacedSender::~PacedSender() {}
270 271
271 void PacedSender::Pause() { 272 void PacedSender::Pause() {
272 CriticalSectionScoped cs(critsect_.get()); 273 CriticalSectionScoped cs(critsect_.get());
273 paused_ = true; 274 paused_ = true;
274 } 275 }
275 276
276 void PacedSender::Resume() { 277 void PacedSender::Resume() {
277 CriticalSectionScoped cs(critsect_.get()); 278 CriticalSectionScoped cs(critsect_.get());
278 paused_ = false; 279 paused_ = false;
279 } 280 }
280 281
281 void PacedSender::SetProbingEnabled(bool enabled) { 282 void PacedSender::SetProbingEnabled(bool enabled) {
282 RTC_CHECK_EQ(0u, packet_counter_); 283 RTC_CHECK_EQ(0u, packet_counter_);
283 probing_enabled_ = enabled; 284 probing_enabled_ = enabled;
284 } 285 }
285 286
286 void PacedSender::UpdateBitrate(int bitrate_kbps, 287 void PacedSender::SetEstimatedBitrate(uint32_t bitrate_bps) {
287 int max_bitrate_kbps, 288 LOG(LS_INFO) << "SetNetWorkEstimateTargetBitrate, bitrate " << bitrate_bps;
288 int min_bitrate_kbps) { 289
289 CriticalSectionScoped cs(critsect_.get()); 290 CriticalSectionScoped cs(critsect_.get());
290 // Don't set media bitrate here as it may be boosted in order to meet max 291 estimated_bitrate_bps_ = bitrate_bps;
291 // queue time constraint. Just update max_bitrate_kbps_ and let media_budget_ 292 pacing_bitrate_kbps_ =
292 // be updated in Process(). 293 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
293 padding_budget_->set_target_rate_kbps(min_bitrate_kbps); 294 kDefaultPaceMultiplier;
294 bitrate_bps_ = 1000 * bitrate_kbps; 295 }
295 max_bitrate_kbps_ = max_bitrate_kbps; 296
297 void PacedSender::SetAllocatedSendBitrate(int allocated_bitrate,
298 int padding_bitrate) {
299 CriticalSectionScoped cs(critsect_.get());
300 min_send_bitrate_kbps_ = allocated_bitrate / 1000;
301 pacing_bitrate_kbps_ =
302 std::max(min_send_bitrate_kbps_, estimated_bitrate_bps_ / 1000) *
303 kDefaultPaceMultiplier;
304 padding_budget_->set_target_rate_kbps(padding_bitrate / 1000);
296 } 305 }
297 306
298 void PacedSender::InsertPacket(RtpPacketSender::Priority priority, 307 void PacedSender::InsertPacket(RtpPacketSender::Priority priority,
299 uint32_t ssrc, 308 uint32_t ssrc,
300 uint16_t sequence_number, 309 uint16_t sequence_number,
301 int64_t capture_time_ms, 310 int64_t capture_time_ms,
302 size_t bytes, 311 size_t bytes,
303 bool retransmission) { 312 bool retransmission) {
304 CriticalSectionScoped cs(critsect_.get()); 313 CriticalSectionScoped cs(critsect_.get());
305 314
306 if (probing_enabled_ && !prober_->IsProbing()) 315 if (probing_enabled_ && !prober_->IsProbing())
307 prober_->SetEnabled(true); 316 prober_->SetEnabled(true);
308 int64_t now_ms = clock_->TimeInMilliseconds(); 317 int64_t now_ms = clock_->TimeInMilliseconds();
309 prober_->OnIncomingPacket(bitrate_bps_, bytes, now_ms); 318 prober_->OnIncomingPacket(estimated_bitrate_bps_, bytes, now_ms);
310 319
311 if (capture_time_ms < 0) 320 if (capture_time_ms < 0)
312 capture_time_ms = now_ms; 321 capture_time_ms = now_ms;
313 322
314 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number, 323 packets_->Push(paced_sender::Packet(priority, ssrc, sequence_number,
315 capture_time_ms, now_ms, bytes, 324 capture_time_ms, now_ms, bytes,
316 retransmission, packet_counter_++)); 325 retransmission, packet_counter_++));
317 } 326 }
318 327
319 int64_t PacedSender::ExpectedQueueTimeMs() const { 328 int64_t PacedSender::ExpectedQueueTimeMs() const {
320 CriticalSectionScoped cs(critsect_.get()); 329 CriticalSectionScoped cs(critsect_.get());
321 RTC_DCHECK_GT(max_bitrate_kbps_, 0); 330 RTC_DCHECK_GT(pacing_bitrate_kbps_, 0u);
322 return static_cast<int64_t>(packets_->SizeInBytes() * 8 / max_bitrate_kbps_); 331 return static_cast<int64_t>(packets_->SizeInBytes() * 8 /
332 pacing_bitrate_kbps_);
323 } 333 }
324 334
325 size_t PacedSender::QueueSizePackets() const { 335 size_t PacedSender::QueueSizePackets() const {
326 CriticalSectionScoped cs(critsect_.get()); 336 CriticalSectionScoped cs(critsect_.get());
327 return packets_->SizeInPackets(); 337 return packets_->SizeInPackets();
328 } 338 }
329 339
330 int64_t PacedSender::QueueInMs() const { 340 int64_t PacedSender::QueueInMs() const {
331 CriticalSectionScoped cs(critsect_.get()); 341 CriticalSectionScoped cs(critsect_.get());
332 342
(...skipping 20 matching lines...) Expand all
353 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_; 363 int64_t elapsed_time_us = clock_->TimeInMicroseconds() - time_last_update_us_;
354 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000; 364 int64_t elapsed_time_ms = (elapsed_time_us + 500) / 1000;
355 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0); 365 return std::max<int64_t>(kMinPacketLimitMs - elapsed_time_ms, 0);
356 } 366 }
357 367
358 void PacedSender::Process() { 368 void PacedSender::Process() {
359 int64_t now_us = clock_->TimeInMicroseconds(); 369 int64_t now_us = clock_->TimeInMicroseconds();
360 CriticalSectionScoped cs(critsect_.get()); 370 CriticalSectionScoped cs(critsect_.get());
361 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000; 371 int64_t elapsed_time_ms = (now_us - time_last_update_us_ + 500) / 1000;
362 time_last_update_us_ = now_us; 372 time_last_update_us_ = now_us;
363 int target_bitrate_kbps = max_bitrate_kbps_; 373 int target_bitrate_kbps = pacing_bitrate_kbps_;
364 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed. 374 // TODO(holmer): Remove the !paused_ check when issue 5307 has been fixed.
365 if (!paused_ && elapsed_time_ms > 0) { 375 if (!paused_ && elapsed_time_ms > 0) {
366 size_t queue_size_bytes = packets_->SizeInBytes(); 376 size_t queue_size_bytes = packets_->SizeInBytes();
367 if (queue_size_bytes > 0) { 377 if (queue_size_bytes > 0) {
368 // Assuming equal size packets and input/output rate, the average packet 378 // Assuming equal size packets and input/output rate, the average packet
369 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if 379 // has avg_time_left_ms left to get queue_size_bytes out of the queue, if
370 // time constraint shall be met. Determine bitrate needed for that. 380 // time constraint shall be met. Determine bitrate needed for that.
371 packets_->UpdateQueueTime(clock_->TimeInMilliseconds()); 381 packets_->UpdateQueueTime(clock_->TimeInMilliseconds());
372 int64_t avg_time_left_ms = std::max<int64_t>( 382 int64_t avg_time_left_ms = std::max<int64_t>(
373 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs()); 383 1, kMaxQueueLengthMs - packets_->AverageQueueTimeMs());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 SendPadding(static_cast<size_t>(padding_needed)); 428 SendPadding(static_cast<size_t>(padding_needed));
419 } 429 }
420 430
421 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { 431 bool PacedSender::SendPacket(const paced_sender::Packet& packet) {
422 // TODO(holmer): Because of this bug issue 5307 we have to send audio 432 // TODO(holmer): Because of this bug issue 5307 we have to send audio
423 // packets even when the pacer is paused. Here we assume audio packets are 433 // packets even when the pacer is paused. Here we assume audio packets are
424 // always high priority and that they are the only high priority packets. 434 // always high priority and that they are the only high priority packets.
425 if (paused_ && packet.priority != kHighPriority) 435 if (paused_ && packet.priority != kHighPriority)
426 return false; 436 return false;
427 critsect_->Leave(); 437 critsect_->Leave();
428 const bool success = callback_->TimeToSendPacket(packet.ssrc, 438 const bool success = packet_sender_->TimeToSendPacket(
429 packet.sequence_number, 439 packet.ssrc, packet.sequence_number, packet.capture_time_ms,
430 packet.capture_time_ms, 440 packet.retransmission);
431 packet.retransmission);
432 critsect_->Enter(); 441 critsect_->Enter();
433 442
434 if (success) { 443 if (success) {
435 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); 444 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes);
436 // TODO(holmer): High priority packets should only be accounted for if we 445 // TODO(holmer): High priority packets should only be accounted for if we
437 // are allocating bandwidth for audio. 446 // are allocating bandwidth for audio.
438 if (packet.priority != kHighPriority) { 447 if (packet.priority != kHighPriority) {
439 // Update media bytes sent. 448 // Update media bytes sent.
440 media_budget_->UseBudget(packet.bytes); 449 media_budget_->UseBudget(packet.bytes);
441 padding_budget_->UseBudget(packet.bytes); 450 padding_budget_->UseBudget(packet.bytes);
442 } 451 }
443 } 452 }
444 453
445 return success; 454 return success;
446 } 455 }
447 456
448 void PacedSender::SendPadding(size_t padding_needed) { 457 void PacedSender::SendPadding(size_t padding_needed) {
449 critsect_->Leave(); 458 critsect_->Leave();
450 size_t bytes_sent = callback_->TimeToSendPadding(padding_needed); 459 size_t bytes_sent = packet_sender_->TimeToSendPadding(padding_needed);
451 critsect_->Enter(); 460 critsect_->Enter();
452 461
453 if (bytes_sent > 0) { 462 if (bytes_sent > 0) {
454 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent); 463 prober_->PacketSent(clock_->TimeInMilliseconds(), bytes_sent);
455 media_budget_->UseBudget(bytes_sent); 464 media_budget_->UseBudget(bytes_sent);
456 padding_budget_->UseBudget(bytes_sent); 465 padding_budget_->UseBudget(bytes_sent);
457 } 466 }
458 } 467 }
459 468
460 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { 469 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) {
461 media_budget_->IncreaseBudget(delta_time_ms); 470 media_budget_->IncreaseBudget(delta_time_ms);
462 padding_budget_->IncreaseBudget(delta_time_ms); 471 padding_budget_->IncreaseBudget(delta_time_ms);
463 } 472 }
464 } // namespace webrtc 473 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/paced_sender.h ('k') | webrtc/modules/pacing/paced_sender_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698