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