VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /proc/self/root/usr/local/lib/node_modules/mediasoup/worker/test/src/RTC/RTCP/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/usr/local/lib/node_modules/mediasoup/worker/test/src/RTC/RTCP/TestSenderReport.cpp
#include "common.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include <catch.hpp>
#include <cstring> // std::memcmp()

using namespace RTC::RTCP;

namespace TestSenderReport
{
	// RTCP Packet. Sender Report and Receiver Report.

	// clang-format off
	uint8_t buffer[] =
	{
		0x80, 0xc8, 0x00, 0x06, // Type: 200 (Sender Report), Count: 0, Length: 6
		0x5d, 0x93, 0x15, 0x34, // SSRC: 0x5d931534
		0xdd, 0x3a, 0xc1, 0xb4, // NTP Sec: 3711615412
		0x76, 0x54, 0x71, 0x71, // NTP Frac: 1985245553
		0x00, 0x08, 0xcf, 0x00, // RTP timestamp: 577280
		0x00, 0x00, 0x0e, 0x18, // Packet count: 3608
		0x00, 0x08, 0xcf, 0x00  // Octet count: 577280
	};
	// clang-format on

	// Sender Report buffer start point.
	uint8_t* srBuffer = buffer + sizeof(Packet::CommonHeader);

	// SR values.
	uint32_t ssrc{ 0x5d931534 };
	uint32_t ntpSec{ 3711615412 };
	uint32_t ntpFrac{ 1985245553 };
	uint32_t rtpTs{ 577280 };
	uint32_t packetCount{ 3608 };
	uint32_t octetCount{ 577280 };

	void verify(SenderReport* report)
	{
		REQUIRE(report->GetSsrc() == ssrc);
		REQUIRE(report->GetNtpSec() == ntpSec);
		REQUIRE(report->GetNtpFrac() == ntpFrac);
		REQUIRE(report->GetRtpTs() == rtpTs);
		REQUIRE(report->GetPacketCount() == packetCount);
		REQUIRE(report->GetOctetCount() == octetCount);
	}
} // namespace TestSenderReport

using namespace TestSenderReport;

SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]")
{
	SECTION("parse SR packet")
	{
		SenderReportPacket* packet = SenderReportPacket::Parse(buffer, sizeof(buffer));

		auto* report = *(packet->Begin());

		verify(report);

		SECTION("serialize packet instance")
		{
			uint8_t serialized[sizeof(buffer)] = { 0 };

			packet->Serialize(serialized);

			SECTION("compare serialized packet with original buffer")
			{
				REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0);
			}
		}

		delete packet;
	}

	SECTION("parse SR")
	{
		SenderReport* report = SenderReport::Parse(srBuffer, sizeof(SenderReport::Header));

		REQUIRE(report);

		verify(report);

		SECTION("serialize SenderReport instance")
		{
			uint8_t serialized[sizeof(SenderReport::Header)] = { 0 };

			report->Serialize(serialized);

			SECTION("compare serialized SenderReport with original buffer")
			{
				REQUIRE(std::memcmp(srBuffer, serialized, sizeof(SenderReport::Header)) == 0);
			}
		}

		delete report;
	}

	SECTION("create SR")
	{
		// Create local report and check content.
		SenderReport report1;

		report1.SetSsrc(ssrc);
		report1.SetNtpSec(ntpSec);
		report1.SetNtpFrac(ntpFrac);
		report1.SetRtpTs(rtpTs);
		report1.SetPacketCount(packetCount);
		report1.SetOctetCount(octetCount);

		verify(&report1);

		SECTION("create a report out of the existing one")
		{
			SenderReport report2(&report1);

			verify(&report2);
		}
	}
}

VaKeR 2022