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