Allow rtp::Packet::*RawExtension to take 0 as an extension id

BUG=webrtc:7433

Review-Url: https://codereview.webrtc.org/2803623004
Cr-Commit-Position: refs/heads/master@{#17610}
This commit is contained in:
danilchap
2017-04-10 01:31:49 -07:00
committed by Commit bot
parent 02465b8a11
commit c547e84ec5
2 changed files with 27 additions and 3 deletions

View File

@ -279,12 +279,16 @@ void Packet::SetCsrcs(const std::vector<uint32_t>& csrcs) {
}
bool Packet::HasRawExtension(int id) const {
if (id == ExtensionManager::kInvalidId)
return false;
RTC_DCHECK_GE(id, kMinExtensionId);
RTC_DCHECK_LE(id, kMaxExtensionId);
return extension_entries_[id - 1].offset != 0;
}
rtc::ArrayView<const uint8_t> Packet::GetRawExtension(int id) const {
if (id == ExtensionManager::kInvalidId)
return nullptr;
RTC_DCHECK_GE(id, kMinExtensionId);
RTC_DCHECK_LE(id, kMaxExtensionId);
const ExtensionInfo& extension = extension_entries_[id - 1];
@ -303,6 +307,8 @@ bool Packet::SetRawExtension(int id, rtc::ArrayView<const uint8_t> data) {
}
rtc::ArrayView<uint8_t> Packet::AllocateRawExtension(int id, size_t length) {
if (id == ExtensionManager::kInvalidId)
return nullptr;
RTC_DCHECK_GE(id, kMinExtensionId);
RTC_DCHECK_LE(id, kMaxExtensionId);
RTC_DCHECK_GE(length, 1);

View File

@ -16,11 +16,12 @@
#include "webrtc/test/gmock.h"
#include "webrtc/test/gtest.h"
using testing::ElementsAreArray;
using testing::make_tuple;
namespace webrtc {
namespace {
using ::testing::ElementsAreArray;
using ::testing::IsEmpty;
using ::testing::make_tuple;
constexpr int8_t kPayloadType = 100;
constexpr uint32_t kSsrc = 0x12345678;
constexpr uint16_t kSeqNum = 88;
@ -363,4 +364,21 @@ TEST(RtpPacketTest, ParseWithoutExtensionManager) {
EXPECT_EQ(time_offset, kTimeOffset);
}
TEST(RtpPacketTest, RawExtensionFunctionsAcceptZeroIdAndReturnFalse) {
RtpPacketReceived::ExtensionManager extensions;
RtpPacketReceived packet(&extensions);
// Use ExtensionManager to set kInvalidId to 0 to demonstrate natural way for
// using zero value as a parameter to Packet::*RawExtension functions.
const int kInvalidId = extensions.GetId(TransmissionOffset::kId);
ASSERT_EQ(kInvalidId, 0);
ASSERT_TRUE(packet.Parse(kPacket, sizeof(kPacket)));
EXPECT_FALSE(packet.HasRawExtension(kInvalidId));
EXPECT_THAT(packet.GetRawExtension(kInvalidId), IsEmpty());
const uint8_t kExtension[] = {'e', 'x', 't'};
EXPECT_FALSE(packet.SetRawExtension(kInvalidId, kExtension));
EXPECT_THAT(packet.AllocateRawExtension(kInvalidId, 3), IsEmpty());
}
} // namespace webrtc