blob: 312dc33f10ef10d3ea7a5981509ebeaa34d72575 [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#include "api/rtp_packet_info.h"
12
13#include <algorithm>
14#include <utility>
15
16namespace webrtc {
17
18RtpPacketInfo::RtpPacketInfo()
Johannes Kronf7de74c2021-04-30 13:10:56 +020019 : ssrc_(0), rtp_timestamp_(0), receive_time_(Timestamp::MinusInfinity()) {}
Chen Xingd2a66862019-06-03 14:53:42 +020020
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020021RtpPacketInfo::RtpPacketInfo(uint32_t ssrc,
22 std::vector<uint32_t> csrcs,
23 uint32_t rtp_timestamp,
24 Timestamp receive_time)
25 : ssrc_(ssrc),
26 csrcs_(std::move(csrcs)),
27 rtp_timestamp_(rtp_timestamp),
28 receive_time_(receive_time) {}
29
Chen Xinge08648d2019-08-05 16:29:13 +020030RtpPacketInfo::RtpPacketInfo(
31 uint32_t ssrc,
32 std::vector<uint32_t> csrcs,
33 uint32_t rtp_timestamp,
34 absl::optional<uint8_t> audio_level,
35 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
Johannes Kronf7de74c2021-04-30 13:10:56 +020036 Timestamp receive_time)
Chen Xinge08648d2019-08-05 16:29:13 +020037 : ssrc_(ssrc),
38 csrcs_(std::move(csrcs)),
39 rtp_timestamp_(rtp_timestamp),
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020040 receive_time_(receive_time),
Chen Xinge08648d2019-08-05 16:29:13 +020041 audio_level_(audio_level),
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020042 absolute_capture_time_(absolute_capture_time) {}
Chen Xinge08648d2019-08-05 16:29:13 +020043
Chen Xingd2a66862019-06-03 14:53:42 +020044RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
Johannes Kronf7de74c2021-04-30 13:10:56 +020045 Timestamp receive_time)
Chen Xingd2a66862019-06-03 14:53:42 +020046 : ssrc_(rtp_header.ssrc),
Chen Xingd2a66862019-06-03 14:53:42 +020047 rtp_timestamp_(rtp_header.timestamp),
Johannes Kronf7de74c2021-04-30 13:10:56 +020048 receive_time_(receive_time) {
Chen Xingd2a66862019-06-03 14:53:42 +020049 const auto& extension = rtp_header.extension;
50 const auto csrcs_count = std::min<size_t>(rtp_header.numCSRCs, kRtpCsrcSize);
51
52 csrcs_.assign(&rtp_header.arrOfCSRCs[0], &rtp_header.arrOfCSRCs[csrcs_count]);
53
54 if (extension.hasAudioLevel) {
55 audio_level_ = extension.audioLevel;
56 }
Chen Xinge08648d2019-08-05 16:29:13 +020057
58 absolute_capture_time_ = extension.absolute_capture_time;
Chen Xingd2a66862019-06-03 14:53:42 +020059}
60
Johannes Kronf7de74c2021-04-30 13:10:56 +020061RtpPacketInfo::RtpPacketInfo(
62 uint32_t ssrc,
63 std::vector<uint32_t> csrcs,
64 uint32_t rtp_timestamp,
65 absl::optional<uint8_t> audio_level,
66 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
67 int64_t receive_time_ms)
68 : RtpPacketInfo(ssrc,
69 csrcs,
70 rtp_timestamp,
71 audio_level,
72 absolute_capture_time,
73 Timestamp::Millis(receive_time_ms)) {}
74RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
75 int64_t receive_time_ms)
76 : RtpPacketInfo(rtp_header, Timestamp::Millis(receive_time_ms)) {}
77
Chen Xingd2a66862019-06-03 14:53:42 +020078bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
79 return (lhs.ssrc() == rhs.ssrc()) && (lhs.csrcs() == rhs.csrcs()) &&
Chen Xingd2a66862019-06-03 14:53:42 +020080 (lhs.rtp_timestamp() == rhs.rtp_timestamp()) &&
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020081 (lhs.receive_time() == rhs.receive_time()) &&
Chen Xingd2a66862019-06-03 14:53:42 +020082 (lhs.audio_level() == rhs.audio_level()) &&
Chen Xinge08648d2019-08-05 16:29:13 +020083 (lhs.absolute_capture_time() == rhs.absolute_capture_time()) &&
Alessio Bazzicaa1d03562022-09-19 18:05:29 +020084 (lhs.local_capture_clock_offset() == rhs.local_capture_clock_offset());
Chen Xingd2a66862019-06-03 14:53:42 +020085}
86
87} // namespace webrtc