Commit 801f7056 by xiongguangjie

fix srt ack packet packet buf length error

parent 642ca499
...@@ -59,10 +59,10 @@ bool ACKPacket::storeToData() { ...@@ -59,10 +59,10 @@ bool ACKPacket::storeToData() {
storeUint32(ptr, rtt_variance); storeUint32(ptr, rtt_variance);
ptr += 4; ptr += 4;
storeUint32(ptr, pkt_recv_rate); storeUint32(ptr, available_buf_size);
ptr += 4; ptr += 4;
storeUint32(ptr, available_buf_size); storeUint32(ptr, pkt_recv_rate);
ptr += 4; ptr += 4;
storeUint32(ptr, estimated_link_capacity); storeUint32(ptr, estimated_link_capacity);
......
...@@ -292,7 +292,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad ...@@ -292,7 +292,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad
return; 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) { 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 * ...@@ -458,12 +458,22 @@ void SrtTransport::handleACKACK(uint8_t *buf, int len, struct sockaddr_storage *
ACKACKPacket::Ptr pkt = std::make_shared<ACKACKPacket>(); ACKACKPacket::Ptr pkt = std::make_shared<ACKACKPacket>();
pkt->loadFromData(buf, len); pkt->loadFromData(buf, len);
uint32_t rtt = DurationCountMicroseconds(_now - _ack_send_timestamp[pkt->ack_number]); if(_ack_send_timestamp.find(pkt->ack_number)!=_ack_send_timestamp.end()){
_rtt_variance = (3 * _rtt_variance + abs((long)_rtt - (long)rtt)) / 4; uint32_t rtt = DurationCountMicroseconds(_now - _ack_send_timestamp[pkt->ack_number]);
_rtt = (7 * rtt + _rtt) / 8; _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; if(_last_recv_ackack_seq_num < pkt->ack_number){
_ack_send_timestamp.erase(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) { void SrtTransport::handlePeerError(uint8_t *buf, int len, struct sockaddr_storage *addr) {
...@@ -484,14 +494,20 @@ void SrtTransport::sendACKPacket() { ...@@ -484,14 +494,20 @@ void SrtTransport::sendACKPacket() {
pkt->pkt_recv_rate = _pkt_recv_rate_context->getPacketRecvRate(recv_rate); pkt->pkt_recv_rate = _pkt_recv_rate_context->getPacketRecvRate(recv_rate);
pkt->estimated_link_capacity = _estimated_link_capacity_context->getEstimatedLinkCapacity(); pkt->estimated_link_capacity = _estimated_link_capacity_context->getEstimatedLinkCapacity();
pkt->recv_rate = recv_rate; pkt->recv_rate = recv_rate;
if(pkt->pkt_recv_rate == 0){ if(1){
TraceL<<pkt->pkt_recv_rate<<" pkt/s "<<recv_rate<<" byte/s "<<pkt->estimated_link_capacity<<" pkt/s (cap)"; 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<<_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(); pkt->storeToData();
_ack_send_timestamp[pkt->ack_number] = _now; _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); sendControlPacket(pkt, true);
// TraceL<<"send ack "<<pkt->dump(); // TraceL<<"send ack "<<pkt->dump();
// TraceL<<_recv_buf->dump(); // TraceL<<_recv_buf->dump();
...@@ -511,7 +527,7 @@ void SrtTransport::sendLightACKPacket() { ...@@ -511,7 +527,7 @@ void SrtTransport::sendLightACKPacket() {
pkt->estimated_link_capacity = 0; pkt->estimated_link_capacity = 0;
pkt->recv_rate = 0; pkt->recv_rate = 0;
pkt->storeToData(); 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); sendControlPacket(pkt, true);
TraceL << "send ack " << pkt->dump(); TraceL << "send ack " << pkt->dump();
} }
......
...@@ -133,7 +133,8 @@ private: ...@@ -133,7 +133,8 @@ private:
uint32_t _rtt_variance = 50 * 1000; uint32_t _rtt_variance = 50 * 1000;
uint32_t _light_ack_pkt_count = 0; uint32_t _light_ack_pkt_count = 0;
uint32_t _ack_number_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; uint32_t _last_pkt_seq = 0;
UTicker _ack_ticker; UTicker _ack_ticker;
......
...@@ -32,6 +32,9 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) { ...@@ -32,6 +32,9 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) {
int64_t upper = median << 3; int64_t upper = median << 3;
int64_t lower = median >> 3; int64_t lower = median >> 3;
int64_t min = median;
int64_t min_size = 0;
bytesps = 0; bytesps = 0;
size_t bytes = 0; size_t bytes = 0;
const size_t *bp = _size_arr; const size_t *bp = _size_arr;
...@@ -43,14 +46,27 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) { ...@@ -43,14 +46,27 @@ uint32_t PacketRecvRateContext::getPacketRecvRate(uint32_t &bytesps) {
sum += *p; // usec counter sum += *p; // usec counter
bytes += *bp; // byte counter bytes += *bp; // byte counter
} }
if(*p < min){
min = *p;
min_size = *bp;
}
++p; // advance packet pointer ++p; // advance packet pointer
++bp; // advance bytes 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)){ if(count>(SIZE>>1)){
bytesps = (unsigned long)ceil(1000000.0 / (double(sum) / double(bytes))); bytesps = (uint32_t)ceil(1000000.0 / (double(sum) / double(bytes)));
auto ret = (uint32_t)ceil(1000000.0 / (sum / count)); auto ret = (uint32_t)ceil(1000000.0 / (double(sum) / double(count)));
return ret; //bytesps = max_byteps;
return max_ret;
}else{
//TraceL<<max_ret<<" pkt/s "<<max_byteps<<" byte/s";
bytesps = 0;
return 0;
} }
bytesps = 0; bytesps = 0;
return 0; return 0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论