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