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

Consumer: use a bitset instead of a set for supported payload types (#919)

This is way more performant.
* Before the change, set.find() could take as much as half of the CPU time
  taken by RtpStreamSend::ReceivePacket().
* After the change, bitset[] CPU time is negligible.

Extra: It takes less space than the set.
上级 9aef3f51
...@@ -187,7 +187,9 @@ namespace RTC ...@@ -187,7 +187,9 @@ namespace RTC
struct RTC::RtpHeaderExtensionIds rtpHeaderExtensionIds; struct RTC::RtpHeaderExtensionIds rtpHeaderExtensionIds;
const std::vector<uint8_t>* producerRtpStreamScores{ nullptr }; const std::vector<uint8_t>* producerRtpStreamScores{ nullptr };
// Others. // Others.
absl::flat_hash_set<uint8_t> supportedCodecPayloadTypes; // Whether a payload type is supported or not is represented in the
// corresponding position of the bitset.
std::bitset<128u> supportedCodecPayloadTypes;
uint64_t lastRtcpSentTime{ 0u }; uint64_t lastRtcpSentTime{ 0u };
uint16_t maxRtcpInterval{ 0u }; uint16_t maxRtcpInterval{ 0u };
bool externallyManagedBitrate{ false }; bool externallyManagedBitrate{ false };
......
...@@ -130,7 +130,7 @@ namespace RTC ...@@ -130,7 +130,7 @@ namespace RTC
for (auto& codec : this->rtpParameters.codecs) for (auto& codec : this->rtpParameters.codecs)
{ {
if (codec.mimeType.IsMediaCodec()) if (codec.mimeType.IsMediaCodec())
this->supportedCodecPayloadTypes.insert(codec.payloadType); this->supportedCodecPayloadTypes[codec.payloadType] = true;
} }
// Fill media SSRCs vector. // Fill media SSRCs vector.
...@@ -192,7 +192,13 @@ namespace RTC ...@@ -192,7 +192,13 @@ namespace RTC
} }
// Add supportedCodecPayloadTypes. // Add supportedCodecPayloadTypes.
jsonObject["supportedCodecPayloadTypes"] = this->supportedCodecPayloadTypes; jsonObject["supportedCodecPayloadTypes"] = json::array();
for (auto i = 0; i < 128; ++i)
{
if (this->supportedCodecPayloadTypes[i])
jsonObject["supportedCodecPayloadTypes"].push_back(i);
}
// Add paused. // Add paused.
jsonObject["paused"] = this->paused; jsonObject["paused"] = this->paused;
......
...@@ -205,7 +205,7 @@ namespace RTC ...@@ -205,7 +205,7 @@ namespace RTC
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
// in the corresponding Producer. // in the corresponding Producer.
if (this->supportedCodecPayloadTypes.find(payloadType) == this->supportedCodecPayloadTypes.end()) if (!this->supportedCodecPayloadTypes[payloadType])
{ {
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType); MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
......
...@@ -270,7 +270,7 @@ namespace RTC ...@@ -270,7 +270,7 @@ namespace RTC
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
// in the corresponding Producer. // in the corresponding Producer.
if (this->supportedCodecPayloadTypes.find(payloadType) == this->supportedCodecPayloadTypes.end()) if (!this->supportedCodecPayloadTypes[payloadType])
{ {
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType); MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
......
...@@ -665,7 +665,7 @@ namespace RTC ...@@ -665,7 +665,7 @@ namespace RTC
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
// in the corresponding Producer. // in the corresponding Producer.
if (this->supportedCodecPayloadTypes.find(payloadType) == this->supportedCodecPayloadTypes.end()) if (!this->supportedCodecPayloadTypes[payloadType])
{ {
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType); MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
......
...@@ -563,7 +563,7 @@ namespace RTC ...@@ -563,7 +563,7 @@ namespace RTC
// NOTE: This may happen if this Consumer supports just some codecs of those // NOTE: This may happen if this Consumer supports just some codecs of those
// in the corresponding Producer. // in the corresponding Producer.
if (this->supportedCodecPayloadTypes.find(payloadType) == this->supportedCodecPayloadTypes.end()) if (!this->supportedCodecPayloadTypes[payloadType])
{ {
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType); MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论