blob: 051508cd01ae518182cee9112dc2883b58e34673 [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
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "media/base/rtp_utils.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
Steve Antone78bcb92017-10-31 09:53:08 -070016#include <vector>
17
Steve Anton10542f22019-01-11 09:11:00 -080018#include "media/base/fake_rtp.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/async_packet_socket.h"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "test/gtest.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace cricket {
23
Sergey Ulanovdc305db2016-01-14 17:14:54 -080024static const uint8_t kRtpPacketWithMarker[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020025 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026// 3 CSRCs (0x01020304, 0x12345678, 0xAABBCCDD)
27// Extension (0xBEDE, 0x1122334455667788)
Sergey Ulanovdc305db2016-01-14 17:14:54 -080028static const uint8_t kRtpPacketWithMarkerAndCsrcAndExtension[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
30 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD,
Yves Gerey665174f2018-06-19 15:03:05 +020031 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
32static const uint8_t kInvalidPacket[] = {0x80, 0x00};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080033static const uint8_t kInvalidPacketWithCsrc[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
Yves Gerey665174f2018-06-19 15:03:05 +020035 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080036static const uint8_t kInvalidPacketWithCsrcAndExtension1[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020037 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34,
39 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, 0xBE, 0xDE, 0x00};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080040static const uint8_t kInvalidPacketWithCsrcAndExtension2[] = {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
42 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD,
Yves Gerey665174f2018-06-19 15:03:05 +020043 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45// PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111
46// No FCI information is needed for PLI.
Sergey Ulanovdc305db2016-01-14 17:14:54 -080047static const uint8_t kNonCompoundRtcpPliFeedbackPacket[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020048 0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50// Packet has only mandatory fixed RTCP header
51// PT = 204, SSRC = 0x1111
Yves Gerey665174f2018-06-19 15:03:05 +020052static const uint8_t kNonCompoundRtcpAppPacket[] = {0x81, 0xCC, 0x00, 0x0C,
53 0x00, 0x00, 0x11, 0x11};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
55// PT = 202, Source count = 0
Yves Gerey665174f2018-06-19 15:03:05 +020056static const uint8_t kNonCompoundRtcpSDESPacket[] = {0x80, 0xCA, 0x00, 0x00};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
Yves Gerey665174f2018-06-19 15:03:05 +020058static uint8_t kFakeTag[4] = {0xba, 0xdd, 0xba, 0xdd};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080059static uint8_t kTestKey[] = "12345678901234567890";
Yves Gerey665174f2018-06-19 15:03:05 +020060static uint8_t kTestAstValue[3] = {0xaa, 0xbb, 0xcc};
Sergey Ulanovdc305db2016-01-14 17:14:54 -080061
62// Valid rtp Message with 2 byte header extension.
63static uint8_t kRtpMsgWith2ByteExtnHeader[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020064 // clang-format off
65 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -080066 0x90, 0x00, 0x00, 0x00,
67 0x00, 0x00, 0x00, 0x00,
68 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
69 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension
70 0x01, 0x00, 0x00, 0x00
Yves Gerey665174f2018-06-19 15:03:05 +020071 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -080072};
73
74// RTP packet with single byte extension header of length 4 bytes.
75// Extension id = 3 and length = 3
76static uint8_t kRtpMsgWithAbsSendTimeExtension[] = {
Yves Gerey665174f2018-06-19 15:03:05 +020077 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
78 0xBE, 0xDE, 0x00, 0x02, 0x22, 0x00, 0x02, 0x1c, 0x32, 0xaa, 0xbb, 0xcc,
Sergey Ulanovdc305db2016-01-14 17:14:54 -080079};
80
81// Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|.
82static const int kAstIndexInRtpMsg = 21;
83
Amit Hilbuchedd20542019-03-18 12:33:43 -070084static const rtc::ArrayView<const char> kPcmuFrameArrayView =
85 rtc::MakeArrayView(reinterpret_cast<const char*>(kPcmuFrame),
86 sizeof(kPcmuFrame));
87static const rtc::ArrayView<const char> kRtcpReportArrayView =
88 rtc::MakeArrayView(reinterpret_cast<const char*>(kRtcpReport),
89 sizeof(kRtcpReport));
90static const rtc::ArrayView<const char> kInvalidPacketArrayView =
91 rtc::MakeArrayView(reinterpret_cast<const char*>(kInvalidPacket),
92 sizeof(kInvalidPacket));
93
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094TEST(RtpUtilsTest, GetRtp) {
Amit Hilbuchedd20542019-03-18 12:33:43 -070095 EXPECT_TRUE(IsRtpPacket(kPcmuFrameArrayView));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97 int pt;
98 EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt));
99 EXPECT_EQ(0, pt);
100 EXPECT_TRUE(GetRtpPayloadType(kRtpPacketWithMarker,
101 sizeof(kRtpPacketWithMarker), &pt));
102 EXPECT_EQ(0, pt);
103
104 int seq_num;
105 EXPECT_TRUE(GetRtpSeqNum(kPcmuFrame, sizeof(kPcmuFrame), &seq_num));
106 EXPECT_EQ(1, seq_num);
107
Peter Boström0c4e06b2015-10-07 12:23:21 +0200108 uint32_t ts;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 EXPECT_TRUE(GetRtpTimestamp(kPcmuFrame, sizeof(kPcmuFrame), &ts));
110 EXPECT_EQ(0u, ts);
111
Peter Boström0c4e06b2015-10-07 12:23:21 +0200112 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 EXPECT_TRUE(GetRtpSsrc(kPcmuFrame, sizeof(kPcmuFrame), &ssrc));
114 EXPECT_EQ(1u, ssrc);
115
116 RtpHeader header;
117 EXPECT_TRUE(GetRtpHeader(kPcmuFrame, sizeof(kPcmuFrame), &header));
118 EXPECT_EQ(0, header.payload_type);
119 EXPECT_EQ(1, header.seq_num);
120 EXPECT_EQ(0u, header.timestamp);
121 EXPECT_EQ(1u, header.ssrc);
122
123 EXPECT_FALSE(GetRtpPayloadType(kInvalidPacket, sizeof(kInvalidPacket), &pt));
124 EXPECT_FALSE(GetRtpSeqNum(kInvalidPacket, sizeof(kInvalidPacket), &seq_num));
125 EXPECT_FALSE(GetRtpTimestamp(kInvalidPacket, sizeof(kInvalidPacket), &ts));
126 EXPECT_FALSE(GetRtpSsrc(kInvalidPacket, sizeof(kInvalidPacket), &ssrc));
127}
128
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000129TEST(RtpUtilsTest, SetRtpHeader) {
Yves Gerey665174f2018-06-19 15:03:05 +0200130 uint8_t packet[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132
Yves Gerey665174f2018-06-19 15:03:05 +0200133 RtpHeader header = {9, 1111, 2222u, 3333u};
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000134 EXPECT_TRUE(SetRtpHeader(packet, sizeof(packet), header));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135
136 // Bits: 10 0 0 0000
137 EXPECT_EQ(128u, packet[0]);
138 size_t len;
139 EXPECT_TRUE(GetRtpHeaderLen(packet, sizeof(packet), &len));
140 EXPECT_EQ(12U, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000141 EXPECT_TRUE(GetRtpHeader(packet, sizeof(packet), &header));
142 EXPECT_EQ(9, header.payload_type);
143 EXPECT_EQ(1111, header.seq_num);
144 EXPECT_EQ(2222u, header.timestamp);
145 EXPECT_EQ(3333u, header.ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146}
147
148TEST(RtpUtilsTest, GetRtpHeaderLen) {
149 size_t len;
150 EXPECT_TRUE(GetRtpHeaderLen(kPcmuFrame, sizeof(kPcmuFrame), &len));
151 EXPECT_EQ(12U, len);
152
153 EXPECT_TRUE(GetRtpHeaderLen(kRtpPacketWithMarkerAndCsrcAndExtension,
154 sizeof(kRtpPacketWithMarkerAndCsrcAndExtension),
155 &len));
156 EXPECT_EQ(sizeof(kRtpPacketWithMarkerAndCsrcAndExtension), len);
157
158 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacket, sizeof(kInvalidPacket), &len));
159 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrc,
160 sizeof(kInvalidPacketWithCsrc), &len));
161 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension1,
162 sizeof(kInvalidPacketWithCsrcAndExtension1),
163 &len));
164 EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension2,
165 sizeof(kInvalidPacketWithCsrcAndExtension2),
166 &len));
167}
168
169TEST(RtpUtilsTest, GetRtcp) {
170 int pt;
171 EXPECT_TRUE(GetRtcpType(kRtcpReport, sizeof(kRtcpReport), &pt));
172 EXPECT_EQ(0xc9, pt);
173
174 EXPECT_FALSE(GetRtcpType(kInvalidPacket, sizeof(kInvalidPacket), &pt));
175
Peter Boström0c4e06b2015-10-07 12:23:21 +0200176 uint32_t ssrc;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpPliFeedbackPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200178 sizeof(kNonCompoundRtcpPliFeedbackPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200180 sizeof(kNonCompoundRtcpAppPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket,
Yves Gerey665174f2018-06-19 15:03:05 +0200182 sizeof(kNonCompoundRtcpSDESPacket), &ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000183}
184
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800185// Invalid RTP packets.
186TEST(RtpUtilsTest, InvalidRtpHeader) {
187 // Rtp message with invalid length.
188 const uint8_t kRtpMsgWithInvalidLength[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200189 // clang-format off
190 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800191 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
192 0xAA, 0xBB, 0xCC, 0XDD, // SSRC
193 0xDD, 0xCC, 0xBB, 0xAA, // Only 1 CSRC, but CC count is 4.
Yves Gerey665174f2018-06-19 15:03:05 +0200194 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800195 };
196 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength,
197 sizeof(kRtpMsgWithInvalidLength), nullptr));
198
199 // Rtp message with single byte header extension, invalid extension length.
200 const uint8_t kRtpMsgWithInvalidExtnLength[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200201 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, 0x0A, 0x00, // Extn length - 0x0A00
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800203 };
204 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength,
205 sizeof(kRtpMsgWithInvalidExtnLength),
206 nullptr));
207}
208
209// Valid RTP packet with a 2byte header extension.
210TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) {
211 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader,
212 sizeof(kRtpMsgWith2ByteExtnHeader), nullptr));
213}
214
215// Valid RTP packet which has 1 byte header AbsSendTime extension in it.
216TEST(RtpUtilsTest, ValidRtpPacketWithAbsSendTimeExtension) {
217 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithAbsSendTimeExtension,
218 sizeof(kRtpMsgWithAbsSendTimeExtension),
219 nullptr));
220}
221
222// Verify handling of a 2 byte extension header RTP messsage. Currently these
223// messages are not supported.
224TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionIn2ByteHeaderExtn) {
225 std::vector<uint8_t> data(
226 kRtpMsgWith2ByteExtnHeader,
227 kRtpMsgWith2ByteExtnHeader + sizeof(kRtpMsgWith2ByteExtnHeader));
228 EXPECT_FALSE(UpdateRtpAbsSendTimeExtension(&data[0], data.size(), 3, 0));
229}
230
231// Verify finding an extension ID in the TURN send indication message.
232TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) {
233 // A valid STUN indication message with a valid RTP header in data attribute
234 // payload field and no extension bit set.
235 uint8_t message_without_extension[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200236 // clang-format off
237 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800238 0x00, 0x16, 0x00, 0x18, // length of
239 0x21, 0x12, 0xA4, 0x42, // magic cookie
240 '0', '1', '2', '3', // transaction id
241 '4', '5', '6', '7',
242 '8', '9', 'a', 'b',
243 0x00, 0x20, 0x00, 0x04, // Mapped address.
244 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x13, 0x00, 0x0C, // Data attribute.
246 0x80, 0x00, 0x00, 0x00, // RTP packet.
247 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00,
Yves Gerey665174f2018-06-19 15:03:05 +0200249 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800250 };
251 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(
252 message_without_extension, sizeof(message_without_extension), 3, 0));
253
254 // A valid STUN indication message with a valid RTP header and a extension
255 // header.
256 uint8_t message[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200257 // clang-format off
258 // clang formatting doesn't respect inline comments.
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800259 0x00, 0x16, 0x00, 0x24, // length of
260 0x21, 0x12, 0xA4, 0x42, // magic cookie
261 '0', '1', '2', '3', // transaction id
262 '4', '5', '6', '7',
263 '8', '9', 'a', 'b',
264 0x00, 0x20, 0x00, 0x04, // Mapped address.
265 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x13, 0x00, 0x18, // Data attribute.
267 0x90, 0x00, 0x00, 0x00, // RTP packet.
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE,
269 0x00, 0x02, 0x22, 0xaa, 0xbb, 0xcc, 0x32, 0xaa, 0xbb, 0xcc,
Yves Gerey665174f2018-06-19 15:03:05 +0200270 // clang-format on
Sergey Ulanovdc305db2016-01-14 17:14:54 -0800271 };
272 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, sizeof(message), 3, 0));
273}
274
275// Test without any packet options variables set. This method should return
276// without HMAC value in the packet.
277TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) {
278 rtc::PacketTimeUpdateParams packet_time_params;
279 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
280 kRtpMsgWithAbsSendTimeExtension +
281 sizeof(kRtpMsgWithAbsSendTimeExtension));
282 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
283 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
284 packet_time_params, 0));
285
286 // Making sure HMAC wasn't updated..
287 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
288 kFakeTag, 4));
289
290 // Verify AbsouluteSendTime extension field wasn't modified.
291 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue,
292 sizeof(kTestAstValue)));
293}
294
295// Veirfy HMAC is updated when packet option parameters are set.
296TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParams) {
297 rtc::PacketTimeUpdateParams packet_time_params;
298 packet_time_params.srtp_auth_key.assign(kTestKey,
299 kTestKey + sizeof(kTestKey));
300 packet_time_params.srtp_auth_tag_len = 4;
301
302 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
303 kRtpMsgWithAbsSendTimeExtension +
304 sizeof(kRtpMsgWithAbsSendTimeExtension));
305 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
306 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
307 packet_time_params, 0));
308
309 uint8_t kExpectedTag[] = {0xc1, 0x7a, 0x8c, 0xa0};
310 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
311 kExpectedTag, sizeof(kExpectedTag)));
312
313 // Verify AbsouluteSendTime extension field is not modified.
314 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue,
315 sizeof(kTestAstValue)));
316}
317
318// Verify finding an extension ID in a raw rtp message.
319TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInRtpPacket) {
320 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
321 kRtpMsgWithAbsSendTimeExtension +
322 sizeof(kRtpMsgWithAbsSendTimeExtension));
323
324 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(),
325 3, 51183266));
326
327 // Verify that the timestamp was updated.
328 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
329 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp,
330 sizeof(kExpectedTimestamp)));
331}
332
333// Verify we update both AbsSendTime extension header and HMAC.
334TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) {
335 rtc::PacketTimeUpdateParams packet_time_params;
336 packet_time_params.srtp_auth_key.assign(kTestKey,
337 kTestKey + sizeof(kTestKey));
338 packet_time_params.srtp_auth_tag_len = 4;
339 packet_time_params.rtp_sendtime_extension_id = 3;
340 // 3 is also present in the test message.
341
342 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension,
343 kRtpMsgWithAbsSendTimeExtension +
344 sizeof(kRtpMsgWithAbsSendTimeExtension));
345 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
346 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
347 packet_time_params, 51183266));
348
349 const uint8_t kExpectedTag[] = {0x81, 0xd1, 0x2c, 0x0e};
350 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
351 kExpectedTag, sizeof(kExpectedTag)));
352
353 // Verify that the timestamp was updated.
354 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
355 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp,
356 sizeof(kExpectedTimestamp)));
357}
358
Amit Hilbuchedd20542019-03-18 12:33:43 -0700359TEST(RtpUtilsTest, InferRtpPacketType) {
360 EXPECT_EQ(RtpPacketType::kRtp, InferRtpPacketType(kPcmuFrameArrayView));
361 EXPECT_EQ(RtpPacketType::kRtcp, InferRtpPacketType(kRtcpReportArrayView));
362 EXPECT_EQ(RtpPacketType::kUnknown,
363 InferRtpPacketType(kInvalidPacketArrayView));
364}
365
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366} // namespace cricket