/* * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// RTP packet with two one-byte header extensions. The last 4 bytes consist of // abs-send-time with extension id = 3 and length = 3. static uint8_t kRtpMsgWithOneByteAbsSendTimeExtension[] = {
0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xBE, 0xDE, 0x00, 0x02, 0x22, 0x00, 0x02, 0x1c, 0x32, 0xaa, 0xbb, 0xcc,
};
// RTP packet with two two-byte header extensions. The last 5 bytes consist of // abs-send-time with extension id = 3 and length = 3. static uint8_t kRtpMsgWithTwoByteAbsSendTimeExtension[] = {
0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x02, 0x02, 0x01, 0x02, 0x03, 0x03, 0xaa, 0xbb, 0xcc,
};
// Index of AbsSendTimeExtn data in message // `kRtpMsgWithOneByteAbsSendTimeExtension`. staticconstint kAstIndexInOneByteRtpMsg = 21; // and in message `kRtpMsgWithTwoByteAbsSendTimeExtension`. staticconstint kAstIndexInTwoByteRtpMsg = 21;
// Valid RTP packet with a 2byte header extension.
TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader, sizeof(kRtpMsgWith2ByteExtnHeader), nullptr));
}
// Valid RTP packet which has 1 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithOneByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithOneByteAbsSendTimeExtension, sizeof(kRtpMsgWithOneByteAbsSendTimeExtension),
nullptr));
}
// Valid RTP packet which has 2 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithTwoByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithTwoByteAbsSendTimeExtension, sizeof(kRtpMsgWithTwoByteAbsSendTimeExtension),
nullptr));
}
// Verify finding an extension ID in the TURN send indication message.
TEST(RtpUtilsTest, UpdateAbsSendTimeExtensionInTurnSendIndication) { // A valid STUN indication message with a valid RTP header in data attribute // payload field and no extension bit set.
uint8_t message_without_extension[] = { // clang-format off // clang formatting doesn't respect inline comments.
0x00, 0x16, 0x00, 0x18, // length of
0x21, 0x12, 0xA4, 0x42, // magic cookie '0', '1', '2', '3', // transaction id '4', '5', '6', '7', '8', '9', 'a', 'b',
0x00, 0x20, 0x00, 0x04, // Mapped address.
0x00, 0x00, 0x00, 0x00,
0x00, 0x13, 0x00, 0x0C, // Data attribute.
0x80, 0x00, 0x00, 0x00, // RTP packet.
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, // clang-format on
};
EXPECT_TRUE(UpdateRtpAbsSendTimeExtension(
message_without_extension, sizeof(message_without_extension), 3, 0));
// Test without any packet options variables set. This method should return // without HMAC value in the packet.
TEST(RtpUtilsTest, ApplyPacketOptionsWithDefaultValues) {
rtc::PacketTimeUpdateParams packet_time_params;
std::vector<uint8_t> rtp_packet(
kRtpMsgWithOneByteAbsSendTimeExtension,
kRtpMsgWithOneByteAbsSendTimeExtension + sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
rtp_packet.insert(rtp_packet.end(), kFakeTag, kFakeTag + sizeof(kFakeTag));
EXPECT_TRUE(ApplyPacketOptions(&rtp_packet[0], rtp_packet.size(),
packet_time_params, 0));
// Making sure HMAC wasn't updated..
EXPECT_EQ(0,
memcmp(&rtp_packet[sizeof(kRtpMsgWithOneByteAbsSendTimeExtension)],
kFakeTag, 4));
// Verify AbsouluteSendTime extension field is not modified.
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInOneByteRtpMsg], kTestAstValue, sizeof(kTestAstValue)));
}
// Verify finding an extension ID in a raw rtp message.
TEST(RtpUtilsTest, UpdateOneByteAbsSendTimeExtensionInRtpPacket) {
std::vector<uint8_t> rtp_packet(
kRtpMsgWithOneByteAbsSendTimeExtension,
kRtpMsgWithOneByteAbsSendTimeExtension + sizeof(kRtpMsgWithOneByteAbsSendTimeExtension));
// Verify that the timestamp was updated. const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInOneByteRtpMsg], kExpectedTimestamp, sizeof(kExpectedTimestamp)));
}
// Verify finding an extension ID in a raw rtp message.
TEST(RtpUtilsTest, UpdateTwoByteAbsSendTimeExtensionInRtpPacket) {
std::vector<uint8_t> rtp_packet(
kRtpMsgWithTwoByteAbsSendTimeExtension,
kRtpMsgWithTwoByteAbsSendTimeExtension + sizeof(kRtpMsgWithTwoByteAbsSendTimeExtension));
// Verify that the timestamp was updated. const uint8_t kExpectedTimestamp[3] = {0xcc, 0xbb, 0xaa};
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInTwoByteRtpMsg], kExpectedTimestamp, sizeof(kExpectedTimestamp)));
}
// Verify we update both AbsSendTime extension header and HMAC.
TEST(RtpUtilsTest, ApplyPacketOptionsWithAuthParamsAndAbsSendTime) {
rtc::PacketTimeUpdateParams packet_time_params;
packet_time_params.srtp_auth_key.assign(kTestKey,
kTestKey + sizeof(kTestKey));
packet_time_params.srtp_auth_tag_len = 4;
packet_time_params.rtp_sendtime_extension_id = 3; // 3 is also present in the test message.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.