Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(844)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/test/bwe.h

Issue 1202253003: More Simulation Framework features (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed std::next to advance iterator Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
(...skipping 21 matching lines...) Expand all
49 50
50 // If the arriving packet (identified by its sequence number) is already 51 // 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 52 // in the LinkedSet, move its Node to the head of the list. Else, create
52 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail() 53 // a PacketIdentifierNode n_ and then UpdateHead(n_), calling RemoveTail()
53 // if the LinkedSet reached its maximum capacity. 54 // if the LinkedSet reached its maximum capacity.
54 void Insert(uint16_t sequence_number, 55 void Insert(uint16_t sequence_number,
55 int64_t send_time_ms, 56 int64_t send_time_ms,
56 int64_t arrival_time_ms, 57 int64_t arrival_time_ms,
57 size_t payload_size); 58 size_t payload_size);
58 59
60 void Insert(PacketIdentifierNode packet_identifier);
61
59 PacketNodeIt begin() { return list_.begin(); } 62 PacketNodeIt begin() { return list_.begin(); }
stefan-webrtc 2015/07/06 08:24:51 Many of the methods below should be const.
magalhaesc 2015/07/06 09:28:06 Done.
60 PacketNodeIt end() { return list_.end(); } 63 PacketNodeIt end() { return list_.end(); }
64
61 bool empty() { return list_.empty(); } 65 bool empty() { return list_.empty(); }
62 size_t size() { return list_.size(); } 66 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_; } 67 size_t capacity() { return capacity_; }
72 68
69 // Gets the highest (absolute value) sequence number.
70 uint16_t Max() { return empty() ? 0 : map_.rbegin()->first; }
71 // Gets the lowest (absolute value) sequence number still saved in the
72 // LinkedSet.
73 uint16_t Min() { return empty() ? 0 : map_.begin()->first; }
74
75 uint16_t OldestSeqNumber();
76 uint16_t NewestSeqNumber();
77
78 void Clear() {
79 map_.clear();
80 list_.clear();
81 }
82
83 void Erase(PacketNodeIt node_rit);
stefan-webrtc 2015/07/06 08:24:51 This doesn't delete a reverse iterator right? If i
magalhaesc 2015/07/06 09:28:06 Previously it was for reverse_iterator, I forgot t
84
73 private: 85 private:
74 // Pop oldest element from the back of the list and remove it from the map. 86 // Pop oldest element from the back of the list and remove it from the map.
75 void RemoveTail(); 87 void RemoveTail();
76 // Add new element to the front of the list and insert it in the map. 88 // Add new element to the front of the list and insert it in the map.
77 void UpdateHead(PacketIdentifierNode* new_head); 89 void UpdateHead(PacketIdentifierNode* new_head);
78 size_t capacity_; 90 size_t capacity_;
79 std::map<uint16_t, PacketNodeIt> map_; 91 std::map<uint16_t, PacketNodeIt> map_;
80 std::list<PacketIdentifierNode*> list_; 92 std::list<PacketIdentifierNode*> list_;
81 }; 93 };
82 94
83 const int kMinBitrateKbps = 150; 95 // Holds information for computing global packet loss.
84 const int kMaxBitrateKbps = 3000; 96 struct LossAccount {
97 LossAccount() : num_total(0), num_lost(0) {}
98 LossAccount(size_t num_total, size_t num_lost)
99 : num_total(num_total), num_lost(num_lost) {}
100 void Add(LossAccount rhs);
101 void Subtract(LossAccount rhs);
102 float LossRatio();
103 size_t num_total;
104 size_t num_lost;
105 };
106
107 const int kMinBitrateKbps = 30;
108 const int kMaxBitrateKbps = 2500;
85 109
86 class BweSender : public Module { 110 class BweSender : public Module {
87 public: 111 public:
88 BweSender() {} 112 BweSender() : running_(true) {}
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;
118 virtual void Pause();
119 virtual void Resume();
120
121 protected:
122 bool running_;
123 int bitrate_kbps_;
94 124
95 private: 125 private:
96 DISALLOW_COPY_AND_ASSIGN(BweSender); 126 DISALLOW_COPY_AND_ASSIGN(BweSender);
97 }; 127 };
98 128
99 class BweReceiver { 129 class BweReceiver {
100 public: 130 public:
101 explicit BweReceiver(int flow_id); 131 explicit BweReceiver(int flow_id);
102 virtual ~BweReceiver() {} 132 virtual ~BweReceiver() {}
103 133
104 virtual void ReceivePacket(int64_t arrival_time_ms, 134 virtual void ReceivePacket(int64_t arrival_time_ms,
105 const MediaPacket& media_packet) {} 135 const MediaPacket& media_packet) {}
106 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; } 136 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; }
107 137
108 float GlobalPacketLossRatio();
109 float RecentPacketLossRatio();
110 size_t GetSetCapacity() { return received_packets_.capacity(); } 138 size_t GetSetCapacity() { return received_packets_.capacity(); }
111 139
140 uint32_t RecentKbps(); // Receiving Rate.
stefan-webrtc 2015/07/06 08:24:51 This method should be const, right? Same with some
magalhaesc 2015/07/06 09:28:06 Done.
141 // Packet loss only for packets arriving in the latest 500ms time window.
142 float RecentPacketLossRatio(); // Plot dynamics.
143 // Computes packet loss during an entire simulation, up to 4 billion packets.
144 float GlobalReceiverPacketLossRatio(); // Plot histogram.
145
112 static const int64_t kPacketLossTimeWindowMs = 500; 146 static const int64_t kPacketLossTimeWindowMs = 500;
147 static const int64_t kReceivingRateTimeWindowMs = 1000;
113 148
114 protected: 149 protected:
150 void RelieveSetAndUpdateLoss();
115 int flow_id_; 151 int flow_id_;
116 // Deals with packets sent more than once. 152 // Deals with packets sent more than once.
117 LinkedSet received_packets_; 153 LinkedSet received_packets_;
154 // Used for calculating recent receiving rate.
155 RateCounter rate_counter_;
156
157 private:
158 void UpdateLoss();
159 void ClearSet();
160 // Packet loss for packets stored in the LinkedSet, up to 1000 packets.
161 // Used to update global loss account whenever the set is filled and cleared.
162 LossAccount LinkedSetPacketLossRatio();
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 = 0,
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);
187
138 } // namespace bwe 188 } // namespace bwe
139 } // namespace testing 189 } // namespace testing
140 } // namespace webrtc 190 } // namespace webrtc
141 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ 191 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698