| 6 |
| 7 | #ifndef LIBTGVOIP_CONGESTIONCONTROL_H |
| 8 | #define LIBTGVOIP_CONGESTIONCONTROL_H |
| 9 |
| 10 | #include <stdlib.h> |
| 11 | #include <stdint.h> |
| 12 | #include "threading.h" |
| 13 | #include "Buffers.h" |
| 14 |
| 15 | #define TGVOIP_CONCTL_ACT_INCREASE 1 |
| 16 | #define TGVOIP_CONCTL_ACT_DECREASE 2 |
| 17 | #define TGVOIP_CONCTL_ACT_NONE 0 |
| 18 |
| 19 | namespace tgvoip{ |
| 20 |
| 21 | struct tgvoip_congestionctl_packet_t{ |
| 22 | uint32_t seq; |
| 23 | double sendTime; |
| 24 | size_t size; |
| 25 | }; |
| 26 | typedef struct tgvoip_congestionctl_packet_t tgvoip_congestionctl_packet_t; |
| 27 |
| 28 | class CongestionControl{ |
| 29 | public: |
| 30 | CongestionControl(); |
| 31 | ~CongestionControl(); |
| 32 |
| 33 | void PacketSent(uint32_t seq, size_t size); |
| 34 | void PacketAcknowledged(uint32_t seq); |
| 35 |
| 36 | double GetAverageRTT(); |
| 37 | double GetMinimumRTT(); |
| 38 | size_t GetInflightDataSize(); |
| 39 | size_t GetCongestionWindow(); |
| 40 | size_t GetAcknowledgedDataSize(); |
| 41 | void Tick(); |
| 42 | int GetBandwidthControlAction(); |
| 43 | uint32_t GetSendLossCount(); |
| 44 |
| 45 | private: |
| 46 | HistoricBuffer<double, 100> rttHistory; |
| 47 | HistoricBuffer<size_t, 30> inflightHistory; |
| 48 | tgvoip_congestionctl_packet_t inflightPackets[100]; |
| 49 | uint32_t lossCount; |
| 50 | double tmpRtt; |
| 51 | double lastActionTime; |
| 52 | double lastActionRtt; |
| 53 | double stateTransitionTime; |
| 54 | int tmpRttCount; |
| 55 | uint32_t lastSentSeq; |
| 56 | uint32_t tickCount; |
| 57 | size_t inflightDataSize; |
| 58 | size_t cwnd; |
| 59 | Mutex mutex; |
| 60 | }; |
| 61 | } |
| 62 |
| 63 | #endif //LIBTGVOIP_CONGESTIONCONTROL_H |
| 64 |