henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "media/base/fakertp.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 14 | #include "media/base/rtputils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "rtc_base/asyncpacketsocket.h" |
| 16 | #include "rtc_base/gunit.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 17 | |
| 18 | namespace cricket { |
| 19 | |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 20 | static const uint8_t kRtpPacketWithMarker[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 21 | 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | // 3 CSRCs (0x01020304, 0x12345678, 0xAABBCCDD) |
| 23 | // Extension (0xBEDE, 0x1122334455667788) |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 24 | static const uint8_t kRtpPacketWithMarkerAndCsrcAndExtension[] = { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 25 | 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 26 | 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 27 | 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}; |
| 28 | static const uint8_t kInvalidPacket[] = {0x80, 0x00}; |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 29 | static const uint8_t kInvalidPacketWithCsrc[] = { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 31 | 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC}; |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 32 | static const uint8_t kInvalidPacketWithCsrcAndExtension1[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 33 | 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 34 | 0x00, 0x00, 0x01, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, |
| 35 | 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, 0xBE, 0xDE, 0x00}; |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 36 | static const uint8_t kInvalidPacketWithCsrcAndExtension2[] = { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 38 | 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 39 | 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | |
| 41 | // PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111 |
| 42 | // No FCI information is needed for PLI. |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 43 | static const uint8_t kNonCompoundRtcpPliFeedbackPacket[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 44 | 0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | |
| 46 | // Packet has only mandatory fixed RTCP header |
| 47 | // PT = 204, SSRC = 0x1111 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 48 | static const uint8_t kNonCompoundRtcpAppPacket[] = {0x81, 0xCC, 0x00, 0x0C, |
| 49 | 0x00, 0x00, 0x11, 0x11}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 50 | |
| 51 | // PT = 202, Source count = 0 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 52 | static const uint8_t kNonCompoundRtcpSDESPacket[] = {0x80, 0xCA, 0x00, 0x00}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 54 | static uint8_t kFakeTag[4] = {0xba, 0xdd, 0xba, 0xdd}; |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 55 | static uint8_t kTestKey[] = "12345678901234567890"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 56 | static uint8_t kTestAstValue[3] = {0xaa, 0xbb, 0xcc}; |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 57 | |
| 58 | // Valid rtp Message with 2 byte header extension. |
| 59 | static uint8_t kRtpMsgWith2ByteExtnHeader[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 60 | // clang-format off |
| 61 | // clang formatting doesn't respect inline comments. |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 62 | 0x90, 0x00, 0x00, 0x00, |
| 63 | 0x00, 0x00, 0x00, 0x00, |
| 64 | 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
| 65 | 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension |
| 66 | 0x01, 0x00, 0x00, 0x00 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 67 | // clang-format on |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | // RTP packet with single byte extension header of length 4 bytes. |
| 71 | // Extension id = 3 and length = 3 |
| 72 | static uint8_t kRtpMsgWithAbsSendTimeExtension[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 73 | 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 74 | 0xBE, 0xDE, 0x00, 0x02, 0x22, 0x00, 0x02, 0x1c, 0x32, 0xaa, 0xbb, 0xcc, |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | // Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|. |
| 78 | static const int kAstIndexInRtpMsg = 21; |
| 79 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | TEST(RtpUtilsTest, GetRtp) { |
pkasting@chromium.org | 0e81fdf | 2015-02-02 23:54:03 +0000 | [diff] [blame] | 81 | EXPECT_TRUE(IsRtpPacket(kPcmuFrame, sizeof(kPcmuFrame))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | |
| 83 | int pt; |
| 84 | EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt)); |
| 85 | EXPECT_EQ(0, pt); |
| 86 | EXPECT_TRUE(GetRtpPayloadType(kRtpPacketWithMarker, |
| 87 | sizeof(kRtpPacketWithMarker), &pt)); |
| 88 | EXPECT_EQ(0, pt); |
| 89 | |
| 90 | int seq_num; |
| 91 | EXPECT_TRUE(GetRtpSeqNum(kPcmuFrame, sizeof(kPcmuFrame), &seq_num)); |
| 92 | EXPECT_EQ(1, seq_num); |
| 93 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 94 | uint32_t ts; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | EXPECT_TRUE(GetRtpTimestamp(kPcmuFrame, sizeof(kPcmuFrame), &ts)); |
| 96 | EXPECT_EQ(0u, ts); |
| 97 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 98 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | EXPECT_TRUE(GetRtpSsrc(kPcmuFrame, sizeof(kPcmuFrame), &ssrc)); |
| 100 | EXPECT_EQ(1u, ssrc); |
| 101 | |
| 102 | RtpHeader header; |
| 103 | EXPECT_TRUE(GetRtpHeader(kPcmuFrame, sizeof(kPcmuFrame), &header)); |
| 104 | EXPECT_EQ(0, header.payload_type); |
| 105 | EXPECT_EQ(1, header.seq_num); |
| 106 | EXPECT_EQ(0u, header.timestamp); |
| 107 | EXPECT_EQ(1u, header.ssrc); |
| 108 | |
| 109 | EXPECT_FALSE(GetRtpPayloadType(kInvalidPacket, sizeof(kInvalidPacket), &pt)); |
| 110 | EXPECT_FALSE(GetRtpSeqNum(kInvalidPacket, sizeof(kInvalidPacket), &seq_num)); |
| 111 | EXPECT_FALSE(GetRtpTimestamp(kInvalidPacket, sizeof(kInvalidPacket), &ts)); |
| 112 | EXPECT_FALSE(GetRtpSsrc(kInvalidPacket, sizeof(kInvalidPacket), &ssrc)); |
| 113 | } |
| 114 | |
pkasting@chromium.org | 0e81fdf | 2015-02-02 23:54:03 +0000 | [diff] [blame] | 115 | TEST(RtpUtilsTest, SetRtpHeader) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 116 | uint8_t packet[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 119 | RtpHeader header = {9, 1111, 2222u, 3333u}; |
pkasting@chromium.org | 0e81fdf | 2015-02-02 23:54:03 +0000 | [diff] [blame] | 120 | EXPECT_TRUE(SetRtpHeader(packet, sizeof(packet), header)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | |
| 122 | // Bits: 10 0 0 0000 |
| 123 | EXPECT_EQ(128u, packet[0]); |
| 124 | size_t len; |
| 125 | EXPECT_TRUE(GetRtpHeaderLen(packet, sizeof(packet), &len)); |
| 126 | EXPECT_EQ(12U, len); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | EXPECT_TRUE(GetRtpHeader(packet, sizeof(packet), &header)); |
| 128 | EXPECT_EQ(9, header.payload_type); |
| 129 | EXPECT_EQ(1111, header.seq_num); |
| 130 | EXPECT_EQ(2222u, header.timestamp); |
| 131 | EXPECT_EQ(3333u, header.ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | TEST(RtpUtilsTest, GetRtpHeaderLen) { |
| 135 | size_t len; |
| 136 | EXPECT_TRUE(GetRtpHeaderLen(kPcmuFrame, sizeof(kPcmuFrame), &len)); |
| 137 | EXPECT_EQ(12U, len); |
| 138 | |
| 139 | EXPECT_TRUE(GetRtpHeaderLen(kRtpPacketWithMarkerAndCsrcAndExtension, |
| 140 | sizeof(kRtpPacketWithMarkerAndCsrcAndExtension), |
| 141 | &len)); |
| 142 | EXPECT_EQ(sizeof(kRtpPacketWithMarkerAndCsrcAndExtension), len); |
| 143 | |
| 144 | EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacket, sizeof(kInvalidPacket), &len)); |
| 145 | EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrc, |
| 146 | sizeof(kInvalidPacketWithCsrc), &len)); |
| 147 | EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension1, |
| 148 | sizeof(kInvalidPacketWithCsrcAndExtension1), |
| 149 | &len)); |
| 150 | EXPECT_FALSE(GetRtpHeaderLen(kInvalidPacketWithCsrcAndExtension2, |
| 151 | sizeof(kInvalidPacketWithCsrcAndExtension2), |
| 152 | &len)); |
| 153 | } |
| 154 | |
| 155 | TEST(RtpUtilsTest, GetRtcp) { |
| 156 | int pt; |
| 157 | EXPECT_TRUE(GetRtcpType(kRtcpReport, sizeof(kRtcpReport), &pt)); |
| 158 | EXPECT_EQ(0xc9, pt); |
| 159 | |
| 160 | EXPECT_FALSE(GetRtcpType(kInvalidPacket, sizeof(kInvalidPacket), &pt)); |
| 161 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 162 | uint32_t ssrc; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpPliFeedbackPacket, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 164 | sizeof(kNonCompoundRtcpPliFeedbackPacket), &ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 166 | sizeof(kNonCompoundRtcpAppPacket), &ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 168 | sizeof(kNonCompoundRtcpSDESPacket), &ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 171 | // Invalid RTP packets. |
| 172 | TEST(RtpUtilsTest, InvalidRtpHeader) { |
| 173 | // Rtp message with invalid length. |
| 174 | const uint8_t kRtpMsgWithInvalidLength[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 175 | // clang-format off |
| 176 | // clang formatting doesn't respect inline comments. |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 177 | 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 178 | 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
| 179 | 0xDD, 0xCC, 0xBB, 0xAA, // Only 1 CSRC, but CC count is 4. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 180 | // clang-format on |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 181 | }; |
| 182 | EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength, |
| 183 | sizeof(kRtpMsgWithInvalidLength), nullptr)); |
| 184 | |
| 185 | // Rtp message with single byte header extension, invalid extension length. |
| 186 | const uint8_t kRtpMsgWithInvalidExtnLength[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 187 | 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 188 | 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, 0x0A, 0x00, // Extn length - 0x0A00 |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 189 | }; |
| 190 | EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength, |
| 191 | sizeof(kRtpMsgWithInvalidExtnLength), |
| 192 | nullptr)); |
| 193 | } |
| 194 | |
| 195 | // Valid RTP packet with a 2byte header extension. |
| 196 | TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) { |
| 197 | EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader, |
| 198 | sizeof(kRtpMsgWith2ByteExtnHeader), nullptr)); |
| 199 | } |
| 200 | |
| 201 | // Valid RTP packet which has 1 byte header AbsSendTime extension in it. |
| 202 | TEST(RtpUtilsTest, ValidRtpPacketWithAbsSendTimeExtension) { |
| 203 | EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithAbsSendTimeExtension, |
| 204 | sizeof(kRtpMsgWithAbsSendTimeExtension), |
| 205 | nullptr)); |
| 206 | } |
| 207 | |
| 208 | // Verify handling of a 2 byte extension header RTP messsage. Currently these |
| 209 | // messages are not supported. |
| 210 | TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { |
| 211 | std::vector<uint8_t> data( |
| 212 | kRtpMsgWith2ByteExtnHeader, |
| 213 | kRtpMsgWith2ByteExtnHeader + sizeof(kRtpMsgWith2ByteExtnHeader)); |
| 214 | EXPECT_FALSE(UpdateRtpAbsSendTimeExtension(&data[0], data.size(), 3, 0)); |
| 215 | } |
| 216 | |
| 217 | // Verify finding an extension ID in the TURN send indication message. |
| 218 | TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) { |
| 219 | // A valid STUN indication message with a valid RTP header in data attribute |
| 220 | // payload field and no extension bit set. |
| 221 | uint8_t message_without_extension[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 222 | // clang-format off |
| 223 | // clang formatting doesn't respect inline comments. |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 224 | 0x00, 0x16, 0x00, 0x18, // length of |
| 225 | 0x21, 0x12, 0xA4, 0x42, // magic cookie |
| 226 | '0', '1', '2', '3', // transaction id |
| 227 | '4', '5', '6', '7', |
| 228 | '8', '9', 'a', 'b', |
| 229 | 0x00, 0x20, 0x00, 0x04, // Mapped address. |
| 230 | 0x00, 0x00, 0x00, 0x00, |
| 231 | 0x00, 0x13, 0x00, 0x0C, // Data attribute. |
| 232 | 0x80, 0x00, 0x00, 0x00, // RTP packet. |
| 233 | 0x00, 0x00, 0x00, 0x00, |
| 234 | 0x00, 0x00, 0x00, 0x00, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 235 | // clang-format on |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 236 | }; |
| 237 | EXPECT_TRUE(UpdateRtpAbsSendTimeExtension( |
| 238 | message_without_extension, sizeof(message_without_extension), 3, 0)); |
| 239 | |
| 240 | // A valid STUN indication message with a valid RTP header and a extension |
| 241 | // header. |
| 242 | uint8_t message[] = { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 243 | // clang-format off |
| 244 | // clang formatting doesn't respect inline comments. |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 245 | 0x00, 0x16, 0x00, 0x24, // length of |
| 246 | 0x21, 0x12, 0xA4, 0x42, // magic cookie |
| 247 | '0', '1', '2', '3', // transaction id |
| 248 | '4', '5', '6', '7', |
| 249 | '8', '9', 'a', 'b', |
| 250 | 0x00, 0x20, 0x00, 0x04, // Mapped address. |
| 251 | 0x00, 0x00, 0x00, 0x00, |
| 252 | 0x00, 0x13, 0x00, 0x18, // Data attribute. |
| 253 | 0x90, 0x00, 0x00, 0x00, // RTP packet. |
| 254 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, |
| 255 | 0x00, 0x02, 0x22, 0xaa, 0xbb, 0xcc, 0x32, 0xaa, 0xbb, 0xcc, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 256 | // clang-format on |
Sergey Ulanov | dc305db | 2016-01-14 17:14:54 -0800 | [diff] [blame] | 257 | }; |
| 258 | EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, sizeof(message), 3, 0)); |
| 259 | } |
| 260 | |
| 261 | // Test without any packet options variables set. This method should return |
| 262 | // without HMAC value in the packet. |
| 263 | TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) { |
| 264 | rtc::PacketTimeUpdateParams packet_time_params; |
| 265 | std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 266 | kRtpMsgWithAbsSendTimeExtension + |
| 267 | sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 268 | rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 269 | EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 270 | packet_time_params, 0)); |
| 271 | |
| 272 | // Making sure HMAC wasn't updated.. |
| 273 | EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 274 | kFakeTag, 4)); |
| 275 | |
| 276 | // Verify AbsouluteSendTime extension field wasn't modified. |
| 277 | EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue, |
| 278 | sizeof(kTestAstValue))); |
| 279 | } |
| 280 | |
| 281 | // Veirfy HMAC is updated when packet option parameters are set. |
| 282 | TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParams) { |
| 283 | rtc::PacketTimeUpdateParams packet_time_params; |
| 284 | packet_time_params.srtp_auth_key.assign(kTestKey, |
| 285 | kTestKey + sizeof(kTestKey)); |
| 286 | packet_time_params.srtp_auth_tag_len = 4; |
| 287 | |
| 288 | std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 289 | kRtpMsgWithAbsSendTimeExtension + |
| 290 | sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 291 | rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 292 | EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 293 | packet_time_params, 0)); |
| 294 | |
| 295 | uint8_t kExpectedTag[] = {0xc1, 0x7a, 0x8c, 0xa0}; |
| 296 | EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 297 | kExpectedTag, sizeof(kExpectedTag))); |
| 298 | |
| 299 | // Verify AbsouluteSendTime extension field is not modified. |
| 300 | EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue, |
| 301 | sizeof(kTestAstValue))); |
| 302 | } |
| 303 | |
| 304 | // Verify finding an extension ID in a raw rtp message. |
| 305 | TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInRtpPacket) { |
| 306 | std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 307 | kRtpMsgWithAbsSendTimeExtension + |
| 308 | sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 309 | |
| 310 | EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(), |
| 311 | 3, 51183266)); |
| 312 | |
| 313 | // Verify that the timestamp was updated. |
| 314 | const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa}; |
| 315 | EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp, |
| 316 | sizeof(kExpectedTimestamp))); |
| 317 | } |
| 318 | |
| 319 | // Verify we update both AbsSendTime extension header and HMAC. |
| 320 | TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) { |
| 321 | rtc::PacketTimeUpdateParams packet_time_params; |
| 322 | packet_time_params.srtp_auth_key.assign(kTestKey, |
| 323 | kTestKey + sizeof(kTestKey)); |
| 324 | packet_time_params.srtp_auth_tag_len = 4; |
| 325 | packet_time_params.rtp_sendtime_extension_id = 3; |
| 326 | // 3 is also present in the test message. |
| 327 | |
| 328 | std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 329 | kRtpMsgWithAbsSendTimeExtension + |
| 330 | sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 331 | rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 332 | EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 333 | packet_time_params, 51183266)); |
| 334 | |
| 335 | const uint8_t kExpectedTag[] = {0x81, 0xd1, 0x2c, 0x0e}; |
| 336 | EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 337 | kExpectedTag, sizeof(kExpectedTag))); |
| 338 | |
| 339 | // Verify that the timestamp was updated. |
| 340 | const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa}; |
| 341 | EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp, |
| 342 | sizeof(kExpectedTimestamp))); |
| 343 | } |
| 344 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 345 | } // namespace cricket |