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

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: Added unittests 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
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
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() {}
117 BweSender(int bitrate_kbps) : bitrate_kbps_(bitrate_kbps) {}
stefan-webrtc 2015/07/09 09:54:59 explicit
magalhaesc 2015/07/09 11:20:07 Done.
89 virtual ~BweSender() {} 118 virtual ~BweSender() {}
90 119
91 virtual int GetFeedbackIntervalMs() const = 0; 120 virtual int GetFeedbackIntervalMs() const = 0;
92 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; 121 virtual void GiveFeedback(const FeedbackPacket& feedback) = 0;
93 virtual void OnPacketsSent(const Packets& packets) = 0; 122 virtual void OnPacketsSent(const Packets& packets) = 0;
94 123
124 protected:
125 int bitrate_kbps_;
126
95 private: 127 private:
96 DISALLOW_COPY_AND_ASSIGN(BweSender); 128 DISALLOW_COPY_AND_ASSIGN(BweSender);
97 }; 129 };
98 130
99 class BweReceiver { 131 class BweReceiver {
100 public: 132 public:
101 explicit BweReceiver(int flow_id); 133 explicit BweReceiver(int flow_id);
134 BweReceiver(int flow_id, int64_t window_size_ms);
135
102 virtual ~BweReceiver() {} 136 virtual ~BweReceiver() {}
103 137
104 virtual void ReceivePacket(int64_t arrival_time_ms, 138 virtual void ReceivePacket(int64_t arrival_time_ms,
105 const MediaPacket& media_packet) {} 139 const MediaPacket& media_packet) {}
106 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; } 140 virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; }
107 141
108 float GlobalPacketLossRatio(); 142 size_t GetSetCapacity() const { return received_packets_.capacity(); }
109 float RecentPacketLossRatio(); 143
110 size_t GetSetCapacity() { return received_packets_.capacity(); } 144 uint32_t RecentKbps() const; // Receiving Rate.
145 // Packet loss only for packets arriving in the latest 500ms time window.
146 float RecentPacketLossRatio(); // Plot dynamics.
147 // Computes packet loss during an entire simulation, up to 4 billion packets.
148 float GlobalReceiverPacketLossRatio(); // Plot histogram.
149
150 double window_size_s() const { return rate_counter_.window_size_s(); }
stefan-webrtc 2015/07/09 09:54:59 BitrateWindowS() instead, so that we understand wh
magalhaesc 2015/07/09 11:20:07 Done.
111 151
112 static const int64_t kPacketLossTimeWindowMs = 500; 152 static const int64_t kPacketLossTimeWindowMs = 500;
153 static const int64_t kReceivingRateTimeWindowMs = 1000;
113 154
114 protected: 155 protected:
156 void RelieveSetAndUpdateLoss();
157 // Packet loss for packets stored in the LinkedSet, up to 1000 packets.
158 // Used to update global loss account whenever the set is filled and cleared.
159 LossAccount LinkedSetPacketLossRatio();
115 int flow_id_; 160 int flow_id_;
116 // Deals with packets sent more than once. 161 // Deals with packets sent more than once.
117 LinkedSet received_packets_; 162 LinkedSet received_packets_;
163 // Used for calculating recent receiving rate.
164 RateCounter rate_counter_;
165 private:
166 void UpdateLoss();
167 void ClearSet();
168 // Used for calculating global packet loss ratio.
169 LossAccount loss_account;
118 }; 170 };
119 171
120 enum BandwidthEstimatorType { 172 enum BandwidthEstimatorType {
121 kNullEstimator, 173 kNullEstimator = 0,
122 kNadaEstimator, 174 kNadaEstimator,
123 kRembEstimator, 175 kRembEstimator,
124 kFullSendSideEstimator, 176 kFullSendSideEstimator,
125 kTcpEstimator 177 kTcpEstimator
126 }; 178 };
127 179
180 const std::string bwe_names[] = {"Null", "NADA", "REMB", "GCC", "TCP"};
181
128 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); 182 int64_t GetAbsSendTimeInMs(uint32_t abs_send_time);
129 183
130 BweSender* CreateBweSender(BandwidthEstimatorType estimator, 184 BweSender* CreateBweSender(BandwidthEstimatorType estimator,
131 int kbps, 185 int kbps,
132 BitrateObserver* observer, 186 BitrateObserver* observer,
133 Clock* clock); 187 Clock* clock);
134 188
135 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type, 189 BweReceiver* CreateBweReceiver(BandwidthEstimatorType type,
136 int flow_id, 190 int flow_id,
137 bool plot); 191 bool plot);
192
138 } // namespace bwe 193 } // namespace bwe
139 } // namespace testing 194 } // namespace testing
140 } // namespace webrtc 195 } // namespace webrtc
141 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_ 196 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698