fix srt ack packet packet buf length error

This commit is contained in:
xiongguangjie 2022-09-22 12:00:02 +08:00
parent 642ca4997a
commit 801f705628
4 changed files with 51 additions and 18 deletions

View File

@ -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);

View File

@ -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<ACKACKPacket>();
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->pkt_recv_rate<<" pkt/s "<<recv_rate<<" byte/s "<<pkt->estimated_link_capacity<<" pkt/s (cap)";
TraceL<<_pkt_recv_rate_context->dump();
if(1){
TraceL<<pkt->pkt_recv_rate<<" pkt/s "<<recv_rate<<" byte/s "<<pkt->estimated_link_capacity<<" pkt/s (cap) "<<pkt->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 "<<pkt->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();
}

View File

@ -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;

View File

@ -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<<max_ret<<" pkt/s "<<max_byteps<<" byte/s";
bytesps = 0;
return 0;
}
bytesps = 0;
return 0;