blob: 639ba3277001ad4e268c2b365dea65c78ed54821 [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 Kron0809e7e2020-01-21 11:54:21 +010020#include "rtc_base/system/rtc_export.h"
Chen Xingd2a66862019-06-03 14:53:42 +020021
22namespace webrtc {
23
Chen Xing12d64de2019-06-13 20:36:12 +020024//
25// Structure to hold information about a received |RtpPacket|. It is primarily
26// used to carry per-packet information from when a packet is received until
27// the information is passed to |SourceTracker|.
28//
Johannes Kron0809e7e2020-01-21 11:54:21 +010029class RTC_EXPORT RtpPacketInfo {
Chen Xingd2a66862019-06-03 14:53:42 +020030 public:
31 RtpPacketInfo();
32
33 RtpPacketInfo(uint32_t ssrc,
34 std::vector<uint32_t> csrcs,
Chen Xingd2a66862019-06-03 14:53:42 +020035 uint32_t rtp_timestamp,
36 absl::optional<uint8_t> audio_level,
Chen Xinge08648d2019-08-05 16:29:13 +020037 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
38 int64_t receive_time_ms);
39
Chen Xingd2a66862019-06-03 14:53:42 +020040 RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms);
41
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 Xingd2a66862019-06-03 14:53:42 +020053 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
54 void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; }
55
56 absl::optional<uint8_t> audio_level() const { return audio_level_; }
57 void set_audio_level(absl::optional<uint8_t> value) { audio_level_ = value; }
58
Chen Xinge08648d2019-08-05 16:29:13 +020059 const absl::optional<AbsoluteCaptureTime>& absolute_capture_time() const {
60 return absolute_capture_time_;
61 }
62 void set_absolute_capture_time(
63 const absl::optional<AbsoluteCaptureTime>& value) {
64 absolute_capture_time_ = value;
65 }
66
Chen Xingd2a66862019-06-03 14:53:42 +020067 int64_t receive_time_ms() const { return receive_time_ms_; }
68 void set_receive_time_ms(int64_t value) { receive_time_ms_ = value; }
69
70 private:
71 // Fields from the RTP header:
72 // https://tools.ietf.org/html/rfc3550#section-5.1
73 uint32_t ssrc_;
74 std::vector<uint32_t> csrcs_;
Chen Xingd2a66862019-06-03 14:53:42 +020075 uint32_t rtp_timestamp_;
76
77 // Fields from the Audio Level header extension:
78 // https://tools.ietf.org/html/rfc6464#section-3
79 absl::optional<uint8_t> audio_level_;
80
Chen Xinge08648d2019-08-05 16:29:13 +020081 // Fields from the Absolute Capture Time header extension:
82 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
83 absl::optional<AbsoluteCaptureTime> absolute_capture_time_;
84
Chen Xingd2a66862019-06-03 14:53:42 +020085 // Local |webrtc::Clock|-based timestamp of when the packet was received.
86 int64_t receive_time_ms_;
87};
88
89bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs);
90
91inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
92 return !(lhs == rhs);
93}
94
95} // namespace webrtc
96
97#endif // API_RTP_PACKET_INFO_H_