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" |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 20 | #include "api/units/timestamp.h" |
Johannes Kron | 0809e7e | 2020-01-21 11:54:21 +0100 | [diff] [blame] | 21 | #include "rtc_base/system/rtc_export.h" |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
Chen Xing | 12d64de | 2019-06-13 20:36:12 +0200 | [diff] [blame] | 25 | // |
| 26 | // Structure to hold information about a received |RtpPacket|. It is primarily |
| 27 | // used to carry per-packet information from when a packet is received until |
| 28 | // the information is passed to |SourceTracker|. |
| 29 | // |
Johannes Kron | 0809e7e | 2020-01-21 11:54:21 +0100 | [diff] [blame] | 30 | class RTC_EXPORT RtpPacketInfo { |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 31 | public: |
| 32 | RtpPacketInfo(); |
| 33 | |
| 34 | RtpPacketInfo(uint32_t ssrc, |
| 35 | std::vector<uint32_t> csrcs, |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 36 | uint32_t rtp_timestamp, |
| 37 | absl::optional<uint8_t> audio_level, |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 38 | absl::optional<AbsoluteCaptureTime> absolute_capture_time, |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 39 | Timestamp receive_time); |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 40 | |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 41 | RtpPacketInfo(const RTPHeader& rtp_header, Timestamp receive_time); |
| 42 | |
| 43 | // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects |
| 44 | // are updated. |
| 45 | RtpPacketInfo(uint32_t ssrc, |
| 46 | std::vector<uint32_t> csrcs, |
| 47 | uint32_t rtp_timestamp, |
| 48 | absl::optional<uint8_t> audio_level, |
| 49 | absl::optional<AbsoluteCaptureTime> absolute_capture_time, |
| 50 | int64_t receive_time_ms); |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 51 | RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms); |
| 52 | |
| 53 | RtpPacketInfo(const RtpPacketInfo& other) = default; |
| 54 | RtpPacketInfo(RtpPacketInfo&& other) = default; |
| 55 | RtpPacketInfo& operator=(const RtpPacketInfo& other) = default; |
| 56 | RtpPacketInfo& operator=(RtpPacketInfo&& other) = default; |
| 57 | |
| 58 | uint32_t ssrc() const { return ssrc_; } |
| 59 | void set_ssrc(uint32_t value) { ssrc_ = value; } |
| 60 | |
| 61 | const std::vector<uint32_t>& csrcs() const { return csrcs_; } |
| 62 | void set_csrcs(std::vector<uint32_t> value) { csrcs_ = std::move(value); } |
| 63 | |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 64 | uint32_t rtp_timestamp() const { return rtp_timestamp_; } |
| 65 | void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; } |
| 66 | |
| 67 | absl::optional<uint8_t> audio_level() const { return audio_level_; } |
| 68 | void set_audio_level(absl::optional<uint8_t> value) { audio_level_ = value; } |
| 69 | |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 70 | const absl::optional<AbsoluteCaptureTime>& absolute_capture_time() const { |
| 71 | return absolute_capture_time_; |
| 72 | } |
| 73 | void set_absolute_capture_time( |
| 74 | const absl::optional<AbsoluteCaptureTime>& value) { |
| 75 | absolute_capture_time_ = value; |
| 76 | } |
| 77 | |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 78 | Timestamp receive_time() const { return receive_time_; } |
| 79 | void set_receive_time(Timestamp value) { receive_time_ = value; } |
| 80 | // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects |
| 81 | // are updated. |
| 82 | int64_t receive_time_ms() const { return receive_time_.ms(); } |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | // Fields from the RTP header: |
| 86 | // https://tools.ietf.org/html/rfc3550#section-5.1 |
| 87 | uint32_t ssrc_; |
| 88 | std::vector<uint32_t> csrcs_; |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 89 | uint32_t rtp_timestamp_; |
| 90 | |
| 91 | // Fields from the Audio Level header extension: |
| 92 | // https://tools.ietf.org/html/rfc6464#section-3 |
| 93 | absl::optional<uint8_t> audio_level_; |
| 94 | |
Chen Xing | e08648d | 2019-08-05 16:29:13 +0200 | [diff] [blame] | 95 | // Fields from the Absolute Capture Time header extension: |
| 96 | // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time |
| 97 | absl::optional<AbsoluteCaptureTime> absolute_capture_time_; |
| 98 | |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 99 | // Local |webrtc::Clock|-based timestamp of when the packet was received. |
Johannes Kron | f7de74c | 2021-04-30 13:10:56 +0200 | [diff] [blame] | 100 | Timestamp receive_time_; |
Chen Xing | d2a6686 | 2019-06-03 14:53:42 +0200 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs); |
| 104 | |
| 105 | inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) { |
| 106 | return !(lhs == rhs); |
| 107 | } |
| 108 | |
| 109 | } // namespace webrtc |
| 110 | |
| 111 | #endif // API_RTP_PACKET_INFO_H_ |