Unverified 提交 9aef3f51 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

RtpPacket: optimize UpdateMid() (#920)

* Make it void since the return value is not used anywhere.
* Cache the mid string size to avoid calling it multiple times.
上级 f4b3558a
......@@ -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
{
......
......@@ -533,7 +533,7 @@ 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();
......@@ -541,25 +541,25 @@ namespace RTC
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);
}
/**
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论