diff --git a/srt/Ack.cpp b/srt/Ack.cpp index f0afc017..44249cb4 100644 --- a/srt/Ack.cpp +++ b/srt/Ack.cpp @@ -59,10 +59,10 @@ bool ACKPacket::storeToData() { storeUint32(ptr, rtt_variance); ptr += 4; - storeUint32(ptr, pkt_recv_rate); + storeUint32(ptr, available_buf_size); ptr += 4; - storeUint32(ptr, available_buf_size); + storeUint32(ptr, pkt_recv_rate); ptr += 4; storeUint32(ptr, estimated_link_capacity); diff --git a/srt/SrtTransport.cpp b/srt/SrtTransport.cpp index 80db04a7..f515557a 100644 --- a/srt/SrtTransport.cpp +++ b/srt/SrtTransport.cpp @@ -292,7 +292,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad return; } - _last_ack_pkt_seq_num = _init_seq_number; + //_last_ack_pkt_seq_num = _init_seq_number; } void SrtTransport::handleHandshake(uint8_t *buf, int len, struct sockaddr_storage *addr) { @@ -458,12 +458,22 @@ void SrtTransport::handleACKACK(uint8_t *buf, int len, struct sockaddr_storage * ACKACKPacket::Ptr pkt = std::make_shared(); pkt->loadFromData(buf, len); - uint32_t rtt = DurationCountMicroseconds(_now - _ack_send_timestamp[pkt->ack_number]); - _rtt_variance = (3 * _rtt_variance + abs((long)_rtt - (long)rtt)) / 4; - _rtt = (7 * rtt + _rtt) / 8; + if(_ack_send_timestamp.find(pkt->ack_number)!=_ack_send_timestamp.end()){ + uint32_t rtt = DurationCountMicroseconds(_now - _ack_send_timestamp[pkt->ack_number]); + _rtt_variance = (3 * _rtt_variance + abs((long)_rtt - (long)rtt)) / 4; + _rtt = (7 * rtt + _rtt) / 8; + // TraceL<<" rtt:"<<_rtt<<" rtt variance:"<<_rtt_variance; + _ack_send_timestamp.erase(pkt->ack_number); - // TraceL<<" rtt:"<<_rtt<<" rtt variance:"<<_rtt_variance; - _ack_send_timestamp.erase(pkt->ack_number); + if(_last_recv_ackack_seq_num < pkt->ack_number){ + _last_recv_ackack_seq_num = pkt->ack_number; + }else{ + if((_last_recv_ackack_seq_num-pkt->ack_number)>(MAX_TS>>1)){ + _last_recv_ackack_seq_num = pkt->ack_number; + } + } + + } } void SrtTransport::handlePeerError(uint8_t *buf, int len, struct sockaddr_storage *addr) { @@ -484,14 +494,20 @@ void SrtTransport::sendACKPacket() { pkt->pkt_recv_rate = _pkt_recv_rate_context->getPacketRecvRate(recv_rate); pkt->estimated_link_capacity = _estimated_link_capacity_context->getEstimatedLinkCapacity(); pkt->recv_rate = recv_rate; - if(pkt->pkt_recv_rate == 0){ - TraceL<pkt_recv_rate<<" pkt/s "<estimated_link_capacity<<" pkt/s (cap)"; - TraceL<<_pkt_recv_rate_context->dump(); + if(1){ + TraceL<pkt_recv_rate<<" pkt/s "<estimated_link_capacity<<" pkt/s (cap) "<available_buf_size<<" available buf"; + //TraceL<<_pkt_recv_rate_context->dump(); + //TraceL<<"recv estimated:"; + //TraceL<< _pkt_recv_rate_context->dump(); + //TraceL<<"recv queue:"; + //TraceL<<_recv_buf->dump(); + } + if(pkt->available_buf_size<2){ + pkt->available_buf_size = 2; } - pkt->storeToData(); _ack_send_timestamp[pkt->ack_number] = _now; - _last_ack_pkt_seq_num = pkt->last_ack_pkt_seq_number; + //_last_ack_pkt_seq_num = pkt->last_ack_pkt_seq_number; sendControlPacket(pkt, true); // TraceL<<"send ack "<dump(); // TraceL<<_recv_buf->dump(); @@ -511,7 +527,7 @@ void SrtTransport::sendLightACKPacket() { pkt->estimated_link_capacity = 0; pkt->recv_rate = 0; pkt->storeToData(); - _last_ack_pkt_seq_num = pkt->last_ack_pkt_seq_number; + //_last_ack_pkt_seq_num = pkt->last_ack_pkt_seq_number; sendControlPacket(pkt, true); TraceL << "send ack " << pkt->dump(); } diff --git a/srt/SrtTransport.hpp b/srt/SrtTransport.hpp index f9817904..ecb2eb42 100644 --- a/srt/SrtTransport.hpp +++ b/srt/SrtTransport.hpp @@ -133,7 +133,8 @@ private: uint32_t _rtt_variance = 50 * 1000; uint32_t _light_ack_pkt_count = 0; uint32_t _ack_number_count = 0; - uint32_t _last_ack_pkt_seq_num = 0; + //uint32_t _last_ack_pkt_seq_num = 0; + uint32_t _last_recv_ackack_seq_num = 0; uint32_t _last_pkt_seq = 0; UTicker _ack_ticker; diff --git a/srt/Statistic.cpp b/srt/Statistic.cpp index 8b069f50..139e39b8 100644 --- a/srt/Statistic.cpp +++ b/srt/Statistic.cpp @@ -32,6 +32,9 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) { int64_t upper = median << 3; int64_t lower = median >> 3; + int64_t min = median; + int64_t min_size = 0; + bytesps = 0; size_t bytes = 0; const size_t *bp = _size_arr; @@ -43,14 +46,27 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) { sum += *p; // usec counter bytes += *bp; // byte counter } + if(*p < min){ + min = *p; + min_size = *bp; + } ++p; // advance packet pointer ++bp; // advance bytes pointer } + uint32_t max_ret = (uint32_t)ceil(1e6/min); + uint32_t max_byteps = (uint32_t)ceil(1e6*min_size/min); + if(count>(SIZE>>1)){ - bytesps = (unsigned long)ceil(1000000.0 / (double(sum) / double(bytes))); - auto ret = (uint32_t)ceil(1000000.0 / (sum / count)); - return ret; + bytesps = (uint32_t)ceil(1000000.0 / (double(sum) / double(bytes))); + auto ret = (uint32_t)ceil(1000000.0 / (double(sum) / double(count))); + //bytesps = max_byteps; + + return max_ret; + }else{ + //TraceL<