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
|
|
|
#ifndef MODULES_PACING_PACED_SENDER_H_
|
|
|
|
|
#define MODULES_PACING_PACED_SENDER_H_
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2019-01-08 10:49:19 +01:00
|
|
|
#include <atomic>
|
2016-03-17 09:17:43 -07:00
|
|
|
#include <memory>
|
2019-08-14 10:43:47 +02:00
|
|
|
#include <vector>
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2018-06-18 10:48:16 +02:00
|
|
|
#include "absl/types/optional.h"
|
2019-07-05 16:53:43 +02:00
|
|
|
#include "api/function_view.h"
|
2019-02-22 13:09:32 +01:00
|
|
|
#include "api/transport/field_trial_based_config.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "api/transport/network_types.h"
|
2019-02-22 13:09:32 +01:00
|
|
|
#include "api/transport/webrtc_key_value_config.h"
|
2019-06-11 11:24:40 +02:00
|
|
|
#include "modules/include/module.h"
|
2018-10-11 20:22:03 +02:00
|
|
|
#include "modules/pacing/bitrate_prober.h"
|
|
|
|
|
#include "modules/pacing/interval_budget.h"
|
2019-08-14 10:43:47 +02:00
|
|
|
#include "modules/pacing/pacing_controller.h"
|
2019-06-12 13:30:02 +02:00
|
|
|
#include "modules/pacing/packet_router.h"
|
2019-07-29 16:38:27 +02:00
|
|
|
#include "modules/pacing/rtp_packet_pacer.h"
|
2019-07-24 14:52:55 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_packet_sender.h"
|
2019-06-18 16:20:11 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/utility/include/process_thread.h"
|
2021-02-09 11:24:59 +01:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2012-11-09 20:56:23 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2018-10-23 12:03:01 +02:00
|
|
|
class Clock;
|
|
|
|
|
class RtcEventLog;
|
2014-07-04 09:20:42 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/10937): Remove the inheritance from Module after
|
|
|
|
|
// updating dependencies.
|
2019-07-29 16:38:27 +02:00
|
|
|
class PacedSender : public Module,
|
|
|
|
|
public RtpPacketPacer,
|
2020-06-30 11:53:37 +00:00
|
|
|
public RtpPacketSender {
|
2012-11-09 20:56:23 +00:00
|
|
|
public:
|
2019-08-09 22:44:47 +02:00
|
|
|
// Expected max pacer delay in ms. If ExpectedQueueTime() is higher than
|
2015-11-20 09:00:37 -08:00
|
|
|
// this value, the packet producers should wait (eg drop frames rather than
|
|
|
|
|
// encoding them). Bitrate sent may temporarily exceed target set by
|
|
|
|
|
// UpdateBitrate() so that this limit will be upheld.
|
|
|
|
|
static const int64_t kMaxQueueLengthMs;
|
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
|
|
|
// Pacing-rate relative to our target send rate.
|
|
|
|
|
// Multiplicative factor that is applied to the target bitrate to calculate
|
|
|
|
|
// the number of bytes that can be transmitted per interval.
|
|
|
|
|
// Increasing this factor will result in lower delays in cases of bitrate
|
|
|
|
|
// overshoots from the encoder.
|
|
|
|
|
static const float kDefaultPaceMultiplier;
|
2014-07-04 09:20:42 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/10937): Make the |process_thread| argument be non
|
|
|
|
|
// optional once all callers have been updated.
|
2019-01-30 11:28:59 +01:00
|
|
|
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 = nullptr,
|
|
|
|
|
ProcessThread* process_thread = nullptr);
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2017-05-31 02:24:52 -07:00
|
|
|
~PacedSender() override;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
// Methods implementing RtpPacketSender.
|
2018-02-20 10:46:39 +01:00
|
|
|
|
2019-06-18 16:20:11 +02:00
|
|
|
// Adds the packet to the queue and calls PacketRouter::SendPacket() when
|
|
|
|
|
// it's time to send.
|
2019-10-02 14:57:46 +02:00
|
|
|
void EnqueuePackets(
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> packet) override;
|
2019-06-18 16:20:11 +02:00
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
// Methods implementing RtpPacketPacer:
|
|
|
|
|
|
|
|
|
|
void CreateProbeCluster(DataRate bitrate, int cluster_id) override;
|
|
|
|
|
|
|
|
|
|
// Temporarily pause all sending.
|
|
|
|
|
void Pause() override;
|
|
|
|
|
|
|
|
|
|
// Resume sending packets.
|
|
|
|
|
void Resume() override;
|
|
|
|
|
|
|
|
|
|
void SetCongestionWindow(DataSize congestion_window_size) override;
|
|
|
|
|
void UpdateOutstandingData(DataSize outstanding_data) override;
|
|
|
|
|
|
|
|
|
|
// Sets the pacing rates. Must be called once before packets can be sent.
|
|
|
|
|
void SetPacingRates(DataRate pacing_rate, DataRate padding_rate) override;
|
|
|
|
|
|
2017-10-20 10:37:47 +02:00
|
|
|
// Currently audio traffic is not accounted by pacer and passed through.
|
|
|
|
|
// With the introduction of audio BWE audio traffic will be accounted for
|
|
|
|
|
// the pacer budget calculation. The audio traffic still will be injected
|
|
|
|
|
// at high priority.
|
2019-07-29 16:38:27 +02:00
|
|
|
void SetAccountForAudioPackets(bool account_for_audio) override;
|
2017-10-20 10:37:47 +02:00
|
|
|
|
2020-01-29 17:42:52 +01:00
|
|
|
void SetIncludeOverhead() override;
|
2020-01-29 18:45:00 +00:00
|
|
|
void SetTransportOverhead(DataSize overhead_per_packet) override;
|
2020-01-29 17:42:52 +01:00
|
|
|
|
2013-12-13 22:03:27 +00:00
|
|
|
// Returns the time since the oldest queued packet was enqueued.
|
2019-07-29 16:38:27 +02:00
|
|
|
TimeDelta OldestPacketWaitTime() const override;
|
2013-03-27 16:36:01 +00:00
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
DataSize QueueSizeData() const override;
|
2014-10-23 11:57:05 +00:00
|
|
|
|
2019-07-29 16:38:27 +02:00
|
|
|
// Returns the time when the first packet was sent;
|
|
|
|
|
absl::optional<Timestamp> FirstSentPacketTime() const override;
|
2017-04-19 23:28:53 -07:00
|
|
|
|
2014-11-04 16:27:16 +00:00
|
|
|
// Returns the number of milliseconds it will take to send the current
|
|
|
|
|
// packets in the queue, given the current size and bitrate, ignoring prio.
|
2019-07-29 16:38:27 +02:00
|
|
|
TimeDelta ExpectedQueueTime() const override;
|
|
|
|
|
|
|
|
|
|
void SetQueueTimeLimit(TimeDelta limit) override;
|
|
|
|
|
|
|
|
|
|
// Below are methods specific to this implementation, such as things related
|
|
|
|
|
// to module processing thread specifics or methods exposed for test.
|
|
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
private:
|
2019-07-29 16:38:27 +02:00
|
|
|
// Methods implementing Module.
|
2019-08-29 18:32:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/10937): Remove the inheritance from Module once all
|
|
|
|
|
// use of it has been cleared up.
|
2014-11-04 16:27:16 +00:00
|
|
|
|
2012-11-09 20:56:23 +00:00
|
|
|
// Returns the number of milliseconds until the module want a worker thread
|
|
|
|
|
// to call Process.
|
2015-03-04 12:58:35 +00:00
|
|
|
int64_t TimeUntilNextProcess() override;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
// TODO(bugs.webrtc.org/10937): Make this private (and non virtual) once
|
|
|
|
|
// dependencies have been updated to not call this via the PacedSender
|
|
|
|
|
// interface.
|
|
|
|
|
public:
|
2012-11-09 20:56:23 +00:00
|
|
|
// Process any pending packets in the queue(s).
|
2016-02-25 04:50:01 -08:00
|
|
|
void Process() override;
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
private:
|
2017-03-15 07:45:36 -07:00
|
|
|
// Called when the prober is associated with a process thread.
|
|
|
|
|
void ProcessThreadAttached(ProcessThread* process_thread) override;
|
2017-06-30 13:27:40 -07:00
|
|
|
|
2019-11-14 18:04:49 +01:00
|
|
|
// In dynamic process mode, refreshes the next process time.
|
|
|
|
|
void MaybeWakupProcessThread();
|
2012-11-09 20:56:23 +00:00
|
|
|
|
2019-08-29 18:32:31 +02:00
|
|
|
// Private implementation of Module to not expose those implementation details
|
|
|
|
|
// publicly and control when the class is registered/deregistered.
|
|
|
|
|
class ModuleProxy : public Module {
|
|
|
|
|
public:
|
|
|
|
|
explicit ModuleProxy(PacedSender* delegate) : delegate_(delegate) {}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int64_t TimeUntilNextProcess() override {
|
|
|
|
|
return delegate_->TimeUntilNextProcess();
|
|
|
|
|
}
|
|
|
|
|
void Process() override { return delegate_->Process(); }
|
|
|
|
|
void ProcessThreadAttached(ProcessThread* process_thread) override {
|
|
|
|
|
return delegate_->ProcessThreadAttached(process_thread);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PacedSender* const delegate_;
|
|
|
|
|
} module_proxy_{this};
|
|
|
|
|
|
2021-02-09 11:24:59 +01:00
|
|
|
mutable Mutex mutex_;
|
2019-11-14 18:04:49 +01:00
|
|
|
const PacingController::ProcessMode process_mode_;
|
2021-02-09 11:24:59 +01:00
|
|
|
PacingController pacing_controller_ RTC_GUARDED_BY(mutex_);
|
2014-07-07 10:20:35 +00:00
|
|
|
|
2019-11-05 11:21:48 +01:00
|
|
|
Clock* const clock_;
|
2019-08-29 18:32:31 +02:00
|
|
|
ProcessThread* const process_thread_;
|
2012-11-09 20:56:23 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_PACING_PACED_SENDER_H_
|