blob: efb78381e64deb245725f367428a8f9319e3e673 [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()
Chen Xing12d64de2019-06-13 20:36:12 +020019 : ssrc_(0), rtp_timestamp_(0), receive_time_ms_(-1) {}
Chen Xingd2a66862019-06-03 14:53:42 +020020
21RtpPacketInfo::RtpPacketInfo(uint32_t ssrc,
22 std::vector<uint32_t> csrcs,
Chen Xingd2a66862019-06-03 14:53:42 +020023 uint32_t rtp_timestamp,
24 absl::optional<uint8_t> audio_level,
25 int64_t receive_time_ms)
26 : ssrc_(ssrc),
27 csrcs_(std::move(csrcs)),
Chen Xingd2a66862019-06-03 14:53:42 +020028 rtp_timestamp_(rtp_timestamp),
29 audio_level_(audio_level),
30 receive_time_ms_(receive_time_ms) {}
31
32RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
33 int64_t receive_time_ms)
34 : ssrc_(rtp_header.ssrc),
Chen Xingd2a66862019-06-03 14:53:42 +020035 rtp_timestamp_(rtp_header.timestamp),
36 receive_time_ms_(receive_time_ms) {
37 const auto& extension = rtp_header.extension;
38 const auto csrcs_count = std::min<size_t>(rtp_header.numCSRCs, kRtpCsrcSize);
39
40 csrcs_.assign(&rtp_header.arrOfCSRCs[0], &rtp_header.arrOfCSRCs[csrcs_count]);
41
42 if (extension.hasAudioLevel) {
43 audio_level_ = extension.audioLevel;
44 }
45}
46
47bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
48 return (lhs.ssrc() == rhs.ssrc()) && (lhs.csrcs() == rhs.csrcs()) &&
Chen Xingd2a66862019-06-03 14:53:42 +020049 (lhs.rtp_timestamp() == rhs.rtp_timestamp()) &&
50 (lhs.audio_level() == rhs.audio_level()) &&
51 (lhs.receive_time_ms() == rhs.receive_time_ms());
52}
53
54} // namespace webrtc