tor-browser

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

rtp_source.h (3626B)


      1 /*
      2 *  Copyright 2019 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 API_TRANSPORT_RTP_RTP_SOURCE_H_
     12 #define API_TRANSPORT_RTP_RTP_SOURCE_H_
     13 
     14 #include <stdint.h>
     15 
     16 #include <optional>
     17 
     18 #include "absl/strings/str_format.h"
     19 #include "api/rtp_headers.h"
     20 #include "api/units/time_delta.h"
     21 #include "api/units/timestamp.h"
     22 
     23 namespace webrtc {
     24 
     25 enum class RtpSourceType {
     26  SSRC,
     27  CSRC,
     28 };
     29 
     30 class RtpSource {
     31 public:
     32  struct Extensions {
     33    std::optional<uint8_t> audio_level;
     34 
     35    // Fields from the Absolute Capture Time header extension:
     36    // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
     37    std::optional<AbsoluteCaptureTime> absolute_capture_time;
     38 
     39    // Clock offset between the local clock and the capturer's clock.
     40    // Do not confuse with `AbsoluteCaptureTime::estimated_capture_clock_offset`
     41    // which instead represents the clock offset between a remote sender and the
     42    // capturer. The following holds:
     43    //   Capture's NTP Clock = Local NTP Clock + Local-Capture Clock Offset
     44    std::optional<TimeDelta> local_capture_clock_offset;
     45  };
     46 
     47  RtpSource() = delete;
     48 
     49  RtpSource(Timestamp timestamp,
     50            uint32_t source_id,
     51            RtpSourceType source_type,
     52            uint32_t rtp_timestamp,
     53            const RtpSource::Extensions& extensions)
     54      : timestamp_(timestamp),
     55        source_id_(source_id),
     56        source_type_(source_type),
     57        extensions_(extensions),
     58        rtp_timestamp_(rtp_timestamp) {}
     59 
     60  RtpSource(const RtpSource&) = default;
     61  RtpSource& operator=(const RtpSource&) = default;
     62  ~RtpSource() = default;
     63 
     64  Timestamp timestamp() const { return timestamp_; }
     65 
     66  // The identifier of the source can be the CSRC or the SSRC.
     67  uint32_t source_id() const { return source_id_; }
     68 
     69  // The source can be either a contributing source or a synchronization source.
     70  RtpSourceType source_type() const { return source_type_; }
     71 
     72  std::optional<uint8_t> audio_level() const { return extensions_.audio_level; }
     73 
     74  void set_audio_level(const std::optional<uint8_t>& level) {
     75    extensions_.audio_level = level;
     76  }
     77 
     78  uint32_t rtp_timestamp() const { return rtp_timestamp_; }
     79 
     80  std::optional<AbsoluteCaptureTime> absolute_capture_time() const {
     81    return extensions_.absolute_capture_time;
     82  }
     83 
     84  std::optional<TimeDelta> local_capture_clock_offset() const {
     85    return extensions_.local_capture_clock_offset;
     86  }
     87 
     88  template <typename Sink>
     89  friend void AbslStringify(Sink& sink, const RtpSource& source) {
     90    absl::Format(&sink, "{ source_type: %s, source_id: %u }",
     91                 source.source_type() == RtpSourceType::CSRC ? "CSRC" : "SSRC",
     92                 source.source_id());
     93  }
     94 
     95  bool operator==(const RtpSource& o) const {
     96    return timestamp_ == o.timestamp() && source_id_ == o.source_id() &&
     97           source_type_ == o.source_type() &&
     98           extensions_.audio_level == o.extensions_.audio_level &&
     99           extensions_.absolute_capture_time ==
    100               o.extensions_.absolute_capture_time &&
    101           rtp_timestamp_ == o.rtp_timestamp();
    102  }
    103 
    104 private:
    105  Timestamp timestamp_;
    106  uint32_t source_id_;
    107  RtpSourceType source_type_;
    108  RtpSource::Extensions extensions_;
    109  uint32_t rtp_timestamp_;
    110 };
    111 
    112 }  // namespace webrtc
    113 
    114 #endif  // API_TRANSPORT_RTP_RTP_SOURCE_H_