fix: crash

This commit is contained in:
tqcq 2024-10-10 10:13:09 +08:00
parent 68955415ed
commit 30a32761f5
4 changed files with 14 additions and 5 deletions

Binary file not shown.

View File

@ -336,14 +336,15 @@ RTPManager::OnRTPDecoded(RTPDecoder::DecodedPacket packet)
auto last_frame = last_packet->ref_frames().back().frame; auto last_frame = last_packet->ref_frames().back().frame;
INFOL("base_offset %lu\n", last_packet->rtp_header_offset_base_frame()); INFOL("base_offset %lu\n", last_packet->rtp_header_offset_base_frame());
INFOL("rtp_start_pos %lu\n", last_packet->rtp_header_offset_base_frame());
INFOL("last_packet_size %lu\n", last_packet->packet_size()); INFOL("last_packet_size %lu\n", last_packet->packet_size());
INFOL("last_frame_size %lu\n", last_frame->size()); INFOL("last_frame_size %lu\n", last_frame->size());
last_packet->InsertAt(prev_sign_data.data(), prev_sign_data.size(), last_packet->packet_size());
last_packet->SetRTSPLength(last_packet->packet_size() + prev_sign_data.size());
last_frame->set_append_length(prev_sign_data.size()); last_frame->set_append_length(prev_sign_data.size());
last_frame->set_sei_end_offset( last_frame->set_sei_end_offset(
last_packet->rtp_header_offset_base_frame() + last_packet->packet_size() + prev_sign_data.size()); last_packet->rtp_header_offset_base_frame() + last_packet->packet_size() + prev_sign_data.size());
last_packet->InsertAt(prev_sign_data.data(), prev_sign_data.size(), last_packet->packet_size());
last_packet->SetRTSPLength(last_packet->packet_size() + prev_sign_data.size());
auto hex = ToHex(prev_sign_data.data(), prev_sign_data.size()); auto hex = ToHex(prev_sign_data.data(), prev_sign_data.size());
INFOL("Insert Sign Data %s\n", hex.c_str()); INFOL("Insert Sign Data %s\n", hex.c_str());
} }

View File

@ -299,7 +299,7 @@ RTPPacket::UnrefUnusedFrame(std::size_t skip_size)
INFOL("Discard %lu byte.\n", skip_size); INFOL("Discard %lu byte.\n", skip_size);
std::size_t erased_size = 0; std::size_t erased_size = 0;
while (skip_size >= _ref_frames.front().frame->size()) { while (!_ref_frames.empty() && skip_size >= _ref_frames.front().frame->size()) {
INFOL("skip size: %ld\n", skip_size); INFOL("skip size: %ld\n", skip_size);
auto cur_frame = _ref_frames.front(); auto cur_frame = _ref_frames.front();
_ref_frames.erase(_ref_frames.begin()); _ref_frames.erase(_ref_frames.begin());
@ -308,10 +308,17 @@ RTPPacket::UnrefUnusedFrame(std::size_t skip_size)
erased_size += cur_frame.frame->size(); erased_size += cur_frame.frame->size();
} }
_tcp_data.erase(_tcp_data.begin(), _tcp_data.begin() + erased_size);
_tcp_start_pos = skip_size; _tcp_start_pos = skip_size;
if (!_ref_frames.empty()) { _ref_frames.front().start_pos = skip_size; } if (!_ref_frames.empty()) { _ref_frames.front().start_pos = skip_size; }
// Rebuild tcp_data
if (erased_size > 0) {
_tcp_data.clear();
for (const auto &frame : _ref_frames) {
std::copy(frame.frame->data(), frame.frame->data() + frame.frame->size(), std::back_inserter(_tcp_data));
}
}
return erased_size > 0; return erased_size > 0;
} }

View File

@ -100,6 +100,7 @@ GetRTSPLength(const void *data)
bool bool
FindRTSPHeader(const void *data, size_t len, void **header_ptr) FindRTSPHeader(const void *data, size_t len, void **header_ptr)
{ {
*header_ptr = nullptr;
if (len < 2 || data == nullptr) { return false; } if (len < 2 || data == nullptr) { return false; }
const uint8_t *ptr = (const uint8_t *) data; const uint8_t *ptr = (const uint8_t *) data;