blob: 68e78d7987356c77899f08795722aa6b2fcd9ab3 [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
Chen Xinge08648d2019-08-05 16:29:13 +020021RtpPacketInfo::RtpPacketInfo(
22 uint32_t ssrc,
23 std::vector<uint32_t> csrcs,
24 uint32_t rtp_timestamp,
25 absl::optional<uint8_t> audio_level,
26 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
Johannes Kronf7de74c2021-04-30 13:10:56 +020027 Timestamp receive_time)
Chen Xinge08648d2019-08-05 16:29:13 +020028 : ssrc_(ssrc),
29 csrcs_(std::move(csrcs)),
30 rtp_timestamp_(rtp_timestamp),
31 audio_level_(audio_level),
32 absolute_capture_time_(absolute_capture_time),
Johannes Kronf7de74c2021-04-30 13:10:56 +020033 receive_time_(receive_time) {}
Chen Xinge08648d2019-08-05 16:29:13 +020034
Chen Xingd2a66862019-06-03 14:53:42 +020035RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
Johannes Kronf7de74c2021-04-30 13:10:56 +020036 Timestamp receive_time)
Chen Xingd2a66862019-06-03 14:53:42 +020037 : ssrc_(rtp_header.ssrc),
Chen Xingd2a66862019-06-03 14:53:42 +020038 rtp_timestamp_(rtp_header.timestamp),
Johannes Kronf7de74c2021-04-30 13:10:56 +020039 receive_time_(receive_time) {
Chen Xingd2a66862019-06-03 14:53:42 +020040 const auto& extension = rtp_header.extension;
41 const auto csrcs_count = std::min<size_t>(rtp_header.numCSRCs, kRtpCsrcSize);
42
43 csrcs_.assign(&rtp_header.arrOfCSRCs[0], &rtp_header.arrOfCSRCs[csrcs_count]);
44
45 if (extension.hasAudioLevel) {
46 audio_level_ = extension.audioLevel;
47 }
Chen Xinge08648d2019-08-05 16:29:13 +020048
49 absolute_capture_time_ = extension.absolute_capture_time;
Chen Xingd2a66862019-06-03 14:53:42 +020050}
51
Johannes Kronf7de74c2021-04-30 13:10:56 +020052RtpPacketInfo::RtpPacketInfo(
53 uint32_t ssrc,
54 std::vector<uint32_t> csrcs,
55 uint32_t rtp_timestamp,
56 absl::optional<uint8_t> audio_level,
57 absl::optional<AbsoluteCaptureTime> absolute_capture_time,
58 int64_t receive_time_ms)
59 : RtpPacketInfo(ssrc,
60 csrcs,
61 rtp_timestamp,
62 audio_level,
63 absolute_capture_time,
64 Timestamp::Millis(receive_time_ms)) {}
65RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
66 int64_t receive_time_ms)
67 : RtpPacketInfo(rtp_header, Timestamp::Millis(receive_time_ms)) {}
68
Chen Xingd2a66862019-06-03 14:53:42 +020069bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
70 return (lhs.ssrc() == rhs.ssrc()) && (lhs.csrcs() == rhs.csrcs()) &&
Chen Xingd2a66862019-06-03 14:53:42 +020071 (lhs.rtp_timestamp() == rhs.rtp_timestamp()) &&
72 (lhs.audio_level() == rhs.audio_level()) &&
Chen Xinge08648d2019-08-05 16:29:13 +020073 (lhs.absolute_capture_time() == rhs.absolute_capture_time()) &&
Johannes Kronf7de74c2021-04-30 13:10:56 +020074 (lhs.receive_time() == rhs.receive_time());
Chen Xingd2a66862019-06-03 14:53:42 +020075}
76
77} // namespace webrtc