blob: f9980a1cb0fe534617ff81d4451c7c1c4fdc9b3b [file] [log] [blame]
Chen Xingd2a66862019-06-03 14:53:42 +02001/*
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 Kronf7de74c2021-04-30 13:10:56 +020020#include "api/units/timestamp.h"
Johannes Kron0809e7e2020-01-21 11:54:21 +010021#include "rtc_base/system/rtc_export.h"
Chen Xingd2a66862019-06-03 14:53:42 +020022
23namespace webrtc {
24
Chen Xing12d64de2019-06-13 20:36:12 +020025//
Artem Titov0e61fdd2021-07-25 21:50:14 +020026// Structure to hold information about a received `RtpPacket`. It is primarily
Chen Xing12d64de2019-06-13 20:36:12 +020027// used to carry per-packet information from when a packet is received until
Artem Titov0e61fdd2021-07-25 21:50:14 +020028// the information is passed to `SourceTracker`.
Chen Xing12d64de2019-06-13 20:36:12 +020029//
Johannes Kron0809e7e2020-01-21 11:54:21 +010030class RTC_EXPORT RtpPacketInfo {
Chen Xingd2a66862019-06-03 14:53:42 +020031 public:
32 RtpPacketInfo();
33
34 RtpPacketInfo(uint32_t ssrc,
35 std::vector<uint32_t> csrcs,
Chen Xingd2a66862019-06-03 14:53:42 +020036 uint32_t rtp_timestamp,
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020037 Timestamp receive_time);
38
39 // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects
40 // are updated.
41 RtpPacketInfo(uint32_t ssrc,
42 std::vector<uint32_t> csrcs,
43 uint32_t rtp_timestamp,
Chen Xingd2a66862019-06-03 14:53:42 +020044 absl::optional<uint8_t> audio_level,
Chen Xinge08648d2019-08-05 16:29:13 +020045 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
Johannes Kronf7de74c2021-04-30 13:10:56 +020046 Timestamp receive_time);
Chen Xinge08648d2019-08-05 16:29:13 +020047
Johannes Kronf7de74c2021-04-30 13:10:56 +020048 RtpPacketInfo(const RTPHeader& rtp_header, Timestamp receive_time);
49
50 // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects
51 // are updated.
52 RtpPacketInfo(uint32_t ssrc,
53 std::vector<uint32_t> csrcs,
54 uint32_t rtp_timestamp,
55 absl::optional<uint8_t> audio_level,
56 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
57 int64_t receive_time_ms);
Chen Xingd2a66862019-06-03 14:53:42 +020058 RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms);
59
60 RtpPacketInfo(const RtpPacketInfo& other) = default;
61 RtpPacketInfo(RtpPacketInfo&& other) = default;
62 RtpPacketInfo& operator=(const RtpPacketInfo& other) = default;
63 RtpPacketInfo& operator=(RtpPacketInfo&& other) = default;
64
65 uint32_t ssrc() const { return ssrc_; }
66 void set_ssrc(uint32_t value) { ssrc_ = value; }
67
68 const std::vector<uint32_t>& csrcs() const { return csrcs_; }
69 void set_csrcs(std::vector<uint32_t> value) { csrcs_ = std::move(value); }
70
Chen Xingd2a66862019-06-03 14:53:42 +020071 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
72 void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; }
73
Johannes Kronf7de74c2021-04-30 13:10:56 +020074 Timestamp receive_time() const { return receive_time_; }
75 void set_receive_time(Timestamp value) { receive_time_ = value; }
76 // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects
77 // are updated.
78 int64_t receive_time_ms() const { return receive_time_.ms(); }
Chen Xingd2a66862019-06-03 14:53:42 +020079
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020080 absl::optional<uint8_t> audio_level() const { return audio_level_; }
81 RtpPacketInfo& set_audio_level(absl::optional<uint8_t> value) {
82 audio_level_ = value;
83 return *this;
84 }
85
86 const absl::optional<AbsoluteCaptureTime>& absolute_capture_time() const {
87 return absolute_capture_time_;
88 }
89 RtpPacketInfo& set_absolute_capture_time(
90 const absl::optional<AbsoluteCaptureTime>& value) {
91 absolute_capture_time_ = value;
92 return *this;
93 }
94
95 const absl::optional<int64_t>& local_capture_clock_offset() const {
96 return local_capture_clock_offset_;
97 }
98 RtpPacketInfo& set_local_capture_clock_offset(
99 const absl::optional<int64_t>& value) {
100 local_capture_clock_offset_ = value;
101 return *this;
102 }
103
Chen Xingd2a66862019-06-03 14:53:42 +0200104 private:
105 // Fields from the RTP header:
106 // https://tools.ietf.org/html/rfc3550#section-5.1
107 uint32_t ssrc_;
108 std::vector<uint32_t> csrcs_;
Chen Xingd2a66862019-06-03 14:53:42 +0200109 uint32_t rtp_timestamp_;
110
Alessio Bazzicaa1d03562022-09-19 18:05:29 +0200111 // Local `webrtc::Clock`-based timestamp of when the packet was received.
112 Timestamp receive_time_;
113
Chen Xingd2a66862019-06-03 14:53:42 +0200114 // Fields from the Audio Level header extension:
115 // https://tools.ietf.org/html/rfc6464#section-3
116 absl::optional<uint8_t> audio_level_;
117
Chen Xinge08648d2019-08-05 16:29:13 +0200118 // Fields from the Absolute Capture Time header extension:
119 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Artem Titov0e61fdd2021-07-25 21:50:14 +0200120 // To not be confused with `local_capture_clock_offset_`, the
121 // `estimated_capture_clock_offset` in `absolute_capture_time_` should
Minyue Li63b30952021-05-19 14:38:25 +0200122 // represent the clock offset between a remote sender and the capturer, and
123 // thus equals to the corresponding values in the received RTP packets,
124 // subjected to possible interpolations.
Chen Xinge08648d2019-08-05 16:29:13 +0200125 absl::optional<AbsoluteCaptureTime> absolute_capture_time_;
126
Minyue Li63b30952021-05-19 14:38:25 +0200127 // Clock offset against capturer's clock. Should be derived from the estimated
128 // capture clock offset defined in the Absolute Capture Time header extension.
129 absl::optional<int64_t> local_capture_clock_offset_;
Chen Xingd2a66862019-06-03 14:53:42 +0200130};
131
132bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs);
133
134inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
135 return !(lhs == rhs);
136}
137
138} // namespace webrtc
139
140#endif // API_RTP_PACKET_INFO_H_