diff --git a/call/call.cc b/call/call.cc index 4651b0be70..fb1d7cd3bc 100644 --- a/call/call.cc +++ b/call/call.cc @@ -47,7 +47,7 @@ #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" #include "modules/rtp_rtcp/source/byte_io.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/utility/include/process_thread.h" #include "modules/video_coding/fec_controller_default.h" #include "rtc_base/checks.h" @@ -144,11 +144,6 @@ std::unique_ptr CreateRtcLogStreamConfig( return rtclog_config; } -bool IsRtcp(const uint8_t* packet, size_t length) { - RtpUtility::RtpHeaderParser rtp_parser(packet, length); - return rtp_parser.RTCP(); -} - TaskQueueBase* GetCurrentTaskQueueOrThread() { TaskQueueBase* current = TaskQueueBase::Current(); if (!current) @@ -1606,7 +1601,7 @@ PacketReceiver::DeliveryStatus Call::DeliverPacket( MediaType media_type, rtc::CopyOnWriteBuffer packet, int64_t packet_time_us) { - if (IsRtcp(packet.cdata(), packet.size())) { + if (IsRtcpPacket(packet)) { RTC_DCHECK_RUN_ON(network_thread_); DeliverRtcp(media_type, std::move(packet)); return DELIVERY_OK; diff --git a/media/base/rtp_utils.cc b/media/base/rtp_utils.cc index 4714175226..3002e2d46c 100644 --- a/media/base/rtp_utils.cc +++ b/media/base/rtp_utils.cc @@ -17,6 +17,7 @@ // PacketTimeUpdateParams is defined in asyncpacketsocket.h. // TODO(sergeyu): Find more appropriate place for PacketTimeUpdateParams. #include "media/base/turn_utils.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "rtc_base/async_packet_socket.h" #include "rtc_base/byte_order.h" #include "rtc_base/checks.h" @@ -279,29 +280,6 @@ bool SetRtpHeader(void* data, size_t len, const RtpHeader& header) { SetRtpSsrc(data, len, header.ssrc)); } -static bool HasCorrectRtpVersion(rtc::ArrayView packet) { - return packet.data()[0] >> 6 == kRtpVersion; -} - -bool IsRtpPacket(rtc::ArrayView packet) { - return packet.size() >= kMinRtpPacketLen && - HasCorrectRtpVersion( - rtc::reinterpret_array_view(packet)); -} - -// Check the RTP payload type. If 63 < payload type < 96, it's RTCP. -// For additional details, see http://tools.ietf.org/html/rfc5761. -bool IsRtcpPacket(rtc::ArrayView packet) { - if (packet.size() < kMinRtcpPacketLen || - !HasCorrectRtpVersion( - rtc::reinterpret_array_view(packet))) { - return false; - } - - char pt = packet[1] & 0x7F; - return (63 < pt) && (pt < 96); -} - bool IsValidRtpPayloadType(int payload_type) { return payload_type >= 0 && payload_type <= 127; } @@ -327,11 +305,11 @@ absl::string_view RtpPacketTypeToString(RtpPacketType packet_type) { } RtpPacketType InferRtpPacketType(rtc::ArrayView packet) { - // RTCP packets are RTP packets so must check that first. - if (IsRtcpPacket(packet)) { + if (webrtc::IsRtcpPacket( + rtc::reinterpret_array_view(packet))) { return RtpPacketType::kRtcp; } - if (IsRtpPacket(packet)) { + if (webrtc::IsRtpPacket(rtc::reinterpret_array_view(packet))) { return RtpPacketType::kRtp; } return RtpPacketType::kUnknown; @@ -532,7 +510,7 @@ bool ApplyPacketOptions(uint8_t* data, // Making sure we have a valid RTP packet at the end. auto packet = rtc::MakeArrayView(data + rtp_start_pos, rtp_length); - if (!IsRtpPacket(rtc::reinterpret_array_view(packet)) || + if (!webrtc::IsRtpPacket(packet) || !ValidateRtpHeader(data + rtp_start_pos, rtp_length, nullptr)) { RTC_NOTREACHED(); return false; diff --git a/media/base/rtp_utils.h b/media/base/rtp_utils.h index 9ef9f9c7ba..7010248a7d 100644 --- a/media/base/rtp_utils.h +++ b/media/base/rtp_utils.h @@ -62,9 +62,6 @@ bool SetRtpSsrc(void* data, size_t len, uint32_t value); // Assumes version 2, no padding, no extensions, no csrcs. bool SetRtpHeader(void* data, size_t len, const RtpHeader& header); -bool IsRtpPacket(rtc::ArrayView packet); - -bool IsRtcpPacket(rtc::ArrayView packet); // Checks the packet header to determine if it can be an RTP or RTCP packet. RtpPacketType InferRtpPacketType(rtc::ArrayView packet); // True if |payload type| is 0-127. diff --git a/media/base/rtp_utils_unittest.cc b/media/base/rtp_utils_unittest.cc index a5e8a810f4..5674d18c3a 100644 --- a/media/base/rtp_utils_unittest.cc +++ b/media/base/rtp_utils_unittest.cc @@ -102,8 +102,6 @@ static const rtc::ArrayView kInvalidPacketArrayView = sizeof(kInvalidPacket)); TEST(RtpUtilsTest, GetRtp) { - EXPECT_TRUE(IsRtpPacket(kPcmuFrameArrayView)); - int pt; EXPECT_TRUE(GetRtpPayloadType(kPcmuFrame, sizeof(kPcmuFrame), &pt)); EXPECT_EQ(0, pt); diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 9766080360..f056df3651 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -52,6 +52,7 @@ rtc_library("rtp_rtcp_format") { "source/rtp_packet.h", "source/rtp_packet_received.h", "source/rtp_packet_to_send.h", + "source/rtp_util.h", "source/rtp_video_layers_allocation_extension.h", ] sources = [ @@ -96,6 +97,7 @@ rtc_library("rtp_rtcp_format") { "source/rtp_packet.cc", "source/rtp_packet_received.cc", "source/rtp_packet_to_send.cc", + "source/rtp_util.cc", "source/rtp_video_layers_allocation_extension.cc", ] @@ -548,6 +550,7 @@ if (rtc_include_tests) { "source/rtp_sender_unittest.cc", "source/rtp_sender_video_unittest.cc", "source/rtp_sequence_number_map_unittest.cc", + "source/rtp_util_unittest.cc", "source/rtp_utility_unittest.cc", "source/rtp_video_layers_allocation_extension_unittest.cc", "source/source_tracker_unittest.cc", diff --git a/modules/rtp_rtcp/source/rtp_util.cc b/modules/rtp_rtcp/source/rtp_util.cc new file mode 100644 index 0000000000..46c641ea2f --- /dev/null +++ b/modules/rtp_rtcp/source/rtp_util.cc @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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 "modules/rtp_rtcp/source/rtp_util.h" + +#include +#include + +#include "api/array_view.h" + +namespace webrtc { +namespace { + +constexpr uint8_t kRtpVersion = 2; +constexpr size_t kMinRtpPacketLen = 12; +constexpr size_t kMinRtcpPacketLen = 4; + +bool HasCorrectRtpVersion(rtc::ArrayView packet) { + return packet[0] >> 6 == kRtpVersion; +} + +// For additional details, see http://tools.ietf.org/html/rfc5761#section-4 +bool PayloadTypeIsReservedForRtcp(uint8_t payload_type) { + return 64 <= payload_type && payload_type < 96; +} + +} // namespace + +bool IsRtpPacket(rtc::ArrayView packet) { + return packet.size() >= kMinRtpPacketLen && HasCorrectRtpVersion(packet) && + !PayloadTypeIsReservedForRtcp(packet[1] & 0x7F); +} + +bool IsRtcpPacket(rtc::ArrayView packet) { + return packet.size() >= kMinRtcpPacketLen && HasCorrectRtpVersion(packet) && + PayloadTypeIsReservedForRtcp(packet[1] & 0x7F); +} + +} // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_util.h b/modules/rtp_rtcp/source/rtp_util.h new file mode 100644 index 0000000000..b85727bf47 --- /dev/null +++ b/modules/rtp_rtcp/source/rtp_util.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef MODULES_RTP_RTCP_SOURCE_RTP_UTIL_H_ +#define MODULES_RTP_RTCP_SOURCE_RTP_UTIL_H_ + +#include + +#include "api/array_view.h" + +namespace webrtc { + +bool IsRtcpPacket(rtc::ArrayView packet); +bool IsRtpPacket(rtc::ArrayView packet); + +} // namespace webrtc + +#endif // MODULES_RTP_RTCP_SOURCE_RTP_UTIL_H_ diff --git a/modules/rtp_rtcp/source/rtp_util_unittest.cc b/modules/rtp_rtcp/source/rtp_util_unittest.cc new file mode 100644 index 0000000000..8f980ecff1 --- /dev/null +++ b/modules/rtp_rtcp/source/rtp_util_unittest.cc @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 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 "modules/rtp_rtcp/source/rtp_util.h" + +#include "test/gmock.h" + +namespace webrtc { +namespace { + +TEST(RtpUtil, IsRtpPacket) { + constexpr uint8_t kMinimalisticRtpPacket[] = {0x80, 97, 0, 0, // + 0, 0, 0, 0, // + 0, 0, 0, 0}; + EXPECT_TRUE(IsRtpPacket(kMinimalisticRtpPacket)); + + constexpr uint8_t kWrongRtpVersion[] = {0xc0, 97, 0, 0, // + 0, 0, 0, 0, // + 0, 0, 0, 0}; + EXPECT_FALSE(IsRtpPacket(kWrongRtpVersion)); + + constexpr uint8_t kPacketWithPayloadForRtcp[] = {0x80, 200, 0, 0, // + 0, 0, 0, 0, // + 0, 0, 0, 0}; + EXPECT_FALSE(IsRtpPacket(kPacketWithPayloadForRtcp)); + + constexpr uint8_t kTooSmallRtpPacket[] = {0x80, 97, 0, 0, // + 0, 0, 0, 0, // + 0, 0, 0}; + EXPECT_FALSE(IsRtpPacket(kTooSmallRtpPacket)); + + EXPECT_FALSE(IsRtpPacket({})); +} + +TEST(RtpUtil, IsRtcpPacket) { + constexpr uint8_t kMinimalisticRtcpPacket[] = {0x80, 202, 0, 0}; + EXPECT_TRUE(IsRtcpPacket(kMinimalisticRtcpPacket)); + + constexpr uint8_t kWrongRtpVersion[] = {0xc0, 202, 0, 0}; + EXPECT_FALSE(IsRtcpPacket(kWrongRtpVersion)); + + constexpr uint8_t kPacketWithPayloadForRtp[] = {0x80, 225, 0, 0}; + EXPECT_FALSE(IsRtcpPacket(kPacketWithPayloadForRtp)); + + constexpr uint8_t kTooSmallRtcpPacket[] = {0x80, 202, 0}; + EXPECT_FALSE(IsRtcpPacket(kTooSmallRtcpPacket)); + + EXPECT_FALSE(IsRtcpPacket({})); +} + +} // namespace +} // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_utility.h b/modules/rtp_rtcp/source/rtp_utility.h index cdda9ef119..cdfff4072f 100644 --- a/modules/rtp_rtcp/source/rtp_utility.h +++ b/modules/rtp_rtcp/source/rtp_utility.h @@ -15,6 +15,7 @@ #include +#include "absl/base/attributes.h" #include "absl/strings/string_view.h" #include "api/rtp_headers.h" #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" @@ -34,6 +35,7 @@ class RtpHeaderParser { RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength); ~RtpHeaderParser(); + ABSL_DEPRECATED("Use IsRtpPacket or IsRtcpPacket") bool RTCP() const; bool ParseRtcp(RTPHeader* header) const; bool Parse(RTPHeader* parsedPacket, diff --git a/test/BUILD.gn b/test/BUILD.gn index 77f003cfbe..82d0b9ea28 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -736,7 +736,6 @@ rtc_library("direct_transport") { "direct_transport.h", ] deps = [ - ":rtp_test_utils", "../api:sequence_checker", "../api:simulated_network_api", "../api:transport_api", @@ -744,6 +743,7 @@ rtc_library("direct_transport") { "../api/units:time_delta", "../call:call_interfaces", "../call:simulated_packet_receiver", + "../modules/rtp_rtcp:rtp_rtcp_format", "../rtc_base:macromagic", "../rtc_base:timeutils", "../rtc_base/synchronization:mutex", @@ -848,9 +848,9 @@ rtc_library("test_common") { ":fake_video_codecs", ":fileutils", ":mock_transport", - ":rtp_test_utils", ":test_support", ":video_test_common", + "../api:array_view", "../api:create_frame_generator", "../api:frame_generator_api", "../api:rtp_headers", diff --git a/test/direct_transport.cc b/test/direct_transport.cc index 9c7a8f88d0..7e9c5aefeb 100644 --- a/test/direct_transport.cc +++ b/test/direct_transport.cc @@ -14,9 +14,9 @@ #include "api/units/time_delta.h" #include "call/call.h" #include "call/fake_network_pipe.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "rtc_base/task_utils/repeating_task.h" #include "rtc_base/time_utils.h" -#include "test/rtp_header_parser.h" namespace webrtc { namespace test { @@ -26,7 +26,7 @@ Demuxer::Demuxer(const std::map& payload_type_map) MediaType Demuxer::GetMediaType(const uint8_t* packet_data, const size_t packet_length) const { - if (!RtpHeaderParser::IsRtcp(packet_data, packet_length)) { + if (IsRtpPacket(rtc::MakeArrayView(packet_data, packet_length))) { RTC_CHECK_GE(packet_length, 2); const uint8_t payload_type = packet_data[1] & 0x7f; std::map::const_iterator it = diff --git a/test/direct_transport_unittest.cc b/test/direct_transport_unittest.cc index 66ab5bcac1..ab00971089 100644 --- a/test/direct_transport_unittest.cc +++ b/test/direct_transport_unittest.cc @@ -18,12 +18,13 @@ namespace test { TEST(DemuxerTest, Demuxing) { constexpr uint8_t kVideoPayloadType = 100; constexpr uint8_t kAudioPayloadType = 101; - constexpr size_t kPacketSize = 10; + constexpr size_t kPacketSize = 12; Demuxer demuxer({{kVideoPayloadType, MediaType::VIDEO}, {kAudioPayloadType, MediaType::AUDIO}}); uint8_t data[kPacketSize]; memset(data, 0, kPacketSize); + data[0] = 0x80; data[1] = kVideoPayloadType; EXPECT_EQ(demuxer.GetMediaType(data, kPacketSize), MediaType::VIDEO); data[1] = kAudioPayloadType; diff --git a/test/fuzzers/rtp_header_parser_fuzzer.cc b/test/fuzzers/rtp_header_parser_fuzzer.cc index cb5bea2456..435c64bbb4 100644 --- a/test/fuzzers/rtp_header_parser_fuzzer.cc +++ b/test/fuzzers/rtp_header_parser_fuzzer.cc @@ -20,7 +20,6 @@ namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { - RtpHeaderParser::IsRtcp(data, size); RtpHeaderParser::GetSsrc(data, size); } diff --git a/test/peer_scenario/tests/remote_estimate_test.cc b/test/peer_scenario/tests/remote_estimate_test.cc index b882ad9dc2..f1d8345fde 100644 --- a/test/peer_scenario/tests/remote_estimate_test.cc +++ b/test/peer_scenario/tests/remote_estimate_test.cc @@ -8,6 +8,7 @@ * be found in the AUTHORS file in the root of the source tree. */ +#include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/rtp_rtcp/source/rtp_utility.h" #include "pc/media_session.h" #include "pc/session_description.h" @@ -29,7 +30,7 @@ absl::optional GetRtpPacketExtensions( const rtc::ArrayView packet, const RtpHeaderExtensionMap& extension_map) { RtpUtility::RtpHeaderParser rtp_parser(packet.data(), packet.size()); - if (!rtp_parser.RTCP()) { + if (IsRtpPacket(packet)) { RTPHeader header; if (rtp_parser.Parse(&header, &extension_map, true)) { return header.extension; diff --git a/test/peer_scenario/tests/unsignaled_stream_test.cc b/test/peer_scenario/tests/unsignaled_stream_test.cc index edcfb36ea3..e0fe02edcf 100644 --- a/test/peer_scenario/tests/unsignaled_stream_test.cc +++ b/test/peer_scenario/tests/unsignaled_stream_test.cc @@ -10,15 +10,14 @@ #include "media/base/stream_params.h" #include "modules/rtp_rtcp/source/byte_io.h" - +#include "modules/rtp_rtcp/source/rtp_util.h" #include "pc/media_session.h" #include "pc/session_description.h" #include "test/field_trial.h" -#include "test/peer_scenario/peer_scenario.h" -#include "test/rtp_header_parser.h" - #include "test/gmock.h" #include "test/gtest.h" +#include "test/peer_scenario/peer_scenario.h" +#include "test/rtp_header_parser.h" namespace webrtc { namespace test { @@ -184,51 +183,48 @@ TEST_P(UnsignaledStreamTest, ReplacesUnsignaledStreamOnCompletedSignaling) { second_ssrc = first_ssrc + 1; send_node->router()->SetWatcher([&](const EmulatedIpPacket& packet) { - if (packet.size() > 1 && packet.cdata()[0] >> 6 == 2 && - !RtpHeaderParser::IsRtcp(packet.data.cdata(), - packet.data.size())) { - if (ByteReader::ReadBigEndian(&(packet.cdata()[8])) == - first_ssrc && - !got_unsignaled_packet) { - // Parse packet and modify the SSRC to simulate a second m= - // section that has not been negotiated yet. - std::vector extensions; - extensions.emplace_back(RtpExtension::kMidUri, - mid_header_extension_id.value()); - RtpHeaderExtensionMap extensions_map(extensions); - RtpPacket parsed_packet; - parsed_packet.IdentifyExtensions(extensions_map); - ASSERT_TRUE(parsed_packet.Parse(packet.data)); - parsed_packet.SetSsrc(second_ssrc); - // The MID extension is present if and only if it was negotiated. - // If present, we either want to remove it or modify it depending - // on setup. - switch (kMidTestConfiguration) { - case MidTestConfiguration::kMidNotNegotiated: - EXPECT_FALSE(parsed_packet.HasExtension()); - break; - case MidTestConfiguration::kMidNegotiatedButMissingFromPackets: - EXPECT_TRUE(parsed_packet.HasExtension()); - ASSERT_TRUE(parsed_packet.RemoveExtension(RtpMid::kId)); - break; - case MidTestConfiguration::kMidNegotiatedAndPresentInPackets: - EXPECT_TRUE(parsed_packet.HasExtension()); - // The simulated second m= section would have a different MID. - // If we don't modify it here then |second_ssrc| would end up - // being mapped to the first m= section which would cause SSRC - // conflicts if we later add the same SSRC to a second m= - // section. Hidden assumption: first m= section does not use - // MID:1. - ASSERT_TRUE(parsed_packet.SetExtension("1")); - break; - } - // Inject the modified packet. - rtc::CopyOnWriteBuffer updated_buffer = parsed_packet.Buffer(); - EmulatedIpPacket updated_packet( - packet.from, packet.to, updated_buffer, packet.arrival_time); - send_node->OnPacketReceived(std::move(updated_packet)); - got_unsignaled_packet = true; + if (IsRtpPacket(packet.data) && + ByteReader::ReadBigEndian(&(packet.cdata()[8])) == + first_ssrc && + !got_unsignaled_packet) { + // Parse packet and modify the SSRC to simulate a second m= + // section that has not been negotiated yet. + std::vector extensions; + extensions.emplace_back(RtpExtension::kMidUri, + mid_header_extension_id.value()); + RtpHeaderExtensionMap extensions_map(extensions); + RtpPacket parsed_packet; + parsed_packet.IdentifyExtensions(extensions_map); + ASSERT_TRUE(parsed_packet.Parse(packet.data)); + parsed_packet.SetSsrc(second_ssrc); + // The MID extension is present if and only if it was negotiated. + // If present, we either want to remove it or modify it depending + // on setup. + switch (kMidTestConfiguration) { + case MidTestConfiguration::kMidNotNegotiated: + EXPECT_FALSE(parsed_packet.HasExtension()); + break; + case MidTestConfiguration::kMidNegotiatedButMissingFromPackets: + EXPECT_TRUE(parsed_packet.HasExtension()); + ASSERT_TRUE(parsed_packet.RemoveExtension(RtpMid::kId)); + break; + case MidTestConfiguration::kMidNegotiatedAndPresentInPackets: + EXPECT_TRUE(parsed_packet.HasExtension()); + // The simulated second m= section would have a different MID. + // If we don't modify it here then |second_ssrc| would end up + // being mapped to the first m= section which would cause SSRC + // conflicts if we later add the same SSRC to a second m= + // section. Hidden assumption: first m= section does not use + // MID:1. + ASSERT_TRUE(parsed_packet.SetExtension("1")); + break; } + // Inject the modified packet. + rtc::CopyOnWriteBuffer updated_buffer = parsed_packet.Buffer(); + EmulatedIpPacket updated_packet( + packet.from, packet.to, updated_buffer, packet.arrival_time); + send_node->OnPacketReceived(std::move(updated_packet)); + got_unsignaled_packet = true; } }); }, diff --git a/test/rtp_file_reader.cc b/test/rtp_file_reader.cc index cc5f6f78a2..1e268cf673 100644 --- a/test/rtp_file_reader.cc +++ b/test/rtp_file_reader.cc @@ -17,6 +17,7 @@ #include #include +#include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/rtp_rtcp/source/rtp_utility.h" #include "rtc_base/checks.h" #include "rtc_base/constructor_magic.h" @@ -434,7 +435,7 @@ class PcapReader : public RtpFileReaderImpl { TRY_PCAP(Read(read_buffer_, marker.payload_length)); RtpUtility::RtpHeaderParser rtp_parser(read_buffer_, marker.payload_length); - if (rtp_parser.RTCP()) { + if (IsRtcpPacket(rtc::MakeArrayView(read_buffer_, marker.payload_length))) { rtp_parser.ParseRtcp(&marker.rtp_header); packets_.push_back(marker); } else { diff --git a/test/rtp_header_parser.cc b/test/rtp_header_parser.cc index 6a7df4b095..48e493ddeb 100644 --- a/test/rtp_header_parser.cc +++ b/test/rtp_header_parser.cc @@ -13,11 +13,6 @@ namespace webrtc { -bool RtpHeaderParser::IsRtcp(const uint8_t* packet, size_t length) { - RtpUtility::RtpHeaderParser rtp_parser(packet, length); - return rtp_parser.RTCP(); -} - absl::optional RtpHeaderParser::GetSsrc(const uint8_t* packet, size_t length) { RtpUtility::RtpHeaderParser rtp_parser(packet, length); diff --git a/test/rtp_header_parser.h b/test/rtp_header_parser.h index ca4eaf657c..f6ed74c043 100644 --- a/test/rtp_header_parser.h +++ b/test/rtp_header_parser.h @@ -19,8 +19,6 @@ namespace webrtc { class RtpHeaderParser { public: - // Returns true if the packet is an RTCP packet, false otherwise. - static bool IsRtcp(const uint8_t* packet, size_t length); static absl::optional GetSsrc(const uint8_t* packet, size_t length); }; } // namespace webrtc diff --git a/test/rtp_rtcp_observer.h b/test/rtp_rtcp_observer.h index 036f5cdc20..f17560f021 100644 --- a/test/rtp_rtcp_observer.h +++ b/test/rtp_rtcp_observer.h @@ -15,14 +15,15 @@ #include #include +#include "api/array_view.h" #include "api/test/simulated_network.h" #include "call/simulated_packet_receiver.h" #include "call/video_send_stream.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "rtc_base/event.h" #include "system_wrappers/include/field_trial.h" #include "test/direct_transport.h" #include "test/gtest.h" -#include "test/rtp_header_parser.h" namespace { const int kShortTimeoutMs = 500; @@ -98,7 +99,7 @@ class PacketTransport : public test::DirectTransport { bool SendRtp(const uint8_t* packet, size_t length, const PacketOptions& options) override { - EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length)); + EXPECT_TRUE(IsRtpPacket(rtc::MakeArrayView(packet, length))); RtpRtcpObserver::Action action; { if (transport_type_ == kSender) { @@ -118,7 +119,7 @@ class PacketTransport : public test::DirectTransport { } bool SendRtcp(const uint8_t* packet, size_t length) override { - EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length)); + EXPECT_TRUE(IsRtcpPacket(rtc::MakeArrayView(packet, length))); RtpRtcpObserver::Action action; { if (transport_type_ == kSender) { diff --git a/test/scenario/call_client.cc b/test/scenario/call_client.cc index cebfc0be0d..be8d39f2a5 100644 --- a/test/scenario/call_client.cc +++ b/test/scenario/call_client.cc @@ -17,6 +17,7 @@ #include "api/rtc_event_log/rtc_event_log_factory.h" #include "api/transport/network_types.h" #include "modules/audio_mixer/audio_mixer_impl.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "test/rtp_header_parser.h" namespace webrtc { @@ -293,7 +294,7 @@ void CallClient::UpdateBitrateConstraints( void CallClient::OnPacketReceived(EmulatedIpPacket packet) { MediaType media_type = MediaType::ANY; - if (!RtpHeaderParser::IsRtcp(packet.cdata(), packet.data.size())) { + if (IsRtpPacket(packet.data)) { auto ssrc = RtpHeaderParser::GetSsrc(packet.cdata(), packet.data.size()); RTC_CHECK(ssrc.has_value()); media_type = ssrc_media_types_[*ssrc]; diff --git a/video/end_to_end_tests/ssrc_tests.cc b/video/end_to_end_tests/ssrc_tests.cc index 0c26311e92..bdca05d647 100644 --- a/video/end_to_end_tests/ssrc_tests.cc +++ b/video/end_to_end_tests/ssrc_tests.cc @@ -14,6 +14,7 @@ #include "call/fake_network_pipe.h" #include "call/simulated_network.h" #include "modules/rtp_rtcp/source/rtp_packet.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "rtc_base/task_queue_for_test.h" #include "test/call_test.h" #include "test/gtest.h" @@ -60,7 +61,7 @@ TEST_F(SsrcEndToEndTest, UnknownRtpPacketGivesUnknownSsrcReturnCode) { DeliveryStatus DeliverPacket(MediaType media_type, rtc::CopyOnWriteBuffer packet, int64_t packet_time_us) override { - if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) { + if (IsRtcpPacket(packet)) { return receiver_->DeliverPacket(media_type, std::move(packet), packet_time_us); } diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc index 81dcf055b8..96553335dd 100644 --- a/video/video_analyzer.cc +++ b/video/video_analyzer.cc @@ -18,6 +18,7 @@ #include "common_video/libyuv/include/webrtc_libyuv.h" #include "modules/rtp_rtcp/source/create_video_rtp_depacketizer.h" #include "modules/rtp_rtcp/source/rtp_packet.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "rtc_base/cpu_time.h" #include "rtc_base/format_macros.h" #include "rtc_base/memory_usage.h" @@ -212,7 +213,7 @@ PacketReceiver::DeliveryStatus VideoAnalyzer::DeliverPacket( int64_t packet_time_us) { // Ignore timestamps of RTCP packets. They're not synchronized with // RTP packet timestamps and so they would confuse wrap_handler_. - if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) { + if (IsRtcpPacket(packet)) { return receiver_->DeliverPacket(media_type, std::move(packet), packet_time_us); } diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc index 9f9b8c16da..0bda716d73 100644 --- a/video/video_send_stream_tests.cc +++ b/video/video_send_stream_tests.cc @@ -30,6 +30,7 @@ #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "modules/rtp_rtcp/source/rtp_packet.h" #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" +#include "modules/rtp_rtcp/source/rtp_util.h" #include "modules/rtp_rtcp/source/video_rtp_depacketizer_vp9.h" #include "modules/video_coding/codecs/vp8/include/vp8.h" #include "modules/video_coding/codecs/vp9/include/vp9.h" @@ -57,7 +58,6 @@ #include "test/gtest.h" #include "test/null_transport.h" #include "test/rtcp_packet_parser.h" -#include "test/rtp_header_parser.h" #include "test/testsupport/perf_test.h" #include "test/video_encoder_proxy_factory.h" #include "video/send_statistics_proxy.h" @@ -1467,7 +1467,7 @@ TEST_F(VideoSendStreamTest, MinTransmitBitrateRespectsRemb) { private: Action OnSendRtp(const uint8_t* packet, size_t length) override { - if (RtpHeaderParser::IsRtcp(packet, length)) + if (IsRtcpPacket(rtc::MakeArrayView(packet, length))) return DROP_PACKET; RtpPacket rtp_packet;