From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/test/rtcp_packet_parser.h | 130 ++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 third_party/libwebrtc/test/rtcp_packet_parser.h (limited to 'third_party/libwebrtc/test/rtcp_packet_parser.h') diff --git a/third_party/libwebrtc/test/rtcp_packet_parser.h b/third_party/libwebrtc/test/rtcp_packet_parser.h new file mode 100644 index 0000000000..0aa1cbf499 --- /dev/null +++ b/third_party/libwebrtc/test/rtcp_packet_parser.h @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2014 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 TEST_RTCP_PACKET_PARSER_H_ +#define TEST_RTCP_PACKET_PARSER_H_ + +#include +#include + +#include "api/array_view.h" +#include "modules/rtp_rtcp/source/rtcp_packet/app.h" +#include "modules/rtp_rtcp/source/rtcp_packet/bye.h" +#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" +#include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" +#include "modules/rtp_rtcp/source/rtcp_packet/fir.h" +#include "modules/rtp_rtcp/source/rtcp_packet/loss_notification.h" +#include "modules/rtp_rtcp/source/rtcp_packet/nack.h" +#include "modules/rtp_rtcp/source/rtcp_packet/pli.h" +#include "modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h" +#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" +#include "modules/rtp_rtcp/source/rtcp_packet/remb.h" +#include "modules/rtp_rtcp/source/rtcp_packet/sdes.h" +#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" +#include "modules/rtp_rtcp/source/rtcp_packet/tmmbn.h" +#include "modules/rtp_rtcp/source/rtcp_packet/tmmbr.h" +#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" +#include "rtc_base/checks.h" + +namespace webrtc { +namespace test { +// Parse RTCP packet of given type. Assumes RTCP header is valid and that there +// is excatly one packet of correct type in the buffer. +template +bool ParseSinglePacket(const uint8_t* buffer, size_t size, Packet* packet) { + rtcp::CommonHeader header; + RTC_CHECK(header.Parse(buffer, size)); + RTC_CHECK_EQ(size, header.NextPacket() - buffer); + return packet->Parse(header); +} +// Same function, but takes raw buffer as single argument instead of pair. +template +bool ParseSinglePacket(rtc::ArrayView buffer, Packet* packet) { + return ParseSinglePacket(buffer.data(), buffer.size(), packet); +} + +class RtcpPacketParser { + public: + // Keeps last parsed packet, count number of parsed packets of given type. + template + class PacketCounter : public TypedRtcpPacket { + public: + int num_packets() const { return num_packets_; } + void Parse(const rtcp::CommonHeader& header) { + if (TypedRtcpPacket::Parse(header)) + ++num_packets_; + } + bool Parse(const rtcp::CommonHeader& header, uint32_t* sender_ssrc) { + const bool result = TypedRtcpPacket::Parse(header); + if (result) { + ++num_packets_; + if (*sender_ssrc == 0) // Use first sender ssrc in compound packet. + *sender_ssrc = TypedRtcpPacket::sender_ssrc(); + } + return result; + } + + private: + int num_packets_ = 0; + }; + + RtcpPacketParser(); + ~RtcpPacketParser(); + + bool Parse(rtc::ArrayView packet); + + PacketCounter* app() { return &app_; } + PacketCounter* bye() { return &bye_; } + PacketCounter* xr() { return &xr_; } + PacketCounter* fir() { return &fir_; } + PacketCounter* nack() { return &nack_; } + PacketCounter* pli() { return &pli_; } + PacketCounter* rrr() { return &rrr_; } + PacketCounter* receiver_report() { + return &receiver_report_; + } + PacketCounter* loss_notification() { + return &loss_notification_; + } + PacketCounter* remb() { return &remb_; } + PacketCounter* sdes() { return &sdes_; } + PacketCounter* sender_report() { return &sender_report_; } + PacketCounter* tmmbn() { return &tmmbn_; } + PacketCounter* tmmbr() { return &tmmbr_; } + PacketCounter* transport_feedback() { + return &transport_feedback_; + } + uint32_t sender_ssrc() const { return sender_ssrc_; } + size_t processed_rtcp_packets() const { return processed_rtcp_packets_; } + + private: + PacketCounter app_; + PacketCounter bye_; + PacketCounter xr_; + PacketCounter fir_; + PacketCounter nack_; + PacketCounter pli_; + PacketCounter rrr_; + PacketCounter receiver_report_; + PacketCounter loss_notification_; + PacketCounter remb_; + PacketCounter sdes_; + PacketCounter sender_report_; + PacketCounter tmmbn_; + PacketCounter tmmbr_; + PacketCounter transport_feedback_; + uint32_t sender_ssrc_ = 0; + size_t processed_rtcp_packets_ = 0; +}; + +} // namespace test +} // namespace webrtc +#endif // TEST_RTCP_PACKET_PARSER_H_ -- cgit v1.2.3