diff --git a/modules/audio_coding/BUILD.gn b/modules/audio_coding/BUILD.gn index d1d17267e5..79148063b9 100644 --- a/modules/audio_coding/BUILD.gn +++ b/modules/audio_coding/BUILD.gn @@ -1106,7 +1106,6 @@ rtc_library("neteq_test_tools") { "../../rtc_base:rtc_base_approved", "../../rtc_base/system:arch", "../../test:rtp_test_utils", - "../rtp_rtcp", "../rtp_rtcp:rtp_rtcp_format", ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] diff --git a/modules/audio_coding/neteq/tools/rtp_file_source.h b/modules/audio_coding/neteq/tools/rtp_file_source.h index 3777e52bb7..d6aab24abc 100644 --- a/modules/audio_coding/neteq/tools/rtp_file_source.h +++ b/modules/audio_coding/neteq/tools/rtp_file_source.h @@ -19,7 +19,6 @@ #include "absl/types/optional.h" #include "modules/audio_coding/neteq/tools/packet_source.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" #include "rtc_base/constructor_magic.h" namespace webrtc { diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 9d78cf37c8..d11a2196a7 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -211,8 +211,6 @@ rtc_library("rtp_rtcp") { "source/rtp_sender_video_frame_transformer_delegate.h", "source/rtp_sequence_number_map.cc", "source/rtp_sequence_number_map.h", - "source/rtp_utility.cc", - "source/rtp_utility.h", "source/source_tracker.cc", "source/source_tracker.h", "source/time_util.cc", @@ -553,7 +551,6 @@ if (rtc_include_tests) { "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", "source/time_util_unittest.cc", diff --git a/modules/rtp_rtcp/source/rtp_sender_unittest.cc b/modules/rtp_rtcp/source/rtp_sender_unittest.cc index 28e0271c4e..8181cd068f 100644 --- a/modules/rtp_rtcp/source/rtp_sender_unittest.cc +++ b/modules/rtp_rtcp/source/rtp_sender_unittest.cc @@ -30,7 +30,6 @@ #include "modules/rtp_rtcp/source/rtp_packet_received.h" #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "modules/rtp_rtcp/source/rtp_sender_video.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" #include "modules/rtp_rtcp/source/video_fec_generator.h" #include "rtc_base/arraysize.h" #include "rtc_base/logging.h" diff --git a/modules/rtp_rtcp/source/rtp_utility.cc b/modules/rtp_rtcp/source/rtp_utility.cc deleted file mode 100644 index 159de27b4e..0000000000 --- a/modules/rtp_rtcp/source/rtp_utility.cc +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright (c) 2012 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_utility.h" - -#include - -#include - -#include "api/array_view.h" -#include "api/video/video_content_type.h" -#include "api/video/video_rotation.h" -#include "api/video/video_timing.h" -#include "modules/rtp_rtcp/include/rtp_cvo.h" -#include "modules/rtp_rtcp/source/byte_io.h" -#include "modules/rtp_rtcp/source/rtp_header_extensions.h" -#include "modules/video_coding/codecs/interface/common_constants.h" -#include "rtc_base/checks.h" -#include "rtc_base/logging.h" - -namespace webrtc { - -namespace RtpUtility { - -enum { - kRtcpExpectedVersion = 2, - kRtcpMinHeaderLength = 4, - kRtcpMinParseLength = 8, - - kRtpExpectedVersion = 2, - kRtpMinParseLength = 12 -}; - -RtpHeaderParser::RtpHeaderParser(const uint8_t* rtpData, - const size_t rtpDataLength) - : _ptrRTPDataBegin(rtpData), - _ptrRTPDataEnd(rtpData ? (rtpData + rtpDataLength) : NULL) {} - -RtpHeaderParser::~RtpHeaderParser() {} - -bool RtpHeaderParser::RTCP() const { - // 72 to 76 is reserved for RTP - // 77 to 79 is not reserver but they are not assigned we will block them - // for RTCP 200 SR == marker bit + 72 - // for RTCP 204 APP == marker bit + 76 - /* - * RTCP - * - * FIR full INTRA-frame request 192 [RFC2032] supported - * NACK negative acknowledgement 193 [RFC2032] - * IJ Extended inter-arrival jitter report 195 [RFC-ietf-avt-rtp-toff - * set-07.txt] http://tools.ietf.org/html/draft-ietf-avt-rtp-toffset-07 - * SR sender report 200 [RFC3551] supported - * RR receiver report 201 [RFC3551] supported - * SDES source description 202 [RFC3551] supported - * BYE goodbye 203 [RFC3551] supported - * APP application-defined 204 [RFC3551] ignored - * RTPFB Transport layer FB message 205 [RFC4585] supported - * PSFB Payload-specific FB message 206 [RFC4585] supported - * XR extended report 207 [RFC3611] supported - */ - - /* 205 RFC 5104 - * FMT 1 NACK supported - * FMT 2 reserved - * FMT 3 TMMBR supported - * FMT 4 TMMBN supported - */ - - /* 206 RFC 5104 - * FMT 1: Picture Loss Indication (PLI) supported - * FMT 2: Slice Lost Indication (SLI) - * FMT 3: Reference Picture Selection Indication (RPSI) - * FMT 4: Full Intra Request (FIR) Command supported - * FMT 5: Temporal-Spatial Trade-off Request (TSTR) - * FMT 6: Temporal-Spatial Trade-off Notification (TSTN) - * FMT 7: Video Back Channel Message (VBCM) - * FMT 15: Application layer FB message - */ - - const ptrdiff_t length = _ptrRTPDataEnd - _ptrRTPDataBegin; - if (length < kRtcpMinHeaderLength) { - return false; - } - - const uint8_t V = _ptrRTPDataBegin[0] >> 6; - if (V != kRtcpExpectedVersion) { - return false; - } - - const uint8_t payloadType = _ptrRTPDataBegin[1]; - switch (payloadType) { - case 192: - return true; - case 193: - // not supported - // pass through and check for a potential RTP packet - return false; - case 195: - case 200: - case 201: - case 202: - case 203: - case 204: - case 205: - case 206: - case 207: - return true; - default: - return false; - } -} - -bool RtpHeaderParser::Parse(RTPHeader* header, - const RtpHeaderExtensionMap* ptrExtensionMap, - bool header_only) const { - const ptrdiff_t length = _ptrRTPDataEnd - _ptrRTPDataBegin; - if (length < kRtpMinParseLength) { - return false; - } - - // Version - const uint8_t V = _ptrRTPDataBegin[0] >> 6; - // Padding - const bool P = ((_ptrRTPDataBegin[0] & 0x20) == 0) ? false : true; - // eXtension - const bool X = ((_ptrRTPDataBegin[0] & 0x10) == 0) ? false : true; - const uint8_t CC = _ptrRTPDataBegin[0] & 0x0f; - const bool M = ((_ptrRTPDataBegin[1] & 0x80) == 0) ? false : true; - - const uint8_t PT = _ptrRTPDataBegin[1] & 0x7f; - - const uint16_t sequenceNumber = - (_ptrRTPDataBegin[2] << 8) + _ptrRTPDataBegin[3]; - - const uint8_t* ptr = &_ptrRTPDataBegin[4]; - - uint32_t RTPTimestamp = ByteReader::ReadBigEndian(ptr); - ptr += 4; - - uint32_t SSRC = ByteReader::ReadBigEndian(ptr); - ptr += 4; - - if (V != kRtpExpectedVersion) { - return false; - } - - const size_t CSRCocts = CC * 4; - - if ((ptr + CSRCocts) > _ptrRTPDataEnd) { - return false; - } - - header->markerBit = M; - header->payloadType = PT; - header->sequenceNumber = sequenceNumber; - header->timestamp = RTPTimestamp; - header->ssrc = SSRC; - header->numCSRCs = CC; - if (!P || header_only) { - header->paddingLength = 0; - } - - for (uint8_t i = 0; i < CC; ++i) { - uint32_t CSRC = ByteReader::ReadBigEndian(ptr); - ptr += 4; - header->arrOfCSRCs[i] = CSRC; - } - - header->headerLength = 12 + CSRCocts; - - // If in effect, MAY be omitted for those packets for which the offset - // is zero. - header->extension.hasTransmissionTimeOffset = false; - header->extension.transmissionTimeOffset = 0; - - // May not be present in packet. - header->extension.hasAbsoluteSendTime = false; - header->extension.absoluteSendTime = 0; - - // May not be present in packet. - header->extension.hasAudioLevel = false; - header->extension.voiceActivity = false; - header->extension.audioLevel = 0; - - // May not be present in packet. - header->extension.hasVideoRotation = false; - header->extension.videoRotation = kVideoRotation_0; - - // May not be present in packet. - header->extension.playout_delay.min_ms = -1; - header->extension.playout_delay.max_ms = -1; - - // May not be present in packet. - header->extension.hasVideoContentType = false; - header->extension.videoContentType = VideoContentType::UNSPECIFIED; - - header->extension.has_video_timing = false; - header->extension.video_timing = {0u, 0u, 0u, 0u, 0u, 0u, false}; - - if (X) { - /* RTP header extension, RFC 3550. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | defined by profile | length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | header extension | - | .... | - */ - const ptrdiff_t remain = _ptrRTPDataEnd - ptr; - if (remain < 4) { - return false; - } - - header->headerLength += 4; - - uint16_t definedByProfile = ByteReader::ReadBigEndian(ptr); - ptr += 2; - - // in 32 bit words - size_t XLen = ByteReader::ReadBigEndian(ptr); - ptr += 2; - XLen *= 4; // in bytes - - if (static_cast(remain) < (4 + XLen)) { - return false; - } - static constexpr uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE; - if (definedByProfile == kRtpOneByteHeaderExtensionId) { - const uint8_t* ptrRTPDataExtensionEnd = ptr + XLen; - ParseOneByteExtensionHeader(header, ptrExtensionMap, - ptrRTPDataExtensionEnd, ptr); - } - header->headerLength += XLen; - } - if (header->headerLength > static_cast(length)) - return false; - - if (P && !header_only) { - // Packet has padding. - if (header->headerLength != static_cast(length)) { - // Packet is not header only. We can parse padding length now. - header->paddingLength = *(_ptrRTPDataEnd - 1); - } else { - RTC_LOG(LS_WARNING) << "Cannot parse padding length."; - // Packet is header only. We have no clue of the padding length. - return false; - } - } - - if (header->headerLength + header->paddingLength > - static_cast(length)) - return false; - return true; -} - -void RtpHeaderParser::ParseOneByteExtensionHeader( - RTPHeader* header, - const RtpHeaderExtensionMap* ptrExtensionMap, - const uint8_t* ptrRTPDataExtensionEnd, - const uint8_t* ptr) const { - if (!ptrExtensionMap) { - return; - } - - while (ptrRTPDataExtensionEnd - ptr > 0) { - // 0 - // 0 1 2 3 4 5 6 7 - // +-+-+-+-+-+-+-+-+ - // | ID | len | - // +-+-+-+-+-+-+-+-+ - - // Note that 'len' is the header extension element length, which is the - // number of bytes - 1. - const int id = (*ptr & 0xf0) >> 4; - const int len = (*ptr & 0x0f); - ptr++; - - if (id == 0) { - // Padding byte, skip ignoring len. - continue; - } - - if (id == 15) { - RTC_LOG(LS_VERBOSE) - << "RTP extension header 15 encountered. Terminate parsing."; - return; - } - - if (ptrRTPDataExtensionEnd - ptr < (len + 1)) { - RTC_LOG(LS_WARNING) << "Incorrect one-byte extension len: " << (len + 1) - << ", bytes left in buffer: " - << (ptrRTPDataExtensionEnd - ptr); - return; - } - - RTPExtensionType type = ptrExtensionMap->GetType(id); - if (type == RtpHeaderExtensionMap::kInvalidType) { - // If we encounter an unknown extension, just skip over it. - RTC_LOG(LS_WARNING) << "Failed to find extension id: " << id; - } else { - switch (type) { - case kRtpExtensionTransmissionTimeOffset: { - if (len != 2) { - RTC_LOG(LS_WARNING) - << "Incorrect transmission time offset len: " << len; - return; - } - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=2 | transmission offset | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - header->extension.transmissionTimeOffset = - ByteReader::ReadBigEndian(ptr); - header->extension.hasTransmissionTimeOffset = true; - break; - } - case kRtpExtensionCsrcAudioLevel: { - RTC_LOG(LS_WARNING) << "Csrc audio level extension not supported"; - return; - } - case kRtpExtensionAudioLevel: { - if (len != 0) { - RTC_LOG(LS_WARNING) << "Incorrect audio level len: " << len; - return; - } - // 0 1 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=0 |V| level | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // - header->extension.audioLevel = ptr[0] & 0x7f; - header->extension.voiceActivity = (ptr[0] & 0x80) != 0; - header->extension.hasAudioLevel = true; - break; - } - case kRtpExtensionAbsoluteSendTime: { - if (len != 2) { - RTC_LOG(LS_WARNING) << "Incorrect absolute send time len: " << len; - return; - } - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=2 | absolute send time | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - header->extension.absoluteSendTime = - ByteReader::ReadBigEndian(ptr); - header->extension.hasAbsoluteSendTime = true; - break; - } - case kRtpExtensionAbsoluteCaptureTime: { - AbsoluteCaptureTime extension; - if (!AbsoluteCaptureTimeExtension::Parse( - rtc::MakeArrayView(ptr, len + 1), &extension)) { - RTC_LOG(LS_WARNING) - << "Incorrect absolute capture time len: " << len; - return; - } - header->extension.absolute_capture_time = extension; - break; - } - case kRtpExtensionVideoRotation: { - if (len != 0) { - RTC_LOG(LS_WARNING) - << "Incorrect coordination of video coordination len: " << len; - return; - } - // 0 1 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=0 |0 0 0 0 C F R R| - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - header->extension.hasVideoRotation = true; - header->extension.videoRotation = - ConvertCVOByteToVideoRotation(ptr[0]); - break; - } - case kRtpExtensionTransportSequenceNumber: { - if (len != 1) { - RTC_LOG(LS_WARNING) - << "Incorrect transport sequence number len: " << len; - return; - } - // 0 1 2 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | L=1 |transport wide sequence number | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - uint16_t sequence_number = ptr[0] << 8; - sequence_number += ptr[1]; - header->extension.transportSequenceNumber = sequence_number; - header->extension.hasTransportSequenceNumber = true; - break; - } - case kRtpExtensionTransportSequenceNumber02: - RTC_LOG(WARNING) << "TransportSequenceNumberV2 unsupported by rtp " - "header parser."; - break; - case kRtpExtensionPlayoutDelay: { - if (len != 2) { - RTC_LOG(LS_WARNING) << "Incorrect playout delay len: " << len; - return; - } - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=2 | MIN delay | MAX delay | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - int min_playout_delay = (ptr[0] << 4) | ((ptr[1] >> 4) & 0xf); - int max_playout_delay = ((ptr[1] & 0xf) << 8) | ptr[2]; - header->extension.playout_delay.min_ms = - min_playout_delay * PlayoutDelayLimits::kGranularityMs; - header->extension.playout_delay.max_ms = - max_playout_delay * PlayoutDelayLimits::kGranularityMs; - break; - } - case kRtpExtensionVideoContentType: { - if (len != 0) { - RTC_LOG(LS_WARNING) << "Incorrect video content type len: " << len; - return; - } - // 0 1 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | ID | len=0 | Content type | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - if (videocontenttypehelpers::IsValidContentType(ptr[0])) { - header->extension.hasVideoContentType = true; - header->extension.videoContentType = - static_cast(ptr[0]); - } - break; - } - case kRtpExtensionVideoTiming: { - if (len != VideoTimingExtension::kValueSizeBytes - 1) { - RTC_LOG(LS_WARNING) << "Incorrect video timing len: " << len; - return; - } - header->extension.has_video_timing = true; - VideoTimingExtension::Parse(rtc::MakeArrayView(ptr, len + 1), - &header->extension.video_timing); - break; - } - case kRtpExtensionVideoLayersAllocation: - RTC_LOG(WARNING) << "VideoLayersAllocation extension unsupported by " - "rtp header parser."; - break; - case kRtpExtensionRtpStreamId: { - std::string name(reinterpret_cast(ptr), len + 1); - if (IsLegalRsidName(name)) { - header->extension.stream_id = name; - } else { - RTC_LOG(LS_WARNING) << "Incorrect RtpStreamId"; - } - break; - } - case kRtpExtensionRepairedRtpStreamId: { - std::string name(reinterpret_cast(ptr), len + 1); - if (IsLegalRsidName(name)) { - header->extension.repaired_stream_id = name; - } else { - RTC_LOG(LS_WARNING) << "Incorrect RepairedRtpStreamId"; - } - break; - } - case kRtpExtensionMid: { - std::string name(reinterpret_cast(ptr), len + 1); - if (IsLegalMidName(name)) { - header->extension.mid = name; - } else { - RTC_LOG(LS_WARNING) << "Incorrect Mid"; - } - break; - } - case kRtpExtensionGenericFrameDescriptor00: - case kRtpExtensionGenericFrameDescriptor02: - RTC_LOG(WARNING) - << "RtpGenericFrameDescriptor unsupported by rtp header parser."; - break; - case kRtpExtensionColorSpace: - RTC_LOG(WARNING) - << "RtpExtensionColorSpace unsupported by rtp header parser."; - break; - case kRtpExtensionInbandComfortNoise: - RTC_LOG(WARNING) << "Inband comfort noise extension unsupported by " - "rtp header parser."; - break; - case kRtpExtensionVideoFrameTrackingId: - RTC_LOG(WARNING) - << "VideoFrameTrackingId unsupported by rtp header parser."; - break; - case kRtpExtensionNone: - case kRtpExtensionNumberOfExtensions: { - RTC_NOTREACHED() << "Invalid extension type: " << type; - return; - } - } - } - ptr += (len + 1); - } -} - -} // namespace RtpUtility -} // namespace webrtc diff --git a/modules/rtp_rtcp/source/rtp_utility.h b/modules/rtp_rtcp/source/rtp_utility.h deleted file mode 100644 index 694cf2c022..0000000000 --- a/modules/rtp_rtcp/source/rtp_utility.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012 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_UTILITY_H_ -#define MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ - -#include - -#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" -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" - -namespace webrtc { -namespace RtpUtility { - -class RtpHeaderParser { - public: - RtpHeaderParser(const uint8_t* rtpData, size_t rtpDataLength); - ~RtpHeaderParser(); - - ABSL_DEPRECATED("Use IsRtpPacket or IsRtcpPacket") - bool RTCP() const; - bool Parse(RTPHeader* parsedPacket, - const RtpHeaderExtensionMap* ptrExtensionMap = nullptr, - bool header_only = false) const; - - private: - void ParseOneByteExtensionHeader(RTPHeader* parsedPacket, - const RtpHeaderExtensionMap* ptrExtensionMap, - const uint8_t* ptrRTPDataExtensionEnd, - const uint8_t* ptr) const; - - const uint8_t* const _ptrRTPDataBegin; - const uint8_t* const _ptrRTPDataEnd; -}; -} // namespace RtpUtility -} // namespace webrtc - -#endif // MODULES_RTP_RTCP_SOURCE_RTP_UTILITY_H_ diff --git a/modules/rtp_rtcp/source/rtp_utility_unittest.cc b/modules/rtp_rtcp/source/rtp_utility_unittest.cc deleted file mode 100644 index 374cb6f8cd..0000000000 --- a/modules/rtp_rtcp/source/rtp_utility_unittest.cc +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2016 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_utility.h" - -#include "modules/rtp_rtcp/include/rtp_header_extension_map.h" -#include "modules/rtp_rtcp/source/rtp_header_extensions.h" -#include "test/gmock.h" -#include "test/gtest.h" - -namespace webrtc { -namespace { - -using ::testing::ElementsAreArray; -using ::testing::make_tuple; - -const int8_t kPayloadType = 100; -const uint32_t kSsrc = 0x12345678; -const uint16_t kSeqNum = 88; -const uint32_t kTimestamp = 0x65431278; - -} // namespace - -TEST(RtpHeaderParser, ParseMinimum) { - // clang-format off - const uint8_t kPacket[] = { - 0x80, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78}; // kSsrc. - // clang-format on - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, nullptr)); - - EXPECT_EQ(kPayloadType, header.payloadType); - EXPECT_EQ(kSeqNum, header.sequenceNumber); - EXPECT_EQ(kTimestamp, header.timestamp); - EXPECT_EQ(kSsrc, header.ssrc); - EXPECT_EQ(0u, header.paddingLength); - EXPECT_EQ(sizeof(kPacket), header.headerLength); -} - -TEST(RtpHeaderParser, ParseWithExtension) { - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x01, // Extension block of size 1 x 32bit words. - 0x12, 0x01, 0x56, 0xce}; - // clang-format on - RtpHeaderExtensionMap extensions; - extensions.Register(1); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - EXPECT_EQ(kPayloadType, header.payloadType); - EXPECT_EQ(kSeqNum, header.sequenceNumber); - EXPECT_EQ(kTimestamp, header.timestamp); - EXPECT_EQ(kSsrc, header.ssrc); - - ASSERT_TRUE(header.extension.hasTransmissionTimeOffset); - EXPECT_EQ(0x156ce, header.extension.transmissionTimeOffset); -} - -TEST(RtpHeaderParser, ParseWithInvalidSizedExtension) { - const size_t kPayloadSize = 7; - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x02, // Extension block of size 2 x 32bit words. - 0x16, // (6+1)-bytes, but Transmission Offset expected to be 3-bytes. - 'e', 'x', 't', - 'd', 'a', 't', 'a', - 'p', 'a', 'y', 'l', 'o', 'a', 'd' - }; - // clang-format on - RtpHeaderExtensionMap extensions; - extensions.Register(1); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - // Extension should be ignored. - EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); - // But shouldn't prevent reading payload. - EXPECT_THAT(sizeof(kPacket) - kPayloadSize, header.headerLength); -} - -TEST(RtpHeaderParser, ParseWithExtensionPadding) { - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x02, // Extension of size 1x32bit word. - 0x02, // A byte of (invalid) padding. - 0x12, 0x1a, 0xda, 0x03, // TransmissionOffset extension. - 0x0f, 0x00, 0x03, // More invalid padding bytes: id=0, but len > 0. - }; - // clang-format on - RtpHeaderExtensionMap extensions; - extensions.Register(1); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - // Parse should skip padding and read extension. - EXPECT_TRUE(header.extension.hasTransmissionTimeOffset); - EXPECT_EQ(0x1ada03, header.extension.transmissionTimeOffset); - EXPECT_EQ(sizeof(kPacket), header.headerLength); -} - -TEST(RtpHeaderParser, ParseWithOverSizedExtension) { - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x01, // Extension of size 1x32bit word. - 0x00, // Add a byte of padding. - 0x12, // Extension id 1 size (2+1). - 0xda, 0x1a // Only 2 bytes of extension payload. - }; - // clang-format on - RtpHeaderExtensionMap extensions; - extensions.Register(1); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - // Parse should ignore extension. - EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); - EXPECT_EQ(sizeof(kPacket), header.headerLength); -} - -TEST(RtpHeaderParser, ParseAll9Extensions) { - const uint8_t kAudioLevel = 0x5a; - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x0c, // Extension of size 12x32bit words. - 0x40, 0x80|kAudioLevel, // AudioLevel. - 0x22, 0x01, 0x56, 0xce, // TransmissionOffset. - 0x62, 0x12, 0x34, 0x56, // AbsoluteSendTime. - 0x7f, 0x12, 0x34, 0x56, 0x78, // AbsoluteCaptureTime. - 0x90, 0xab, 0xcd, 0xef, // AbsoluteCaptureTime. (cont.) - 0x11, 0x22, 0x33, 0x44, // AbsoluteCaptureTime. (cont.) - 0x55, 0x66, 0x77, 0x88, // AbsoluteCaptureTime. (cont.) - 0x81, 0xce, 0xab, // TransportSequenceNumber. - 0xa0, 0x03, // VideoRotation. - 0xb2, 0x12, 0x48, 0x76, // PlayoutDelayLimits. - 0xc2, 'r', 't', 'x', // RtpStreamId - 0xd5, 's', 't', 'r', 'e', 'a', 'm', // RepairedRtpStreamId - 0x00, // Padding to 32bit boundary. - }; - // clang-format on - ASSERT_EQ(sizeof(kPacket) % 4, 0u); - - RtpHeaderExtensionMap extensions; - extensions.Register(2); - extensions.Register(4); - extensions.Register(6); - extensions.Register(7); - extensions.Register(8); - extensions.Register(0xa); - extensions.Register(0xb); - extensions.Register(0xc); - extensions.Register(0xd); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - EXPECT_TRUE(header.extension.hasTransmissionTimeOffset); - EXPECT_EQ(0x156ce, header.extension.transmissionTimeOffset); - - EXPECT_TRUE(header.extension.hasAudioLevel); - EXPECT_TRUE(header.extension.voiceActivity); - EXPECT_EQ(kAudioLevel, header.extension.audioLevel); - - EXPECT_TRUE(header.extension.hasAbsoluteSendTime); - EXPECT_EQ(0x123456U, header.extension.absoluteSendTime); - - ASSERT_TRUE(header.extension.absolute_capture_time.has_value()); - EXPECT_EQ(0x1234567890abcdefULL, - header.extension.absolute_capture_time->absolute_capture_timestamp); - ASSERT_TRUE(header.extension.absolute_capture_time - ->estimated_capture_clock_offset.has_value()); - EXPECT_EQ(0x1122334455667788LL, header.extension.absolute_capture_time - ->estimated_capture_clock_offset.value()); - - EXPECT_TRUE(header.extension.hasTransportSequenceNumber); - EXPECT_EQ(0xceab, header.extension.transportSequenceNumber); - - EXPECT_TRUE(header.extension.hasVideoRotation); - EXPECT_EQ(kVideoRotation_270, header.extension.videoRotation); - - EXPECT_EQ(0x124 * PlayoutDelayLimits::kGranularityMs, - header.extension.playout_delay.min_ms); - EXPECT_EQ(0x876 * PlayoutDelayLimits::kGranularityMs, - header.extension.playout_delay.max_ms); - EXPECT_EQ(header.extension.stream_id, "rtx"); - EXPECT_EQ(header.extension.repaired_stream_id, "stream"); -} - -TEST(RtpHeaderParser, ParseMalformedRsidExtensions) { - // clang-format off - const uint8_t kPacket[] = { - 0x90, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0xbe, 0xde, 0x00, 0x03, // Extension of size 3x32bit words. - 0xc2, '\0', 't', 'x', // empty RtpStreamId - 0xd5, 's', 't', 'r', '\0', 'a', 'm', // RepairedRtpStreamId - 0x00, // Padding to 32bit boundary. - }; - // clang-format on - ASSERT_EQ(sizeof(kPacket) % 4, 0u); - - RtpHeaderExtensionMap extensions; - extensions.Register(0xc); - extensions.Register(0xd); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - EXPECT_TRUE(header.extension.stream_id.empty()); - EXPECT_TRUE(header.extension.repaired_stream_id.empty()); -} - -TEST(RtpHeaderParser, ParseWithCsrcsExtensionAndPadding) { - const uint8_t kPacketPaddingSize = 8; - const uint32_t kCsrcs[] = {0x34567890, 0x32435465}; - const size_t kPayloadSize = 7; - // clang-format off - const uint8_t kPacket[] = { - 0xb2, kPayloadType, 0x00, kSeqNum, - 0x65, 0x43, 0x12, 0x78, // kTimestamp. - 0x12, 0x34, 0x56, 0x78, // kSsrc. - 0x34, 0x56, 0x78, 0x90, // kCsrcs[0]. - 0x32, 0x43, 0x54, 0x65, // kCsrcs[1]. - 0xbe, 0xde, 0x00, 0x01, // Extension. - 0x12, 0x00, 0x56, 0xce, // TransmissionTimeOffset with id = 1. - 'p', 'a', 'y', 'l', 'o', 'a', 'd', - 'p', 'a', 'd', 'd', 'i', 'n', 'g', kPacketPaddingSize}; - // clang-format on - RtpHeaderExtensionMap extensions; - extensions.Register(1); - RtpUtility::RtpHeaderParser parser(kPacket, sizeof(kPacket)); - RTPHeader header; - - EXPECT_TRUE(parser.Parse(&header, &extensions)); - - EXPECT_EQ(kPayloadType, header.payloadType); - EXPECT_EQ(kSeqNum, header.sequenceNumber); - EXPECT_EQ(kTimestamp, header.timestamp); - EXPECT_EQ(kSsrc, header.ssrc); - EXPECT_THAT(make_tuple(header.arrOfCSRCs, header.numCSRCs), - ElementsAreArray(kCsrcs)); - EXPECT_EQ(kPacketPaddingSize, header.paddingLength); - EXPECT_THAT(sizeof(kPacket) - kPayloadSize - kPacketPaddingSize, - header.headerLength); - EXPECT_TRUE(header.extension.hasTransmissionTimeOffset); - EXPECT_EQ(0x56ce, header.extension.transmissionTimeOffset); -} - -} // namespace webrtc diff --git a/modules/rtp_rtcp/source/ulpfec_generator.cc b/modules/rtp_rtcp/source/ulpfec_generator.cc index 4873693164..a5ce8c9dd9 100644 --- a/modules/rtp_rtcp/source/ulpfec_generator.cc +++ b/modules/rtp_rtcp/source/ulpfec_generator.cc @@ -20,7 +20,6 @@ #include "modules/rtp_rtcp/source/byte_io.h" #include "modules/rtp_rtcp/source/forward_error_correction.h" #include "modules/rtp_rtcp/source/forward_error_correction_internal.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" #include "rtc_base/checks.h" #include "rtc_base/synchronization/mutex.h" diff --git a/rtc_tools/rtc_event_log_visualizer/analyzer.cc b/rtc_tools/rtc_event_log_visualizer/analyzer.cc index 30340d1338..3de0f90f46 100644 --- a/rtc_tools/rtc_event_log_visualizer/analyzer.cc +++ b/rtc_tools/rtc_event_log_visualizer/analyzer.cc @@ -49,7 +49,6 @@ #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" #include "modules/rtp_rtcp/source/rtp_header_extensions.h" #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" #include "rtc_base/checks.h" #include "rtc_base/format_macros.h" #include "rtc_base/logging.h" diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn index 1561e8b845..8300fca3a4 100644 --- a/test/fuzzers/BUILD.gn +++ b/test/fuzzers/BUILD.gn @@ -231,14 +231,6 @@ webrtc_fuzzer_test("rtp_packetizer_av1_fuzzer") { ] } -webrtc_fuzzer_test("rtp_header_fuzzer") { - sources = [ "rtp_header_fuzzer.cc" ] - deps = [ - "../../modules/rtp_rtcp", - "../../modules/rtp_rtcp:rtp_rtcp_format", - ] -} - webrtc_fuzzer_test("congestion_controller_feedback_fuzzer") { sources = [ "congestion_controller_feedback_fuzzer.cc" ] deps = [ diff --git a/test/fuzzers/rtp_header_fuzzer.cc b/test/fuzzers/rtp_header_fuzzer.cc deleted file mode 100644 index b5905f0de3..0000000000 --- a/test/fuzzers/rtp_header_fuzzer.cc +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2016 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 - -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "modules/rtp_rtcp/source/rtp_packet_received.h" -#include "modules/rtp_rtcp/source/rtp_utility.h" - -namespace webrtc { -// We decide which header extensions to register by reading four bytes -// from the beginning of `data` and interpreting it as a bitmask over -// the RTPExtensionType enum. This assert ensures four bytes are enough. -static_assert(kRtpExtensionNumberOfExtensions <= 32, - "Insufficient bits read to configure all header extensions. Add " - "an extra byte and update the switches."); - -void FuzzOneInput(const uint8_t* data, size_t size) { - if (size <= 4) - return; - - // Don't use the configuration byte as part of the packet. - std::bitset<32> extensionMask(*reinterpret_cast(data)); - data += 4; - size -= 4; - - RtpPacketReceived::ExtensionManager extensions(/*extmap_allow_mixed=*/true); - // Start at local_id = 1 since 0 is an invalid extension id. - int local_id = 1; - // Skip i = 0 since it maps to kRtpExtensionNone. - for (int i = 1; i < kRtpExtensionNumberOfExtensions; i++) { - RTPExtensionType extension_type = static_cast(i); - if (extensionMask[i]) { - // Extensions are registered with an ID, which you signal to the - // peer so they know what to expect. This code only cares about - // parsing so the value of the ID isn't relevant. - extensions.RegisterByType(local_id++, extension_type); - } - } - - RTPHeader rtp_header; - RtpUtility::RtpHeaderParser rtp_parser(data, size); - rtp_parser.Parse(&rtp_header, &extensions); -} -} // namespace webrtc