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