2017-02-02 17:24:40 +01:00
|
|
|
//
|
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBTGVOIP_CONGESTIONCONTROL_H
|
|
|
|
#define LIBTGVOIP_CONGESTIONCONTROL_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2017-04-17 20:57:07 +02:00
|
|
|
#include <stdint.h>
|
2017-02-02 17:24:40 +01:00
|
|
|
#include "threading.h"
|
2018-07-17 18:48:21 +02:00
|
|
|
#include "Buffers.h"
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
#define TGVOIP_CONCTL_ACT_INCREASE 1
|
|
|
|
#define TGVOIP_CONCTL_ACT_DECREASE 2
|
|
|
|
#define TGVOIP_CONCTL_ACT_NONE 0
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
namespace tgvoip{
|
|
|
|
|
2017-02-02 17:24:40 +01:00
|
|
|
struct tgvoip_congestionctl_packet_t{
|
|
|
|
uint32_t seq;
|
|
|
|
double sendTime;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
typedef struct tgvoip_congestionctl_packet_t tgvoip_congestionctl_packet_t;
|
|
|
|
|
2017-04-28 13:17:56 +02:00
|
|
|
class CongestionControl{
|
2017-02-02 17:24:40 +01:00
|
|
|
public:
|
2017-04-28 13:17:56 +02:00
|
|
|
CongestionControl();
|
|
|
|
~CongestionControl();
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
void PacketSent(uint32_t seq, size_t size);
|
2019-04-15 01:43:10 +02:00
|
|
|
void PacketLost(uint32_t seq);
|
2017-02-02 17:24:40 +01:00
|
|
|
void PacketAcknowledged(uint32_t seq);
|
|
|
|
|
|
|
|
double GetAverageRTT();
|
|
|
|
double GetMinimumRTT();
|
|
|
|
size_t GetInflightDataSize();
|
|
|
|
size_t GetCongestionWindow();
|
|
|
|
size_t GetAcknowledgedDataSize();
|
|
|
|
void Tick();
|
|
|
|
int GetBandwidthControlAction();
|
|
|
|
uint32_t GetSendLossCount();
|
|
|
|
|
|
|
|
private:
|
2018-07-17 18:48:21 +02:00
|
|
|
HistoricBuffer<double, 100> rttHistory;
|
|
|
|
HistoricBuffer<size_t, 30> inflightHistory;
|
2017-02-02 17:24:40 +01:00
|
|
|
tgvoip_congestionctl_packet_t inflightPackets[100];
|
|
|
|
uint32_t lossCount;
|
|
|
|
double tmpRtt;
|
|
|
|
double lastActionTime;
|
|
|
|
double lastActionRtt;
|
|
|
|
double stateTransitionTime;
|
|
|
|
int tmpRttCount;
|
|
|
|
uint32_t lastSentSeq;
|
|
|
|
uint32_t tickCount;
|
|
|
|
size_t inflightDataSize;
|
|
|
|
size_t cwnd;
|
|
|
|
};
|
2017-04-28 13:17:56 +02:00
|
|
|
}
|
2017-02-02 17:24:40 +01:00
|
|
|
|
|
|
|
#endif //LIBTGVOIP_CONGESTIONCONTROL_H
|