tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

rtp_header_extension_map.h (2387B)


      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 
     17 #include "absl/strings/string_view.h"
     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 
     23 namespace webrtc {
     24 
     25 class RtpHeaderExtensionMap {
     26 public:
     27  static constexpr RTPExtensionType kInvalidType = kRtpExtensionNone;
     28  static constexpr int kInvalidId = 0;
     29 
     30  RtpHeaderExtensionMap();
     31  explicit RtpHeaderExtensionMap(bool extmap_allow_mixed);
     32  explicit RtpHeaderExtensionMap(ArrayView<const RtpExtension> extensions);
     33 
     34  void Reset(ArrayView<const RtpExtension> extensions);
     35 
     36  template <typename Extension>
     37  bool Register(int id) {
     38    return Register(id, Extension::kId, Extension::Uri());
     39  }
     40  bool RegisterByType(int id, RTPExtensionType type);
     41  bool RegisterByUri(int id, absl::string_view uri);
     42 
     43  bool IsRegistered(RTPExtensionType type) const {
     44    return GetId(type) != kInvalidId;
     45  }
     46  // Return kInvalidType if not found.
     47  RTPExtensionType GetType(int id) const;
     48  // Return kInvalidId if not found.
     49  uint8_t GetId(RTPExtensionType type) const {
     50    RTC_DCHECK_GT(type, kRtpExtensionNone);
     51    RTC_DCHECK_LT(type, kRtpExtensionNumberOfExtensions);
     52    return ids_[type];
     53  }
     54 
     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.
     60  bool ExtmapAllowMixed() const { return 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, absl::string_view 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_