1 /*
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 
16 namespace webrtc {
17 
RtpPacketInfo()18 RtpPacketInfo::RtpPacketInfo()
19     : ssrc_(0), rtp_timestamp_(0), receive_time_ms_(-1) {}
20 
RtpPacketInfo(uint32_t ssrc,std::vector<uint32_t> csrcs,uint32_t rtp_timestamp,absl::optional<uint8_t> audio_level,absl::optional<AbsoluteCaptureTime> absolute_capture_time,int64_t receive_time_ms)21 RtpPacketInfo::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,
27     int64_t receive_time_ms)
28     : ssrc_(ssrc),
29       csrcs_(std::move(csrcs)),
30       rtp_timestamp_(rtp_timestamp),
31       audio_level_(audio_level),
32       absolute_capture_time_(absolute_capture_time),
33       receive_time_ms_(receive_time_ms) {}
34 
RtpPacketInfo(const RTPHeader & rtp_header,int64_t receive_time_ms)35 RtpPacketInfo::RtpPacketInfo(const RTPHeader& rtp_header,
36                              int64_t receive_time_ms)
37     : ssrc_(rtp_header.ssrc),
38       rtp_timestamp_(rtp_header.timestamp),
39       receive_time_ms_(receive_time_ms) {
40   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   }
48 
49   absolute_capture_time_ = extension.absolute_capture_time;
50 }
51 
operator ==(const RtpPacketInfo & lhs,const RtpPacketInfo & rhs)52 bool operator==(const RtpPacketInfo& lhs, const RtpPacketInfo& rhs) {
53   return (lhs.ssrc() == rhs.ssrc()) && (lhs.csrcs() == rhs.csrcs()) &&
54          (lhs.rtp_timestamp() == rhs.rtp_timestamp()) &&
55          (lhs.audio_level() == rhs.audio_level()) &&
56          (lhs.absolute_capture_time() == rhs.absolute_capture_time()) &&
57          (lhs.receive_time_ms() == rhs.receive_time_ms());
58 }
59 
60 }  // namespace webrtc
61