xref: /aosp_15_r20/external/webrtc/modules/pacing/rtp_packet_pacer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_PACING_RTP_PACKET_PACER_H_
12 #define MODULES_PACING_RTP_PACKET_PACER_H_
13 
14 #include <stdint.h>
15 
16 #include <vector>
17 
18 #include "absl/types/optional.h"
19 #include "api/units/data_rate.h"
20 #include "api/units/data_size.h"
21 #include "api/units/time_delta.h"
22 #include "api/units/timestamp.h"
23 #include "modules/rtp_rtcp/include/rtp_packet_sender.h"
24 
25 namespace webrtc {
26 
27 class RtpPacketPacer {
28  public:
29   virtual ~RtpPacketPacer() = default;
30 
31   virtual void CreateProbeClusters(
32       std::vector<ProbeClusterConfig> probe_cluster_configs) = 0;
33 
34   // Temporarily pause all sending.
35   virtual void Pause() = 0;
36 
37   // Resume sending packets.
38   virtual void Resume() = 0;
39 
40   virtual void SetCongested(bool congested) = 0;
41 
42   // Sets the pacing rates. Must be called once before packets can be sent.
43   virtual void SetPacingRates(DataRate pacing_rate, DataRate padding_rate) = 0;
44 
45   // Time since the oldest packet currently in the queue was added.
46   virtual TimeDelta OldestPacketWaitTime() const = 0;
47 
48   // Sum of payload + padding bytes of all packets currently in the pacer queue.
49   virtual DataSize QueueSizeData() const = 0;
50 
51   // Returns the time when the first packet was sent.
52   virtual absl::optional<Timestamp> FirstSentPacketTime() const = 0;
53 
54   // Returns the expected number of milliseconds it will take to send the
55   // current packets in the queue, given the current size and bitrate, ignoring
56   // priority.
57   virtual TimeDelta ExpectedQueueTime() const = 0;
58 
59   // Set the average upper bound on pacer queuing delay. The pacer may send at
60   // a higher rate than what was configured via SetPacingRates() in order to
61   // keep ExpectedQueueTimeMs() below `limit_ms` on average.
62   virtual void SetQueueTimeLimit(TimeDelta limit) = 0;
63 
64   // Currently audio traffic is not accounted by pacer and passed through.
65   // With the introduction of audio BWE audio traffic will be accounted for
66   // the pacer budget calculation. The audio traffic still will be injected
67   // at high priority.
68   virtual void SetAccountForAudioPackets(bool account_for_audio) = 0;
69   virtual void SetIncludeOverhead() = 0;
70   virtual void SetTransportOverhead(DataSize overhead_per_packet) = 0;
71 };
72 
73 }  // namespace webrtc
74 #endif  // MODULES_PACING_RTP_PACKET_PACER_H_
75