2011-12-16 14:31:37 +00:00
|
|
|
/*
|
2012-08-13 17:13:27 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-12-16 14:31:37 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-05 16:22:53 +00:00
|
|
|
#include <assert.h>
|
2011-12-16 14:31:37 +00:00
|
|
|
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/common_types.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h"
|
2015-03-17 14:33:12 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
|
2011-12-16 14:31:37 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
RtpHeaderExtensionMap::RtpHeaderExtensionMap() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpHeaderExtensionMap::~RtpHeaderExtensionMap() {
|
|
|
|
|
Erase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RtpHeaderExtensionMap::Erase() {
|
2012-01-19 12:58:53 +00:00
|
|
|
while (!extensionMap_.empty()) {
|
|
|
|
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
delete it->second;
|
|
|
|
|
extensionMap_.erase(it);
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
int32_t RtpHeaderExtensionMap::Register(const RTPExtensionType type,
|
|
|
|
|
const uint8_t id) {
|
2015-04-01 15:33:06 -07:00
|
|
|
return Register(type, id, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t RtpHeaderExtensionMap::RegisterInactive(const RTPExtensionType type,
|
|
|
|
|
const uint8_t id) {
|
|
|
|
|
return Register(type, id, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t RtpHeaderExtensionMap::Register(const RTPExtensionType type,
|
|
|
|
|
const uint8_t id,
|
|
|
|
|
bool active) {
|
2011-12-16 14:31:37 +00:00
|
|
|
if (id < 1 || id > 14) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
|
|
|
|
extensionMap_.find(id);
|
|
|
|
|
if (it != extensionMap_.end()) {
|
2013-03-01 17:03:02 +00:00
|
|
|
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.
|
2015-04-01 15:33:06 -07:00
|
|
|
it->second->active = active;
|
2013-03-01 17:03:02 +00:00
|
|
|
return 0;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2015-04-01 15:33:06 -07:00
|
|
|
extensionMap_[id] = new HeaderExtension(type, active);
|
2011-12-16 14:31:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 15:33:06 -07:00
|
|
|
bool RtpHeaderExtensionMap::SetActive(const RTPExtensionType type,
|
|
|
|
|
bool active) {
|
|
|
|
|
for (auto& kv : extensionMap_) {
|
|
|
|
|
if (kv.second->type == type) {
|
|
|
|
|
kv.second->active = active;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
int32_t RtpHeaderExtensionMap::Deregister(const RTPExtensionType type) {
|
|
|
|
|
uint8_t id;
|
2011-12-16 14:31:37 +00:00
|
|
|
if (GetId(type, &id) != 0) {
|
2012-08-13 17:13:27 +00:00
|
|
|
return 0;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::iterator it =
|
|
|
|
|
extensionMap_.find(id);
|
2013-03-01 17:03:02 +00:00
|
|
|
assert(it != extensionMap_.end());
|
2012-01-19 12:58:53 +00:00
|
|
|
delete it->second;
|
|
|
|
|
extensionMap_.erase(it);
|
2011-12-16 14:31:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-17 16:10:14 +00:00
|
|
|
bool RtpHeaderExtensionMap::IsRegistered(RTPExtensionType type) const {
|
|
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
for (; it != extensionMap_.end(); ++it) {
|
|
|
|
|
if (it->second->type == type)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
int32_t RtpHeaderExtensionMap::GetType(const uint8_t id,
|
|
|
|
|
RTPExtensionType* type) const {
|
2011-12-16 14:31:37 +00:00
|
|
|
assert(type);
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.find(id);
|
|
|
|
|
if (it == extensionMap_.end()) {
|
2011-12-16 14:31:37 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
HeaderExtension* extension = it->second;
|
2011-12-16 14:31:37 +00:00
|
|
|
*type = extension->type;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 05:25:10 -07:00
|
|
|
RTPExtensionType RtpHeaderExtensionMap::GetType(uint8_t id) const {
|
|
|
|
|
auto it = extensionMap_.find(id);
|
|
|
|
|
if (it == extensionMap_.end()) {
|
|
|
|
|
return kInvalidType;
|
|
|
|
|
}
|
|
|
|
|
return it->second->type;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
int32_t RtpHeaderExtensionMap::GetId(const RTPExtensionType type,
|
|
|
|
|
uint8_t* id) const {
|
2011-12-16 14:31:37 +00:00
|
|
|
assert(id);
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
|
|
|
|
|
while (it != extensionMap_.end()) {
|
|
|
|
|
HeaderExtension* extension = it->second;
|
2011-12-16 14:31:37 +00:00
|
|
|
if (extension->type == type) {
|
2012-01-19 12:58:53 +00:00
|
|
|
*id = it->first;
|
2011-12-16 14:31:37 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
it++;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 05:25:10 -07:00
|
|
|
uint8_t RtpHeaderExtensionMap::GetId(RTPExtensionType type) const {
|
|
|
|
|
for (auto kv : extensionMap_) {
|
|
|
|
|
if (kv.second->type == type)
|
|
|
|
|
return kv.first;
|
|
|
|
|
}
|
|
|
|
|
return kInvalidId;
|
|
|
|
|
}
|
|
|
|
|
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t RtpHeaderExtensionMap::GetTotalLengthInBytes() const {
|
2011-12-16 14:31:37 +00:00
|
|
|
// Get length for each extension block.
|
Use size_t more consistently for packet/payload lengths.
See design doc at https://docs.google.com/a/chromium.org/document/d/1I6nmE9D_BmCY-IoV6MDPY2V6WYpEI-dg2apWXTfZyUI/edit?usp=sharing for more information.
This CL was reviewed and approved in pieces in the following CLs:
https://webrtc-codereview.appspot.com/24209004/
https://webrtc-codereview.appspot.com/24229004/
https://webrtc-codereview.appspot.com/24259004/
https://webrtc-codereview.appspot.com/25109004/
https://webrtc-codereview.appspot.com/26099004/
https://webrtc-codereview.appspot.com/27069004/
https://webrtc-codereview.appspot.com/27969004/
https://webrtc-codereview.appspot.com/27989004/
https://webrtc-codereview.appspot.com/29009004/
https://webrtc-codereview.appspot.com/30929004/
https://webrtc-codereview.appspot.com/30939004/
https://webrtc-codereview.appspot.com/31999004/
Committing as TBR to the original reviewers.
BUG=chromium:81439
TEST=none
TBR=pthatcher,henrik.lundin,tina.legrand,stefan,tkchin,glaznev,kjellander,perkj,mflodman,henrika,asapersson,niklas.enbom
Review URL: https://webrtc-codereview.appspot.com/23129004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7726 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-11-20 22:28:14 +00:00
|
|
|
size_t length = 0;
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
while (it != extensionMap_.end()) {
|
|
|
|
|
HeaderExtension* extension = it->second;
|
2015-04-01 15:33:06 -07:00
|
|
|
if (extension->active) {
|
|
|
|
|
length += extension->length;
|
|
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
it++;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
// Add RTP extension header length.
|
|
|
|
|
if (length > 0) {
|
2013-05-07 12:36:21 +00:00
|
|
|
length += kRtpOneByteHeaderLength;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2015-03-17 14:33:12 +00:00
|
|
|
// Pad up to nearest 32bit word.
|
|
|
|
|
length = RtpUtility::Word32Align(length);
|
2011-12-16 14:31:37 +00:00
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
int32_t RtpHeaderExtensionMap::GetLengthUntilBlockStartInBytes(
|
|
|
|
|
const RTPExtensionType type) const {
|
|
|
|
|
uint8_t id;
|
|
|
|
|
if (GetId(type, &id) != 0) {
|
|
|
|
|
// Not registered.
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// Get length until start of extension block type.
|
2013-05-07 12:36:21 +00:00
|
|
|
uint16_t length = kRtpOneByteHeaderLength;
|
2012-01-19 12:58:53 +00:00
|
|
|
|
|
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
while (it != extensionMap_.end()) {
|
|
|
|
|
HeaderExtension* extension = it->second;
|
2012-01-16 11:06:31 +00:00
|
|
|
if (extension->type == type) {
|
2015-04-01 15:33:06 -07:00
|
|
|
if (!extension->active) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-16 11:06:31 +00:00
|
|
|
break;
|
2015-04-01 15:33:06 -07:00
|
|
|
} else if (extension->active) {
|
2012-01-16 11:06:31 +00:00
|
|
|
length += extension->length;
|
|
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
it++;
|
2012-01-16 11:06:31 +00:00
|
|
|
}
|
|
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t RtpHeaderExtensionMap::Size() const {
|
2015-04-01 15:33:06 -07:00
|
|
|
int32_t count = 0;
|
|
|
|
|
for (auto& kv : extensionMap_) {
|
|
|
|
|
if (kv.second->active) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTPExtensionType RtpHeaderExtensionMap::First() const {
|
2015-04-01 15:33:06 -07:00
|
|
|
for (auto& kv : extensionMap_) {
|
|
|
|
|
if (kv.second->active) {
|
|
|
|
|
return kv.second->type;
|
|
|
|
|
}
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2015-04-01 15:33:06 -07:00
|
|
|
|
|
|
|
|
return kRtpExtensionNone;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-16 11:06:31 +00:00
|
|
|
RTPExtensionType RtpHeaderExtensionMap::Next(RTPExtensionType type) const {
|
|
|
|
|
uint8_t id;
|
2011-12-16 14:31:37 +00:00
|
|
|
if (GetId(type, &id) != 0) {
|
2012-01-04 17:04:51 +00:00
|
|
|
return kRtpExtensionNone;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.find(id);
|
2015-04-01 15:33:06 -07:00
|
|
|
if (it == extensionMap_.end() || !it->second->active) {
|
2012-01-04 17:04:51 +00:00
|
|
|
return kRtpExtensionNone;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2015-04-01 15:33:06 -07:00
|
|
|
while ((++it) != extensionMap_.end()) {
|
|
|
|
|
if (it->second->active) {
|
|
|
|
|
return it->second->type;
|
|
|
|
|
}
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
2015-04-01 15:33:06 -07:00
|
|
|
|
|
|
|
|
return kRtpExtensionNone;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RtpHeaderExtensionMap::GetCopy(RtpHeaderExtensionMap* map) const {
|
|
|
|
|
assert(map);
|
2012-01-19 12:58:53 +00:00
|
|
|
std::map<uint8_t, HeaderExtension*>::const_iterator it =
|
|
|
|
|
extensionMap_.begin();
|
|
|
|
|
while (it != extensionMap_.end()) {
|
|
|
|
|
HeaderExtension* extension = it->second;
|
2015-04-01 15:33:06 -07:00
|
|
|
map->Register(extension->type, it->first, extension->active);
|
2012-01-19 12:58:53 +00:00
|
|
|
it++;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|