| 6 |
| #define LIBTGVOIP_SCREAMCONGESTIONCONTROLLER_H |
| 7 |
| 8 | #include "../Buffers.h" |
| 9 | #include <vector> |
| 10 | #include <stdint.h> |
| 11 |
| 12 | namespace tgvoip{ |
| 13 | namespace video{ |
| 14 | class ScreamCongestionController{ |
| 15 | public: |
| 16 | ScreamCongestionController(); |
| 17 | void AdjustBitrate(); |
| 18 | void ProcessAcks(float oneWayDelay, uint32_t bytesNewlyAcked, uint32_t lossCount, double rtt); |
| 19 | void ProcessPacketSent(uint32_t size); |
| 20 | void ProcessPacketLost(uint32_t size); |
| 21 | double GetPacingInterval(); |
| 22 | void UpdateMediaRate(uint32_t frameSize); |
| 23 | uint32_t GetBitrate(); |
| 24 |
| 25 | private: |
| 26 | void UpdateVariables(float qdelay); |
| 27 | void UpdateCWnd(float qdelay); |
| 28 | void AdjustQDelayTarget(float qdelay); |
| 29 | void CalculateSendWindow(float qdelay); |
| 30 |
| 31 | void UpdateBytesInFlightHistory(); |
| 32 |
| 33 | struct ValueSample{ |
| 34 | uint32_t sample; |
| 35 | double time; |
| 36 | }; |
| 37 |
| 38 | float qdelayTarget; |
| 39 | float qdelayFractionAvg=0.0f; |
| 40 | HistoricBuffer<float, 20> qdelayFractionHist; |
| 41 | float qdelayTrend=0.0f; |
| 42 | float qdelayTrendMem=0.0f; |
| 43 | HistoricBuffer<float, 100> qdelayNormHist; |
| 44 | bool inFastIncrease=true; |
| 45 | uint32_t cwnd; |
| 46 | uint32_t bytesNewlyAcked=0; |
| 47 | uint32_t maxBytesInFlight=0; |
| 48 | uint32_t sendWnd=0; |
| 49 | uint32_t targetBitrate=0; |
| 50 | uint32_t targetBitrateLastMax=1; |
| 51 | float rateTransmit=0.0f; |
| 52 | float rateAck=0.0f; |
| 53 | float rateMedia=0.0f; |
| 54 | float rateMediaMedian=0.0f; |
| 55 | float sRTT=0.0f; |
| 56 | uint32_t rtpQueueSize=0; |
| 57 | uint32_t rtpSize=1024; //0; |
| 58 | float lossEventRate=0.0f; |
| 59 |
| 60 | bool lossPending=false; |
| 61 | float prevOneWayDelay=0.0f; |
| 62 | double ignoreLossesUntil=0.0; |
| 63 | uint32_t prevLossCount=0; |
| 64 | double lastTimeQDelayTrendWasGreaterThanLo=0.0; |
| 65 | double lastVariablesUpdateTime=0.0; |
| 66 | double lastRateAdjustmentTime=0.0; |
| 67 | double lastCWndUpdateTime=0.0; |
| 68 | uint32_t bytesInFlight=0; |
| 69 | std::vector<ValueSample> bytesInFlightHistory; |
| 70 | uint32_t bytesSent=0; |
| 71 | uint32_t bytesAcked=0; |
| 72 | uint32_t bytesMedia=0; |
| 73 | double rateTransmitUpdateTime=0.0; |
| 74 | double rateMediaUpdateTime=0.0; |
| 75 | HistoricBuffer<float, 25> rateMediaHistory; |
| 76 | }; |
| 77 | } |
| 78 | } |
| 79 |
| 80 | #endif //LIBTGVOIP_SCREAMCONGESTIONCONTROLLER_H |
| 81 |