Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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_RTP_PACKET_INFO_H_ |
| 12 | #define API_RTP_PACKET_INFO_H_ |
| 13 | |
| 14 | #include <cstdint> |
| 15 | #include <utility> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/rtp_headers.h" |
Alessio Bazzica | 56b96ff | 2022-09-20 11:16:16 +0200 | [diff] [blame^] | 20 | #include "api/units/time_delta.h" |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 21 | #include "api/units/timestamp.h" |
Johannes Kron | 0809e7e | 2020-01-21 11:54:21 +0100 | [diff] [blame] | 22 | #include "rtc_base/system/rtc_export.h" |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
Chen Xing | 12d64de | 2019-06-13 20:36:12 +0200 | [diff] [blame] | 26 | // |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 27 | // Structure to hold information about a received `RtpPacket`. It is primarily |
Chen Xing | 12d64de | 2019-06-13 20:36:12 +0200 | [diff] [blame] | 28 | // used to carry per-packet information from when a packet is received until |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame] | 29 | // the information is passed to `SourceTracker`. |
Chen Xing | 12d64de | 2019-06-13 20:36:12 +0200 | [diff] [blame] | 30 | // |
Johannes Kron | 0809e7e | 2020-01-21 11:54:21 +0100 | [diff] [blame] | 31 | class RTC_EXPORT RtpPacketInfo { |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 32 | public: |
| 33 | RtpPacketInfo(); |
| 34 | |
| 35 | RtpPacketInfo(uint32_t ssrc, |
| 36 | std::vector<uint32_t> csrcs, |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 37 | uint32_t rtp_timestamp, |
Alessio Bazzica | a1d0356 | 2022-09-19 18:05:29 +0200 | [diff] [blame] | 38 | Timestamp receive_time); |
| 39 | |
| 40 | // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects |
| 41 | // are updated. |
| 42 | RtpPacketInfo(uint32_t ssrc, |
| 43 | std::vector<uint32_t> csrcs, |
| 44 | uint32_t rtp_timestamp, |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 45 | absl::optional<uint8_t> audio_level, |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 46 | absl::optional<AbsoluteCaptureTime> absolute_capture_time, |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 47 | Timestamp receive_time); |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 48 | |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 49 | RtpPacketInfo(const RTPHeader& rtp_header, Timestamp receive_time); |
| 50 | |
| 51 | // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects |
| 52 | // are updated. |
| 53 | RtpPacketInfo(uint32_t ssrc, |
| 54 | std::vector<uint32_t> csrcs, |
| 55 | uint32_t rtp_timestamp, |
| 56 | absl::optional<uint8_t> audio_level, |
| 57 | absl::optional<AbsoluteCaptureTime> absolute_capture_time, |
| 58 | int64_t receive_time_ms); |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 59 | RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms); |
| 60 | |
| 61 | RtpPacketInfo(const RtpPacketInfo& other) = default; |
| 62 | RtpPacketInfo(RtpPacketInfo&& other) = default; |
| 63 | RtpPacketInfo& operator=(const RtpPacketInfo& other) = default; |
| 64 | RtpPacketInfo& operator=(RtpPacketInfo&& other) = default; |
| 65 | |
| 66 | uint32_t ssrc() const { return ssrc_; } |
| 67 | void set_ssrc(uint32_t value) { ssrc_ = value; } |
| 68 | |
| 69 | const std::vector<uint32_t>& csrcs() const { return csrcs_; } |
| 70 | void set_csrcs(std::vector<uint32_t> value) { csrcs_ = std::move(value); } |
| 71 | |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 72 | uint32_t rtp_timestamp() const { return rtp_timestamp_; } |
| 73 | void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; } |
| 74 | |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 75 | Timestamp receive_time() const { return receive_time_; } |
| 76 | void set_receive_time(Timestamp value) { receive_time_ = value; } |
| 77 | // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects |
| 78 | // are updated. |
| 79 | int64_t receive_time_ms() const { return receive_time_.ms(); } |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 80 | |
Alessio Bazzica | a1d0356 | 2022-09-19 18:05:29 +0200 | [diff] [blame] | 81 | absl::optional<uint8_t> audio_level() const { return audio_level_; } |
| 82 | RtpPacketInfo& set_audio_level(absl::optional<uint8_t> value) { |
| 83 | audio_level_ = value; |
| 84 | return *this; |
| 85 | } |
| 86 | |
| 87 | const absl::optional<AbsoluteCaptureTime>& absolute_capture_time() const { |
| 88 | return absolute_capture_time_; |
| 89 | } |
| 90 | RtpPacketInfo& set_absolute_capture_time( |
| 91 | const absl::optional<AbsoluteCaptureTime>& value) { |
| 92 | absolute_capture_time_ = value; |
| 93 | return *this; |
| 94 | } |
| 95 | |
Alessio Bazzica | 56b96ff | 2022-09-20 11:16:16 +0200 | [diff] [blame^] | 96 | const absl::optional<TimeDelta>& local_capture_clock_offset() const { |
Alessio Bazzica | a1d0356 | 2022-09-19 18:05:29 +0200 | [diff] [blame] | 97 | return local_capture_clock_offset_; |
| 98 | } |
| 99 | RtpPacketInfo& set_local_capture_clock_offset( |
Alessio Bazzica | 56b96ff | 2022-09-20 11:16:16 +0200 | [diff] [blame^] | 100 | absl::optional<TimeDelta> value) { |
Alessio Bazzica | a1d0356 | 2022-09-19 18:05:29 +0200 | [diff] [blame] | 101 | local_capture_clock_offset_ = value; |
| 102 | return *this; |
| 103 | } |
| 104 | |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 105 | private: |
| 106 | // Fields from the RTP header: |
| 107 | // https://tools.ietf.org/html/rfc3550#section-5.1 |
| 108 | uint32_t ssrc_; |
| 109 | std::vector<uint32_t> csrcs_; |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 110 | uint32_t rtp_timestamp_; |
| 111 | |
Alessio Bazzica | a1d0356 | 2022-09-19 18:05:29 +0200 | [diff] [blame] | 112 | // Local `webrtc::Clock`-based timestamp of when the packet was received. |
| 113 | Timestamp receive_time_; |
| 114 | |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 115 | // Fields from the Audio Level header extension: |
| 116 | // https://tools.ietf.org/html/rfc6464#section-3 |
| 117 | absl::optional<uint8_t> audio_level_; |
| 118 | |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 119 | // Fields from the Absolute Capture Time header extension: |
| 120 | // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time |
| 121 | absl::optional<AbsoluteCaptureTime> absolute_capture_time_; |
| 122 | |
Alessio Bazzica | 56b96ff | 2022-09-20 11:16:16 +0200 | [diff] [blame^] | 123 | // Clock offset between the local clock and the capturer's clock. |
| 124 | // Do not confuse with `AbsoluteCaptureTime::estimated_capture_clock_offset` |
| 125 | // which instead represents the clock offset between a remote sender and the |
| 126 | // capturer. The following holds: |
| 127 | // Capture's NTP Clock = Local NTP Clock + Local-Capture Clock Offset |
| 128 | absl::optional<TimeDelta> local_capture_clock_offset_; |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs); |
| 132 | |
| 133 | inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) { |
| 134 | return !(lhs == rhs); |
| 135 | } |
| 136 | |
| 137 | } // namespace webrtc |
| 138 | |
| 139 | #endif // API_RTP_PACKET_INFO_H_ |