2012-11-09 20:56:23 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/pacing/paced_sender.h"
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2016-02-08 23:18:25 -08:00
|
|
|
#include <algorithm>
|
2018-10-26 13:10:23 +02:00
|
|
|
#include <utility>
|
2019-07-05 16:53:43 +02:00
|
|
|
#include <vector>
|
2014-07-07 10:20:35 +00:00
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2019-08-07 12:24:53 +02:00
|
|
|
#include "api/rtc_event_log/rtc_event_log.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/utility/include/process_thread.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2019-08-29 18:32:31 +02:00
|
|
|
#include "rtc_base/location.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2019-07-29 16:38:27 +02:00
|
|
|
#include "rtc_base/time_utils.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-02-22 13:09:32 +01:00
|
|
|
namespace webrtc {
|
2015-11-20 09:00:37 -08:00
|
|
|
const int64_t PacedSender::kMaxQueueLengthMs = 2000;
|
Revert "Revert "Revert "Reland "Moved congestion controller to task queue.""""
This reverts commit 65792c5a5c542201f7b9feefded505842692e6ed.
Reason for revert: <INSERT REASONING HERE>
Original change's description:
> Revert "Revert "Reland "Moved congestion controller to task queue."""
>
> This reverts commit 4e849f6925b2ac44b0957a228d7131fc391fca54.
>
> Reason for revert: <INSERT REASONING HERE>
>
> Original change's description:
> > Revert "Reland "Moved congestion controller to task queue.""
> >
> > This reverts commit 57daeb7ac7f3d80992905b53fea500953fcfd793.
> >
> > Reason for revert: Cause increased congestion and deadlocks in downstream project
> >
> > Original change's description:
> > > Reland "Moved congestion controller to task queue."
> > >
> > > This is a reland of 0cbcba7ea0dced1a7f353c64d6cf91d46ccb29f9.
> > >
> > > Original change's description:
> > > > Moved congestion controller to task queue.
> > > >
> > > > The goal of this work is to make it easier to experiment with the
> > > > bandwidth estimation implementation. For this reason network control
> > > > functionality is moved from SendSideCongestionController(SSCC),
> > > > PacedSender and BitrateController to the newly created
> > > > GoogCcNetworkController which implements the newly created
> > > > NetworkControllerInterface. This allows the implementation to be
> > > > replaced at runtime in the future.
> > > >
> > > > This is the first part of a split of a larger CL, see:
> > > > https://webrtc-review.googlesource.com/c/src/+/39788/8
> > > > For further explanations.
> > > >
> > > > Bug: webrtc:8415
> > > > Change-Id: I770189c04cc31b313bd4e57821acff55fbcb1ad3
> > > > Reviewed-on: https://webrtc-review.googlesource.com/43840
> > > > Commit-Queue: Sebastian Jansson <srte@webrtc.org>
> > > > Reviewed-by: Björn Terelius <terelius@webrtc.org>
> > > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > > Cr-Commit-Position: refs/heads/master@{#21868}
> > >
> > > Bug: webrtc:8415
> > > Change-Id: I1d1756a30deed5b421b1c91c1918a13b6bb455da
> > > Reviewed-on: https://webrtc-review.googlesource.com/48000
> > > Reviewed-by: Stefan Holmer <stefan@webrtc.org>
> > > Commit-Queue: Sebastian Jansson <srte@webrtc.org>
> > > Cr-Commit-Position: refs/heads/master@{#21899}
> >
> > TBR=terelius@webrtc.org,stefan@webrtc.org,srte@webrtc.org
> >
> > # Not skipping CQ checks because original CL landed > 1 day ago.
> >
> > Bug: webrtc:8415
> > Change-Id: Ida8074dcac2cc28b3629228eb22846d8a8e81b83
> > Reviewed-on: https://webrtc-review.googlesource.com/52980
> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> > Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#22017}
>
> TBR=danilchap@webrtc.org,terelius@webrtc.org,stefan@webrtc.org,srte@webrtc.org
>
> Change-Id: I3393b74370c4f4d0955f50728005b2b925be169b
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8415
> Reviewed-on: https://webrtc-review.googlesource.com/53262
> Reviewed-by: Sebastian Jansson <srte@webrtc.org>
> Commit-Queue: Sebastian Jansson <srte@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22023}
TBR=danilchap@webrtc.org,terelius@webrtc.org,stefan@webrtc.org,srte@webrtc.org
Change-Id: Id68ad986ee51142b7be3381d0793709b4392fe2c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8415
Reviewed-on: https://webrtc-review.googlesource.com/53360
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22024}
2018-02-14 16:53:38 +00:00
|
|
|
const float PacedSender::kDefaultPaceMultiplier = 2.5f;
|
2014-07-04 09:20:42 +00:00
|
|
|
|
2019-01-30 11:28:59 +01:00
|
|
|
PacedSender::PacedSender(Clock* clock,
|
2019-06-12 13:30:02 +02:00
|
|
|
PacketRouter* packet_router,
|
2019-02-22 13:09:32 +01:00
|
|
|
RtcEventLog* event_log,
|
2019-08-29 18:32:31 +02:00
|
|
|
const WebRtcKeyValueConfig* field_trials,
|
|
|
|
|
ProcessThread* process_thread)
|
2019-11-14 18:04:49 +01:00
|
|
|
: process_mode_((field_trials != nullptr &&
|
|
|
|
|
field_trials->Lookup("WebRTC-Pacer-DynamicProcess")
|
|
|
|
|
.find("Enabled") == 0)
|
|
|
|
|
? PacingController::ProcessMode::kDynamic
|
|
|
|
|
: PacingController::ProcessMode::kPeriodic),
|
|
|
|
|
pacing_controller_(clock,
|
2019-08-14 10:43:47 +02:00
|
|
|
static_cast<PacingController::PacketSender*>(this),
|
|
|
|
|
event_log,
|
2019-11-14 14:15:15 +01:00
|
|
|
field_trials,
|
2019-11-14 18:04:49 +01:00
|
|
|
process_mode_),
|
2019-11-05 11:21:48 +01:00
|
|
|
clock_(clock),
|
2019-06-12 13:30:02 +02:00
|
|
|
packet_router_(packet_router),
|
2019-08-29 18:32:31 +02:00
|
|
|
process_thread_(process_thread) {
|
|
|
|
|
if (process_thread_)
|
|
|
|
|
process_thread_->RegisterModule(&module_proxy_, RTC_FROM_HERE);
|
|
|
|
|
}
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
PacedSender::~PacedSender() {
|
2019-11-14 18:04:49 +01:00
|
|
|
if (process_thread_) {
|
2019-08-29 18:32:31 +02:00
|
|
|
process_thread_->DeRegisterModule(&module_proxy_);
|
2019-11-14 18:04:49 +01:00
|
|
|
}
|
2019-08-29 18:32:31 +02:00
|
|
|
}
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
void PacedSender::CreateProbeCluster(DataRate bitrate, int cluster_id) {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
return pacing_controller_.CreateProbeCluster(bitrate, cluster_id);
|
2016-08-17 11:11:59 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 23:39:29 +00:00
|
|
|
void PacedSender::Pause() {
|
2017-03-15 07:45:36 -07:00
|
|
|
{
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
pacing_controller_.Pause();
|
2017-03-15 07:45:36 -07:00
|
|
|
}
|
2019-08-29 18:32:31 +02:00
|
|
|
|
2017-03-15 07:45:36 -07:00
|
|
|
// Tell the process thread to call our TimeUntilNextProcess() method to get
|
|
|
|
|
// a new (longer) estimate for when to call Process().
|
2019-11-14 18:04:49 +01:00
|
|
|
if (process_thread_) {
|
2019-08-29 18:32:31 +02:00
|
|
|
process_thread_->WakeUp(&module_proxy_);
|
2019-11-14 18:04:49 +01:00
|
|
|
}
|
2013-03-22 23:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PacedSender::Resume() {
|
2017-03-15 07:45:36 -07:00
|
|
|
{
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
pacing_controller_.Resume();
|
2017-03-15 07:45:36 -07:00
|
|
|
}
|
2019-08-29 18:32:31 +02:00
|
|
|
|
2017-03-15 07:45:36 -07:00
|
|
|
// Tell the process thread to call our TimeUntilNextProcess() method to
|
|
|
|
|
// refresh the estimate for when to call Process().
|
2019-11-14 18:04:49 +01:00
|
|
|
if (process_thread_) {
|
2019-08-29 18:32:31 +02:00
|
|
|
process_thread_->WakeUp(&module_proxy_);
|
2019-11-14 18:04:49 +01:00
|
|
|
}
|
2013-03-22 23:39:29 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
void PacedSender::SetCongestionWindow(DataSize congestion_window_size) {
|
2019-11-14 18:04:49 +01:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
pacing_controller_.SetCongestionWindow(congestion_window_size);
|
|
|
|
|
}
|
|
|
|
|
MaybeWakupProcessThread();
|
2018-03-09 12:48:01 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
void PacedSender::UpdateOutstandingData(DataSize outstanding_data) {
|
2019-11-14 18:04:49 +01:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
pacing_controller_.UpdateOutstandingData(outstanding_data);
|
|
|
|
|
}
|
|
|
|
|
MaybeWakupProcessThread();
|
2018-09-04 18:40:19 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
void PacedSender::SetPacingRates(DataRate pacing_rate, DataRate padding_rate) {
|
2019-11-14 18:04:49 +01:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
pacing_controller_.SetPacingRates(pacing_rate, padding_rate);
|
|
|
|
|
}
|
|
|
|
|
MaybeWakupProcessThread();
|
2018-02-20 10:46:39 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-02 14:57:46 +02:00
|
|
|
void PacedSender::EnqueuePackets(
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
2019-11-14 18:04:49 +01:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
for (auto& packet : packets) {
|
|
|
|
|
pacing_controller_.EnqueuePacket(std::move(packet));
|
|
|
|
|
}
|
2019-10-02 14:57:46 +02:00
|
|
|
}
|
2019-11-14 18:04:49 +01:00
|
|
|
MaybeWakupProcessThread();
|
2012-11-09 20:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 10:37:47 +02:00
|
|
|
void PacedSender::SetAccountForAudioPackets(bool account_for_audio) {
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
pacing_controller_.SetAccountForAudioPackets(account_for_audio);
|
2017-10-20 10:37:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
TimeDelta PacedSender::ExpectedQueueTime() const {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
return pacing_controller_.ExpectedQueueTime();
|
2013-11-27 14:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
DataSize PacedSender::QueueSizeData() const {
|
2019-01-08 10:49:19 +01:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
return pacing_controller_.QueueSizeData();
|
2019-01-08 10:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
absl::optional<Timestamp> PacedSender::FirstSentPacketTime() const {
|
2017-04-19 23:28:53 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
return pacing_controller_.FirstSentPacketTime();
|
2017-04-19 23:28:53 -07:00
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
TimeDelta PacedSender::OldestPacketWaitTime() const {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
return pacing_controller_.OldestPacketWaitTime();
|
2014-10-23 11:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-15 22:09:40 +00:00
|
|
|
int64_t PacedSender::TimeUntilNextProcess() {
|
2017-03-30 01:14:41 -07:00
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
|
2019-11-14 14:15:15 +01:00
|
|
|
Timestamp next_send_time = pacing_controller_.NextSendTime();
|
|
|
|
|
return std::max(TimeDelta::Zero(), next_send_time - clock_->CurrentTime())
|
|
|
|
|
.ms();
|
2018-10-26 13:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PacedSender::Process() {
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
2019-08-14 10:43:47 +02:00
|
|
|
pacing_controller_.ProcessPackets();
|
2012-11-09 20:56:23 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-15 07:45:36 -07:00
|
|
|
void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) {
|
2018-05-23 11:13:31 +02:00
|
|
|
RTC_LOG(LS_INFO) << "ProcessThreadAttached 0x" << process_thread;
|
2019-08-29 18:32:31 +02:00
|
|
|
RTC_DCHECK(!process_thread || process_thread == process_thread_);
|
2017-03-15 07:45:36 -07:00
|
|
|
}
|
|
|
|
|
|
2019-11-14 18:04:49 +01:00
|
|
|
void PacedSender::MaybeWakupProcessThread() {
|
|
|
|
|
// Tell the process thread to call our TimeUntilNextProcess() method to get
|
|
|
|
|
// a new time for when to call Process().
|
|
|
|
|
if (process_thread_ &&
|
|
|
|
|
process_mode_ == PacingController::ProcessMode::kDynamic) {
|
|
|
|
|
process_thread_->WakeUp(&module_proxy_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
void PacedSender::SetQueueTimeLimit(TimeDelta limit) {
|
2019-11-14 18:04:49 +01:00
|
|
|
{
|
|
|
|
|
rtc::CritScope cs(&critsect_);
|
|
|
|
|
pacing_controller_.SetQueueTimeLimit(limit);
|
|
|
|
|
}
|
|
|
|
|
MaybeWakupProcessThread();
|
2019-08-14 10:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PacedSender::SendRtpPacket(std::unique_ptr<RtpPacketToSend> packet,
|
|
|
|
|
const PacedPacketInfo& cluster_info) {
|
|
|
|
|
critsect_.Leave();
|
|
|
|
|
packet_router_->SendPacket(std::move(packet), cluster_info);
|
|
|
|
|
critsect_.Enter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> PacedSender::GeneratePadding(
|
|
|
|
|
DataSize size) {
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> padding_packets;
|
|
|
|
|
critsect_.Leave();
|
|
|
|
|
padding_packets = packet_router_->GeneratePadding(size.bytes());
|
|
|
|
|
critsect_.Enter();
|
|
|
|
|
return padding_packets;
|
|
|
|
|
}
|
2012-11-09 20:56:23 +00:00
|
|
|
} // namespace webrtc
|