Chromium Code Reviews| Index: webrtc/modules/remote_bitrate_estimator/test/bwe.h |
| diff --git a/webrtc/modules/remote_bitrate_estimator/test/bwe.h b/webrtc/modules/remote_bitrate_estimator/test/bwe.h |
| index 6aa79cac2a82143c4de90b5b110c3b4cbfb4db0c..420fb5d3902c8ed18091e372d71b614f95158f5e 100644 |
| --- a/webrtc/modules/remote_bitrate_estimator/test/bwe.h |
| +++ b/webrtc/modules/remote_bitrate_estimator/test/bwe.h |
| @@ -15,11 +15,32 @@ |
| #include "webrtc/modules/remote_bitrate_estimator/test/packet.h" |
| #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| +#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_framework.h" |
| namespace webrtc { |
| namespace testing { |
| namespace bwe { |
| +// Overload map comparator. |
| +class SequenceNumberOlderThan { |
| + public: |
| + bool operator()(uint16_t seq_num_1, uint16_t seq_num_2) const { |
| + return IsNewerSequenceNumber(seq_num_2, seq_num_1); |
| + } |
| +}; |
| + |
| +// Holds information for computing global packet loss. |
| +struct LossAccount { |
| + LossAccount() : num_total(0), num_lost(0) {} |
| + LossAccount(size_t num_total, size_t num_lost) |
| + : num_total(num_total), num_lost(num_lost) {} |
| + void Add(LossAccount rhs); |
| + void Subtract(LossAccount rhs); |
| + float LossRatio(); |
| + size_t num_total; |
| + size_t num_lost; |
| +}; |
| + |
| // Holds only essential information about packets to be saved for |
| // further use, e.g. for calculating packet loss and receiving rate. |
| struct PacketIdentifierNode { |
| @@ -56,19 +77,21 @@ class LinkedSet { |
| int64_t arrival_time_ms, |
| size_t payload_size); |
| + void Insert(PacketIdentifierNode packet_identifier); |
| + |
| PacketNodeIt begin() { return list_.begin(); } |
| PacketNodeIt end() { return list_.end(); } |
| - bool empty() { return list_.empty(); } |
| - size_t size() { return list_.size(); } |
| - // Gets the latest arrived sequence number. |
| - uint16_t find_max() { return map_.rbegin()->first; } |
| - // Gets the first arrived sequence number still saved in the LinkedSet. |
| - uint16_t find_min() { return map_.begin()->first; } |
| - // Gets the lowest saved sequence number that is >= than the input key. |
| - uint16_t lower_bound(uint16_t key) { return map_.lower_bound(key)->first; } |
| - // Gets the highest saved sequence number that is <= than the input key. |
| - uint16_t upper_bound(uint16_t key) { return map_.upper_bound(key)->first; } |
| - size_t capacity() { return capacity_; } |
| + |
| + bool empty() const { return list_.empty(); } |
| + size_t size() const { return list_.size(); } |
| + size_t capacity() const { return capacity_; } |
| + |
| + uint16_t OldestSeqNumber() const { return empty() ? 0 : map_.begin()->first; } |
| + uint16_t NewestSeqNumber() const { |
| + return empty() ? 0 : map_.rbegin()->first; |
| + } |
| + |
| + void Erase(PacketNodeIt node_it); |
| private: |
| // Pop oldest element from the back of the list and remove it from the map. |
| @@ -76,22 +99,26 @@ class LinkedSet { |
| // Add new element to the front of the list and insert it in the map. |
| void UpdateHead(PacketIdentifierNode* new_head); |
| size_t capacity_; |
| - std::map<uint16_t, PacketNodeIt> map_; |
| + std::map<uint16_t, PacketNodeIt, SequenceNumberOlderThan> map_; |
| std::list<PacketIdentifierNode*> list_; |
| }; |
| -const int kMinBitrateKbps = 20; |
| -const int kMaxBitrateKbps = 3000; |
| +const int kMinBitrateKbps = 50; |
| +const int kMaxBitrateKbps = 2500; |
| class BweSender : public Module { |
| public: |
| BweSender() {} |
| + explicit BweSender(int bitrate_kbps) : bitrate_kbps_(bitrate_kbps) {} |
| virtual ~BweSender() {} |
| virtual int GetFeedbackIntervalMs() const = 0; |
| virtual void GiveFeedback(const FeedbackPacket& feedback) = 0; |
| virtual void OnPacketsSent(const Packets& packets) = 0; |
| + protected: |
| + int bitrate_kbps_; |
| + |
| private: |
| DISALLOW_COPY_AND_ASSIGN(BweSender); |
| }; |
| @@ -99,22 +126,42 @@ class BweSender : public Module { |
| class BweReceiver { |
| public: |
| explicit BweReceiver(int flow_id); |
| + BweReceiver(int flow_id, int64_t window_size_ms); |
| + |
| virtual ~BweReceiver() {} |
| virtual void ReceivePacket(int64_t arrival_time_ms, |
| - const MediaPacket& media_packet) {} |
| + const MediaPacket& media_packet); |
| virtual FeedbackPacket* GetFeedback(int64_t now_ms) { return NULL; } |
| - float GlobalPacketLossRatio(); |
| - float RecentPacketLossRatio(); |
| size_t GetSetCapacity() { return received_packets_.capacity(); } |
| + double BitrateWindowS() const { return rate_counter_.BitrateWindowS(); } |
| + uint32_t RecentKbps() const; // Receiving Rate. |
| + |
| + // Computes packet loss during an entire simulation, up to 4 billion packets. |
| + float GlobalReceiverPacketLossRatio(); // Plot histogram. |
| + float RecentPacketLossRatio(); // Plot dynamics. |
| + |
| + 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.
|
| + // Packet loss for packets stored in the LinkedSet, up to 1000 packets. |
| + // Used to update global loss account whenever the set is filled and cleared. |
| + LossAccount LinkedSetPacketLossRatio(); |
| + |
| + // Deals with packets sent more than once. |
| + LinkedSet received_packets_; |
| static const int64_t kPacketLossTimeWindowMs = 500; |
| + static const int64_t kReceivingRateTimeWindowMs = 1000; |
| protected: |
| int flow_id_; |
| - // Deals with packets sent more than once. |
| - LinkedSet received_packets_; |
| + // Used for calculating recent receiving rate. |
| + RateCounter rate_counter_; |
| + |
| + private: |
| + void UpdateLoss(); |
| + // Used for calculating global packet loss ratio. |
| + LossAccount loss_account_; |
| }; |
| enum BandwidthEstimatorType { |
| @@ -125,6 +172,8 @@ enum BandwidthEstimatorType { |
| kTcpEstimator |
| }; |
| +const std::string bwe_names[] = {"Null", "NADA", "REMB", "GCC", "TCP"}; |
| + |
| int64_t GetAbsSendTimeInMs(uint32_t abs_send_time); |
| BweSender* CreateBweSender(BandwidthEstimatorType estimator, |