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