Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 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" |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 17 | #include "api/rtp_headers.h" |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | enum class RtpSourceType { |
| 23 | SSRC, |
| 24 | CSRC, |
| 25 | }; |
| 26 | |
| 27 | class RtpSource { |
| 28 | public: |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 29 | struct Extensions { |
| 30 | absl::optional<uint8_t> audio_level; |
| 31 | absl::optional<AbsoluteCaptureTime> absolute_capture_time; |
| 32 | }; |
| 33 | |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 34 | RtpSource() = delete; |
| 35 | |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 36 | // TODO(bugs.webrtc.org/10739): Remove this constructor once all clients |
| 37 | // migrate to the version with absolute capture time. |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 38 | RtpSource(int64_t timestamp_ms, |
| 39 | uint32_t source_id, |
| 40 | RtpSourceType source_type, |
| 41 | absl::optional<uint8_t> audio_level, |
| 42 | uint32_t rtp_timestamp) |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 43 | : RtpSource(timestamp_ms, |
| 44 | source_id, |
| 45 | source_type, |
| 46 | rtp_timestamp, |
| 47 | {audio_level, absl::nullopt}) {} |
| 48 | |
| 49 | RtpSource(int64_t timestamp_ms, |
| 50 | uint32_t source_id, |
| 51 | RtpSourceType source_type, |
| 52 | uint32_t rtp_timestamp, |
| 53 | const RtpSource::Extensions& extensions) |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 54 | : timestamp_ms_(timestamp_ms), |
| 55 | source_id_(source_id), |
| 56 | source_type_(source_type), |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 57 | extensions_(extensions), |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 58 | rtp_timestamp_(rtp_timestamp) {} |
| 59 | |
| 60 | RtpSource(const RtpSource&) = default; |
| 61 | RtpSource& operator=(const RtpSource&) = default; |
| 62 | ~RtpSource() = default; |
| 63 | |
| 64 | int64_t timestamp_ms() const { return timestamp_ms_; } |
| 65 | void update_timestamp_ms(int64_t timestamp_ms) { |
| 66 | RTC_DCHECK_LE(timestamp_ms_, timestamp_ms); |
| 67 | timestamp_ms_ = timestamp_ms; |
| 68 | } |
| 69 | |
| 70 | // The identifier of the source can be the CSRC or the SSRC. |
| 71 | uint32_t source_id() const { return source_id_; } |
| 72 | |
| 73 | // The source can be either a contributing source or a synchronization source. |
| 74 | RtpSourceType source_type() const { return source_type_; } |
| 75 | |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 76 | absl::optional<uint8_t> audio_level() const { |
| 77 | return extensions_.audio_level; |
| 78 | } |
| 79 | |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 80 | void set_audio_level(const absl::optional<uint8_t>& level) { |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 81 | extensions_.audio_level = level; |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | uint32_t rtp_timestamp() const { return rtp_timestamp_; } |
| 85 | |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 86 | absl::optional<AbsoluteCaptureTime> absolute_capture_time() const { |
| 87 | return extensions_.absolute_capture_time; |
| 88 | } |
| 89 | |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 90 | bool operator==(const RtpSource& o) const { |
| 91 | return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() && |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 92 | source_type_ == o.source_type() && |
| 93 | extensions_.audio_level == o.extensions_.audio_level && |
| 94 | extensions_.absolute_capture_time == |
| 95 | o.extensions_.absolute_capture_time && |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 96 | rtp_timestamp_ == o.rtp_timestamp(); |
| 97 | } |
| 98 | |
| 99 | private: |
| 100 | int64_t timestamp_ms_; |
| 101 | uint32_t source_id_; |
| 102 | RtpSourceType source_type_; |
Ruslan Burakov | d51cc7b | 2019-11-20 16:48:34 +0100 | [diff] [blame^] | 103 | RtpSource::Extensions extensions_; |
Niels Möller | a837030 | 2019-09-02 15:16:49 +0200 | [diff] [blame] | 104 | uint32_t rtp_timestamp_; |
| 105 | }; |
| 106 | |
| 107 | } // namespace webrtc |
| 108 | |
| 109 | #endif // API_TRANSPORT_RTP_RTP_SOURCE_H_ |