Revert of Simplify and extend RtpHeaderExtensionMap (patchset #12 id:260001 of https://codereview.webrtc.org/2452293004/ )
Reason for revert: breaks downstream project Original issue's description: > Simplify and extend RtpHeaderExtensionMap > Add register functions for various codepaths. > Add initialize-list constructor to create usable const RtpHeaderExtensionMap > Optimize implementation for GetId/GetType. > > BUG=webrtc:1994 > > Committed: https://crrev.com/d1d26fbeb37a69471a34004c6ac2d3fafde5d404 > Cr-Commit-Position: refs/heads/master@{#14986} TBR=sprang@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:1994 Review-Url: https://codereview.webrtc.org/2484863007 Cr-Commit-Position: refs/heads/master@{#14988}
This commit is contained in:
@ -8,143 +8,148 @@
|
|||||||
* be found in the AUTHORS file in the root of the source tree.
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
#include <assert.h>
|
||||||
|
|
||||||
#include "webrtc/base/arraysize.h"
|
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/common_types.h"
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace {
|
|
||||||
|
|
||||||
using RtpUtility::Word32Align;
|
constexpr uint8_t RtpHeaderExtensionMap::kInvalidId;
|
||||||
|
|
||||||
struct ExtensionInfo {
|
RtpHeaderExtensionMap::RtpHeaderExtensionMap() {
|
||||||
RTPExtensionType type;
|
|
||||||
size_t value_size;
|
|
||||||
const char* uri;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename Extension>
|
|
||||||
constexpr ExtensionInfo CreateExtensionInfo() {
|
|
||||||
return {Extension::kId, Extension::kValueSizeBytes, Extension::kUri};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ExtensionInfo kExtensions[] = {
|
RtpHeaderExtensionMap::~RtpHeaderExtensionMap() {
|
||||||
CreateExtensionInfo<TransmissionOffset>(),
|
Erase();
|
||||||
CreateExtensionInfo<AudioLevel>(),
|
}
|
||||||
CreateExtensionInfo<AbsoluteSendTime>(),
|
|
||||||
CreateExtensionInfo<VideoOrientation>(),
|
|
||||||
CreateExtensionInfo<TransportSequenceNumber>(),
|
|
||||||
CreateExtensionInfo<PlayoutDelayLimits>(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Because of kRtpExtensionNone, NumberOfExtension is 1 bigger than the actual
|
void RtpHeaderExtensionMap::Erase() {
|
||||||
// number of known extensions.
|
while (!extensionMap_.empty()) {
|
||||||
static_assert(arraysize(kExtensions) ==
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
||||||
static_cast<int>(kRtpExtensionNumberOfExtensions) - 1,
|
extensionMap_.begin();
|
||||||
"kExtensions expect to list all known extensions");
|
delete it->second;
|
||||||
|
extensionMap_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t ValueSize(RTPExtensionType type) {
|
int32_t RtpHeaderExtensionMap::Register(RTPExtensionType type, uint8_t id) {
|
||||||
for (const ExtensionInfo& extension : kExtensions)
|
if (id < 1 || id > 14) {
|
||||||
if (type == extension.type)
|
return -1;
|
||||||
return extension.value_size;
|
}
|
||||||
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
||||||
RTC_NOTREACHED();
|
extensionMap_.find(id);
|
||||||
|
if (it != extensionMap_.end()) {
|
||||||
|
if (it->second->type != type) {
|
||||||
|
// An extension is already registered with the same id
|
||||||
|
// but a different type, so return failure.
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// This extension type is already registered with this id,
|
||||||
|
// so return success.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
RTC_DCHECK_EQ(kInvalidId, GetId(type));
|
||||||
|
extensionMap_[id] = new HeaderExtension(type);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
int32_t RtpHeaderExtensionMap::Deregister(const RTPExtensionType type) {
|
||||||
|
uint8_t id;
|
||||||
constexpr RTPExtensionType RtpHeaderExtensionMap::kInvalidType;
|
if (GetId(type, &id) != 0) {
|
||||||
constexpr uint8_t RtpHeaderExtensionMap::kInvalidId;
|
return 0;
|
||||||
constexpr uint8_t RtpHeaderExtensionMap::kMinId;
|
}
|
||||||
constexpr uint8_t RtpHeaderExtensionMap::kMaxId;
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
||||||
|
extensionMap_.find(id);
|
||||||
RtpHeaderExtensionMap::RtpHeaderExtensionMap() {
|
assert(it != extensionMap_.end());
|
||||||
total_values_size_bytes_ = 0;
|
delete it->second;
|
||||||
for (auto& type : types_)
|
extensionMap_.erase(it);
|
||||||
type = kInvalidType;
|
return 0;
|
||||||
for (auto& id : ids_)
|
|
||||||
id = kInvalidId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpHeaderExtensionMap::RtpHeaderExtensionMap(
|
bool RtpHeaderExtensionMap::IsRegistered(RTPExtensionType type) const {
|
||||||
std::initializer_list<RtpExtension> extensions)
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
||||||
: RtpHeaderExtensionMap() {
|
extensionMap_.begin();
|
||||||
for (const RtpExtension& extension : extensions)
|
for (; it != extensionMap_.end(); ++it) {
|
||||||
RegisterByUri(extension.id, extension.uri);
|
if (it->second->type == type)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtpHeaderExtensionMap::RegisterByType(uint8_t id, RTPExtensionType type) {
|
|
||||||
for (const ExtensionInfo& extension : kExtensions)
|
|
||||||
if (type == extension.type)
|
|
||||||
return Register(id, extension.type, extension.value_size, extension.uri);
|
|
||||||
RTC_NOTREACHED();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtpHeaderExtensionMap::RegisterByUri(uint8_t id, const std::string& uri) {
|
int32_t RtpHeaderExtensionMap::GetType(const uint8_t id,
|
||||||
for (const ExtensionInfo& extension : kExtensions)
|
RTPExtensionType* type) const {
|
||||||
if (uri == extension.uri)
|
assert(type);
|
||||||
return Register(id, extension.type, extension.value_size, extension.uri);
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
||||||
LOG(LS_WARNING) << "Unknown extension uri:'" << uri
|
extensionMap_.find(id);
|
||||||
<< "', id: " << static_cast<int>(id) << '.';
|
if (it == extensionMap_.end()) {
|
||||||
return false;
|
return -1;
|
||||||
|
}
|
||||||
|
HeaderExtension* extension = it->second;
|
||||||
|
*type = extension->type;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
RTPExtensionType RtpHeaderExtensionMap::GetType(uint8_t id) const {
|
||||||
|
auto it = extensionMap_.find(id);
|
||||||
|
if (it == extensionMap_.end()) {
|
||||||
|
return kInvalidType;
|
||||||
|
}
|
||||||
|
return it->second->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t RtpHeaderExtensionMap::GetId(const RTPExtensionType type,
|
||||||
|
uint8_t* id) const {
|
||||||
|
assert(id);
|
||||||
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
||||||
|
extensionMap_.begin();
|
||||||
|
|
||||||
|
while (it != extensionMap_.end()) {
|
||||||
|
HeaderExtension* extension = it->second;
|
||||||
|
if (extension->type == type) {
|
||||||
|
*id = it->first;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t RtpHeaderExtensionMap::GetId(RTPExtensionType type) const {
|
||||||
|
for (auto kv : extensionMap_) {
|
||||||
|
if (kv.second->type == type)
|
||||||
|
return kv.first;
|
||||||
|
}
|
||||||
|
return kInvalidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t RtpHeaderExtensionMap::GetTotalLengthInBytes() const {
|
size_t RtpHeaderExtensionMap::GetTotalLengthInBytes() const {
|
||||||
if (total_values_size_bytes_ == 0)
|
// Get length for each extension block.
|
||||||
return 0;
|
size_t length = 0;
|
||||||
return Word32Align(kRtpOneByteHeaderLength + total_values_size_bytes_);
|
for (const auto& kv : extensionMap_)
|
||||||
|
length += kv.second->length;
|
||||||
|
// Add RTP extension header length.
|
||||||
|
if (length > 0)
|
||||||
|
length += kRtpOneByteHeaderLength;
|
||||||
|
// Pad up to nearest 32bit word.
|
||||||
|
length = RtpUtility::Word32Align(length);
|
||||||
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t RtpHeaderExtensionMap::Deregister(RTPExtensionType type) {
|
int32_t RtpHeaderExtensionMap::Size() const {
|
||||||
if (IsRegistered(type)) {
|
return extensionMap_.size();
|
||||||
uint8_t id = GetId(type);
|
|
||||||
total_values_size_bytes_ -= (ValueSize(type) + 1);
|
|
||||||
types_[id] = kInvalidType;
|
|
||||||
ids_[type] = kInvalidId;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RtpHeaderExtensionMap::Register(uint8_t id,
|
void RtpHeaderExtensionMap::GetCopy(RtpHeaderExtensionMap* map) const {
|
||||||
RTPExtensionType type,
|
assert(map);
|
||||||
size_t value_size,
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
||||||
const char* uri) {
|
extensionMap_.begin();
|
||||||
RTC_DCHECK_GT(type, kRtpExtensionNone);
|
while (it != extensionMap_.end()) {
|
||||||
RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
|
HeaderExtension* extension = it->second;
|
||||||
RTC_DCHECK_GE(value_size, 1U);
|
map->Register(extension->type, it->first);
|
||||||
RTC_DCHECK_LE(value_size, 16U);
|
it++;
|
||||||
|
|
||||||
if (id < kMinId || id > kMaxId) {
|
|
||||||
LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
|
|
||||||
<< "' with invalid id:" << static_cast<int>(id) << ".";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetType(id) == type) { // Same type/id pair already registered.
|
|
||||||
LOG(LS_VERBOSE) << "Reregistering extension uri:'" << uri
|
|
||||||
<< "', id:" << static_cast<int>(id);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetType(id) != kInvalidType) { // |id| used by another extension type.
|
|
||||||
LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
|
|
||||||
<< "', id:" << static_cast<int>(id)
|
|
||||||
<< ". Id already in use by extension type "
|
|
||||||
<< static_cast<int>(GetType(id));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
RTC_DCHECK(!IsRegistered(type));
|
|
||||||
|
|
||||||
types_[id] = type;
|
|
||||||
ids_[type] = id;
|
|
||||||
total_values_size_bytes_ += (value_size + 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -11,13 +11,10 @@
|
|||||||
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
|
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
|
||||||
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
|
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_RTP_HEADER_EXTENSION_H_
|
||||||
|
|
||||||
#include <initializer_list>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "webrtc/base/basictypes.h"
|
|
||||||
#include "webrtc/base/checks.h"
|
|
||||||
#include "webrtc/config.h"
|
|
||||||
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||||
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
@ -38,63 +35,74 @@ const int kPlayoutDelayGranularityMs = 10;
|
|||||||
// Maximum playout delay value in milliseconds.
|
// Maximum playout delay value in milliseconds.
|
||||||
const int kPlayoutDelayMaxMs = 40950;
|
const int kPlayoutDelayMaxMs = 40950;
|
||||||
|
|
||||||
|
struct HeaderExtension {
|
||||||
|
explicit HeaderExtension(RTPExtensionType extension_type)
|
||||||
|
: type(extension_type), length(0) {
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init() {
|
||||||
|
// TODO(solenberg): Create handler classes for header extensions so we can
|
||||||
|
// get rid of switches like these as well as handling code spread out all
|
||||||
|
// over.
|
||||||
|
switch (type) {
|
||||||
|
case kRtpExtensionTransmissionTimeOffset:
|
||||||
|
length = kTransmissionTimeOffsetLength;
|
||||||
|
break;
|
||||||
|
case kRtpExtensionAudioLevel:
|
||||||
|
length = kAudioLevelLength;
|
||||||
|
break;
|
||||||
|
case kRtpExtensionAbsoluteSendTime:
|
||||||
|
length = kAbsoluteSendTimeLength;
|
||||||
|
break;
|
||||||
|
case kRtpExtensionVideoRotation:
|
||||||
|
length = kVideoRotationLength;
|
||||||
|
break;
|
||||||
|
case kRtpExtensionTransportSequenceNumber:
|
||||||
|
length = kTransportSequenceNumberLength;
|
||||||
|
break;
|
||||||
|
case kRtpExtensionPlayoutDelay:
|
||||||
|
length = kPlayoutDelayLength;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const RTPExtensionType type;
|
||||||
|
uint8_t length;
|
||||||
|
};
|
||||||
|
|
||||||
class RtpHeaderExtensionMap {
|
class RtpHeaderExtensionMap {
|
||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
|
static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
|
||||||
static constexpr uint8_t kInvalidId = 0;
|
static constexpr uint8_t kInvalidId = 0;
|
||||||
|
|
||||||
RtpHeaderExtensionMap();
|
RtpHeaderExtensionMap();
|
||||||
RtpHeaderExtensionMap(std::initializer_list<RtpExtension>);
|
~RtpHeaderExtensionMap();
|
||||||
|
|
||||||
template <typename Extension>
|
void Erase();
|
||||||
bool Register(uint8_t id) {
|
|
||||||
return Register(id, Extension::kId, Extension::kValueSizeBytes,
|
|
||||||
Extension::kUri);
|
|
||||||
}
|
|
||||||
bool RegisterByType(uint8_t id, RTPExtensionType type);
|
|
||||||
bool RegisterByUri(uint8_t id, const std::string& uri);
|
|
||||||
|
|
||||||
bool IsRegistered(RTPExtensionType type) const {
|
int32_t Register(RTPExtensionType type, uint8_t id);
|
||||||
return GetId(type) != kInvalidId;
|
|
||||||
}
|
int32_t Deregister(RTPExtensionType type);
|
||||||
|
|
||||||
|
bool IsRegistered(RTPExtensionType type) const;
|
||||||
|
|
||||||
|
int32_t GetType(uint8_t id, RTPExtensionType* type) const;
|
||||||
// Return kInvalidType if not found.
|
// Return kInvalidType if not found.
|
||||||
RTPExtensionType GetType(uint8_t id) const {
|
RTPExtensionType GetType(uint8_t id) const;
|
||||||
RTC_DCHECK_GE(id, kMinId);
|
|
||||||
RTC_DCHECK_LE(id, kMaxId);
|
|
||||||
return types_[id];
|
|
||||||
}
|
|
||||||
// Return kInvalidId if not found.
|
|
||||||
uint8_t GetId(RTPExtensionType type) const {
|
|
||||||
RTC_DCHECK_GT(type, kRtpExtensionNone);
|
|
||||||
RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
|
|
||||||
return ids_[type];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
int32_t GetId(const RTPExtensionType type, uint8_t* id) const;
|
||||||
|
// Return kInvalidId if not found.
|
||||||
|
uint8_t GetId(RTPExtensionType type) const;
|
||||||
size_t GetTotalLengthInBytes() const;
|
size_t GetTotalLengthInBytes() const;
|
||||||
|
|
||||||
// TODO(danilchap): Remove use of the functions below.
|
void GetCopy(RtpHeaderExtensionMap* map) const;
|
||||||
void Erase() { *this = RtpHeaderExtensionMap(); }
|
|
||||||
int32_t Register(RTPExtensionType type, uint8_t id) {
|
int32_t Size() const;
|
||||||
return RegisterByType(id, type) ? 0 : -1;
|
|
||||||
}
|
|
||||||
int32_t Deregister(RTPExtensionType type);
|
|
||||||
int32_t GetType(uint8_t id, RTPExtensionType* type) const {
|
|
||||||
*type = GetType(id);
|
|
||||||
return *type == kInvalidType ? -1 : 0;
|
|
||||||
}
|
|
||||||
void GetCopy(RtpHeaderExtensionMap* copy) const { *copy = *this; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr uint8_t kMinId = 1;
|
std::map<uint8_t, HeaderExtension*> extensionMap_;
|
||||||
static constexpr uint8_t kMaxId = 14;
|
|
||||||
bool Register(uint8_t id,
|
|
||||||
RTPExtensionType type,
|
|
||||||
size_t value_size,
|
|
||||||
const char* uri);
|
|
||||||
|
|
||||||
size_t total_values_size_bytes_ = 0;
|
|
||||||
RTPExtensionType types_[kMaxId + 1];
|
|
||||||
uint8_t ids_[kRtpExtensionNumberOfExtensions];
|
|
||||||
};
|
};
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
|
|||||||
@ -10,99 +10,87 @@
|
|||||||
|
|
||||||
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
||||||
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
|
|
||||||
#include "webrtc/test/gtest.h"
|
#include "webrtc/test/gtest.h"
|
||||||
#include "webrtc/typedefs.h"
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, RegisterByType) {
|
class RtpHeaderExtensionTest : public ::testing::Test {
|
||||||
RtpHeaderExtensionMap map;
|
protected:
|
||||||
EXPECT_FALSE(map.IsRegistered(TransmissionOffset::kId));
|
RtpHeaderExtensionTest() {}
|
||||||
|
~RtpHeaderExtensionTest() {}
|
||||||
|
|
||||||
EXPECT_TRUE(map.RegisterByType(3, TransmissionOffset::kId));
|
RtpHeaderExtensionMap map_;
|
||||||
|
static const uint8_t kId;
|
||||||
|
};
|
||||||
|
|
||||||
EXPECT_TRUE(map.IsRegistered(TransmissionOffset::kId));
|
const uint8_t RtpHeaderExtensionTest::kId = 3;
|
||||||
EXPECT_EQ(3, map.GetId(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(TransmissionOffset::kId, map.GetType(3));
|
TEST_F(RtpHeaderExtensionTest, Register) {
|
||||||
|
EXPECT_EQ(0, map_.Size());
|
||||||
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
EXPECT_TRUE(map_.IsRegistered(kRtpExtensionTransmissionTimeOffset));
|
||||||
|
EXPECT_EQ(1, map_.Size());
|
||||||
|
EXPECT_EQ(0, map_.Deregister(kRtpExtensionTransmissionTimeOffset));
|
||||||
|
EXPECT_EQ(0, map_.Size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, RegisterByUri) {
|
TEST_F(RtpHeaderExtensionTest, RegisterIllegalArg) {
|
||||||
RtpHeaderExtensionMap map;
|
|
||||||
|
|
||||||
EXPECT_TRUE(map.RegisterByUri(3, TransmissionOffset::kUri));
|
|
||||||
|
|
||||||
EXPECT_TRUE(map.IsRegistered(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(3, map.GetId(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(TransmissionOffset::kId, map.GetType(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, RegisterWithTrait) {
|
|
||||||
RtpHeaderExtensionMap map;
|
|
||||||
|
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
|
||||||
|
|
||||||
EXPECT_TRUE(map.IsRegistered(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(3, map.GetId(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(TransmissionOffset::kId, map.GetType(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, RegisterDuringContruction) {
|
|
||||||
const RtpHeaderExtensionMap map = {{TransmissionOffset::kUri, 1},
|
|
||||||
{AbsoluteSendTime::kUri, 3}};
|
|
||||||
|
|
||||||
EXPECT_EQ(1, map.GetId(TransmissionOffset::kId));
|
|
||||||
EXPECT_EQ(3, map.GetId(AbsoluteSendTime::kId));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, RegisterIllegalArg) {
|
|
||||||
RtpHeaderExtensionMap map;
|
|
||||||
// Valid range for id: [1-14].
|
// Valid range for id: [1-14].
|
||||||
EXPECT_FALSE(map.Register<TransmissionOffset>(0));
|
EXPECT_EQ(-1, map_.Register(kRtpExtensionTransmissionTimeOffset, 0));
|
||||||
EXPECT_FALSE(map.Register<TransmissionOffset>(15));
|
EXPECT_EQ(-1, map_.Register(kRtpExtensionTransmissionTimeOffset, 15));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, Idempotent) {
|
TEST_F(RtpHeaderExtensionTest, Idempotent) {
|
||||||
RtpHeaderExtensionMap map;
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
EXPECT_EQ(0, map_.Deregister(kRtpExtensionTransmissionTimeOffset));
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
EXPECT_EQ(0, map_.Deregister(kRtpExtensionTransmissionTimeOffset));
|
||||||
|
|
||||||
map.Deregister(TransmissionOffset::kId);
|
|
||||||
map.Deregister(TransmissionOffset::kId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, NonUniqueId) {
|
TEST_F(RtpHeaderExtensionTest, NonUniqueId) {
|
||||||
RtpHeaderExtensionMap map;
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
EXPECT_EQ(-1, map_.Register(kRtpExtensionAudioLevel, kId));
|
||||||
|
|
||||||
EXPECT_FALSE(map.Register<AudioLevel>(3));
|
|
||||||
EXPECT_TRUE(map.Register<AudioLevel>(4));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, GetTotalLength) {
|
TEST_F(RtpHeaderExtensionTest, GetTotalLength) {
|
||||||
RtpHeaderExtensionMap map;
|
EXPECT_EQ(0u, map_.GetTotalLengthInBytes());
|
||||||
EXPECT_EQ(0u, map.GetTotalLengthInBytes());
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
EXPECT_EQ(kRtpOneByteHeaderLength + kTransmissionTimeOffsetLength,
|
||||||
EXPECT_EQ(kRtpOneByteHeaderLength + (TransmissionOffset::kValueSizeBytes + 1),
|
map_.GetTotalLengthInBytes());
|
||||||
map.GetTotalLengthInBytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, GetType) {
|
TEST_F(RtpHeaderExtensionTest, GetType) {
|
||||||
RtpHeaderExtensionMap map;
|
RTPExtensionType typeOut;
|
||||||
EXPECT_EQ(RtpHeaderExtensionMap::kInvalidType, map.GetType(3));
|
EXPECT_EQ(-1, map_.GetType(kId, &typeOut));
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
|
||||||
|
|
||||||
EXPECT_EQ(TransmissionOffset::kId, map.GetType(3));
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
EXPECT_EQ(0, map_.GetType(kId, &typeOut));
|
||||||
|
EXPECT_EQ(kRtpExtensionTransmissionTimeOffset, typeOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(RtpHeaderExtensionTest, GetId) {
|
TEST_F(RtpHeaderExtensionTest, GetId) {
|
||||||
RtpHeaderExtensionMap map;
|
uint8_t idOut;
|
||||||
EXPECT_EQ(RtpHeaderExtensionMap::kInvalidId,
|
EXPECT_EQ(-1, map_.GetId(kRtpExtensionTransmissionTimeOffset, &idOut));
|
||||||
map.GetId(TransmissionOffset::kId));
|
|
||||||
EXPECT_TRUE(map.Register<TransmissionOffset>(3));
|
|
||||||
|
|
||||||
EXPECT_EQ(3, map.GetId(TransmissionOffset::kId));
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
EXPECT_EQ(0, map_.GetId(kRtpExtensionTransmissionTimeOffset, &idOut));
|
||||||
|
EXPECT_EQ(kId, idOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RtpHeaderExtensionTest, GetCopy) {
|
||||||
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
|
||||||
|
RtpHeaderExtensionMap mapOut;
|
||||||
|
map_.GetCopy(&mapOut);
|
||||||
|
EXPECT_EQ(1, mapOut.Size());
|
||||||
|
EXPECT_EQ(kId, mapOut.GetId(kRtpExtensionTransmissionTimeOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(RtpHeaderExtensionTest, Erase) {
|
||||||
|
EXPECT_EQ(0, map_.Register(kRtpExtensionTransmissionTimeOffset, kId));
|
||||||
|
EXPECT_EQ(1, map_.Size());
|
||||||
|
map_.Erase();
|
||||||
|
EXPECT_EQ(0, map_.Size());
|
||||||
|
}
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
@ -33,7 +33,8 @@ namespace webrtc {
|
|||||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
constexpr RTPExtensionType AbsoluteSendTime::kId;
|
constexpr RTPExtensionType AbsoluteSendTime::kId;
|
||||||
constexpr uint8_t AbsoluteSendTime::kValueSizeBytes;
|
constexpr uint8_t AbsoluteSendTime::kValueSizeBytes;
|
||||||
constexpr const char* AbsoluteSendTime::kUri;
|
const char* const AbsoluteSendTime::kUri =
|
||||||
|
"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
|
||||||
|
|
||||||
bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* time_24bits) {
|
bool AbsoluteSendTime::Parse(const uint8_t* data, uint32_t* time_24bits) {
|
||||||
*time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data);
|
*time_24bits = ByteReader<uint32_t, 3>::ReadBigEndian(data);
|
||||||
@ -59,7 +60,8 @@ bool AbsoluteSendTime::Write(uint8_t* data, int64_t time_ms) {
|
|||||||
//
|
//
|
||||||
constexpr RTPExtensionType AudioLevel::kId;
|
constexpr RTPExtensionType AudioLevel::kId;
|
||||||
constexpr uint8_t AudioLevel::kValueSizeBytes;
|
constexpr uint8_t AudioLevel::kValueSizeBytes;
|
||||||
constexpr const char* AudioLevel::kUri;
|
const char* const AudioLevel::kUri =
|
||||||
|
"urn:ietf:params:rtp-hdrext:ssrc-audio-level";
|
||||||
|
|
||||||
bool AudioLevel::Parse(const uint8_t* data,
|
bool AudioLevel::Parse(const uint8_t* data,
|
||||||
bool* voice_activity,
|
bool* voice_activity,
|
||||||
@ -95,7 +97,8 @@ bool AudioLevel::Write(uint8_t* data,
|
|||||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
constexpr RTPExtensionType TransmissionOffset::kId;
|
constexpr RTPExtensionType TransmissionOffset::kId;
|
||||||
constexpr uint8_t TransmissionOffset::kValueSizeBytes;
|
constexpr uint8_t TransmissionOffset::kValueSizeBytes;
|
||||||
constexpr const char* TransmissionOffset::kUri;
|
const char* const TransmissionOffset::kUri =
|
||||||
|
"urn:ietf:params:rtp-hdrext:toffset";
|
||||||
|
|
||||||
bool TransmissionOffset::Parse(const uint8_t* data, int32_t* rtp_time) {
|
bool TransmissionOffset::Parse(const uint8_t* data, int32_t* rtp_time) {
|
||||||
*rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data);
|
*rtp_time = ByteReader<int32_t, 3>::ReadBigEndian(data);
|
||||||
@ -115,7 +118,8 @@ bool TransmissionOffset::Write(uint8_t* data, int32_t rtp_time) {
|
|||||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
constexpr RTPExtensionType TransportSequenceNumber::kId;
|
constexpr RTPExtensionType TransportSequenceNumber::kId;
|
||||||
constexpr uint8_t TransportSequenceNumber::kValueSizeBytes;
|
constexpr uint8_t TransportSequenceNumber::kValueSizeBytes;
|
||||||
constexpr const char* TransportSequenceNumber::kUri;
|
const char* const TransportSequenceNumber::kUri =
|
||||||
|
"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions";
|
||||||
|
|
||||||
bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) {
|
bool TransportSequenceNumber::Parse(const uint8_t* data, uint16_t* value) {
|
||||||
*value = ByteReader<uint16_t>::ReadBigEndian(data);
|
*value = ByteReader<uint16_t>::ReadBigEndian(data);
|
||||||
@ -140,7 +144,7 @@ bool TransportSequenceNumber::Write(uint8_t* data, uint16_t value) {
|
|||||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
constexpr RTPExtensionType VideoOrientation::kId;
|
constexpr RTPExtensionType VideoOrientation::kId;
|
||||||
constexpr uint8_t VideoOrientation::kValueSizeBytes;
|
constexpr uint8_t VideoOrientation::kValueSizeBytes;
|
||||||
constexpr const char* VideoOrientation::kUri;
|
const char* const VideoOrientation::kUri = "urn:3gpp:video-orientation";
|
||||||
|
|
||||||
bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) {
|
bool VideoOrientation::Parse(const uint8_t* data, VideoRotation* rotation) {
|
||||||
*rotation = ConvertCVOByteToVideoRotation(data[0]);
|
*rotation = ConvertCVOByteToVideoRotation(data[0]);
|
||||||
@ -169,7 +173,8 @@ bool VideoOrientation::Write(uint8_t* data, uint8_t value) {
|
|||||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
constexpr RTPExtensionType PlayoutDelayLimits::kId;
|
constexpr RTPExtensionType PlayoutDelayLimits::kId;
|
||||||
constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes;
|
constexpr uint8_t PlayoutDelayLimits::kValueSizeBytes;
|
||||||
constexpr const char* PlayoutDelayLimits::kUri;
|
const char* const PlayoutDelayLimits::kUri =
|
||||||
|
"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
|
||||||
|
|
||||||
bool PlayoutDelayLimits::Parse(const uint8_t* data,
|
bool PlayoutDelayLimits::Parse(const uint8_t* data,
|
||||||
PlayoutDelay* playout_delay) {
|
PlayoutDelay* playout_delay) {
|
||||||
|
|||||||
@ -20,8 +20,7 @@ class AbsoluteSendTime {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
|
static constexpr RTPExtensionType kId = kRtpExtensionAbsoluteSendTime;
|
||||||
static constexpr uint8_t kValueSizeBytes = 3;
|
static constexpr uint8_t kValueSizeBytes = 3;
|
||||||
static constexpr const char* kUri =
|
static const char* const kUri;
|
||||||
"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
|
|
||||||
|
|
||||||
static bool Parse(const uint8_t* data, uint32_t* time_24bits);
|
static bool Parse(const uint8_t* data, uint32_t* time_24bits);
|
||||||
static bool Write(uint8_t* data, int64_t time_ms);
|
static bool Write(uint8_t* data, int64_t time_ms);
|
||||||
@ -35,8 +34,7 @@ class AudioLevel {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
|
static constexpr RTPExtensionType kId = kRtpExtensionAudioLevel;
|
||||||
static constexpr uint8_t kValueSizeBytes = 1;
|
static constexpr uint8_t kValueSizeBytes = 1;
|
||||||
static constexpr const char* kUri =
|
static const char* const kUri;
|
||||||
"urn:ietf:params:rtp-hdrext:ssrc-audio-level";
|
|
||||||
|
|
||||||
static bool Parse(const uint8_t* data,
|
static bool Parse(const uint8_t* data,
|
||||||
bool* voice_activity,
|
bool* voice_activity,
|
||||||
@ -48,7 +46,7 @@ class TransmissionOffset {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
|
static constexpr RTPExtensionType kId = kRtpExtensionTransmissionTimeOffset;
|
||||||
static constexpr uint8_t kValueSizeBytes = 3;
|
static constexpr uint8_t kValueSizeBytes = 3;
|
||||||
static constexpr const char* kUri = "urn:ietf:params:rtp-hdrext:toffset";
|
static const char* const kUri;
|
||||||
|
|
||||||
static bool Parse(const uint8_t* data, int32_t* rtp_time);
|
static bool Parse(const uint8_t* data, int32_t* rtp_time);
|
||||||
static bool Write(uint8_t* data, int32_t rtp_time);
|
static bool Write(uint8_t* data, int32_t rtp_time);
|
||||||
@ -58,9 +56,8 @@ class TransportSequenceNumber {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
|
static constexpr RTPExtensionType kId = kRtpExtensionTransportSequenceNumber;
|
||||||
static constexpr uint8_t kValueSizeBytes = 2;
|
static constexpr uint8_t kValueSizeBytes = 2;
|
||||||
static constexpr const char* kUri =
|
static const char* const kUri;
|
||||||
"http://www.ietf.org/id/"
|
|
||||||
"draft-holmer-rmcat-transport-wide-cc-extensions-01";
|
|
||||||
static bool Parse(const uint8_t* data, uint16_t* value);
|
static bool Parse(const uint8_t* data, uint16_t* value);
|
||||||
static bool Write(uint8_t* data, uint16_t value);
|
static bool Write(uint8_t* data, uint16_t value);
|
||||||
};
|
};
|
||||||
@ -69,7 +66,7 @@ class VideoOrientation {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
|
static constexpr RTPExtensionType kId = kRtpExtensionVideoRotation;
|
||||||
static constexpr uint8_t kValueSizeBytes = 1;
|
static constexpr uint8_t kValueSizeBytes = 1;
|
||||||
static constexpr const char* kUri = "urn:3gpp:video-orientation";
|
static const char* const kUri;
|
||||||
|
|
||||||
static bool Parse(const uint8_t* data, VideoRotation* value);
|
static bool Parse(const uint8_t* data, VideoRotation* value);
|
||||||
static bool Write(uint8_t* data, VideoRotation value);
|
static bool Write(uint8_t* data, VideoRotation value);
|
||||||
@ -81,8 +78,7 @@ class PlayoutDelayLimits {
|
|||||||
public:
|
public:
|
||||||
static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
|
static constexpr RTPExtensionType kId = kRtpExtensionPlayoutDelay;
|
||||||
static constexpr uint8_t kValueSizeBytes = 3;
|
static constexpr uint8_t kValueSizeBytes = 3;
|
||||||
static constexpr const char* kUri =
|
static const char* const kUri;
|
||||||
"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
|
|
||||||
|
|
||||||
// Playout delay in milliseconds. A playout delay limit (min or max)
|
// Playout delay in milliseconds. A playout delay limit (min or max)
|
||||||
// has 12 bits allocated. This allows a range of 0-4095 values which
|
// has 12 bits allocated. This allows a range of 0-4095 values which
|
||||||
|
|||||||
Reference in New Issue
Block a user