Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NACK messages corruption #1118

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/rtc/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ RTC_CPP_EXPORT message_ptr make_message(binary &&data, Message::Type type = Mess
unsigned int stream = 0,
shared_ptr<Reliability> reliability = nullptr);

RTC_CPP_EXPORT message_ptr make_message(size_t size, message_ptr orig);

RTC_CPP_EXPORT message_ptr make_message(message_variant data);

#if RTC_ENABLE_MEDIA
Expand Down
3 changes: 2 additions & 1 deletion src/impl/dtlssrtptransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ bool DtlsSrtpTransport::sendMedia(message_ptr message) {

// srtp_protect() and srtp_protect_rtcp() assume that they can write SRTP_MAX_TRAILER_LEN (for
// the authentication tag) into the location in memory immediately following the RTP packet.
message->resize(size + SRTP_MAX_TRAILER_LEN);
// Copy instead of resizing so we don't interfere with media handlers keeping references
message = make_message(size + SRTP_MAX_TRAILER_LEN, message);

if (IsRtcp(*message)) { // Demultiplex RTCP and RTP using payload type
if (srtp_err_status_t err = srtp_protect_rtcp(mSrtpOut, message->data(), &size)) {
Expand Down
11 changes: 11 additions & 0 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ message_ptr make_message(binary &&data, Message::Type type, unsigned int stream,
return message;
}

message_ptr make_message(size_t size, message_ptr orig) {
if(!orig)
return nullptr;

auto message = std::make_shared<Message>(size, orig->type);
std::copy(orig->begin(), std::min(orig->end(), orig->begin() + size), message->begin());
message->stream = orig->stream;
message->reliability = orig->reliability;
return message;
}

message_ptr make_message(message_variant data) {
return std::visit( //
overloaded{
Expand Down
Loading