Move helpers to parse base rtp packet fields to rtp_rtcp module
rtp_rtcp_format is lighter build target than rtc_media_base and a more natural place to keep rtp parsing functions. Bug: None Change-Id: Ibcb5661cc65edbdc89a63f3e411d7ad1218353cc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/226330 Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34504}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
4261a73b56
commit
99a71f49c0
@ -14,6 +14,8 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "api/array_view.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
@ -43,4 +45,19 @@ bool IsRtcpPacket(rtc::ArrayView<const uint8_t> packet) {
|
||||
PayloadTypeIsReservedForRtcp(packet[1] & 0x7F);
|
||||
}
|
||||
|
||||
int ParseRtpPayloadType(rtc::ArrayView<const uint8_t> rtp_packet) {
|
||||
RTC_DCHECK(IsRtpPacket(rtp_packet));
|
||||
return rtp_packet[1] & 0x7F;
|
||||
}
|
||||
|
||||
uint16_t ParseRtpSequenceNumber(rtc::ArrayView<const uint8_t> rtp_packet) {
|
||||
RTC_DCHECK(IsRtpPacket(rtp_packet));
|
||||
return ByteReader<uint16_t>::ReadBigEndian(rtp_packet.data() + 2);
|
||||
}
|
||||
|
||||
uint32_t ParseRtpSsrc(rtc::ArrayView<const uint8_t> rtp_packet) {
|
||||
RTC_DCHECK(IsRtpPacket(rtp_packet));
|
||||
return ByteReader<uint32_t>::ReadBigEndian(rtp_packet.data() + 8);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -20,6 +20,12 @@ namespace webrtc {
|
||||
bool IsRtcpPacket(rtc::ArrayView<const uint8_t> packet);
|
||||
bool IsRtpPacket(rtc::ArrayView<const uint8_t> packet);
|
||||
|
||||
// Returns base rtp header fields of the rtp packet.
|
||||
// Behaviour is undefined when `!IsRtpPacket(rtp_packet)`.
|
||||
int ParseRtpPayloadType(rtc::ArrayView<const uint8_t> rtp_packet);
|
||||
uint16_t ParseRtpSequenceNumber(rtc::ArrayView<const uint8_t> rtp_packet);
|
||||
uint32_t ParseRtpSsrc(rtc::ArrayView<const uint8_t> rtp_packet);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_RTP_RTCP_SOURCE_RTP_UTIL_H_
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
namespace webrtc {
|
||||
namespace {
|
||||
|
||||
TEST(RtpUtil, IsRtpPacket) {
|
||||
TEST(RtpUtilTest, IsRtpPacket) {
|
||||
constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, //
|
||||
0, 0, 0, 0, //
|
||||
0, 0, 0, 0};
|
||||
@ -39,7 +39,7 @@ TEST(RtpUtil, IsRtpPacket) {
|
||||
EXPECT_FALSE(IsRtpPacket({}));
|
||||
}
|
||||
|
||||
TEST(RtpUtil, IsRtcpPacket) {
|
||||
TEST(RtpUtilTest, IsRtcpPacket) {
|
||||
constexpr uint8_t kMinimalisticRtcpPacket[] = {0x80, 202, 0, 0};
|
||||
EXPECT_TRUE(IsRtcpPacket(kMinimalisticRtcpPacket));
|
||||
|
||||
@ -55,5 +55,32 @@ TEST(RtpUtil, IsRtcpPacket) {
|
||||
EXPECT_FALSE(IsRtcpPacket({}));
|
||||
}
|
||||
|
||||
TEST(RtpUtilTest, ParseRtpPayloadType) {
|
||||
constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, //
|
||||
0, 0, 0, 0, //
|
||||
0x12, 0x34, 0x56, 0x78};
|
||||
EXPECT_EQ(ParseRtpPayloadType(kMinimalisticRtpPacket), 97);
|
||||
|
||||
constexpr uint8_t kMinimalisticRtpPacketWithMarker[] = {
|
||||
0x80, 0x80 | 97, 0, 0, //
|
||||
0, 0, 0, 0, //
|
||||
0x12, 0x34, 0x56, 0x78};
|
||||
EXPECT_EQ(ParseRtpPayloadType(kMinimalisticRtpPacketWithMarker), 97);
|
||||
}
|
||||
|
||||
TEST(RtpUtilTest, ParseRtpSequenceNumber) {
|
||||
constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0x12, 0x34, //
|
||||
0, 0, 0, 0, //
|
||||
0, 0, 0, 0};
|
||||
EXPECT_EQ(ParseRtpSequenceNumber(kMinimalisticRtpPacket), 0x1234);
|
||||
}
|
||||
|
||||
TEST(RtpUtilTest, ParseRtpSsrc) {
|
||||
constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, //
|
||||
0, 0, 0, 0, //
|
||||
0x12, 0x34, 0x56, 0x78};
|
||||
EXPECT_EQ(ParseRtpSsrc(kMinimalisticRtpPacket), 0x12345678u);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user