mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
fix recv cycle buffer crash and avoid send nak packet exceed mtu
This commit is contained in:
parent
6503d95853
commit
b771274a7f
@ -515,7 +515,7 @@ bool NAKPacket::loadFromData(uint8_t *buf, size_t len) {
|
|||||||
bool NAKPacket::storeToData() {
|
bool NAKPacket::storeToData() {
|
||||||
control_type = NAK;
|
control_type = NAK;
|
||||||
sub_type = 0;
|
sub_type = 0;
|
||||||
size_t cif_size = getCIFSize();
|
size_t cif_size = getCIFSize(lost_list);
|
||||||
|
|
||||||
_data = BufferRaw::create();
|
_data = BufferRaw::create();
|
||||||
_data->setCapacity(HEADER_SIZE + cif_size);
|
_data->setCapacity(HEADER_SIZE + cif_size);
|
||||||
@ -544,9 +544,9 @@ bool NAKPacket::storeToData() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t NAKPacket::getCIFSize() {
|
size_t NAKPacket::getCIFSize(std::list<LostPair> &lost) {
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
for (auto it : lost_list) {
|
for (auto it : lost) {
|
||||||
if (it.first + 1 == it.second) {
|
if (it.first + 1 == it.second) {
|
||||||
size += 4;
|
size += 4;
|
||||||
} else {
|
} else {
|
||||||
|
@ -275,9 +275,7 @@ public:
|
|||||||
bool storeToData() override;
|
bool storeToData() override;
|
||||||
|
|
||||||
std::list<LostPair> lost_list;
|
std::list<LostPair> lost_list;
|
||||||
|
static size_t getCIFSize(std::list<LostPair> &lost);
|
||||||
private:
|
|
||||||
size_t getCIFSize();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -243,6 +243,7 @@ PacketRecvQueue::PacketRecvQueue(uint32_t max_size, uint32_t init_seq, uint32_t
|
|||||||
, _pkt_expected_seq(init_seq)
|
, _pkt_expected_seq(init_seq)
|
||||||
, _pkt_buf(max_size) {}
|
, _pkt_buf(max_size) {}
|
||||||
bool PacketRecvQueue::inputPacket(DataPacket::Ptr pkt, std::list<DataPacket::Ptr> &out) {
|
bool PacketRecvQueue::inputPacket(DataPacket::Ptr pkt, std::list<DataPacket::Ptr> &out) {
|
||||||
|
// TraceL << dump() << " seq:" << pkt->packet_seq_number;
|
||||||
while (_size > 0 && _start == _end) {
|
while (_size > 0 && _start == _end) {
|
||||||
if (_pkt_buf[_start]) {
|
if (_pkt_buf[_start]) {
|
||||||
out.push_back(_pkt_buf[_start]);
|
out.push_back(_pkt_buf[_start]);
|
||||||
@ -385,6 +386,8 @@ std::string PacketRecvQueue::dump() {
|
|||||||
<< " first:" << getFirst()->packet_seq_number;
|
<< " first:" << getFirst()->packet_seq_number;
|
||||||
printer << " last:" << getLast()->packet_seq_number;
|
printer << " last:" << getLast()->packet_seq_number;
|
||||||
printer << " latency:" << timeLatency() / 1e3;
|
printer << " latency:" << timeLatency() / 1e3;
|
||||||
|
printer << " start:" << _start;
|
||||||
|
printer << " end:" << _end;
|
||||||
}
|
}
|
||||||
return std::move(printer);
|
return std::move(printer);
|
||||||
}
|
}
|
||||||
@ -438,8 +441,20 @@ void PacketRecvQueue::insertToCycleBuf(DataPacket::Ptr pkt, uint32_t diff) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_pkt_buf[pos] = pkt;
|
_pkt_buf[pos] = pkt;
|
||||||
if (pos >= _end && (_start <= _end || pos < _start)) {
|
|
||||||
|
if (_start <= _end && pos >= _end) {
|
||||||
_end = (pos + 1) % _pkt_cap;
|
_end = (pos + 1) % _pkt_cap;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_start <= _end && pos < _start) {
|
||||||
|
_end = (pos + 1) % _pkt_cap;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_start > _end && _end <= pos && _start > pos) {
|
||||||
|
_end = (pos + 1) % _pkt_cap;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PacketRecvQueue::tryInsertPkt(DataPacket::Ptr pkt) {
|
void PacketRecvQueue::tryInsertPkt(DataPacket::Ptr pkt) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "Util/onceToken.h"
|
#include "Util/onceToken.h"
|
||||||
|
#include <iterator>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "Ack.hpp"
|
#include "Ack.hpp"
|
||||||
@ -435,15 +436,42 @@ void SrtTransport::sendLightACKPacket() {
|
|||||||
|
|
||||||
void SrtTransport::sendNAKPacket(std::list<PacketQueue::LostPair> &lost_list) {
|
void SrtTransport::sendNAKPacket(std::list<PacketQueue::LostPair> &lost_list) {
|
||||||
NAKPacket::Ptr pkt = std::make_shared<NAKPacket>();
|
NAKPacket::Ptr pkt = std::make_shared<NAKPacket>();
|
||||||
|
std::list<PacketQueue::LostPair> tmp;
|
||||||
|
auto size = NAKPacket::getCIFSize(lost_list);
|
||||||
|
size_t paylaod_size = getPayloadSize();
|
||||||
|
if (size > paylaod_size) {
|
||||||
|
WarnL << "loss report cif size " << size;
|
||||||
|
size_t num = paylaod_size / 8;
|
||||||
|
|
||||||
pkt->dst_socket_id = _peer_socket_id;
|
size_t msgNum = (lost_list.size() + num - 1) / num;
|
||||||
pkt->timestamp = DurationCountMicroseconds(_now - _start_timestamp);
|
decltype(lost_list.begin()) cur, next;
|
||||||
pkt->lost_list = lost_list;
|
for (size_t i = 0; i < msgNum; ++i) {
|
||||||
|
cur = lost_list.begin();
|
||||||
|
std::advance(cur, i * num);
|
||||||
|
|
||||||
pkt->storeToData();
|
if (i == msgNum - 1) {
|
||||||
|
next = lost_list.end();
|
||||||
|
} else {
|
||||||
|
next = lost_list.begin();
|
||||||
|
std::advance(next, (i + 1) * num);
|
||||||
|
}
|
||||||
|
tmp.assign(cur, next);
|
||||||
|
pkt->dst_socket_id = _peer_socket_id;
|
||||||
|
pkt->timestamp = DurationCountMicroseconds(_now - _start_timestamp);
|
||||||
|
pkt->lost_list = tmp;
|
||||||
|
pkt->storeToData();
|
||||||
|
sendControlPacket(pkt, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pkt->dst_socket_id = _peer_socket_id;
|
||||||
|
pkt->timestamp = DurationCountMicroseconds(_now - _start_timestamp);
|
||||||
|
pkt->lost_list = lost_list;
|
||||||
|
pkt->storeToData();
|
||||||
|
sendControlPacket(pkt, true);
|
||||||
|
}
|
||||||
|
|
||||||
// TraceL<<"send NAK "<<pkt->dump();
|
// TraceL<<"send NAK "<<pkt->dump();
|
||||||
sendControlPacket(pkt, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrtTransport::sendShutDown() {
|
void SrtTransport::sendShutDown() {
|
||||||
|
Loading…
Reference in New Issue
Block a user