/*
* 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 .
*/
#include "media/base/rtp_utils.h"
#include <cstdint>
#include <cstring>
#include "media/base/fake_rtp.h"
#include "test/gtest.h"
namespace webrtc {
namespace {
const uint8_t kInvalidPacket[] = {0 x80, 0 x00};
// PT = 206, FMT = 1, Sender SSRC = 0x1111, Media SSRC = 0x1111
// No FCI information is needed for PLI.
const uint8_t kNonCompoundRtcpPliFeedbackPacket[] = {
0 x81, 0 xCE, 0 x00, 0 x0C, 0 x00, 0 x00, 0 x11, 0 x11, 0 x00, 0 x00, 0 x11, 0 x11};
// Packet has only mandatory fixed RTCP header
// PT = 204, SSRC = 0x1111
const uint8_t kNonCompoundRtcpAppPacket[] = {0 x81, 0 xCC, 0 x00, 0 x0C,
0 x00, 0 x00, 0 x11, 0 x11};
// PT = 202, Source count = 0
const uint8_t kNonCompoundRtcpSDESPacket[] = {0 x80, 0 xCA, 0 x00, 0 x00};
// Valid rtp Message with 2 byte header extension.
uint8_t kRtpMsgWith2ByteExtnHeader[] = {
// clang-format off
// clang formatting doesn't respect inline comments.
0 x90, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00,
0 xAA, 0 xBB, 0 xCC, 0 XDD, // SSRC
0 x10, 0 x00, 0 x00, 0 x01, // 2 Byte header extension
0 x01, 0 x00, 0 x00, 0 x00
// clang-format on
};
// RTP packet with two one-byte header extensions. The last 4 bytes consist of
// abs-send-time with extension id = 3 and length = 3.
uint8_t kRtpMsgWithOneByteAbsSendTimeExtension[] = {
0 x90, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 xBE, 0 xDE, 0 x00, 0 x02, 0 x22, 0 x00, 0 x02, 0 x1c, 0 x32, 0 xaa, 0 xbb, 0 xcc,
};
// RTP packet with two two-byte header extensions. The last 5 bytes consist of
// abs-send-time with extension id = 3 and length = 3.
uint8_t kRtpMsgWithTwoByteAbsSendTimeExtension[] = {
0 x90, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x10, 0 x00, 0 x00, 0 x02, 0 x02, 0 x01, 0 x02, 0 x03, 0 x03, 0 xaa, 0 xbb, 0 xcc,
};
} // namespace
TEST(RtpUtilsTest, GetRtcp) {
int pt;
EXPECT_TRUE(GetRtcpType(kRtcpReport, sizeof (kRtcpReport), &pt));
EXPECT_EQ(0 xc9, pt);
EXPECT_FALSE(GetRtcpType(kInvalidPacket, sizeof (kInvalidPacket), &pt));
uint32_t ssrc;
EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpPliFeedbackPacket,
sizeof (kNonCompoundRtcpPliFeedbackPacket), &ssrc));
EXPECT_TRUE(GetRtcpSsrc(kNonCompoundRtcpAppPacket,
sizeof (kNonCompoundRtcpAppPacket), &ssrc));
EXPECT_FALSE(GetRtcpSsrc(kNonCompoundRtcpSDESPacket,
sizeof (kNonCompoundRtcpSDESPacket), &ssrc));
}
TEST(RtpUtilsTest, InferRtpPacketType) {
EXPECT_EQ(RtpPacketType::kRtp, InferRtpPacketType(kPcmuFrame));
EXPECT_EQ(RtpPacketType::kRtcp, InferRtpPacketType(kRtcpReport));
EXPECT_EQ(RtpPacketType::kUnknown, InferRtpPacketType(kInvalidPacket));
}
// Invalid RTP packets.
TEST(RtpUtilsTest, InvalidRtpHeader) {
// Rtp message with invalid length.
const uint8_t kRtpMsgWithInvalidLength[] = {
// clang-format off
// clang formatting doesn't respect inline comments.
0 x94, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 xAA, 0 xBB, 0 xCC, 0 XDD, // SSRC
0 xDD, 0 xCC, 0 xBB, 0 xAA, // Only 1 CSRC, but CC count is 4.
// clang-format on
};
EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidLength, nullptr));
// Rtp message with single byte header extension, invalid extension length.
const uint8_t kRtpMsgWithInvalidExtnLength[] = {
0 x90, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 xBE, 0 xDE, 0 x0A, 0 x00, // Extn length - 0x0A00
};
EXPECT_FALSE(ValidateRtpHeader(kRtpMsgWithInvalidExtnLength,
nullptr));
}
// Valid RTP packet with a 2byte header extension.
TEST(RtpUtilsTest, Valid2ByteExtnHdrRtpMessage) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWith2ByteExtnHeader, nullptr));
}
// Valid RTP packet which has 1 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithOneByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithOneByteAbsSendTimeExtension,
nullptr));
}
// Valid RTP packet which has 2 byte header AbsSendTime extension in it.
TEST(RtpUtilsTest, ValidRtpPacketWithTwoByteAbsSendTimeExtension) {
EXPECT_TRUE(ValidateRtpHeader(kRtpMsgWithTwoByteAbsSendTimeExtension,
nullptr));
}
} // namespace webrtc
Messung V0.5 in Prozent C=81 H=100 G=90
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-27)
¤
*© Formatika GbR, Deutschland