• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2015 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 WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_PACKET_H_
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_PACKET_H_
13 
14 #include <list>
15 #include <map>
16 #include <vector>
17 
18 #include "webrtc/common_types.h"
19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
20 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
21 
22 namespace webrtc {
23 namespace testing {
24 namespace bwe {
25 
26 class Packet {
27  public:
28   enum Type { kMedia, kFeedback };
29 
30   Packet();
31   Packet(int flow_id, int64_t send_time_us, size_t payload_size);
32   virtual ~Packet();
33 
34   virtual bool operator<(const Packet& rhs) const;
35 
flow_id()36   virtual int flow_id() const { return flow_id_; }
37   virtual void set_send_time_us(int64_t send_time_us);
send_time_us()38   virtual int64_t send_time_us() const { return send_time_us_; }
sender_timestamp_us()39   virtual int64_t sender_timestamp_us() const { return sender_timestamp_us_; }
payload_size()40   virtual size_t payload_size() const { return payload_size_; }
41   virtual Packet::Type GetPacketType() const = 0;
set_sender_timestamp_us(int64_t sender_timestamp_us)42   virtual void set_sender_timestamp_us(int64_t sender_timestamp_us) {
43     sender_timestamp_us_ = sender_timestamp_us;
44   }
set_paced(bool paced)45   virtual void set_paced(bool paced) { paced_ = paced; }
paced()46   virtual bool paced() const { return paced_; }
creation_time_ms()47   virtual int64_t creation_time_ms() const {
48     return (creation_time_us_ + 500) / 1000;
49   }
sender_timestamp_ms()50   virtual int64_t sender_timestamp_ms() const {
51     return (sender_timestamp_us_ + 500) / 1000;
52   }
send_time_ms()53   virtual int64_t send_time_ms() const { return (send_time_us_ + 500) / 1000; }
54 
55  protected:
56   int flow_id_;
57   int64_t creation_time_us_;  // Time when the packet was created.
58   int64_t send_time_us_;  // Time the packet left last processor touching it.
59   int64_t sender_timestamp_us_;  // Time the packet left the Sender.
60   size_t payload_size_;  // Size of the (non-existent, simulated) payload.
61   bool paced_;           // True if sent through paced sender.
62 };
63 
64 class MediaPacket : public Packet {
65  public:
66   MediaPacket();
67   MediaPacket(int flow_id,
68               int64_t send_time_us,
69               size_t payload_size,
70               uint16_t sequence_number);
71   MediaPacket(int flow_id,
72               int64_t send_time_us,
73               size_t payload_size,
74               const RTPHeader& header);
75   MediaPacket(int64_t send_time_us, uint16_t sequence_number);
76 
~MediaPacket()77   virtual ~MediaPacket() {}
78 
GetAbsSendTimeInMs()79   int64_t GetAbsSendTimeInMs() const {
80     int64_t timestamp = header_.extension.absoluteSendTime
81                         << kAbsSendTimeInterArrivalUpshift;
82     return 1000.0 * timestamp / static_cast<double>(1 << kInterArrivalShift);
83   }
84   void SetAbsSendTimeMs(int64_t abs_send_time_ms);
header()85   const RTPHeader& header() const { return header_; }
GetPacketType()86   virtual Packet::Type GetPacketType() const { return kMedia; }
sequence_number()87   uint16_t sequence_number() const { return header_.sequenceNumber; }
88 
89  private:
90   static const int kAbsSendTimeFraction = 18;
91   static const int kAbsSendTimeInterArrivalUpshift = 8;
92   static const int kInterArrivalShift =
93       kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift;
94 
95   RTPHeader header_;
96 };
97 
98 class FeedbackPacket : public Packet {
99  public:
FeedbackPacket(int flow_id,int64_t this_send_time_us,int64_t latest_send_time_ms)100   FeedbackPacket(int flow_id,
101                  int64_t this_send_time_us,
102                  int64_t latest_send_time_ms)
103       : Packet(flow_id, this_send_time_us, 0),
104         latest_send_time_ms_(latest_send_time_ms) {}
~FeedbackPacket()105   virtual ~FeedbackPacket() {}
106 
GetPacketType()107   virtual Packet::Type GetPacketType() const { return kFeedback; }
latest_send_time_ms()108   int64_t latest_send_time_ms() const { return latest_send_time_ms_; }
109 
110  private:
111   int64_t latest_send_time_ms_;  // Time stamp for the latest sent FbPacket.
112 };
113 
114 class RembFeedback : public FeedbackPacket {
115  public:
116   RembFeedback(int flow_id,
117                int64_t send_time_us,
118                int64_t latest_send_time_ms,
119                uint32_t estimated_bps,
120                RTCPReportBlock report_block);
~RembFeedback()121   virtual ~RembFeedback() {}
122 
estimated_bps()123   uint32_t estimated_bps() const { return estimated_bps_; }
report_block()124   RTCPReportBlock report_block() const { return report_block_; }
125 
126  private:
127   const uint32_t estimated_bps_;
128   const RTCPReportBlock report_block_;
129 };
130 
131 class SendSideBweFeedback : public FeedbackPacket {
132  public:
133   typedef std::map<uint16_t, int64_t> ArrivalTimesMap;
134   SendSideBweFeedback(int flow_id,
135                       int64_t send_time_us,
136                       int64_t latest_send_time_ms,
137                       const std::vector<PacketInfo>& packet_feedback_vector);
~SendSideBweFeedback()138   virtual ~SendSideBweFeedback() {}
139 
packet_feedback_vector()140   const std::vector<PacketInfo>& packet_feedback_vector() const {
141     return packet_feedback_vector_;
142   }
143 
144  private:
145   const std::vector<PacketInfo> packet_feedback_vector_;
146 };
147 
148 class NadaFeedback : public FeedbackPacket {
149  public:
NadaFeedback(int flow_id,int64_t this_send_time_us,int64_t exp_smoothed_delay_ms,int64_t est_queuing_delay_signal_ms,int64_t congestion_signal,float derivative,float receiving_rate,int64_t latest_send_time_ms)150   NadaFeedback(int flow_id,
151                int64_t this_send_time_us,
152                int64_t exp_smoothed_delay_ms,
153                int64_t est_queuing_delay_signal_ms,
154                int64_t congestion_signal,
155                float derivative,
156                float receiving_rate,
157                int64_t latest_send_time_ms)
158       : FeedbackPacket(flow_id, this_send_time_us, latest_send_time_ms),
159         exp_smoothed_delay_ms_(exp_smoothed_delay_ms),
160         est_queuing_delay_signal_ms_(est_queuing_delay_signal_ms),
161         congestion_signal_(congestion_signal),
162         derivative_(derivative),
163         receiving_rate_(receiving_rate) {}
~NadaFeedback()164   virtual ~NadaFeedback() {}
165 
exp_smoothed_delay_ms()166   int64_t exp_smoothed_delay_ms() const { return exp_smoothed_delay_ms_; }
est_queuing_delay_signal_ms()167   int64_t est_queuing_delay_signal_ms() const {
168     return est_queuing_delay_signal_ms_;
169   }
congestion_signal()170   int64_t congestion_signal() const { return congestion_signal_; }
derivative()171   float derivative() const { return derivative_; }
receiving_rate()172   float receiving_rate() const { return receiving_rate_; }
173 
174  private:
175   int64_t exp_smoothed_delay_ms_;        // Referred as d_hat_n.
176   int64_t est_queuing_delay_signal_ms_;  // Referred as d_tilde_n.
177   int64_t congestion_signal_;            // Referred as x_n.
178   float derivative_;                     // Referred as x'_n.
179   float receiving_rate_;                 // Referred as R_r.
180 };
181 
182 class TcpFeedback : public FeedbackPacket {
183  public:
TcpFeedback(int flow_id,int64_t send_time_us,int64_t latest_send_time_ms,const std::vector<uint16_t> & acked_packets)184   TcpFeedback(int flow_id,
185               int64_t send_time_us,
186               int64_t latest_send_time_ms,
187               const std::vector<uint16_t>& acked_packets)
188       : FeedbackPacket(flow_id, send_time_us, latest_send_time_ms),
189         acked_packets_(acked_packets) {}
~TcpFeedback()190   virtual ~TcpFeedback() {}
191 
acked_packets()192   const std::vector<uint16_t>& acked_packets() const { return acked_packets_; }
193 
194  private:
195   const std::vector<uint16_t> acked_packets_;
196 };
197 
198 typedef std::list<Packet*> Packets;
199 typedef std::list<Packet*>::iterator PacketsIt;
200 typedef std::list<Packet*>::const_iterator PacketsConstIt;
201 
202 }  // namespace bwe
203 }  // namespace testing
204 }  // namespace webrtc
205 #endif  // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_PACKET_H_
206