Skip to content

Commit

Permalink
Merge branch 'v0.20'
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Feb 23, 2024
2 parents b7f1f03 + 6d41052 commit 437a758
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 437a758

Please sign in to comment.