blob: 21cfefb748e5c5413ccd6a936a14f9b990d5ede6 [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"
Chen Xinge08648d2019-08-05 16:29:13 +020020#include "rtc_base/deprecation.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//
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 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,
39 int64_t receive_time_ms);
40
41 // TODO(bugs.webrtc.org/10739): Will be removed sometime after 2019-09-19.
42 RTC_DEPRECATED
43 RtpPacketInfo(uint32_t ssrc,
44 std::vector<uint32_t> csrcs,
45 uint32_t rtp_timestamp,
46 absl::optional<uint8_t> audio_level,
Chen Xingd2a66862019-06-03 14:53:42 +020047 int64_t receive_time_ms);
48
49 RtpPacketInfo(const RTPHeader& rtp_header, int64_t receive_time_ms);
50
51 RtpPacketInfo(const RtpPacketInfo& other) = default;
52 RtpPacketInfo(RtpPacketInfo&& other) = default;
53 RtpPacketInfo& operator=(const RtpPacketInfo& other) = default;
54 RtpPacketInfo& operator=(RtpPacketInfo&& other) = default;
55
56 uint32_t ssrc() const { return ssrc_; }
57 void set_ssrc(uint32_t value) { ssrc_ = value; }
58
59 const std::vector<uint32_t>& csrcs() const { return csrcs_; }
60 void set_csrcs(std::vector<uint32_t> value) { csrcs_ = std::move(value); }
61
Chen Xingd2a66862019-06-03 14:53:42 +020062 uint32_t rtp_timestamp() const { return rtp_timestamp_; }
63 void set_rtp_timestamp(uint32_t value) { rtp_timestamp_ = value; }
64
65 absl::optional<uint8_t> audio_level() const { return audio_level_; }
66 void set_audio_level(absl::optional<uint8_t> value) { audio_level_ = value; }
67
Chen Xinge08648d2019-08-05 16:29:13 +020068 const absl::optional<AbsoluteCaptureTime>& absolute_capture_time() const {
69 return absolute_capture_time_;
70 }
71 void set_absolute_capture_time(
72 const absl::optional<AbsoluteCaptureTime>& value) {
73 absolute_capture_time_ = value;
74 }
75
Chen Xingd2a66862019-06-03 14:53:42 +020076 int64_t receive_time_ms() const { return receive_time_ms_; }
77 void set_receive_time_ms(int64_t value) { receive_time_ms_ = value; }
78
79 private:
80 // Fields from the RTP header:
81 // https://tools.ietf.org/html/rfc3550#section-5.1
82 uint32_t ssrc_;
83 std::vector<uint32_t> csrcs_;
Chen Xingd2a66862019-06-03 14:53:42 +020084 uint32_t rtp_timestamp_;
85
86 // Fields from the Audio Level header extension:
87 // https://tools.ietf.org/html/rfc6464#section-3
88 absl::optional<uint8_t> audio_level_;
89
Chen Xinge08648d2019-08-05 16:29:13 +020090 // Fields from the Absolute Capture Time header extension:
91 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
92 absl::optional<AbsoluteCaptureTime> absolute_capture_time_;
93
Chen Xingd2a66862019-06-03 14:53:42 +020094 // Local |webrtc::Clock|-based timestamp of when the packet was received.
95 int64_t receive_time_ms_;
96};
97
98bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs);
99
100inline bool operator!=(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
101 return !(lhs == rhs);
102}
103
104} // namespace webrtc
105
106#endif // API_RTP_PACKET_INFO_H_