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 ...@@ -315,7 +315,7 @@ namespace RTC
return true; return true;
} }
bool UpdateMid(const std::string& mid); void UpdateMid(const std::string& mid);
bool ReadRid(std::string& rid) const bool ReadRid(std::string& rid) const
{ {
......
...@@ -533,7 +533,7 @@ namespace RTC ...@@ -533,7 +533,7 @@ namespace RTC
MS_ASSERT(ptr == this->payload, "wrong ptr calculation"); MS_ASSERT(ptr == this->payload, "wrong ptr calculation");
} }
bool RtpPacket::UpdateMid(const std::string& mid) void RtpPacket::UpdateMid(const std::string& mid)
{ {
MS_TRACE(); MS_TRACE();
...@@ -541,25 +541,25 @@ namespace RTC ...@@ -541,25 +541,25 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen); uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
if (!extenValue) if (!extenValue)
return false; return;
size_t midLen = mid.length();
// Here we assume that there is MidMaxLength available bytes, even if now // Here we assume that there is MidMaxLength available bytes, even if now
// they are padding bytes. // they are padding bytes.
if (mid.size() > RTC::MidMaxLength) if (midLen > RTC::MidMaxLength)
{ {
MS_ERROR( MS_ERROR(
"no enough space for MID value [MidMaxLength:%" PRIu8 ", mid:'%s']", "no enough space for MID value [MidMaxLength:%" PRIu8 ", mid:'%s']",
RTC::MidMaxLength, RTC::MidMaxLength,
mid.c_str()); mid.c_str());
return false; return;
} }
std::memcpy(extenValue, mid.c_str(), mid.size()); std::memcpy(extenValue, mid.c_str(), midLen);
SetExtensionLength(this->midExtensionId, mid.size());
return true; SetExtensionLength(this->midExtensionId, midLen);
} }
/** /**
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论