2015-02-16 12:02:20 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_
|
|
|
|
|
#define MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_
|
2015-02-16 12:02:20 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <iterator>
|
2015-12-15 00:51:54 -08:00
|
|
|
#include <list>
|
|
|
|
|
#include <map>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <utility>
|
2015-02-16 12:02:20 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/bitrate_controller/include/bitrate_controller.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "modules/include/module.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/remote_bitrate_estimator/test/bwe_test_framework.h"
|
|
|
|
|
#include "modules/remote_bitrate_estimator/test/packet.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gtest_prod_util.h"
|
2018-08-03 19:24:25 +02:00
|
|
|
#include "rtc_base/numerics/sequence_number_util.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2015-02-16 12:02:20 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace testing {
|
|
|
|
|
namespace bwe {
|
|
|
|
|
|
2015-07-15 16:31:18 +02:00
|
|
|
// 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;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-08 11:29:08 +02:00
|
|
|
// Holds only essential information about packets to be saved for
|
|
|
|
|
// further use, e.g. for calculating packet loss and receiving rate.
|
|
|
|
|
struct PacketIdentifierNode {
|
2018-08-03 19:24:25 +02:00
|
|
|
PacketIdentifierNode(int64_t unwrapped_sequence_number,
|
2015-06-08 11:29:08 +02:00
|
|
|
int64_t send_time_ms,
|
|
|
|
|
int64_t arrival_time_ms,
|
|
|
|
|
size_t payload_size)
|
2018-08-03 19:24:25 +02:00
|
|
|
: unwrapped_sequence_number(unwrapped_sequence_number),
|
2015-06-08 11:29:08 +02:00
|
|
|
send_time_ms(send_time_ms),
|
|
|
|
|
arrival_time_ms(arrival_time_ms),
|
|
|
|
|
payload_size(payload_size) {}
|
|
|
|
|
|
2018-08-03 19:24:25 +02:00
|
|
|
int64_t unwrapped_sequence_number;
|
2015-06-08 11:29:08 +02:00
|
|
|
int64_t send_time_ms;
|
|
|
|
|
int64_t arrival_time_ms;
|
|
|
|
|
size_t payload_size;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-07 19:12:47 +02:00
|
|
|
typedef std::list<PacketIdentifierNode>::iterator PacketNodeIt;
|
2015-06-08 11:29:08 +02:00
|
|
|
|
|
|
|
|
// FIFO implementation for a limited capacity set.
|
|
|
|
|
// Used for keeping the latest arrived packets while avoiding duplicates.
|
|
|
|
|
// Allows efficient insertion, deletion and search.
|
|
|
|
|
class LinkedSet {
|
|
|
|
|
public:
|
2018-07-18 15:37:01 +02:00
|
|
|
explicit LinkedSet(int capacity);
|
2015-07-14 03:53:57 -07:00
|
|
|
~LinkedSet();
|
2015-06-08 11:29:08 +02:00
|
|
|
|
|
|
|
|
// If the arriving packet (identified by its sequence number) is already
|
2018-08-07 19:12:47 +02:00
|
|
|
// in the LinkedSet, move its Node to the head of the list.
|
|
|
|
|
// Else, add a PacketIdentifierNode n_ at the head of the list,
|
|
|
|
|
// calling RemoveTail() if the LinkedSet reached its maximum capacity.
|
2015-06-08 11:29:08 +02:00
|
|
|
void Insert(uint16_t sequence_number,
|
|
|
|
|
int64_t send_time_ms,
|
|
|
|
|
int64_t arrival_time_ms,
|
|
|
|
|
size_t payload_size);
|
|
|
|
|
|
|
|
|
|
PacketNodeIt begin() { return list_.begin(); }
|
|
|
|
|
PacketNodeIt end() { return list_.end(); }
|
2015-07-15 16:31:18 +02:00
|
|
|
|
|
|
|
|
bool empty() const { return list_.empty(); }
|
|
|
|
|
size_t size() const { return list_.size(); }
|
|
|
|
|
size_t capacity() const { return capacity_; }
|
|
|
|
|
|
2018-08-03 19:24:25 +02:00
|
|
|
// Return size of interval covering current set, i.e.:
|
|
|
|
|
// unwrapped newest seq number - unwrapped oldest seq number + 1
|
|
|
|
|
int64_t Range() const {
|
|
|
|
|
return empty() ? 0 : map_.rbegin()->first - map_.begin()->first + 1;
|
2015-07-15 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Erase(PacketNodeIt node_it);
|
2015-06-08 11:29:08 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Pop oldest element from the back of the list and remove it from the map.
|
|
|
|
|
void RemoveTail();
|
|
|
|
|
size_t capacity_;
|
2018-08-03 19:24:25 +02:00
|
|
|
// We want to keep track of the current oldest and newest sequence_numbers.
|
|
|
|
|
// To get strict weak ordering, we unwrap uint16_t into an int64_t.
|
|
|
|
|
SeqNumUnwrapper<uint16_t> unwrapper_;
|
|
|
|
|
std::map<int64_t, PacketNodeIt> map_;
|
2018-08-07 19:12:47 +02:00
|
|
|
std::list<PacketIdentifierNode> list_;
|
2015-06-08 11:29:08 +02:00
|
|
|
};
|
|
|
|
|
|
2016-08-04 06:42:07 -07:00
|
|
|
const int kMinBitrateKbps = 10;
|
2016-12-01 07:29:09 -08:00
|
|
|
const int kMaxBitrateKbps = 25000;
|
2015-02-24 13:24:19 +00:00
|
|
|
|
2015-02-17 16:03:45 +00:00
|
|
|
class BweSender : public Module {
|
2015-02-16 12:02:20 +00:00
|
|
|
public:
|
2015-02-17 16:03:45 +00:00
|
|
|
BweSender() {}
|
2015-07-15 16:31:18 +02:00
|
|
|
explicit BweSender(int bitrate_kbps) : bitrate_kbps_(bitrate_kbps) {}
|
2018-07-18 15:37:01 +02:00
|
|
|
~BweSender() override {}
|
2015-02-16 12:02:20 +00:00
|
|
|
|
|
|
|
|
virtual int GetFeedbackIntervalMs() const = 0;
|
|
|
|
|
virtual void GiveFeedback(const FeedbackPacket& feedback) = 0;
|
2015-03-18 13:40:54 +00:00
|
|
|
virtual void OnPacketsSent(const Packets& packets) = 0;
|
2015-02-16 12:02:20 +00:00
|
|
|
|
2015-07-15 16:31:18 +02:00
|
|
|
protected:
|
|
|
|
|
int bitrate_kbps_;
|
|
|
|
|
|
2015-02-16 12:02:20 +00:00
|
|
|
private:
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(BweSender);
|
2015-02-16 12:02:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class BweReceiver {
|
|
|
|
|
public:
|
2015-06-08 11:29:08 +02:00
|
|
|
explicit BweReceiver(int flow_id);
|
2015-07-15 16:31:18 +02:00
|
|
|
BweReceiver(int flow_id, int64_t window_size_ms);
|
|
|
|
|
|
2015-02-16 12:02:20 +00:00
|
|
|
virtual ~BweReceiver() {}
|
|
|
|
|
|
|
|
|
|
virtual void ReceivePacket(int64_t arrival_time_ms,
|
2015-07-15 16:31:18 +02:00
|
|
|
const MediaPacket& media_packet);
|
2018-07-18 15:37:01 +02:00
|
|
|
virtual FeedbackPacket* GetFeedback(int64_t now_ms);
|
2015-02-16 12:02:20 +00:00
|
|
|
|
2015-06-08 11:29:08 +02:00
|
|
|
size_t GetSetCapacity() { return received_packets_.capacity(); }
|
2015-07-15 16:31:18 +02:00
|
|
|
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.
|
2015-06-08 11:29:08 +02:00
|
|
|
|
|
|
|
|
static const int64_t kPacketLossTimeWindowMs = 500;
|
2015-07-15 16:31:18 +02:00
|
|
|
static const int64_t kReceivingRateTimeWindowMs = 1000;
|
2015-06-08 11:29:08 +02:00
|
|
|
|
2015-02-16 12:02:20 +00:00
|
|
|
protected:
|
|
|
|
|
int flow_id_;
|
2015-06-08 11:29:08 +02:00
|
|
|
// Deals with packets sent more than once.
|
|
|
|
|
LinkedSet received_packets_;
|
2015-07-15 16:31:18 +02:00
|
|
|
// Used for calculating recent receiving rate.
|
|
|
|
|
RateCounter rate_counter_;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FRIEND_TEST_ALL_PREFIXES(BweReceiverTest, RecentKbps);
|
|
|
|
|
FRIEND_TEST_ALL_PREFIXES(BweReceiverTest, Loss);
|
|
|
|
|
|
|
|
|
|
void UpdateLoss();
|
|
|
|
|
void RelieveSetAndUpdateLoss();
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
|
|
// Used for calculating global packet loss ratio.
|
|
|
|
|
LossAccount loss_account_;
|
2015-02-16 12:02:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum BandwidthEstimatorType {
|
|
|
|
|
kNullEstimator,
|
2015-02-17 16:03:45 +00:00
|
|
|
kNadaEstimator,
|
2015-02-16 12:02:20 +00:00
|
|
|
kRembEstimator,
|
2016-10-25 07:04:37 -07:00
|
|
|
kSendSideEstimator,
|
This is an initial cl, which contains small amount of implemented functions, and large amount of unimplemented ones.
Code should implement BBR which is the congestion controlling algorithm. BBR tries to estimate two values bottle-neck bandwidth(bw) and round trip time(rtt),then use these two values to set two control parameters pacing rate(pacing_rate),the rate at which data should be sent and congestion window size (cwnd), cwnd is the upper bound for data in flight,data_in_flight <= cwnd at all time.
BBR has four modes:
1)Startup-ramping up throughput discovering estimated bw.
2)Drain-after Startup decrease throughput to drain queues.
3)Probe Bandwidth-most of the time BBR should be in this mode,
sending data at the rate of estimated bw, while sometimes trying to discover new bandwidth.
4)Probe Rtt-in this mode BBR tries to discover new rtt for the connection.
The key moment in BBR is when we receive feedback from the receiver,as this is the only moment which should effect our two estimators. At this moment all the switches between modes should happen, except switch to ProbeRtt mode (switching to ProbeRtt mode should happen when current min_rtt value expires).
This cl serves to emphasize the structure of Bbr, when switches happen and what key classes/functions should be implemented for proper functionality.
BUG=webrtc:7713
NOTRY=True
Review-Url: https://codereview.webrtc.org/2904183002
Cr-Commit-Position: refs/heads/master@{#18444}
2017-06-05 06:01:26 -07:00
|
|
|
kTcpEstimator,
|
|
|
|
|
kBbrEstimator
|
2015-02-16 12:02:20 +00:00
|
|
|
};
|
|
|
|
|
|
2018-02-20 10:46:39 +01:00
|
|
|
const char* const bwe_names[] = {"Null", "NADA", "REMB",
|
|
|
|
|
"GoogCc", "TCP", "BBR"};
|
2015-07-15 16:31:18 +02:00
|
|
|
|
2015-02-24 13:24:19 +00:00
|
|
|
int64_t GetAbsSendTimeInMs(uint32_t abs_send_time);
|
|
|
|
|
|
2015-02-17 16:03:45 +00:00
|
|
|
BweSender* CreateBweSender(BandwidthEstimatorType estimator,
|
|
|
|
|
int kbps,
|
|
|
|
|
BitrateObserver* observer,
|
|
|
|
|
Clock* clock);
|
2015-02-16 12:02:20 +00:00
|
|
|
|
|
|
|
|
BweReceiver* CreateBweReceiver(BandwidthEstimatorType type,
|
|
|
|
|
int flow_id,
|
|
|
|
|
bool plot);
|
|
|
|
|
} // namespace bwe
|
|
|
|
|
} // namespace testing
|
|
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_REMOTE_BITRATE_ESTIMATOR_TEST_BWE_H_
|