OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/media/base/fakertp.h" | 28 #include "talk/media/base/fakertp.h" |
29 #include "talk/media/base/rtputils.h" | 29 #include "talk/media/base/rtputils.h" |
| 30 #include "webrtc/base/asyncpacketsocket.h" |
30 #include "webrtc/base/gunit.h" | 31 #include "webrtc/base/gunit.h" |
31 | 32 |
32 namespace cricket { | 33 namespace cricket { |
33 | 34 |
34 static const unsigned char kRtpPacketWithMarker[] = { | 35 static const uint8_t kRtpPacketWithMarker[] = { |
35 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 | 36 0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 |
36 }; | 37 }; |
37 // 3 CSRCs (0x01020304, 0x12345678, 0xAABBCCDD) | 38 // 3 CSRCs (0x01020304, 0x12345678, 0xAABBCCDD) |
38 // Extension (0xBEDE, 0x1122334455667788) | 39 // Extension (0xBEDE, 0x1122334455667788) |
39 static const unsigned char kRtpPacketWithMarkerAndCsrcAndExtension[] = { | 40 static const uint8_t kRtpPacketWithMarkerAndCsrcAndExtension[] = { |
40 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | 41 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
41 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, | 42 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, |
42 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 | 43 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 |
43 }; | 44 }; |
44 static const unsigned char kInvalidPacket[] = { 0x80, 0x00 }; | 45 static const uint8_t kInvalidPacket[] = { 0x80, 0x00 }; |
45 static const unsigned char kInvalidPacketWithCsrc[] = { | 46 static const uint8_t kInvalidPacketWithCsrc[] = { |
46 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | 47 0x83, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
47 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC | 48 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC |
48 }; | 49 }; |
49 static const unsigned char kInvalidPacketWithCsrcAndExtension1[] = { | 50 static const uint8_t kInvalidPacketWithCsrcAndExtension1[] = { |
50 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | 51 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
51 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, | 52 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, |
52 0xBE, 0xDE, 0x00 | 53 0xBE, 0xDE, 0x00 |
53 }; | 54 }; |
54 static const unsigned char kInvalidPacketWithCsrcAndExtension2[] = { | 55 static const uint8_t kInvalidPacketWithCsrcAndExtension2[] = { |
55 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, | 56 0x93, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
56 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, | 57 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC, 0xDD, |
57 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 | 58 0xBE, 0xDE, 0x00, 0x02, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 |
58 }; | 59 }; |
59 | 60 |
60 // PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111 | 61 // PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111 |
61 // No FCI information is needed for PLI. | 62 // No FCI information is needed for PLI. |
62 static const unsigned char kNonCompoundRtcpPliFeedbackPacket[] = { | 63 static const uint8_t kNonCompoundRtcpPliFeedbackPacket[] = { |
63 0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11 | 64 0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11 |
64 }; | 65 }; |
65 | 66 |
66 // Packet has only mandatory fixed RTCP header | 67 // Packet has only mandatory fixed RTCP header |
67 // PT = 204, SSRC = 0x1111 | 68 // PT = 204, SSRC = 0x1111 |
68 static const unsigned char kNonCompoundRtcpAppPacket[] = { | 69 static const uint8_t kNonCompoundRtcpAppPacket[] = { |
69 0x81, 0xCC, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11 | 70 0x81, 0xCC, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11 |
70 }; | 71 }; |
71 | 72 |
72 // PT = 202, Source count = 0 | 73 // PT = 202, Source count = 0 |
73 static const unsigned char kNonCompoundRtcpSDESPacket[] = { | 74 static const uint8_t kNonCompoundRtcpSDESPacket[] = { |
74 0x80, 0xCA, 0x00, 0x00 | 75 0x80, 0xCA, 0x00, 0x00 |
75 }; | 76 }; |
76 | 77 |
| 78 static uint8_t kFakeTag[4] = { 0xba, 0xdd, 0xba, 0xdd }; |
| 79 static uint8_t kTestKey[] = "12345678901234567890"; |
| 80 static uint8_t kTestAstValue[3] = { 0xaa, 0xbb, 0xcc }; |
| 81 |
| 82 // Valid rtp Message with 2 byte header extension. |
| 83 static uint8_t kRtpMsgWith2ByteExtnHeader[] = { |
| 84 0x90, 0x00, 0x00, 0x00, |
| 85 0x00, 0x00, 0x00, 0x00, |
| 86 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
| 87 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension |
| 88 0x01, 0x00, 0x00, 0x00 |
| 89 }; |
| 90 |
| 91 // RTP packet with single byte extension header of length 4 bytes. |
| 92 // Extension id = 3 and length = 3 |
| 93 static uint8_t kRtpMsgWithAbsSendTimeExtension[] = { |
| 94 0x90, 0x00, 0x00, 0x00, |
| 95 0x00, 0x00, 0x00, 0x00, |
| 96 0x00, 0x00, 0x00, 0x00, |
| 97 0xBE, 0xDE, 0x00, 0x02, |
| 98 0x22, 0x00, 0x02, 0x1c, |
| 99 0x32, 0xaa, 0xbb, 0xcc, |
| 100 }; |
| 101 |
| 102 // Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|. |
| 103 static const int kAstIndexInRtpMsg = 21; |
| 104 |
77 TEST(RtpUtilsTest, GetRtp) { | 105 TEST(RtpUtilsTest, GetRtp) { |
78 EXPECT_TRUE(IsRtpPacket(kPcmuFrame, sizeof(kPcmuFrame))); | 106 EXPECT_TRUE(IsRtpPacket(kPcmuFrame, sizeof(kPcmuFrame))); |
79 | 107 |
80 int pt; | 108 int pt; |
81 EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt)); | 109 EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt)); |
82 EXPECT_EQ(0, pt); | 110 EXPECT_EQ(0, pt); |
83 EXPECT_TRUE(GetRtpPayloadType(kRtpPacketWithMarker, | 111 EXPECT_TRUE(GetRtpPayloadType(kRtpPacketWithMarker, |
84 sizeof(kRtpPacketWithMarker), &pt)); | 112 sizeof(kRtpPacketWithMarker), &pt)); |
85 EXPECT_EQ(0, pt); | 113 EXPECT_EQ(0, pt); |
86 | 114 |
(...skipping 16 matching lines...) Expand all Loading... |
103 EXPECT_EQ(0u, header.timestamp); | 131 EXPECT_EQ(0u, header.timestamp); |
104 EXPECT_EQ(1u, header.ssrc); | 132 EXPECT_EQ(1u, header.ssrc); |
105 | 133 |
106 EXPECT_FALSE(GetRtpPayloadType(kInvalidPacket, sizeof(kInvalidPacket), &pt)); | 134 EXPECT_FALSE(GetRtpPayloadType(kInvalidPacket, sizeof(kInvalidPacket), &pt)); |
107 EXPECT_FALSE(GetRtpSeqNum(kInvalidPacket, sizeof(kInvalidPacket), &seq_num)); | 135 EXPECT_FALSE(GetRtpSeqNum(kInvalidPacket, sizeof(kInvalidPacket), &seq_num)); |
108 EXPECT_FALSE(GetRtpTimestamp(kInvalidPacket, sizeof(kInvalidPacket), &ts)); | 136 EXPECT_FALSE(GetRtpTimestamp(kInvalidPacket, sizeof(kInvalidPacket), &ts)); |
109 EXPECT_FALSE(GetRtpSsrc(kInvalidPacket, sizeof(kInvalidPacket), &ssrc)); | 137 EXPECT_FALSE(GetRtpSsrc(kInvalidPacket, sizeof(kInvalidPacket), &ssrc)); |
110 } | 138 } |
111 | 139 |
112 TEST(RtpUtilsTest, SetRtpHeader) { | 140 TEST(RtpUtilsTest, SetRtpHeader) { |
113 unsigned char packet[] = { | 141 uint8_t packet[] = { |
114 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
115 }; | 143 }; |
116 | 144 |
117 RtpHeader header = { 9, 1111, 2222u, 3333u }; | 145 RtpHeader header = { 9, 1111, 2222u, 3333u }; |
118 EXPECT_TRUE(SetRtpHeader(packet, sizeof(packet), header)); | 146 EXPECT_TRUE(SetRtpHeader(packet, sizeof(packet), header)); |
119 | 147 |
120 // Bits: 10 0 0 0000 | 148 // Bits: 10 0 0 0000 |
121 EXPECT_EQ(128u, packet[0]); | 149 EXPECT_EQ(128u, packet[0]); |
122 size_t len; | 150 size_t len; |
123 EXPECT_TRUE(GetRtpHeaderLen(packet, sizeof(packet), &len)); | 151 EXPECT_TRUE(GetRtpHeaderLen(packet, sizeof(packet), &len)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 sizeof(kNonCompoundRtcpPliFeedbackPacket), | 190 sizeof(kNonCompoundRtcpPliFeedbackPacket), |
163 &ssrc)); | 191 &ssrc)); |
164 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket, | 192 EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket, |
165 sizeof(kNonCompoundRtcpAppPacket), | 193 sizeof(kNonCompoundRtcpAppPacket), |
166 &ssrc)); | 194 &ssrc)); |
167 EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket, | 195 EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket, |
168 sizeof(kNonCompoundRtcpSDESPacket), | 196 sizeof(kNonCompoundRtcpSDESPacket), |
169 &ssrc)); | 197 &ssrc)); |
170 } | 198 } |
171 | 199 |
| 200 // Invalid RTP packets. |
| 201 TEST(RtpUtilsTest, InvalidRtpHeader) { |
| 202 // Rtp message with invalid length. |
| 203 const uint8_t kRtpMsgWithInvalidLength[] = { |
| 204 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 205 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
| 206 0xDD, 0xCC, 0xBB, 0xAA, // Only 1 CSRC, but CC count is 4. |
| 207 }; |
| 208 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength, |
| 209 sizeof(kRtpMsgWithInvalidLength), nullptr)); |
| 210 |
| 211 // Rtp message with single byte header extension, invalid extension length. |
| 212 const uint8_t kRtpMsgWithInvalidExtnLength[] = { |
| 213 0x90, 0x00, 0x00, 0x00, |
| 214 0x00, 0x00, 0x00, 0x00, |
| 215 0x00, 0x00, 0x00, 0x00, |
| 216 0xBE, 0xDE, 0x0A, 0x00, // Extn length - 0x0A00 |
| 217 }; |
| 218 EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength, |
| 219 sizeof(kRtpMsgWithInvalidExtnLength), |
| 220 nullptr)); |
| 221 } |
| 222 |
| 223 // Valid RTP packet with a 2byte header extension. |
| 224 TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) { |
| 225 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader, |
| 226 sizeof(kRtpMsgWith2ByteExtnHeader), nullptr)); |
| 227 } |
| 228 |
| 229 // Valid RTP packet which has 1 byte header AbsSendTime extension in it. |
| 230 TEST(RtpUtilsTest, ValidRtpPacketWithAbsSendTimeExtension) { |
| 231 EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithAbsSendTimeExtension, |
| 232 sizeof(kRtpMsgWithAbsSendTimeExtension), |
| 233 nullptr)); |
| 234 } |
| 235 |
| 236 // Verify handling of a 2 byte extension header RTP messsage. Currently these |
| 237 // messages are not supported. |
| 238 TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { |
| 239 std::vector<uint8_t> data( |
| 240 kRtpMsgWith2ByteExtnHeader, |
| 241 kRtpMsgWith2ByteExtnHeader + sizeof(kRtpMsgWith2ByteExtnHeader)); |
| 242 EXPECT_FALSE(UpdateRtpAbsSendTimeExtension(&data[0], data.size(), 3, 0)); |
| 243 } |
| 244 |
| 245 // Verify finding an extension ID in the TURN send indication message. |
| 246 TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) { |
| 247 // A valid STUN indication message with a valid RTP header in data attribute |
| 248 // payload field and no extension bit set. |
| 249 uint8_t message_without_extension[] = { |
| 250 0x00, 0x16, 0x00, 0x18, // length of |
| 251 0x21, 0x12, 0xA4, 0x42, // magic cookie |
| 252 '0', '1', '2', '3', // transaction id |
| 253 '4', '5', '6', '7', |
| 254 '8', '9', 'a', 'b', |
| 255 0x00, 0x20, 0x00, 0x04, // Mapped address. |
| 256 0x00, 0x00, 0x00, 0x00, |
| 257 0x00, 0x13, 0x00, 0x0C, // Data attribute. |
| 258 0x80, 0x00, 0x00, 0x00, // RTP packet. |
| 259 0x00, 0x00, 0x00, 0x00, |
| 260 0x00, 0x00, 0x00, 0x00, |
| 261 }; |
| 262 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension( |
| 263 message_without_extension, sizeof(message_without_extension), 3, 0)); |
| 264 |
| 265 // A valid STUN indication message with a valid RTP header and a extension |
| 266 // header. |
| 267 uint8_t message[] = { |
| 268 0x00, 0x16, 0x00, 0x24, // length of |
| 269 0x21, 0x12, 0xA4, 0x42, // magic cookie |
| 270 '0', '1', '2', '3', // transaction id |
| 271 '4', '5', '6', '7', |
| 272 '8', '9', 'a', 'b', |
| 273 0x00, 0x20, 0x00, 0x04, // Mapped address. |
| 274 0x00, 0x00, 0x00, 0x00, |
| 275 0x00, 0x13, 0x00, 0x18, // Data attribute. |
| 276 0x90, 0x00, 0x00, 0x00, // RTP packet. |
| 277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xDE, |
| 278 0x00, 0x02, 0x22, 0xaa, 0xbb, 0xcc, 0x32, 0xaa, 0xbb, 0xcc, |
| 279 }; |
| 280 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(message, sizeof(message), 3, 0)); |
| 281 } |
| 282 |
| 283 // Test without any packet options variables set. This method should return |
| 284 // without HMAC value in the packet. |
| 285 TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) { |
| 286 rtc::PacketTimeUpdateParams packet_time_params; |
| 287 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 288 kRtpMsgWithAbsSendTimeExtension + |
| 289 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 290 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 291 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 292 packet_time_params, 0)); |
| 293 |
| 294 // Making sure HMAC wasn't updated.. |
| 295 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 296 kFakeTag, 4)); |
| 297 |
| 298 // Verify AbsouluteSendTime extension field wasn't modified. |
| 299 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue, |
| 300 sizeof(kTestAstValue))); |
| 301 } |
| 302 |
| 303 // Veirfy HMAC is updated when packet option parameters are set. |
| 304 TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParams) { |
| 305 rtc::PacketTimeUpdateParams packet_time_params; |
| 306 packet_time_params.srtp_auth_key.assign(kTestKey, |
| 307 kTestKey + sizeof(kTestKey)); |
| 308 packet_time_params.srtp_auth_tag_len = 4; |
| 309 |
| 310 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 311 kRtpMsgWithAbsSendTimeExtension + |
| 312 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 313 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 314 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 315 packet_time_params, 0)); |
| 316 |
| 317 uint8_t kExpectedTag[] = {0xc1, 0x7a, 0x8c, 0xa0}; |
| 318 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 319 kExpectedTag, sizeof(kExpectedTag))); |
| 320 |
| 321 // Verify AbsouluteSendTime extension field is not modified. |
| 322 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kTestAstValue, |
| 323 sizeof(kTestAstValue))); |
| 324 } |
| 325 |
| 326 // Verify finding an extension ID in a raw rtp message. |
| 327 TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInRtpPacket) { |
| 328 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 329 kRtpMsgWithAbsSendTimeExtension + |
| 330 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 331 |
| 332 EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(&rtp_packet[0], rtp_packet.size(), |
| 333 3, 51183266)); |
| 334 |
| 335 // Verify that the timestamp was updated. |
| 336 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa}; |
| 337 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp, |
| 338 sizeof(kExpectedTimestamp))); |
| 339 } |
| 340 |
| 341 // Verify we update both AbsSendTime extension header and HMAC. |
| 342 TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) { |
| 343 rtc::PacketTimeUpdateParams packet_time_params; |
| 344 packet_time_params.srtp_auth_key.assign(kTestKey, |
| 345 kTestKey + sizeof(kTestKey)); |
| 346 packet_time_params.srtp_auth_tag_len = 4; |
| 347 packet_time_params.rtp_sendtime_extension_id = 3; |
| 348 // 3 is also present in the test message. |
| 349 |
| 350 std::vector<uint8_t> rtp_packet(kRtpMsgWithAbsSendTimeExtension, |
| 351 kRtpMsgWithAbsSendTimeExtension + |
| 352 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 353 rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag)); |
| 354 EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(), |
| 355 packet_time_params, 51183266)); |
| 356 |
| 357 const uint8_t kExpectedTag[] = {0x81, 0xd1, 0x2c, 0x0e}; |
| 358 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 359 kExpectedTag, sizeof(kExpectedTag))); |
| 360 |
| 361 // Verify that the timestamp was updated. |
| 362 const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa}; |
| 363 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], kExpectedTimestamp, |
| 364 sizeof(kExpectedTimestamp))); |
| 365 } |
| 366 |
| 367 |
172 } // namespace cricket | 368 } // namespace cricket |
OLD | NEW |