Add RtpPacket::IsExtensionReserved().

This is a small utility method to check whether an extension has been
reserved, so that can be checked before attempting to set an extension
without the need to actually try setting it and potentially failing
with warning loggins as a result.

Bug: webrtc:10633
Change-Id: Ie6f2c4f3f5e94a30dbf60aec6290ebee72681d9c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144461
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28455}
This commit is contained in:
Erik Språng
2019-07-02 21:24:47 +02:00
committed by Commit Bot
parent 6038926379
commit 1d46f9c599
3 changed files with 39 additions and 0 deletions

View File

@ -617,4 +617,13 @@ bool RtpPacket::HasExtension(ExtensionType type) const {
return !FindExtension(type).empty(); return !FindExtension(type).empty();
} }
bool RtpPacket::IsExtensionReserved(ExtensionType type) const {
uint8_t id = extensions_.GetId(type);
if (id == ExtensionManager::kInvalidId) {
// Extension not registered.
return false;
}
return FindExtensionInfo(id) != nullptr;
}
} // namespace webrtc } // namespace webrtc

View File

@ -99,6 +99,10 @@ class RtpPacket {
bool HasExtension() const; bool HasExtension() const;
bool HasExtension(ExtensionType type) const; bool HasExtension(ExtensionType type) const;
template <typename Extension>
bool IsExtensionReserved() const;
bool IsExtensionReserved(ExtensionType type) const;
template <typename Extension, typename FirstValue, typename... Values> template <typename Extension, typename FirstValue, typename... Values>
bool GetExtension(FirstValue, Values...) const; bool GetExtension(FirstValue, Values...) const;
@ -186,6 +190,11 @@ bool RtpPacket::HasExtension() const {
return HasExtension(Extension::kId); return HasExtension(Extension::kId);
} }
template <typename Extension>
bool RtpPacket::IsExtensionReserved() const {
return IsExtensionReserved(Extension::kId);
}
template <typename Extension, typename FirstValue, typename... Values> template <typename Extension, typename FirstValue, typename... Values>
bool RtpPacket::GetExtension(FirstValue first, Values... values) const { bool RtpPacket::GetExtension(FirstValue first, Values... values) const {
auto raw = FindExtension(Extension::kId); auto raw = FindExtension(Extension::kId);

View File

@ -952,4 +952,25 @@ TEST(RtpPacketTest,
kFeedbackRequest->sequence_count); kFeedbackRequest->sequence_count);
} }
TEST(RtpPacketTest, IsExtensionReserved) {
// Register two extensions.
RtpPacketToSend::ExtensionManager extensions;
extensions.Register(kRtpExtensionTransmissionTimeOffset,
kTransmissionOffsetExtensionId);
extensions.Register(kRtpExtensionAudioLevel, kAudioLevelExtensionId);
RtpPacketReceived packet(&extensions);
// Reserve slot for only one of them.
EXPECT_TRUE(packet.ReserveExtension<TransmissionOffset>());
// Non-registered extension cannot be reserved.
EXPECT_FALSE(packet.ReserveExtension<VideoContentTypeExtension>());
// Only the extension that is both registered and reserved matches
// IsExtensionReserved().
EXPECT_FALSE(packet.IsExtensionReserved<VideoContentTypeExtension>());
EXPECT_FALSE(packet.IsExtensionReserved<AudioLevel>());
EXPECT_TRUE(packet.IsExtensionReserved<TransmissionOffset>());
}
} // namespace webrtc } // namespace webrtc