webrtc_m130/modules/pacing/paced_sender.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

200 lines
6.0 KiB
C++
Raw Normal View History

/*
* 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.
*/
#include "modules/pacing/paced_sender.h"
#include <algorithm>
#include <utility>
#include <vector>
#include "absl/memory/memory.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/checks.h"
#include "rtc_base/location.h"
#include "rtc_base/logging.h"
#include "rtc_base/time_utils.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
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;
PacedSender::PacedSender(Clock* clock,
PacketRouter* packet_router,
RtcEventLog* event_log,
const WebRtcKeyValueConfig* field_trials,
ProcessThread* process_thread)
: process_mode_((field_trials != nullptr &&
field_trials->Lookup("WebRTC-Pacer-DynamicProcess")
.find("Enabled") == 0)
? PacingController::ProcessMode::kDynamic
: PacingController::ProcessMode::kPeriodic),
pacing_controller_(clock,
static_cast<PacingController::PacketSender*>(this),
event_log,
field_trials,
process_mode_),
clock_(clock),
packet_router_(packet_router),
process_thread_(process_thread) {
if (process_thread_)
process_thread_->RegisterModule(&module_proxy_, RTC_FROM_HERE);
}
PacedSender::~PacedSender() {
if (process_thread_) {
process_thread_->DeRegisterModule(&module_proxy_);
}
}
void PacedSender::CreateProbeCluster(DataRate bitrate, int cluster_id) {
rtc::CritScope cs(&critsect_);
return pacing_controller_.CreateProbeCluster(bitrate, cluster_id);
}
void PacedSender::Pause() {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.Pause();
}
// Tell the process thread to call our TimeUntilNextProcess() method to get
// a new (longer) estimate for when to call Process().
if (process_thread_) {
process_thread_->WakeUp(&module_proxy_);
}
}
void PacedSender::Resume() {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.Resume();
}
// Tell the process thread to call our TimeUntilNextProcess() method to
// refresh the estimate for when to call Process().
if (process_thread_) {
process_thread_->WakeUp(&module_proxy_);
}
}
void PacedSender::SetCongestionWindow(DataSize congestion_window_size) {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.SetCongestionWindow(congestion_window_size);
}
MaybeWakupProcessThread();
}
void PacedSender::UpdateOutstandingData(DataSize outstanding_data) {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.UpdateOutstandingData(outstanding_data);
}
MaybeWakupProcessThread();
}
void PacedSender::SetPacingRates(DataRate pacing_rate, DataRate padding_rate) {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.SetPacingRates(pacing_rate, padding_rate);
}
MaybeWakupProcessThread();
}
void PacedSender::EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
{
rtc::CritScope cs(&critsect_);
for (auto& packet : packets) {
pacing_controller_.EnqueuePacket(std::move(packet));
}
}
MaybeWakupProcessThread();
}
void PacedSender::SetAccountForAudioPackets(bool account_for_audio) {
rtc::CritScope cs(&critsect_);
pacing_controller_.SetAccountForAudioPackets(account_for_audio);
}
TimeDelta PacedSender::ExpectedQueueTime() const {
rtc::CritScope cs(&critsect_);
return pacing_controller_.ExpectedQueueTime();
}
DataSize PacedSender::QueueSizeData() const {
rtc::CritScope cs(&critsect_);
return pacing_controller_.QueueSizeData();
}
absl::optional<Timestamp> PacedSender::FirstSentPacketTime() const {
rtc::CritScope cs(&critsect_);
return pacing_controller_.FirstSentPacketTime();
}
TimeDelta PacedSender::OldestPacketWaitTime() const {
rtc::CritScope cs(&critsect_);
return pacing_controller_.OldestPacketWaitTime();
}
int64_t PacedSender::TimeUntilNextProcess() {
rtc::CritScope cs(&critsect_);
Timestamp next_send_time = pacing_controller_.NextSendTime();
return std::max(TimeDelta::Zero(), next_send_time - clock_->CurrentTime())
.ms();
}
void PacedSender::Process() {
rtc::CritScope cs(&critsect_);
pacing_controller_.ProcessPackets();
}
void PacedSender::ProcessThreadAttached(ProcessThread* process_thread) {
RTC_LOG(LS_INFO) << "ProcessThreadAttached 0x" << process_thread;
RTC_DCHECK(!process_thread || process_thread == process_thread_);
}
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_);
}
}
void PacedSender::SetQueueTimeLimit(TimeDelta limit) {
{
rtc::CritScope cs(&critsect_);
pacing_controller_.SetQueueTimeLimit(limit);
}
MaybeWakupProcessThread();
}
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;
}
} // namespace webrtc