webrtc/modules/rtp_rtcp/source/rtp_header_extension_map.cc
Johannes Kron 54047bea1b Reland "Extend TransportSequenceNumber RTP header extension"
This reverts commit 109b5fb5f5.

Reason for revert: The failing libfuzzer was fixed in commit d6c6f16063

Original change's description:
> Revert "Extend TransportSequenceNumber RTP header extension"
> 
> This reverts commit 28c7362bc4.
> 
> Reason for revert: It breaks Linux64 Release (libfuzzer):
> https://logs.chromium.org/logs/webrtc/buildbucket/cr-buildbucket.appspot.com/8921003137877469920/+/steps/compile/0/stdout
> 
> Original change's description:
> > Extend TransportSequenceNumber RTP header extension
> > 
> > Extend TransportSequenceNumber RTP header extension to support
> > feedback on sender request.
> > 
> > Bug: webrtc:10262
> > Change-Id: Ibc1cf18162d15cd102e951c9dc697d8ea536ebb6
> > Reviewed-on: https://webrtc-review.googlesource.com/c/123233
> > Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
> > Reviewed-by: Alex Loiko <aleloi@webrtc.org>
> > Commit-Queue: Johannes Kron <kron@webrtc.org>
> > Cr-Commit-Position: refs/heads/master@{#26766}
> 
> TBR=danilchap@webrtc.org,aleloi@webrtc.org,kron@webrtc.org
> 
> Change-Id: Ie8a73f5fdffd99919ceaa1ae8911a1645f2077e9
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:10262
> Reviewed-on: https://webrtc-review.googlesource.com/c/123522
> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#26767}

TBR=danilchap@webrtc.org,mbonadei@webrtc.org,aleloi@webrtc.org,kron@webrtc.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: webrtc:10262
Change-Id: I0f854299a46c042cfbdf8b8cc8cd965a228142c8
Reviewed-on: https://webrtc-review.googlesource.com/c/123764
Reviewed-by: Johannes Kron <kron@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Alex Loiko <aleloi@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26798}
2019-02-21 16:01:30 +00:00

147 lines
4.9 KiB
C++

/*
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor_extension.h"
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
namespace webrtc {
namespace {
struct ExtensionInfo {
RTPExtensionType type;
const char* uri;
};
template <typename Extension>
constexpr ExtensionInfo CreateExtensionInfo() {
return {Extension::kId, Extension::kUri};
}
constexpr ExtensionInfo kExtensions[] = {
CreateExtensionInfo<TransmissionOffset>(),
CreateExtensionInfo<AudioLevel>(),
CreateExtensionInfo<AbsoluteSendTime>(),
CreateExtensionInfo<VideoOrientation>(),
CreateExtensionInfo<TransportSequenceNumber>(),
CreateExtensionInfo<TransportSequenceNumberV2>(),
CreateExtensionInfo<PlayoutDelayLimits>(),
CreateExtensionInfo<VideoContentTypeExtension>(),
CreateExtensionInfo<VideoTimingExtension>(),
CreateExtensionInfo<FrameMarkingExtension>(),
CreateExtensionInfo<RtpStreamId>(),
CreateExtensionInfo<RepairedRtpStreamId>(),
CreateExtensionInfo<RtpMid>(),
CreateExtensionInfo<RtpGenericFrameDescriptorExtension00>(),
CreateExtensionInfo<RtpGenericFrameDescriptorExtension01>(),
CreateExtensionInfo<ColorSpaceExtension>(),
};
// Because of kRtpExtensionNone, NumberOfExtension is 1 bigger than the actual
// number of known extensions.
static_assert(arraysize(kExtensions) ==
static_cast<int>(kRtpExtensionNumberOfExtensions) - 1,
"kExtensions expect to list all known extensions");
} // namespace
constexpr RTPExtensionType RtpHeaderExtensionMap::kInvalidType;
constexpr int RtpHeaderExtensionMap::kInvalidId;
RtpHeaderExtensionMap::RtpHeaderExtensionMap() : RtpHeaderExtensionMap(false) {}
RtpHeaderExtensionMap::RtpHeaderExtensionMap(bool extmap_allow_mixed)
: extmap_allow_mixed_(extmap_allow_mixed) {
for (auto& id : ids_)
id = kInvalidId;
}
RtpHeaderExtensionMap::RtpHeaderExtensionMap(
rtc::ArrayView<const RtpExtension> extensions)
: RtpHeaderExtensionMap(false) {
for (const RtpExtension& extension : extensions)
RegisterByUri(extension.id, extension.uri);
}
bool RtpHeaderExtensionMap::RegisterByType(int id, RTPExtensionType type) {
for (const ExtensionInfo& extension : kExtensions)
if (type == extension.type)
return Register(id, extension.type, extension.uri);
RTC_NOTREACHED();
return false;
}
bool RtpHeaderExtensionMap::RegisterByUri(int id, const std::string& uri) {
for (const ExtensionInfo& extension : kExtensions)
if (uri == extension.uri)
return Register(id, extension.type, extension.uri);
RTC_LOG(LS_WARNING) << "Unknown extension uri:'" << uri << "', id: " << id
<< '.';
return false;
}
RTPExtensionType RtpHeaderExtensionMap::GetType(int id) const {
RTC_DCHECK_GE(id, RtpExtension::kMinId);
RTC_DCHECK_LE(id, RtpExtension::kMaxId);
for (int type = kRtpExtensionNone + 1; type < kRtpExtensionNumberOfExtensions;
++type) {
if (ids_[type] == id) {
return static_cast<RTPExtensionType>(type);
}
}
return kInvalidType;
}
int32_t RtpHeaderExtensionMap::Deregister(RTPExtensionType type) {
if (IsRegistered(type)) {
ids_[type] = kInvalidId;
}
return 0;
}
bool RtpHeaderExtensionMap::Register(int id,
RTPExtensionType type,
const char* uri) {
RTC_DCHECK_GT(type, kRtpExtensionNone);
RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
if (id < RtpExtension::kMinId || id > RtpExtension::kMaxId) {
RTC_LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
<< "' with invalid id:" << id << ".";
return false;
}
RTPExtensionType registered_type = GetType(id);
if (registered_type == type) { // Same type/id pair already registered.
RTC_LOG(LS_VERBOSE) << "Reregistering extension uri:'" << uri
<< "', id:" << id;
return true;
}
if (registered_type !=
kInvalidType) { // |id| used by another extension type.
RTC_LOG(LS_WARNING) << "Failed to register extension uri:'" << uri
<< "', id:" << id
<< ". Id already in use by extension type "
<< static_cast<int>(registered_type);
return false;
}
RTC_DCHECK(!IsRegistered(type));
// There is a run-time check above id fits into uint8_t.
ids_[type] = static_cast<uint8_t>(id);
return true;
}
} // namespace webrtc