1 /*
2  *  Copyright (c) 2017 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_REMOTE_BITRATE_ESTIMATOR_TEST_BBR_PACED_SENDER_H_
12 #define MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BBR_PACED_SENDER_H_
13 
14 #include <list>
15 #include <memory>
16 
17 #include "modules/pacing/paced_sender.h"
18 #include "modules/pacing/pacer.h"
19 
20 namespace webrtc {
21 namespace testing {
22 namespace bwe {
23 class CongestionWindow;
24 }
25 }  // namespace testing
26 
27 struct Packet {
PacketPacket28   Packet(RtpPacketSender::Priority priority,
29          uint32_t ssrc,
30          uint16_t seq_number,
31          int64_t capture_time_ms,
32          int64_t enqueue_time_ms,
33          size_t size_in_bytes,
34          bool retransmission)
35       : priority(priority),
36         ssrc(ssrc),
37         sequence_number(seq_number),
38         capture_time_ms(capture_time_ms),
39         enqueue_time_ms(enqueue_time_ms),
40         size_in_bytes(size_in_bytes),
41         retransmission(retransmission) {}
42   RtpPacketSender::Priority priority;
43   uint32_t ssrc;
44   uint16_t sequence_number;
45   int64_t capture_time_ms;
46   int64_t enqueue_time_ms;
47   size_t size_in_bytes;
48   bool retransmission;
49 };
50 
51 class Clock;
52 class RtcEventLog;
53 struct Packet;
54 class BbrPacedSender : public Pacer {
55  public:
56   BbrPacedSender(const Clock* clock,
57                  PacedSender::PacketSender* packet_sender,
58                  RtcEventLog* event_log);
59   ~BbrPacedSender() override;
60   void SetEstimatedBitrateAndCongestionWindow(
61       uint32_t bitrate_bps,
62       bool in_probe_rtt,
63       uint64_t congestion_window) override;
64   void SetMinBitrate(int min_send_bitrate_bps);
65   void InsertPacket(RtpPacketSender::Priority priority,
66                     uint32_t ssrc,
67                     uint16_t sequence_number,
68                     int64_t capture_time_ms,
69                     size_t bytes,
70                     bool retransmission) override;
SetAccountForAudioPackets(bool account_for_audio)71   void SetAccountForAudioPackets(bool account_for_audio) override {}
72   int64_t TimeUntilNextProcess() override;
73   void OnBytesAcked(size_t bytes) override;
74   void Process() override;
75   bool TryToSendPacket(Packet* packet);
76 
77  private:
78   const Clock* const clock_;
79   PacedSender::PacketSender* const packet_sender_;
80   uint32_t estimated_bitrate_bps_;
81   uint32_t min_send_bitrate_kbps_;
82   uint32_t pacing_bitrate_kbps_;
83   int64_t time_last_update_us_;
84   int64_t time_last_update_ms_;
85   int64_t next_packet_send_time_;
86   float rounding_error_time_ms_;
87   std::list<Packet*> packets_;
88   // TODO(gnish): integrate |max_data_inflight| into congestion window class.
89   size_t max_data_inflight_bytes_;
90   std::unique_ptr<testing::bwe::CongestionWindow> congestion_window_;
91 };
92 }  // namespace webrtc
93 #endif  // MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BBR_PACED_SENDER_H_
94