for srt push fix ack paramter error result in pkt lost

This commit is contained in:
xiongguangjie
2022-06-03 20:18:34 +08:00
parent 7038924c6f
commit 7606dd7110
7 changed files with 142 additions and 69 deletions

View File

@@ -2,33 +2,47 @@
#include "Statistic.hpp"
namespace SRT {
void PacketRecvRateContext::inputPacket(TimePoint ts) {
void PacketRecvRateContext::inputPacket(TimePoint& ts) {
if(_pkt_map.size()>100){
_pkt_map.erase(_pkt_map.begin());
}
_pkt_map.emplace(ts,ts);
auto tmp = DurationCountMicroseconds(ts - _start);
_pkt_map.emplace(tmp,tmp);
}
uint32_t PacketRecvRateContext::getPacketRecvRate() {
if(_pkt_map.size()<2){
return 0;
if (_pkt_map.size() < 2) {
return 50000;
}
int64_t dur = 1000;
for (auto it = _pkt_map.begin(); it != _pkt_map.end(); ++it) {
auto next = it;
++next;
if (next != _pkt_map.end()) {
if ((next->first - it->first) < dur) {
dur = next->first - it->first;
}
} else {
break;
}
}
auto first = _pkt_map.begin();
auto last = _pkt_map.rbegin();
double dur = DurationCountMicroseconds(last->first - first->first)/1000000.0;
double rate = _pkt_map.size()/dur;
return (uint32_t)rate;
double rate = 1e6 / (double)dur;
if(rate <=1000){
return 50000;
}
return rate;
}
void EstimatedLinkCapacityContext::inputPacket(TimePoint ts) {
if(_pkt_map.size()>16){
void EstimatedLinkCapacityContext::inputPacket(TimePoint& ts) {
if (_pkt_map.size() > 16) {
_pkt_map.erase(_pkt_map.begin());
}
_pkt_map.emplace(ts,ts);
auto tmp = DurationCountMicroseconds(ts - _start);
_pkt_map.emplace(tmp, tmp);
}
uint32_t EstimatedLinkCapacityContext::getEstimatedLinkCapacity() {
decltype(_pkt_map.begin()) next;
std::vector<SteadyClock::duration> tmp;
std::vector<int64_t> tmp;
for(auto it = _pkt_map.begin();it != _pkt_map.end();++it){
next = it;
@@ -47,19 +61,20 @@ uint32_t EstimatedLinkCapacityContext::getEstimatedLinkCapacity() {
if(tmp.size()<16){
return 1000;
}
return 1000;
double dur =DurationCountMicroseconds(tmp[tmp.size()/2])/1e6;
double dur =tmp[0]/1e6;
return (uint32_t)(1.0/dur);
}
void RecvRateContext::inputPacket(TimePoint ts, size_t size ) {
void RecvRateContext::inputPacket(TimePoint& ts, size_t size ) {
if (_pkt_map.size() > 100) {
_pkt_map.erase(_pkt_map.begin());
}
_pkt_map.emplace(ts, size);
auto tmp = DurationCountMicroseconds(ts - _start);
_pkt_map.emplace(tmp, tmp);
}
uint32_t RecvRateContext::getRecvRate() {
if(_pkt_map.size()<2){
@@ -68,7 +83,7 @@ uint32_t RecvRateContext::getRecvRate() {
auto first = _pkt_map.begin();
auto last = _pkt_map.rbegin();
double dur = DurationCountMicroseconds(last->first - first->first)/1000000.0;
double dur = (last->first - first->first)/1000000.0;
size_t bytes = 0;
for(auto it : _pkt_map){