blob: d88b1606dcaafa92f1b912c52e4e837b35f8e43f [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <string.h>
12#include <cstdint>
Steve Antone78bcb92017-10-31 09:53:08 -070013#include <vector>
14
Steve Anton10542f22019-01-11 09:11:00 -080015#include "media/base/fake_rtp.h"
16#include "media/base/rtp_utils.h"
17#include "rtc_base/async_packet_socket.h"
Yves Gerey3e707812018-11-28 16:47:49 +010018#include "test/gtest.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
20namespace cricket {
21
Sergey Ulanovdc305db2016-01-14 17:14:54 -080022static const uint8_t kRtpPacketWithMarker[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020023 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024// 3 CSRCs (0x01020304, 0x12345678, 0xAABBCCDD)
25// Extension (0xBEDE, 0x1122334455667788)
Sergey Ulanovdc305db2016-01-14 17:14:54 -080026static const uint8_t kRtpPacketWithMarkerAndCsrcAndExtension[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
28 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD,
Yves Gerey665174f2018-06-19 15:03:05 +020029 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
30static const uint8_t kInvalidPacket[] = {0x80, 0x00};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080031static const uint8_t kInvalidPacketWithCsrc[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
Yves Gerey665174f2018-06-19 15:03:05 +020033 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080034static const uint8_t kInvalidPacketWithCsrcAndExtension1[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020035 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34,
37 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, 0xBE, 0xDE, 0x00};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080038static const uint8_t kInvalidPacketWithCsrcAndExtension2[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
40 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD,
Yves Gerey665174f2018-06-19 15:03:05 +020041 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042
43// PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111
44// No FCI information is needed for PLI.
Sergey Ulanovdc305db2016-01-14 17:14:54 -080045static const uint8_t kNonCompoundRtcpPliFeedbackPacket[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020046 0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48// Packet has only mandatory fixed RTCP header
49// PT = 204, SSRC = 0x1111
Yves Gerey665174f2018-06-19 15:03:05 +020050static const uint8_t kNonCompoundRtcpAppPacket[] = {0x81, 0xCC, 0x00, 0x0C,
51 0x00, 0x00, 0x11, 0x11};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
53// PT = 202, Source count = 0
Yves Gerey665174f2018-06-19 15:03:05 +020054static const uint8_t kNonCompoundRtcpSDESPacket[] = {0x80, 0xCA, 0x00, 0x00};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
Yves Gerey665174f2018-06-19 15:03:05 +020056static uint8_t kFakeTag[4] = {0xba, 0xdd, 0xba, 0xdd};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080057static uint8_t kTestKey[] = "12345678901234567890";
Yves Gerey665174f2018-06-19 15:03:05 +020058static uint8_t kTestAstValue[3] = {0xaa, 0xbb, 0xcc};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080059
60// Valid rtp Message with 2 byte header extension.
61static uint8_t kRtpMsgWith2ByteExtnHeader[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020062 // clang-format off
63 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -080064 0x90, 0x00, 0x00, 0x00,
65 0x00, 0x00, 0x00, 0x00,
66 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
67 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension
68 0x01, 0x00, 0x00, 0x00
Yves Gerey665174f2018-06-19 15:03:05 +020069 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -080070};
71
72// RTP packet with single byte extension header of length 4 bytes.
73// Extension id = 3 and length = 3
74static uint8_t kRtpMsgWithAbsSendTimeExtension[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020075 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
76 0xBE, 0xDE, 0x00, 0x02, 0x22, 0x00, 0x02, 0x1c, 0x32, 0xaa, 0xbb, 0xcc,
Sergey Ulanovdc305db2016-01-14 17:14:54 -080077};
78
79// Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|.
80static const int kAstIndexInRtpMsg = 21;
81
Amit Hilbuchedd20542019-03-18 12:33:43 -070082static const rtc::ArrayView<const char> kPcmuFrameArrayView =
83 rtc::MakeArrayView(reinterpret_cast<const char*>(kPcmuFrame),
84 sizeof(kPcmuFrame));
85static const rtc::ArrayView<const char> kRtcpReportArrayView =
86 rtc::MakeArrayView(reinterpret_cast<const char*>(kRtcpReport),
87 sizeof(kRtcpReport));
88static const rtc::ArrayView<const char> kInvalidPacketArrayView =
89 rtc::MakeArrayView(reinterpret_cast<const char*>(kInvalidPacket),
90 sizeof(kInvalidPacket));
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092TEST(RtpUtilsTest, GetRtp) {
Amit Hilbuchedd20542019-03-18 12:33:43 -070093 EXPECT_TRUE(IsRtpPacket(kPcmuFrameArrayView));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
95 int pt;
96 EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt));
97 EXPECT_EQ(0, pt);
98 EXPECT_TRUE(GetRtpPayloadType(kRtpPacketWithMarker,
99 sizeof(kRtpPacketWithMarker), &pt));
100 EXPECT_EQ(0, pt);
101
102 int seq_num;
103 EXPECT_TRUE(GetRtpSeqNum(kPcmuFrame, sizeof(kPcmuFrame), &seq_num));
104 EXPECT_EQ(1, seq_num);
105
Peter Boström0c4e06b2015-10-07 12:23:21 +0200106 uint32_t ts;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 EXPECT_TRUE(GetRtpTimestamp(kPcmuFrame, sizeof(kPcmuFrame), &ts));
108 EXPECT_EQ(0u, ts);
109
Peter Boström0c4e06b2015-10-07 12:23:21 +0200110 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 EXPECT_TRUE(GetRtpSsrc(kPcmuFrame, sizeof(kPcmuFrame), &ssrc));
112 EXPECT_EQ(1u, ssrc);
113
114 RtpHeader header;
115 EXPECT_TRUE(GetRtpHeader(kPcmuFrame, sizeof(kPcmuFrame), &header));
116 EXPECT_EQ(0, header.payload_type);
117 EXPECT_EQ(1, header.seq_num);
118 EXPECT_EQ(0u, header.timestamp);
119 EXPECT_EQ(1u, header.ssrc);
120
121 EXPECT_FALSE(GetRtpPayloadType(kInvalidPacket, sizeof(kInvalidPacket), &pt));
122 EXPECT_FALSE(GetRtpSeqNum(kInvalidPacket, sizeof(kInvalidPacket), &seq_num));
123 EXPECT_FALSE(GetRtpTimestamp(kInvalidPacket, sizeof(kInvalidPacket), &ts));
124 EXPECT_FALSE(GetRtpSsrc(kInvalidPacket, sizeof(kInvalidPacket), &ssrc));
125}
126
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000127TEST(RtpUtilsTest, SetRtpHeader) {
Yves Gerey665174f2018-06-19 15:03:05 +0200128 uint8_t packet[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
Yves Gerey665174f2018-06-19 15:03:05 +0200131 RtpHeader header = {9, 1111, 2222u, 3333u};
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000132 EXPECT_TRUE(SetRtpHeader(packet, sizeof(packet), header));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133
134 // Bits: 10 0 0 0000
135 EXPECT_EQ(128u, packet[0]);
136 size_t len;
137 EXPECT_TRUE(GetRtpHeaderLen(packet, sizeof(packet), &len));
138 EXPECT_EQ(12U, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 EXPECT_TRUE(GetRtpHeader(packet, sizeof(packet), &header));
140 EXPECT_EQ(9, header.payload_type);
141 EXPECT_EQ(1111, header.seq_num);
142 EXPECT_EQ(2222u, header.timestamp);
143 EXPECT_EQ(3333u, header.ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144}
145
146TEST(RtpUtilsTest, GetRtpHeaderLen) {
147 size_t len;
148 EXPECT_TRUE(GetRtpHeaderLen(kPcmuFrame, sizeof(kPcmuFrame), &len));
149 EXPECT_EQ(12U, len);
150
151 EXPECT_TRUE(GetRtpHeaderLen(kRtpPacketWithMarkerAndCsrcAndExtension,
152 sizeof(kRtpPacketWithMarkerAndCsrcAndExtension),
153 &len));
154 EXPECT_EQ(sizeof(kRtpPacketWithMarkerAndCsrcAndExtension), len);
155
156 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacket, sizeof(kInvalidPacket), &len));
157 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrc,
158 sizeof(kInvalidPacketWithCsrc), &len));
159 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension1,
160 sizeof(kInvalidPacketWithCsrcAndExtension1),
161 &len));
162 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension2,
163 sizeof(kInvalidPacketWithCsrcAndExtension2),
164 &len));
165}
166
167TEST(RtpUtilsTest, GetRtcp) {
168 int pt;
169 EXPECT_TRUE(GetRtcpType(kRtcpReport, sizeof(kRtcpReport), &pt));
170 EXPECT_EQ(0xc9, pt);
171
172 EXPECT_FALSE(GetRtcpType(kInvalidPacket, sizeof(kInvalidPacket), &pt));
173
Peter Boström0c4e06b2015-10-07 12:23:21 +0200174 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpPliFeedbackPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200176 sizeof(kNonCompoundRtcpPliFeedbackPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200178 sizeof(kNonCompoundRtcpAppPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200180 sizeof(kNonCompoundRtcpSDESPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181}
182
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800183// Invalid RTP packets.
184TEST(RtpUtilsTest, InvalidRtpHeader) {
185 // Rtp message with invalid length.
186 const uint8_t kRtpMsgWithInvalidLength[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200187 // clang-format off
188 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800189 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
191 0xDD, 0xCC, 0xBB, 0xAA, // Only 1 CSRC, but CC count is 4.
Yves Gerey665174f2018-06-19 15:03:05 +0200192 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800193 };
194 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength,
195 sizeof(kRtpMsgWithInvalidLength), nullptr));
196
197 // Rtp message with single byte header extension, invalid extension length.
198 const uint8_t kRtpMsgWithInvalidExtnLength[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200199 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, 0x0A, 0x00, // Extn length - 0x0A00
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800201 };
202 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength,
203 sizeof(kRtpMsgWithInvalidExtnLength),
204 nullptr));
205}
206
207// Valid RTP packet with a 2byte header extension.
208TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) {
209 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader,
210 sizeof(kRtpMsgWith2ByteExtnHeader), nullptr));
211}
212
213// Valid RTP packet which has 1 byte header AbsSendTime extension in it.
214TEST(RtpUtilsTest, ValidRtpPacketWithAbsSendTimeExtension) {
215 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithAbsSendTimeExtension,
216 sizeof(kRtpMsgWithAbsSendTimeExtension),
217 nullptr));
218}
219
220// Verify handling of a 2 byte extension header RTP messsage. Currently these
221// messages are not supported.
222TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionIn2ByteHeaderExtn) {
223 std::vector<uint8_t> data(
224 kRtpMsgWith2ByteExtnHeader,
225 kRtpMsgWith2ByteExtnHeader + sizeof(kRtpMsgWith2ByteExtnHeader));
226 EXPECT_FALSE(UpdateRtpAbsSendTimeExtension(&data[0], data.size(), 3, 0));
227}
228
229// Verify finding an extension ID in the TURN send indication message.
230TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) {
231 // A valid STUN indication message with a valid RTP header in data attribute
232 // payload field and no extension bit set.
233 uint8_t message_without_extension[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200234 // clang-format off
235 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800236 0x00, 0x16, 0x00, 0x18, // length of
237 0x21, 0x12, 0xA4, 0x42, // magic cookie
238 '0', '1', '2', '3', // transaction id
239 '4', '5', '6', '7',
240 '8', '9', 'a', 'b',
241 0x00, 0x20, 0x00, 0x04, // Mapped address.
242 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x13, 0x00, 0x0C, // Data attribute.
244 0x80, 0x00, 0x00, 0x00, // RTP packet.
245 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00,
Yves Gerey665174f2018-06-19 15:03:05 +0200247 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800248 };
249 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(
250 message_without_extension, sizeof(message_without_extension), 3, 0));
251
252 // A valid STUN indication message with a valid RTP header and a extension
253 // header.
254 uint8_t message[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200255 // clang-format off
256 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800257 0x00, 0x16, 0x00, 0x24, // length of
258 0x21, 0x12, 0xA4, 0x42, // magic cookie
259 '0', '1', '2', '3', // transaction id
260 '4', '5', '6', '7',
261 '8', '9', 'a', 'b',
262 0x00, 0x20, 0x00, 0x04, // Mapped address.
263 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x13, 0x00, 0x18, // Data attribute.
265 0x90, 0x00, 0x00, 0x00, // RTP packet.
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE,
267 0x00, 0x02, 0x22, 0xaa, 0xbb, 0xcc, 0x32, 0xaa, 0xbb, 0xcc,
Yves Gerey665174f2018-06-19 15:03:05 +0200268 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800269 };
270 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, sizeof(message), 3, 0));
271}
272
273// Test without any packet options variables set. This method should return
274// without HMAC value in the packet.
275TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) {
276 rtc::PacketTimeUpdateParams packet_time_params;
277 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
278 kRtpMsgWithAbsSendTimeExtension +
279 sizeof(kRtpMsgWithAbsSendTimeExtension));
280 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
281 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
282 packet_time_params, 0));
283
284 // Making sure HMAC wasn't updated..
285 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
286 kFakeTag, 4));
287
288 // Verify AbsouluteSendTime extension field wasn't modified.
289 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue,
290 sizeof(kTestAstValue)));
291}
292
293// Veirfy HMAC is updated when packet option parameters are set.
294TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParams) {
295 rtc::PacketTimeUpdateParams packet_time_params;
296 packet_time_params.srtp_auth_key.assign(kTestKey,
297 kTestKey + sizeof(kTestKey));
298 packet_time_params.srtp_auth_tag_len = 4;
299
300 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
301 kRtpMsgWithAbsSendTimeExtension +
302 sizeof(kRtpMsgWithAbsSendTimeExtension));
303 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
304 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
305 packet_time_params, 0));
306
307 uint8_t kExpectedTag[] = {0xc1, 0x7a, 0x8c, 0xa0};
308 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
309 kExpectedTag, sizeof(kExpectedTag)));
310
311 // Verify AbsouluteSendTime extension field is not modified.
312 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue,
313 sizeof(kTestAstValue)));
314}
315
316// Verify finding an extension ID in a raw rtp message.
317TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInRtpPacket) {
318 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
319 kRtpMsgWithAbsSendTimeExtension +
320 sizeof(kRtpMsgWithAbsSendTimeExtension));
321
322 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(),
323 3, 51183266));
324
325 // Verify that the timestamp was updated.
326 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
327 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp,
328 sizeof(kExpectedTimestamp)));
329}
330
331// Verify we update both AbsSendTime extension header and HMAC.
332TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) {
333 rtc::PacketTimeUpdateParams packet_time_params;
334 packet_time_params.srtp_auth_key.assign(kTestKey,
335 kTestKey + sizeof(kTestKey));
336 packet_time_params.srtp_auth_tag_len = 4;
337 packet_time_params.rtp_sendtime_extension_id = 3;
338 // 3 is also present in the test message.
339
340 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
341 kRtpMsgWithAbsSendTimeExtension +
342 sizeof(kRtpMsgWithAbsSendTimeExtension));
343 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
344 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
345 packet_time_params, 51183266));
346
347 const uint8_t kExpectedTag[] = {0x81, 0xd1, 0x2c, 0x0e};
348 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
349 kExpectedTag, sizeof(kExpectedTag)));
350
351 // Verify that the timestamp was updated.
352 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
353 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp,
354 sizeof(kExpectedTimestamp)));
355}
356
Amit Hilbuchedd20542019-03-18 12:33:43 -0700357TEST(RtpUtilsTest, InferRtpPacketType) {
358 EXPECT_EQ(RtpPacketType::kRtp, InferRtpPacketType(kPcmuFrameArrayView));
359 EXPECT_EQ(RtpPacketType::kRtcp, InferRtpPacketType(kRtcpReportArrayView));
360 EXPECT_EQ(RtpPacketType::kUnknown,
361 InferRtpPacketType(kInvalidPacketArrayView));
362}
363
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364} // namespace cricket