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