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