CongestionControl.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // libtgvoip is free and unencumbered public domain software.
  3. // For more information, see http://unlicense.org or the UNLICENSE file
  4. // you should have received with this source code distribution.
  5. //
  6. #ifndef LIBTGVOIP_CONGESTIONCONTROL_H
  7. #define LIBTGVOIP_CONGESTIONCONTROL_H
  8. #include <stdlib.h>
  9. #include <stdint.h>
  10. #include "threading.h"
  11. #include "Buffers.h"
  12. #define TGVOIP_CONCTL_ACT_INCREASE 1
  13. #define TGVOIP_CONCTL_ACT_DECREASE 2
  14. #define TGVOIP_CONCTL_ACT_NONE 0
  15. namespace tgvoip{
  16. struct tgvoip_congestionctl_packet_t{
  17. uint32_t seq;
  18. double sendTime;
  19. size_t size;
  20. };
  21. typedef struct tgvoip_congestionctl_packet_t tgvoip_congestionctl_packet_t;
  22. class CongestionControl{
  23. public:
  24. CongestionControl();
  25. ~CongestionControl();
  26. void PacketSent(uint32_t seq, size_t size);
  27. void PacketAcknowledged(uint32_t seq);
  28. double GetAverageRTT();
  29. double GetMinimumRTT();
  30. size_t GetInflightDataSize();
  31. size_t GetCongestionWindow();
  32. size_t GetAcknowledgedDataSize();
  33. void Tick();
  34. int GetBandwidthControlAction();
  35. uint32_t GetSendLossCount();
  36. private:
  37. HistoricBuffer<double, 100> rttHistory;
  38. HistoricBuffer<size_t, 30> inflightHistory;
  39. tgvoip_congestionctl_packet_t inflightPackets[100];
  40. uint32_t lossCount;
  41. double tmpRtt;
  42. double lastActionTime;
  43. double lastActionRtt;
  44. double stateTransitionTime;
  45. int tmpRttCount;
  46. uint32_t lastSentSeq;
  47. uint32_t tickCount;
  48. size_t inflightDataSize;
  49. size_t cwnd;
  50. Mutex mutex;
  51. };
  52. }
  53. #endif //LIBTGVOIP_CONGESTIONCONTROL_H