| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 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 | |
| Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 11 | #include "api/rtp_packet_info.h" |
| 12 | |
| 13 | #include <cstdint> |
| Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 14 | #include <optional> |
| Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
| Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 17 | #include "api/rtp_headers.h" |
| Alessio Bazzica | 56b96ffe | 2022-09-20 09:16:16 | [diff] [blame] | 18 | #include "api/units/time_delta.h" |
| Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 19 | #include "api/units/timestamp.h" |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 20 | #include "test/gtest.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | TEST(RtpPacketInfoTest, Ssrc) { |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 25 | constexpr uint32_t kValue = 4038189233; |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 26 | |
| 27 | RtpPacketInfo lhs; |
| 28 | RtpPacketInfo rhs; |
| 29 | |
| 30 | EXPECT_TRUE(lhs == rhs); |
| 31 | EXPECT_FALSE(lhs != rhs); |
| 32 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 33 | rhs.set_ssrc(kValue); |
| 34 | EXPECT_EQ(rhs.ssrc(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 35 | |
| 36 | EXPECT_FALSE(lhs == rhs); |
| 37 | EXPECT_TRUE(lhs != rhs); |
| 38 | |
| 39 | lhs = rhs; |
| 40 | |
| 41 | EXPECT_TRUE(lhs == rhs); |
| 42 | EXPECT_FALSE(lhs != rhs); |
| 43 | |
| 44 | rhs = RtpPacketInfo(); |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 45 | EXPECT_NE(rhs.ssrc(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 46 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 47 | rhs = RtpPacketInfo(/*ssrc=*/kValue, /*csrcs=*/{}, /*rtp_timestamp=*/{}, |
| 48 | /*receive_time=*/Timestamp::Zero()); |
| 49 | EXPECT_EQ(rhs.ssrc(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | TEST(RtpPacketInfoTest, Csrcs) { |
| 53 | const std::vector<uint32_t> value = {4038189233, 3016333617, 1207992985}; |
| 54 | |
| 55 | RtpPacketInfo lhs; |
| 56 | RtpPacketInfo rhs; |
| 57 | |
| 58 | EXPECT_TRUE(lhs == rhs); |
| 59 | EXPECT_FALSE(lhs != rhs); |
| 60 | |
| 61 | rhs.set_csrcs(value); |
| 62 | EXPECT_EQ(rhs.csrcs(), value); |
| 63 | |
| 64 | EXPECT_FALSE(lhs == rhs); |
| 65 | EXPECT_TRUE(lhs != rhs); |
| 66 | |
| 67 | lhs = rhs; |
| 68 | |
| 69 | EXPECT_TRUE(lhs == rhs); |
| 70 | EXPECT_FALSE(lhs != rhs); |
| 71 | |
| 72 | rhs = RtpPacketInfo(); |
| 73 | EXPECT_NE(rhs.csrcs(), value); |
| 74 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 75 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/value, /*rtp_timestamp=*/{}, |
| 76 | /*receive_time=*/Timestamp::Zero()); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 77 | EXPECT_EQ(rhs.csrcs(), value); |
| 78 | } |
| 79 | |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 80 | TEST(RtpPacketInfoTest, RtpTimestamp) { |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 81 | constexpr uint32_t kValue = 4038189233; |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 82 | |
| 83 | RtpPacketInfo lhs; |
| 84 | RtpPacketInfo rhs; |
| 85 | |
| 86 | EXPECT_TRUE(lhs == rhs); |
| 87 | EXPECT_FALSE(lhs != rhs); |
| 88 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 89 | rhs.set_rtp_timestamp(kValue); |
| 90 | EXPECT_EQ(rhs.rtp_timestamp(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 91 | |
| 92 | EXPECT_FALSE(lhs == rhs); |
| 93 | EXPECT_TRUE(lhs != rhs); |
| 94 | |
| 95 | lhs = rhs; |
| 96 | |
| 97 | EXPECT_TRUE(lhs == rhs); |
| 98 | EXPECT_FALSE(lhs != rhs); |
| 99 | |
| 100 | rhs = RtpPacketInfo(); |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 101 | EXPECT_NE(rhs.rtp_timestamp(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 102 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 103 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/{}, /*rtp_timestamp=*/kValue, |
| 104 | /*receive_time=*/Timestamp::Zero()); |
| 105 | EXPECT_EQ(rhs.rtp_timestamp(), kValue); |
| Minyue Li | 63b3095 | 2021-05-19 12:38:25 | [diff] [blame] | 106 | } |
| 107 | |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 108 | TEST(RtpPacketInfoTest, ReceiveTimeMs) { |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 109 | constexpr Timestamp kValue = Timestamp::Micros(8868963877546349045LL); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 110 | |
| 111 | RtpPacketInfo lhs; |
| 112 | RtpPacketInfo rhs; |
| 113 | |
| 114 | EXPECT_TRUE(lhs == rhs); |
| 115 | EXPECT_FALSE(lhs != rhs); |
| 116 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 117 | rhs.set_receive_time(kValue); |
| 118 | EXPECT_EQ(rhs.receive_time(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 119 | |
| 120 | EXPECT_FALSE(lhs == rhs); |
| 121 | EXPECT_TRUE(lhs != rhs); |
| 122 | |
| 123 | lhs = rhs; |
| 124 | |
| 125 | EXPECT_TRUE(lhs == rhs); |
| 126 | EXPECT_FALSE(lhs != rhs); |
| 127 | |
| 128 | rhs = RtpPacketInfo(); |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 129 | EXPECT_NE(rhs.receive_time(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 130 | |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 131 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/{}, /*rtp_timestamp=*/{}, |
| 132 | /*receive_time=*/kValue); |
| 133 | EXPECT_EQ(rhs.receive_time(), kValue); |
| 134 | } |
| 135 | |
| 136 | TEST(RtpPacketInfoTest, AudioLevel) { |
| Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 137 | constexpr std::optional<uint8_t> kValue = 31; |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 138 | |
| 139 | RtpPacketInfo lhs; |
| 140 | RtpPacketInfo rhs; |
| 141 | |
| 142 | EXPECT_TRUE(lhs == rhs); |
| 143 | EXPECT_FALSE(lhs != rhs); |
| 144 | |
| 145 | rhs.set_audio_level(kValue); |
| 146 | EXPECT_EQ(rhs.audio_level(), kValue); |
| 147 | |
| 148 | EXPECT_FALSE(lhs == rhs); |
| 149 | EXPECT_TRUE(lhs != rhs); |
| 150 | |
| 151 | lhs = rhs; |
| 152 | |
| 153 | EXPECT_TRUE(lhs == rhs); |
| 154 | EXPECT_FALSE(lhs != rhs); |
| 155 | |
| 156 | rhs = RtpPacketInfo(); |
| 157 | EXPECT_NE(rhs.audio_level(), kValue); |
| 158 | |
| 159 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/{}, /*rtp_timestamp=*/{}, |
| 160 | /*receive_time=*/Timestamp::Zero()); |
| 161 | rhs.set_audio_level(kValue); |
| 162 | EXPECT_EQ(rhs.audio_level(), kValue); |
| 163 | } |
| 164 | |
| 165 | TEST(RtpPacketInfoTest, AbsoluteCaptureTime) { |
| Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 166 | constexpr std::optional<AbsoluteCaptureTime> kValue = AbsoluteCaptureTime{ |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 167 | .absolute_capture_timestamp = 12, .estimated_capture_clock_offset = 34}; |
| 168 | |
| 169 | RtpPacketInfo lhs; |
| 170 | RtpPacketInfo rhs; |
| 171 | |
| 172 | EXPECT_TRUE(lhs == rhs); |
| 173 | EXPECT_FALSE(lhs != rhs); |
| 174 | |
| 175 | rhs.set_absolute_capture_time(kValue); |
| 176 | EXPECT_EQ(rhs.absolute_capture_time(), kValue); |
| 177 | |
| 178 | EXPECT_FALSE(lhs == rhs); |
| 179 | EXPECT_TRUE(lhs != rhs); |
| 180 | |
| 181 | lhs = rhs; |
| 182 | |
| 183 | EXPECT_TRUE(lhs == rhs); |
| 184 | EXPECT_FALSE(lhs != rhs); |
| 185 | |
| 186 | rhs = RtpPacketInfo(); |
| 187 | EXPECT_NE(rhs.absolute_capture_time(), kValue); |
| 188 | |
| 189 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/{}, /*rtp_timestamp=*/{}, |
| 190 | /*receive_time=*/Timestamp::Zero()); |
| 191 | rhs.set_absolute_capture_time(kValue); |
| 192 | EXPECT_EQ(rhs.absolute_capture_time(), kValue); |
| 193 | } |
| 194 | |
| 195 | TEST(RtpPacketInfoTest, LocalCaptureClockOffset) { |
| Alessio Bazzica | 56b96ffe | 2022-09-20 09:16:16 | [diff] [blame] | 196 | constexpr TimeDelta kValue = TimeDelta::Micros(8868963877546349045LL); |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 197 | |
| 198 | RtpPacketInfo lhs; |
| 199 | RtpPacketInfo rhs; |
| 200 | |
| 201 | EXPECT_TRUE(lhs == rhs); |
| 202 | EXPECT_FALSE(lhs != rhs); |
| 203 | |
| 204 | rhs.set_local_capture_clock_offset(kValue); |
| 205 | EXPECT_EQ(rhs.local_capture_clock_offset(), kValue); |
| 206 | |
| 207 | EXPECT_FALSE(lhs == rhs); |
| 208 | EXPECT_TRUE(lhs != rhs); |
| 209 | |
| 210 | lhs = rhs; |
| 211 | |
| 212 | EXPECT_TRUE(lhs == rhs); |
| 213 | EXPECT_FALSE(lhs != rhs); |
| 214 | |
| 215 | rhs = RtpPacketInfo(); |
| Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 216 | EXPECT_EQ(rhs.local_capture_clock_offset(), std::nullopt); |
| Alessio Bazzica | a1d0356 | 2022-09-19 16:05:29 | [diff] [blame] | 217 | |
| 218 | rhs = RtpPacketInfo(/*ssrc=*/{}, /*csrcs=*/{}, /*rtp_timestamp=*/{}, |
| 219 | /*receive_time=*/Timestamp::Zero()); |
| 220 | rhs.set_local_capture_clock_offset(kValue); |
| 221 | EXPECT_EQ(rhs.local_capture_clock_offset(), kValue); |
| Chen Xing | d2a6686 | 2019-06-03 12:53:42 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | } // namespace webrtc |