ZLMediaKit/srt/Ack.cpp

85 lines
2.0 KiB
C++
Raw Normal View History

2022-06-03 13:25:32 +08:00
#include "Ack.hpp"
#include "Common.hpp"
namespace SRT {
2022-06-07 09:52:20 +08:00
bool ACKPacket::loadFromData(uint8_t *buf, size_t len) {
if (len < ACK_CIF_SIZE + ControlPacket::HEADER_SIZE) {
2022-06-03 13:25:32 +08:00
return false;
}
_data = BufferRaw::create();
_data->assign((char *)(buf), len);
ControlPacket::loadHeader();
ack_number = loadUint32(type_specific_info);
2022-06-07 09:52:20 +08:00
uint8_t *ptr = (uint8_t *)_data->data() + ControlPacket::HEADER_SIZE;
2022-06-03 13:25:32 +08:00
last_ack_pkt_seq_number = loadUint32(ptr);
ptr += 4;
rtt = loadUint32(ptr);
ptr += 4;
rtt_variance = loadUint32(ptr);
ptr += 4;
available_buf_size = loadUint32(ptr);
ptr += 4;
pkt_recv_rate = loadUint32(ptr);
ptr += 4;
estimated_link_capacity = loadUint32(ptr);
ptr += 4;
recv_rate = loadUint32(ptr);
2022-06-07 09:52:20 +08:00
ptr += 4;
2022-06-03 13:25:32 +08:00
return true;
}
2022-06-07 09:52:20 +08:00
bool ACKPacket::storeToData() {
2022-06-03 13:25:32 +08:00
_data = BufferRaw::create();
_data->setCapacity(HEADER_SIZE + ACK_CIF_SIZE);
_data->setSize(HEADER_SIZE + ACK_CIF_SIZE);
control_type = ControlPacket::ACK;
sub_type = 0;
2022-06-07 09:52:20 +08:00
storeUint32(type_specific_info, ack_number);
2022-06-03 13:25:32 +08:00
storeToHeader();
2022-06-07 09:52:20 +08:00
uint8_t *ptr = (uint8_t *)_data->data() + ControlPacket::HEADER_SIZE;
storeUint32(ptr, last_ack_pkt_seq_number);
2022-06-03 13:25:32 +08:00
ptr += 4;
2022-06-07 09:52:20 +08:00
storeUint32(ptr, rtt);
2022-06-03 13:25:32 +08:00
ptr += 4;
2022-06-07 09:52:20 +08:00
storeUint32(ptr, rtt_variance);
2022-06-03 13:25:32 +08:00
ptr += 4;
storeUint32(ptr, available_buf_size);
2022-06-03 13:25:32 +08:00
ptr += 4;
storeUint32(ptr, pkt_recv_rate);
2022-06-03 13:25:32 +08:00
ptr += 4;
2022-06-07 09:52:20 +08:00
storeUint32(ptr, estimated_link_capacity);
2022-06-03 13:25:32 +08:00
ptr += 4;
2022-06-07 09:52:20 +08:00
storeUint32(ptr, recv_rate);
2022-06-03 13:25:32 +08:00
ptr += 4;
return true;
}
2022-06-07 09:52:20 +08:00
std::string ACKPacket::dump() {
_StrPrinter printer;
2022-06-07 09:52:20 +08:00
printer << "last_ack_pkt_seq_number=" << last_ack_pkt_seq_number << " rtt=" << rtt
<< " rtt_variance=" << rtt_variance << " pkt_recv_rate=" << pkt_recv_rate
<< " available_buf_size=" << available_buf_size << " estimated_link_capacity=" << estimated_link_capacity
<< " recv_rate=" << recv_rate;
return std::move(printer);
}
2022-06-07 09:52:20 +08:00
} // namespace SRT