1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-02 09:37:52 +01:00
libtgvoip/controller/net/CongestionControl.h

84 lines
2.0 KiB
C
Raw Normal View History

2020-01-22 12:43:51 +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 "tools/Buffers.h"
2020-03-22 21:25:02 +01:00
#include "tools/threading.h"
2020-03-24 17:10:40 +01:00
#include <cstdint>
#include <map>
2020-03-22 21:25:02 +01:00
#include <stdlib.h>
2020-01-22 12:43:51 +01:00
#define TGVOIP_CONCTL_ACT_INCREASE 1
#define TGVOIP_CONCTL_ACT_DECREASE 2
#define TGVOIP_CONCTL_ACT_NONE 0
#define TGVOIP_CONCTL_LOST_AFTER 2
2020-01-22 12:43:51 +01:00
namespace tgvoip
{
struct tgvoip_congestionctl_packet_t
{
2020-03-22 21:25:02 +01:00
uint32_t seq;
uint8_t streamId;
double sendTime;
bool ack = false;
size_t size;
2020-01-22 12:43:51 +01:00
};
typedef struct tgvoip_congestionctl_packet_t tgvoip_congestionctl_packet_t;
2020-03-29 17:20:17 +02:00
struct Packet;
2020-03-24 12:15:04 +01:00
struct CongestionControlPacket
{
CongestionControlPacket(uint32_t _seq, uint8_t _streamId);
CongestionControlPacket(const Packet &pkt);
uint32_t seq;
uint8_t streamId;
};
2020-01-22 12:43:51 +01:00
class CongestionControl
{
public:
2020-03-22 21:25:02 +01:00
CongestionControl();
~CongestionControl();
2020-01-22 12:43:51 +01:00
2020-03-24 12:15:04 +01:00
void PacketSent(const CongestionControlPacket &pkt, size_t size);
void PacketLost(const CongestionControlPacket &pkt);
void PacketAcknowledged(const CongestionControlPacket &pkt);
2020-01-22 12:43:51 +01:00
2020-03-22 21:25:02 +01:00
double GetAverageRTT();
double GetMinimumRTT();
size_t GetInflightDataSize();
size_t GetCongestionWindow();
size_t GetAcknowledgedDataSize();
void Tick();
int GetBandwidthControlAction();
uint32_t GetSendLossCount();
2020-01-22 12:43:51 +01:00
private:
2020-03-22 21:25:02 +01:00
HistoricBuffer<double, 100> rttHistory;
HistoricBuffer<size_t, 30> inflightHistory;
std::array<tgvoip_congestionctl_packet_t, 100> inflightPackets{};
uint32_t lossCount = 0;
double tmpRtt = 0.0;
double lastActionTime = 0;
double lastActionRtt = 0;
double stateTransitionTime = 0;
uint32_t tmpRttCount = 0;
2020-03-24 12:15:04 +01:00
std::map<uint8_t, uint32_t> lastSentSeq;
2020-03-22 21:25:02 +01:00
uint32_t tickCount = 0;
size_t inflightDataSize = 0;
2020-03-13 21:12:58 +01:00
2020-03-22 21:25:02 +01:00
size_t cwnd;
size_t max;
size_t min;
2020-01-22 12:43:51 +01:00
};
} // namespace tgvoip
#endif //LIBTGVOIP_CONGESTIONCONTROL_H