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 "absl/types/optional.h"
17 #include "api/units/data_rate.h"
18 #include "api/units/data_size.h"
19 #include "api/units/time_delta.h"
20 #include "api/units/timestamp.h"
21 #include "modules/rtp_rtcp/include/rtp_packet_sender.h"
22 
23 namespace webrtc {
24 
25 class RtpPacketPacer {
26  public:
27   virtual ~RtpPacketPacer() = default;
28 
29   virtual void CreateProbeCluster(DataRate bitrate, int cluster_id) = 0;
30 
31   // Temporarily pause all sending.
32   virtual void Pause() = 0;
33 
34   // Resume sending packets.
35   virtual void Resume() = 0;
36 
37   virtual void SetCongestionWindow(DataSize congestion_window_size) = 0;
38   virtual void UpdateOutstandingData(DataSize outstanding_data) = 0;
39 
40   // Sets the pacing rates. Must be called once before packets can be sent.
41   virtual void SetPacingRates(DataRate pacing_rate, DataRate padding_rate) = 0;
42 
43   // Time since the oldest packet currently in the queue was added.
44   virtual TimeDelta OldestPacketWaitTime() const = 0;
45 
46   // Sum of payload + padding bytes of all packets currently in the pacer queue.
47   virtual DataSize QueueSizeData() const = 0;
48 
49   // Returns the time when the first packet was sent.
50   virtual absl::optional<Timestamp> FirstSentPacketTime() const = 0;
51 
52   // Returns the expected number of milliseconds it will take to send the
53   // current packets in the queue, given the current size and bitrate, ignoring
54   // priority.
55   virtual TimeDelta ExpectedQueueTime() const = 0;
56 
57   // Set the average upper bound on pacer queuing delay. The pacer may send at
58   // a higher rate than what was configured via SetPacingRates() in order to
59   // keep ExpectedQueueTimeMs() below |limit_ms| on average.
60   virtual void SetQueueTimeLimit(TimeDelta limit) = 0;
61 
62   // Currently audio traffic is not accounted by pacer and passed through.
63   // With the introduction of audio BWE audio traffic will be accounted for
64   // the pacer budget calculation. The audio traffic still will be injected
65   // at high priority.
66   virtual void SetAccountForAudioPackets(bool account_for_audio) = 0;
67   virtual void SetIncludeOverhead() = 0;
68   virtual void SetTransportOverhead(DataSize overhead_per_packet) = 0;
69 };
70 
71 }  // namespace webrtc
72 #endif  // MODULES_PACING_RTP_PACKET_PACER_H_
73