OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ | 11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ |
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ | 12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ |
13 | 13 |
14 #include <sstream> | 14 #include <sstream> |
15 | 15 |
16 #include "webrtc/modules/remote_bitrate_estimator/test/packet.h" | 16 #include "webrtc/modules/remote_bitrate_estimator/test/packet.h" |
17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 namespace testing { | 21 namespace testing { |
21 namespace bwe { | 22 namespace bwe { |
22 | 23 |
| 24 // Overload map comparator. |
| 25 class SequenceNumberOlderThan { |
| 26 public: |
| 27 bool operator()(uint16_t seq_num_1, uint16_t seq_num_2) const { |
| 28 return IsNewerSequenceNumber(seq_num_2, seq_num_1); |
| 29 } |
| 30 }; |
| 31 |
23 // Holds only essential information about packets to be saved for | 32 // Holds only essential information about packets to be saved for |
24 // further use, e.g. for calculating packet loss and receiving rate. | 33 // further use, e.g. for calculating packet loss and receiving rate. |
25 struct PacketIdentifierNode { | 34 struct PacketIdentifierNode { |
26 PacketIdentifierNode(uint16_t sequence_number, | 35 PacketIdentifierNode(uint16_t sequence_number, |
27 int64_t send_time_ms, | 36 int64_t send_time_ms, |
28 int64_t arrival_time_ms, | 37 int64_t arrival_time_ms, |
29 size_t payload_size) | 38 size_t payload_size) |
30 : sequence_number(sequence_number), | 39 : sequence_number(sequence_number), |
31 send_time_ms(send_time_ms), | 40 send_time_ms(send_time_ms), |
32 arrival_time_ms(arrival_time_ms), | 41 arrival_time_ms(arrival_time_ms), |
(...skipping 16 matching lines...) Expand all Loading... |
49 | 58 |
50 // If the arriving packet (identified by its sequence number) is already | 59 // If the arriving packet (identified by its sequence number) is already |
51 // in the LinkedSet, move its Node to the head of the list. Else, create | 60 // in the LinkedSet, move its Node to the head of the list. Else, create |
52 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail() | 61 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail() |
53 // if the LinkedSet reached its maximum capacity. | 62 // if the LinkedSet reached its maximum capacity. |
54 void Insert(uint16_t sequence_number, | 63 void Insert(uint16_t sequence_number, |
55 int64_t send_time_ms, | 64 int64_t send_time_ms, |
56 int64_t arrival_time_ms, | 65 int64_t arrival_time_ms, |
57 size_t payload_size); | 66 size_t payload_size); |
58 | 67 |
| 68 void Insert(PacketIdentifierNode packet_identifier); |
| 69 |
59 PacketNodeIt begin() { return list_.begin(); } | 70 PacketNodeIt begin() { return list_.begin(); } |
60 PacketNodeIt end() { return list_.end(); } | 71 PacketNodeIt end() { return list_.end(); } |
61 bool empty() { return list_.empty(); } | 72 |
62 size_t size() { return list_.size(); } | 73 bool empty() const { return list_.empty(); } |
63 // Gets the latest arrived sequence number. | 74 size_t size() const { return list_.size(); } |
64 uint16_t find_max() { return map_.rbegin()->first; } | 75 size_t capacity() const { return capacity_; } |
65 // Gets the first arrived sequence number still saved in the LinkedSet. | 76 |
66 uint16_t find_min() { return map_.begin()->first; } | 77 uint16_t OldestSeqNumber() const { |
67 // Gets the lowest saved sequence number that is >= than the input key. | 78 return empty() ? 0 : map_.rbegin()->first; |
68 uint16_t lower_bound(uint16_t key) { return map_.lower_bound(key)->first; } | 79 } |
69 // Gets the highest saved sequence number that is <= than the input key. | 80 uint16_t NewestSeqNumber() const { return empty() ? 0 : map_.begin()->first; } |
70 uint16_t upper_bound(uint16_t key) { return map_.upper_bound(key)->first; } | 81 |
71 size_t capacity() { return capacity_; } | 82 void Clear() { |
| 83 map_.clear(); |
| 84 list_.clear(); |
| 85 } |
| 86 |
| 87 void Erase(PacketNodeIt node_it); |
72 | 88 |
73 private: | 89 private: |
74 // Pop oldest element from the back of the list and remove it from the map. | 90 // Pop oldest element from the back of the list and remove it from the map. |
75 void RemoveTail(); | 91 void RemoveTail(); |
76 // Add new element to the front of the list and insert it in the map. | 92 // Add new element to the front of the list and insert it in the map. |
77 void UpdateHead(PacketIdentifierNode* new_head); | 93 void UpdateHead(PacketIdentifierNode* new_head); |
78 size_t capacity_; | 94 size_t capacity_; |
79 std::map<uint16_t, PacketNodeIt> map_; | 95 std::map<uint16_t, PacketNodeIt, SequenceNumberOlderThan> map_; |
80 std::list<PacketIdentifierNode*> list_; | 96 std::list<PacketIdentifierNode*> list_; |
81 }; | 97 }; |
82 | 98 |
83 const int kMinBitrateKbps = 150; | 99 // Holds information for computing global packet loss. |
84 const int kMaxBitrateKbps = 3000; | 100 struct LossAccount { |
| 101 LossAccount() : num_total(0), num_lost(0) {} |
| 102 LossAccount(size_t num_total, size_t num_lost) |
| 103 : num_total(num_total), num_lost(num_lost) {} |
| 104 void Add(LossAccount rhs); |
| 105 void Subtract(LossAccount rhs); |
| 106 float LossRatio(); |
| 107 size_t num_total; |
| 108 size_t num_lost; |
| 109 }; |
| 110 |
| 111 const int kMinBitrateKbps = 30; |
| 112 const int kMaxBitrateKbps = 2500; |
85 | 113 |
86 class BweSender : public Module { | 114 class BweSender : public Module { |
87 public: | 115 public: |
88 BweSender() {} | 116 BweSender() {} |
89 virtual ~BweSender() {} | 117 virtual ~BweSender() {} |
90 | 118 |
91 virtual int GetFeedbackIntervalMs() const = 0; | 119 virtual int GetFeedbackIntervalMs() const = 0; |
92 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; | 120 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; |
93 virtual void OnPacketsSent(const Packets& packets) = 0; | 121 virtual void OnPacketsSent(const Packets& packets) = 0; |
94 | 122 |
| 123 protected: |
| 124 int bitrate_kbps_; |
| 125 |
95 private: | 126 private: |
96 DISALLOW_COPY_AND_ASSIGN(BweSender); | 127 DISALLOW_COPY_AND_ASSIGN(BweSender); |
97 }; | 128 }; |
98 | 129 |
99 class BweReceiver { | 130 class BweReceiver { |
100 public: | 131 public: |
101 explicit BweReceiver(int flow_id); | 132 explicit BweReceiver(int flow_id); |
| 133 BweReceiver(int flow_id, int64_t window_size_ms); |
| 134 |
102 virtual ~BweReceiver() {} | 135 virtual ~BweReceiver() {} |
103 | 136 |
104 virtual void ReceivePacket(int64_t arrival_time_ms, | 137 virtual void ReceivePacket(int64_t arrival_time_ms, |
105 const MediaPacket& media_packet) {} | 138 const MediaPacket& media_packet) {} |
106 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; } | 139 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; } |
107 | 140 |
108 float GlobalPacketLossRatio(); | 141 size_t GetSetCapacity() const { return received_packets_.capacity(); } |
109 float RecentPacketLossRatio(); | 142 |
110 size_t GetSetCapacity() { return received_packets_.capacity(); } | 143 uint32_t RecentKbps() const; // Receiving Rate. |
| 144 // Packet loss only for packets arriving in the latest 500ms time window. |
| 145 float RecentPacketLossRatio(); // Plot dynamics. |
| 146 // Computes packet loss during an entire simulation, up to 4 billion packets. |
| 147 float GlobalReceiverPacketLossRatio(); // Plot histogram. |
111 | 148 |
112 static const int64_t kPacketLossTimeWindowMs = 500; | 149 static const int64_t kPacketLossTimeWindowMs = 500; |
| 150 static const int64_t kReceivingRateTimeWindowMs = 1000; |
113 | 151 |
114 protected: | 152 protected: |
| 153 void RelieveSetAndUpdateLoss(); |
115 int flow_id_; | 154 int flow_id_; |
116 // Deals with packets sent more than once. | 155 // Deals with packets sent more than once. |
117 LinkedSet received_packets_; | 156 LinkedSet received_packets_; |
| 157 // Used for calculating recent receiving rate. |
| 158 RateCounter rate_counter_; |
| 159 |
| 160 private: |
| 161 void UpdateLoss(); |
| 162 void ClearSet(); |
| 163 // Packet loss for packets stored in the LinkedSet, up to 1000 packets. |
| 164 // Used to update global loss account whenever the set is filled and cleared. |
| 165 LossAccount LinkedSetPacketLossRatio(); |
| 166 // Used for calculating global packet loss ratio. |
| 167 LossAccount loss_account; |
118 }; | 168 }; |
119 | 169 |
120 enum BandwidthEstimatorType { | 170 enum BandwidthEstimatorType { |
121 kNullEstimator, | 171 kNullEstimator = 0, |
122 kNadaEstimator, | 172 kNadaEstimator, |
123 kRembEstimator, | 173 kRembEstimator, |
124 kFullSendSideEstimator, | 174 kFullSendSideEstimator, |
125 kTcpEstimator | 175 kTcpEstimator |
126 }; | 176 }; |
127 | 177 |
| 178 const std::string bwe_names[] = {"Null", "NADA", "REMB", "GCC", "TCP"}; |
| 179 |
128 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); | 180 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); |
129 | 181 |
130 BweSender* CreateBweSender(BandwidthEstimatorType estimator, | 182 BweSender* CreateBweSender(BandwidthEstimatorType estimator, |
131 int kbps, | 183 int kbps, |
132 BitrateObserver* observer, | 184 BitrateObserver* observer, |
133 Clock* clock); | 185 Clock* clock); |
134 | 186 |
135 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type, | 187 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type, |
136 int flow_id, | 188 int flow_id, |
137 bool plot); | 189 bool plot); |
| 190 |
138 } // namespace bwe | 191 } // namespace bwe |
139 } // namespace testing | 192 } // namespace testing |
140 } // namespace webrtc | 193 } // namespace webrtc |
141 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ | 194 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ |
OLD | NEW |