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 |
23 // Holds only essential information about packets to be saved for | 24 // Holds only essential information about packets to be saved for |
24 // further use, e.g. for calculating packet loss and receiving rate. | 25 // further use, e.g. for calculating packet loss and receiving rate. |
25 struct PacketIdentifierNode { | 26 struct PacketIdentifierNode { |
26 PacketIdentifierNode(uint16_t sequence_number, | 27 PacketIdentifierNode(uint16_t sequence_number, |
27 int64_t send_time_ms, | 28 int64_t send_time_ms, |
28 int64_t arrival_time_ms, | 29 int64_t arrival_time_ms, |
29 size_t payload_size) | 30 size_t payload_size) |
30 : sequence_number(sequence_number), | 31 : sequence_number(sequence_number), |
31 send_time_ms(send_time_ms), | 32 send_time_ms(send_time_ms), |
32 arrival_time_ms(arrival_time_ms), | 33 arrival_time_ms(arrival_time_ms), |
33 payload_size(payload_size) {} | 34 payload_size(payload_size) {} |
34 | 35 |
36 PacketIdentifierNode copy(); | |
stefan-webrtc
2015/07/02 11:03:41
Not sure why this is needed. You can simply use th
magalhaesc
2015/07/02 17:06:18
Done.
| |
37 | |
35 uint16_t sequence_number; | 38 uint16_t sequence_number; |
36 int64_t send_time_ms; | 39 int64_t send_time_ms; |
37 int64_t arrival_time_ms; | 40 int64_t arrival_time_ms; |
38 size_t payload_size; | 41 size_t payload_size; |
39 }; | 42 }; |
40 | 43 |
41 typedef std::list<PacketIdentifierNode*>::iterator PacketNodeIt; | 44 typedef std::list<PacketIdentifierNode*>::iterator PacketNodeIt; |
42 | 45 |
43 // FIFO implementation for a limited capacity set. | 46 // FIFO implementation for a limited capacity set. |
44 // Used for keeping the latest arrived packets while avoiding duplicates. | 47 // Used for keeping the latest arrived packets while avoiding duplicates. |
45 // Allows efficient insertion, deletion and search. | 48 // Allows efficient insertion, deletion and search. |
46 class LinkedSet { | 49 class LinkedSet { |
47 public: | 50 public: |
48 explicit LinkedSet(int capacity) : capacity_(capacity) {} | 51 explicit LinkedSet(int capacity) : capacity_(capacity) {} |
49 | 52 |
50 // If the arriving packet (identified by its sequence number) is already | 53 // 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 | 54 // in the LinkedSet, move its Node to the head of the list. Else, create |
52 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail() | 55 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail() |
53 // if the LinkedSet reached its maximum capacity. | 56 // if the LinkedSet reached its maximum capacity. |
54 void Insert(uint16_t sequence_number, | 57 void Insert(uint16_t sequence_number, |
55 int64_t send_time_ms, | 58 int64_t send_time_ms, |
56 int64_t arrival_time_ms, | 59 int64_t arrival_time_ms, |
57 size_t payload_size); | 60 size_t payload_size); |
58 | 61 |
62 void Insert(PacketIdentifierNode packet_identifier); | |
63 | |
59 PacketNodeIt begin() { return list_.begin(); } | 64 PacketNodeIt begin() { return list_.begin(); } |
60 PacketNodeIt end() { return list_.end(); } | 65 PacketNodeIt end() { return list_.end(); } |
61 bool empty() { return list_.empty(); } | 66 bool empty() { return list_.empty(); } |
62 size_t size() { return list_.size(); } | 67 size_t size() { return list_.size(); } |
63 // Gets the latest arrived sequence number. | |
64 uint16_t find_max() { return map_.rbegin()->first; } | |
65 // Gets the first arrived sequence number still saved in the LinkedSet. | |
66 uint16_t find_min() { return map_.begin()->first; } | |
67 // Gets the lowest saved sequence number that is >= than the input key. | |
68 uint16_t lower_bound(uint16_t key) { return map_.lower_bound(key)->first; } | |
69 // Gets the highest saved sequence number that is <= than the input key. | |
70 uint16_t upper_bound(uint16_t key) { return map_.upper_bound(key)->first; } | |
71 size_t capacity() { return capacity_; } | 68 size_t capacity() { return capacity_; } |
72 | 69 |
70 // Gets the highest (absolute value) sequence number. | |
71 uint16_t Max() { return empty() ? 0 : map_.rbegin()->first; } | |
72 // Gets the lowest (absolute value) sequence number still saved in the | |
73 // LinkedSet. | |
74 uint16_t Min() { return empty() ? 0 : map_.begin()->first; } | |
75 | |
76 uint16_t OldestSeqNumber(); | |
77 uint16_t NewestSeqNumber(); | |
78 | |
79 void Clear() { | |
80 map_.clear(); | |
81 list_.clear(); | |
82 } | |
83 | |
73 private: | 84 private: |
74 // Pop oldest element from the back of the list and remove it from the map. | 85 // Pop oldest element from the back of the list and remove it from the map. |
75 void RemoveTail(); | 86 void RemoveTail(); |
76 // Add new element to the front of the list and insert it in the map. | 87 // Add new element to the front of the list and insert it in the map. |
77 void UpdateHead(PacketIdentifierNode* new_head); | 88 void UpdateHead(PacketIdentifierNode* new_head); |
78 size_t capacity_; | 89 size_t capacity_; |
79 std::map<uint16_t, PacketNodeIt> map_; | 90 std::map<uint16_t, PacketNodeIt> map_; |
80 std::list<PacketIdentifierNode*> list_; | 91 std::list<PacketIdentifierNode*> list_; |
81 }; | 92 }; |
82 | 93 |
94 // Holds information for computing global packet loss. | |
95 struct LossAccount { | |
96 LossAccount() : num_total(0), num_lost(0) {} | |
97 LossAccount(uint32_t num_total, uint32_t num_lost) | |
98 : num_total(num_total), num_lost(num_lost) {} | |
99 void Add(LossAccount addend); | |
100 void Subtract(LossAccount subtrahend); | |
stefan-webrtc
2015/07/02 11:03:41
Switch addend and subtrahend to "loss" or "rhs" (r
magalhaesc
2015/07/02 17:06:18
Done.
| |
101 float LossRatio(); | |
102 uint32_t num_total; | |
103 uint32_t num_lost; | |
104 }; | |
105 | |
83 const int kMinBitrateKbps = 150; | 106 const int kMinBitrateKbps = 150; |
84 const int kMaxBitrateKbps = 3000; | 107 const int kMaxBitrateKbps = 1500; |
stefan-webrtc
2015/07/02 11:03:41
Should make these 30 / 2500, right?
magalhaesc
2015/07/02 17:06:18
right
| |
85 | 108 |
86 class BweSender : public Module { | 109 class BweSender : public Module { |
87 public: | 110 public: |
88 BweSender() {} | 111 BweSender() : running_(true) {} |
89 virtual ~BweSender() {} | 112 virtual ~BweSender() {} |
90 | 113 |
91 virtual int GetFeedbackIntervalMs() const = 0; | 114 virtual int GetFeedbackIntervalMs() const = 0; |
92 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; | 115 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; |
93 virtual void OnPacketsSent(const Packets& packets) = 0; | 116 virtual void OnPacketsSent(const Packets& packets) = 0; |
117 virtual void Pause(); | |
118 virtual void Resume(); | |
119 | |
120 protected: | |
121 bool running_; | |
122 int bitrate_kbps_; | |
94 | 123 |
95 private: | 124 private: |
96 DISALLOW_COPY_AND_ASSIGN(BweSender); | 125 DISALLOW_COPY_AND_ASSIGN(BweSender); |
97 }; | 126 }; |
98 | 127 |
99 class BweReceiver { | 128 class BweReceiver { |
100 public: | 129 public: |
101 explicit BweReceiver(int flow_id); | 130 explicit BweReceiver(int flow_id); |
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(); } |
111 | 138 |
139 uint32_t RecentKbps(); // Receiving Rate calculated over latest 1000ms. | |
140 // Packet loss only for packets arriving in the latest 500ms time window. | |
141 float RecentPacketLossRatio(); // Plot dynamics. | |
142 // Computes packet loss during an entire simulation, up to 4 billion packets. | |
143 float GlobalReceiverPacketLossRatio(); // Plot histogram. | |
144 | |
112 static const int64_t kPacketLossTimeWindowMs = 500; | 145 static const int64_t kPacketLossTimeWindowMs = 500; |
146 static const int64_t kReceivingRateTimeWindowMs = 1000; | |
stefan-webrtc
2015/07/02 11:03:41
Do these constants have to be public?
magalhaesc
2015/07/02 17:06:18
We made them public to use on nada_unittests.cc
Do
stefan-webrtc
2015/07/03 09:32:10
No, this is OK.
| |
113 | 147 |
114 protected: | 148 protected: |
149 void RelieveSetAndUpdateLoss(); | |
115 int flow_id_; | 150 int flow_id_; |
116 // Deals with packets sent more than once. | 151 // Deals with packets sent more than once. |
117 LinkedSet received_packets_; | 152 LinkedSet received_packets_; |
153 // Used for calculating recent receiving rate. | |
154 RateCounter rate_counter_; | |
155 | |
156 private: | |
157 void UpdateLoss(); | |
158 void ClearSet(); | |
159 // Packet loss for packets stored in the LinkedSet, up to 1000 packets. | |
160 // Used to update global loss account whenever the set is filled and cleared. | |
161 LossAccount LinkedSetPacketLossRatio(); | |
162 // Used for calculating global packet loss ratio. | |
163 LossAccount loss_account; | |
118 }; | 164 }; |
119 | 165 |
120 enum BandwidthEstimatorType { | 166 enum BandwidthEstimatorType { |
121 kNullEstimator, | 167 kNullEstimator = 0, |
122 kNadaEstimator, | 168 kNadaEstimator, |
123 kRembEstimator, | 169 kRembEstimator, |
124 kFullSendSideEstimator, | 170 kFullSendSideEstimator, |
125 kTcpEstimator | 171 kTcpEstimator |
126 }; | 172 }; |
127 | 173 |
174 const std::string bwe_names[] = {"Null", "NADA", "REMB", "GCC", "TCP"}; | |
175 | |
128 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); | 176 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); |
129 | 177 |
130 BweSender* CreateBweSender(BandwidthEstimatorType estimator, | 178 BweSender* CreateBweSender(BandwidthEstimatorType estimator, |
131 int kbps, | 179 int kbps, |
132 BitrateObserver* observer, | 180 BitrateObserver* observer, |
133 Clock* clock); | 181 Clock* clock); |
134 | 182 |
135 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type, | 183 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type, |
136 int flow_id, | 184 int flow_id, |
137 bool plot); | 185 bool plot); |
186 | |
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 |