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" |
| 17 | #include "rtc_base/checks.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | enum class RtpSourceType { |
| 22 | SSRC, |
| 23 | CSRC, |
| 24 | }; |
| 25 | |
| 26 | class RtpSource { |
| 27 | public: |
| 28 | RtpSource() = delete; |
| 29 | |
| 30 | RtpSource(int64_t timestamp_ms, |
| 31 | uint32_t source_id, |
| 32 | RtpSourceType source_type, |
| 33 | absl::optional<uint8_t> audio_level, |
| 34 | uint32_t rtp_timestamp) |
| 35 | : timestamp_ms_(timestamp_ms), |
| 36 | source_id_(source_id), |
| 37 | source_type_(source_type), |
| 38 | audio_level_(audio_level), |
| 39 | rtp_timestamp_(rtp_timestamp) {} |
| 40 | |
| 41 | RtpSource(const RtpSource&) = default; |
| 42 | RtpSource& operator=(const RtpSource&) = default; |
| 43 | ~RtpSource() = default; |
| 44 | |
| 45 | int64_t timestamp_ms() const { return timestamp_ms_; } |
| 46 | void update_timestamp_ms(int64_t timestamp_ms) { |
| 47 | RTC_DCHECK_LE(timestamp_ms_, timestamp_ms); |
| 48 | timestamp_ms_ = timestamp_ms; |
| 49 | } |
| 50 | |
| 51 | // The identifier of the source can be the CSRC or the SSRC. |
| 52 | uint32_t source_id() const { return source_id_; } |
| 53 | |
| 54 | // The source can be either a contributing source or a synchronization source. |
| 55 | RtpSourceType source_type() const { return source_type_; } |
| 56 | |
| 57 | absl::optional<uint8_t> audio_level() const { return audio_level_; } |
| 58 | void set_audio_level(const absl::optional<uint8_t>& level) { |
| 59 | audio_level_ = level; |
| 60 | } |
| 61 | |
| 62 | uint32_t rtp_timestamp() const { return rtp_timestamp_; } |
| 63 | |
| 64 | bool operator==(const RtpSource& o) const { |
| 65 | return timestamp_ms_ == o.timestamp_ms() && source_id_ == o.source_id() && |
| 66 | source_type_ == o.source_type() && audio_level_ == o.audio_level_ && |
| 67 | rtp_timestamp_ == o.rtp_timestamp(); |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | int64_t timestamp_ms_; |
| 72 | uint32_t source_id_; |
| 73 | RtpSourceType source_type_; |
| 74 | absl::optional<uint8_t> audio_level_; |
| 75 | uint32_t rtp_timestamp_; |
| 76 | }; |
| 77 | |
| 78 | } // namespace webrtc |
| 79 | |
| 80 | #endif // API_TRANSPORT_RTP_RTP_SOURCE_H_ |