blob: 13d3a3922a2cc043c69a20c47ca99ff9953a4b06 [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,
37 absl::optional<uint8_t> audio_level,
Chen Xinge08648d2019-08-05 16:29:13 +020038 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
Johannes Kronf7de74c2021-04-30 13:10:56 +020039 Timestamp receive_time);
Chen Xinge08648d2019-08-05 16:29:13 +020040
Johannes Kronf7de74c2021-04-30 13:10:56 +020041 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 Xingd2a66862019-06-03 14:53:42 +020051 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 Xingd2a66862019-06-03 14:53:42 +020064 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 Xinge08648d2019-08-05 16:29:13 +020070 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
Minyue Li63b30952021-05-19 14:38:25 +020078 const absl::optional<int64_t>& local_capture_clock_offset() const {
79 return local_capture_clock_offset_;
80 }
81
82 void set_local_capture_clock_offset(const absl::optional<int64_t>& value) {
83 local_capture_clock_offset_ = value;
84 }
85
Johannes Kronf7de74c2021-04-30 13:10:56 +020086 Timestamp receive_time() const { return receive_time_; }
87 void set_receive_time(Timestamp value) { receive_time_ = value; }
88 // TODO(bugs.webrtc.org/12722): Deprecated, remove once downstream projects
89 // are updated.
90 int64_t receive_time_ms() const { return receive_time_.ms(); }
Chen Xingd2a66862019-06-03 14:53:42 +020091
92 private:
93 // Fields from the RTP header:
94 // https://tools.ietf.org/html/rfc3550#section-5.1
95 uint32_t ssrc_;
96 std::vector<uint32_t> csrcs_;
Chen Xingd2a66862019-06-03 14:53:42 +020097 uint32_t rtp_timestamp_;
98
99 // Fields from the Audio Level header extension:
100 // https://tools.ietf.org/html/rfc6464#section-3
101 absl::optional<uint8_t> audio_level_;
102
Chen Xinge08648d2019-08-05 16:29:13 +0200103 // Fields from the Absolute Capture Time header extension:
104 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Artem Titov0e61fdd2021-07-25 21:50:14 +0200105 // To not be confused with `local_capture_clock_offset_`, the
106 // `estimated_capture_clock_offset` in `absolute_capture_time_` should
Minyue Li63b30952021-05-19 14:38:25 +0200107 // represent the clock offset between a remote sender and the capturer, and
108 // thus equals to the corresponding values in the received RTP packets,
109 // subjected to possible interpolations.
Chen Xinge08648d2019-08-05 16:29:13 +0200110 absl::optional<AbsoluteCaptureTime> absolute_capture_time_;
111
Minyue Li63b30952021-05-19 14:38:25 +0200112 // Clock offset against capturer's clock. Should be derived from the estimated
113 // capture clock offset defined in the Absolute Capture Time header extension.
114 absl::optional<int64_t> local_capture_clock_offset_;
115
Chen Xingd2a66862019-06-03 14:53:42 +0200116 // Local |webrtc::Clock|-based timestamp of when the packet was received.
Johannes Kronf7de74c2021-04-30 13:10:56 +0200117 Timestamp receive_time_;
Chen Xingd2a66862019-06-03 14:53:42 +0200118};
119
120bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs);
121
122inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
123 return !(lhs == rhs);
124}
125
126} // namespace webrtc
127
128#endif // API_RTP_PACKET_INFO_H_