1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_EXTENSION_MAP_H_ 12 #define MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_EXTENSION_MAP_H_ 13 14 #include <stdint.h> 15 16 #include <string> 17 18 #include "api/array_view.h" 19 #include "api/rtp_parameters.h" 20 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 21 #include "rtc_base/checks.h" 22 #include "rtc_base/deprecation.h" 23 24 namespace webrtc { 25 26 class RtpHeaderExtensionMap { 27 public: 28 static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone; 29 static constexpr int kInvalidId = 0; 30 31 RtpHeaderExtensionMap(); 32 explicit RtpHeaderExtensionMap(bool extmap_allow_mixed); 33 explicit RtpHeaderExtensionMap(rtc::ArrayView<const RtpExtension> extensions); 34 35 template <typename Extension> Register(int id)36 bool Register(int id) { 37 return Register(id, Extension::kId, Extension::kUri); 38 } 39 bool RegisterByType(int id, RTPExtensionType type); 40 bool RegisterByUri(int id, absl::string_view uri); 41 IsRegistered(RTPExtensionType type)42 bool IsRegistered(RTPExtensionType type) const { 43 return GetId(type) != kInvalidId; 44 } 45 // Return kInvalidType if not found. 46 RTPExtensionType GetType(int id) const; 47 // Return kInvalidId if not found. GetId(RTPExtensionType type)48 uint8_t GetId(RTPExtensionType type) const { 49 RTC_DCHECK_GT(type, kRtpExtensionNone); 50 RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions); 51 return ids_[type]; 52 } 53 54 int32_t Deregister(RTPExtensionType type); 55 void Deregister(absl::string_view uri); 56 57 // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285. 58 // Set to true if it's allowed to mix one- and two-byte RTP header extensions 59 // in the same stream. ExtmapAllowMixed()60 bool ExtmapAllowMixed() const { return extmap_allow_mixed_; } SetExtmapAllowMixed(bool extmap_allow_mixed)61 void SetExtmapAllowMixed(bool extmap_allow_mixed) { 62 extmap_allow_mixed_ = extmap_allow_mixed; 63 } 64 65 private: 66 bool Register(int id, RTPExtensionType type, const char* uri); 67 68 uint8_t ids_[kRtpExtensionNumberOfExtensions]; 69 bool extmap_allow_mixed_; 70 }; 71 72 } // namespace webrtc 73 74 #endif // MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_EXTENSION_MAP_H_ 75