Skip to content

Commit

Permalink
RtpPacket: optimize UpdateMid() (#920)
Browse files Browse the repository at this point in the history
* Make it void since the return value is not used anywhere.
* Cache the mid string size to avoid calling it multiple times.
  • Loading branch information
jmillan authored Sep 30, 2022
1 parent f4b3558 commit 9aef3f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion worker/include/RTC/RtpPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ namespace RTC
return true;
}

bool UpdateMid(const std::string& mid);
void UpdateMid(const std::string& mid);

bool ReadRid(std::string& rid) const
{
Expand Down
16 changes: 8 additions & 8 deletions worker/src/RTC/RtpPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,33 +533,33 @@ namespace RTC
MS_ASSERT(ptr == this->payload, "wrong ptr calculation");
}

bool RtpPacket::UpdateMid(const std::string& mid)
void RtpPacket::UpdateMid(const std::string& mid)
{
MS_TRACE();

uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);

if (!extenValue)
return false;
return;

size_t midLen = mid.length();

// Here we assume that there is MidMaxLength available bytes, even if now
// they are padding bytes.
if (mid.size() > RTC::MidMaxLength)
if (midLen > RTC::MidMaxLength)
{
MS_ERROR(
"no enough space for MID value [MidMaxLength:%" PRIu8 ", mid:'%s']",
RTC::MidMaxLength,
mid.c_str());

return false;
return;
}

std::memcpy(extenValue, mid.c_str(), mid.size());

SetExtensionLength(this->midExtensionId, mid.size());
std::memcpy(extenValue, mid.c_str(), midLen);

return true;
SetExtensionLength(this->midExtensionId, midLen);
}

/**
Expand Down

0 comments on commit 9aef3f5

Please sign in to comment.