xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/include/rtp_header_extension_map.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 "absl/strings/string_view.h"
19 #include "api/array_view.h"
20 #include "api/rtp_parameters.h"
21 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "rtc_base/checks.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   void Reset(rtc::ArrayView<const RtpExtension> extensions);
36 
37   template <typename Extension>
Register(int id)38   bool Register(int id) {
39     return Register(id, Extension::kId, Extension::Uri());
40   }
41   bool RegisterByType(int id, RTPExtensionType type);
42   bool RegisterByUri(int id, absl::string_view uri);
43 
IsRegistered(RTPExtensionType type)44   bool IsRegistered(RTPExtensionType type) const {
45     return GetId(type) != kInvalidId;
46   }
47   // Return kInvalidType if not found.
48   RTPExtensionType GetType(int id) const;
49   // Return kInvalidId if not found.
GetId(RTPExtensionType type)50   uint8_t GetId(RTPExtensionType type) const {
51     RTC_DCHECK_GT(type, kRtpExtensionNone);
52     RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
53     return ids_[type];
54   }
55 
56   void Deregister(absl::string_view uri);
57 
58   // Corresponds to the SDP attribute extmap-allow-mixed, see RFC8285.
59   // Set to true if it's allowed to mix one- and two-byte RTP header extensions
60   // in the same stream.
ExtmapAllowMixed()61   bool ExtmapAllowMixed() const { return extmap_allow_mixed_; }
SetExtmapAllowMixed(bool extmap_allow_mixed)62   void SetExtmapAllowMixed(bool extmap_allow_mixed) {
63     extmap_allow_mixed_ = extmap_allow_mixed;
64   }
65 
66  private:
67   bool Register(int id, RTPExtensionType type, absl::string_view uri);
68 
69   uint8_t ids_[kRtpExtensionNumberOfExtensions];
70   bool extmap_allow_mixed_;
71 };
72 
73 }  // namespace webrtc
74 
75 #endif  // MODULES_RTP_RTCP_INCLUDE_RTP_HEADER_EXTENSION_MAP_H_
76