blob: bc8784c6a8dc0174dbcfe5708af2498fc466436d [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"
Alessio Bazzica56b96ff2022-09-20 11:16:16 +020020#include "api/units/time_delta.h"
Johannes Kronf7de74c2021-04-30 13:10:56 +020021#include "api/units/timestamp.h"
Johannes Kron0809e7e2020-01-21 11:54:21 +010022#include "rtc_base/system/rtc_export.h"
Chen Xingd2a66862019-06-03 14:53:42 +020023
24namespace webrtc {
25
Chen Xing12d64de2019-06-13 20:36:12 +020026//
Artem Titov0e61fdd2021-07-25 21:50:14 +020027// Structure to hold information about a received `RtpPacket`. It is primarily
Chen Xing12d64de2019-06-13 20:36:12 +020028// used to carry per-packet information from when a packet is received until
Artem Titov0e61fdd2021-07-25 21:50:14 +020029// the information is passed to `SourceTracker`.
Chen Xing12d64de2019-06-13 20:36:12 +020030//
Johannes Kron0809e7e2020-01-21 11:54:21 +010031class RTC_EXPORT RtpPacketInfo {
Chen Xingd2a66862019-06-03 14:53:42 +020032 public:
33 RtpPacketInfo();
34
35 RtpPacketInfo(uint32_t ssrc,
36 std::vector<uint32_t> csrcs,
Chen Xingd2a66862019-06-03 14:53:42 +020037 uint32_t rtp_timestamp,
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020038 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 Xingd2a66862019-06-03 14:53:42 +020045 absl::optional<uint8_t> audio_level,
Chen Xinge08648d2019-08-05 16:29:13 +020046 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
Johannes Kronf7de74c2021-04-30 13:10:56 +020047 Timestamp receive_time);
Chen Xinge08648d2019-08-05 16:29:13 +020048
Johannes Kronf7de74c2021-04-30 13:10:56 +020049 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 Xingd2a66862019-06-03 14:53:42 +020059 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 Xingd2a66862019-06-03 14:53:42 +020072 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
73 void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; }
74
Johannes Kronf7de74c2021-04-30 13:10:56 +020075 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 Xingd2a66862019-06-03 14:53:42 +020080
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020081 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 Bazzica56b96ff2022-09-20 11:16:16 +020096 const absl::optional<TimeDelta>& local_capture_clock_offset() const {
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020097 return local_capture_clock_offset_;
98 }
99 RtpPacketInfo& set_local_capture_clock_offset(
Alessio Bazzica56b96ff2022-09-20 11:16:16 +0200100 absl::optional<TimeDelta> value) {
Alessio Bazzicaa1d03562022-09-19 18:05:29 +0200101 local_capture_clock_offset_ = value;
102 return *this;
103 }
104
Chen Xingd2a66862019-06-03 14:53:42 +0200105 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 Xingd2a66862019-06-03 14:53:42 +0200110 uint32_t rtp_timestamp_;
111
Alessio Bazzicaa1d03562022-09-19 18:05:29 +0200112 // Local `webrtc::Clock`-based timestamp of when the packet was received.
113 Timestamp receive_time_;
114
Chen Xingd2a66862019-06-03 14:53:42 +0200115 // 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 Xinge08648d2019-08-05 16:29:13 +0200119 // 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 Bazzica56b96ff2022-09-20 11:16:16 +0200123 // 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 Xingd2a66862019-06-03 14:53:42 +0200129};
130
131bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs);
132
133inline 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_