From d92022ef2e76045f94ce37f41d31ea345102ec74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Mon, 1 Jul 2024 20:51:56 +0200 Subject: [PATCH 01/17] Worker tests: use unique pointers when possible (WIP) ### Details - Avoid having allocated pointers outside `unique_ptr` pointers. - So caution with all those mediasoup `Parse()` static methods that return an allocated pointer. - Working on `TestXr.cpp`. - `TestRtpStreamSend.cpp`: Use `unique_ptr` instead of `shared_ptr`. --- worker/test/src/RTC/RTCP/TestXr.cpp | 37 ++++++++++++----------- worker/test/src/RTC/TestRtpStreamSend.cpp | 22 ++++++-------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index b047d32389..82680a0eca 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -28,7 +28,7 @@ SCENARIO("RTCP XR parsing", "[parser][rtcp][xr]") SECTION("parse XR packet") { - auto* packet = ExtendedReportPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet(ExtendedReportPacket::Parse(buffer, sizeof(buffer))); REQUIRE(packet); // Despite total buffer size is 40 bytes, our GetSize() method doesn't not @@ -113,18 +113,15 @@ SCENARIO("RTCP XR parsing", "[parser][rtcp][xr]") packet->Serialize(serialized); - auto* packet2 = ExtendedReportPacket::Parse(serialized, serializedBufferLength); + std::unique_ptr packet2( + ExtendedReportPacket::Parse(serialized, serializedBufferLength)); REQUIRE(packet2->GetType() == Type::XR); REQUIRE(packet2->GetCount() == 0); REQUIRE(packet2->GetSize() == 36); REQUIRE(std::memcmp(clonedBuffer, serialized, serializedBufferLength) == 0); - - delete packet2; } - - delete packet; } } @@ -133,7 +130,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create RRT") { // Create local report and check content. - auto* report1 = new ReceiverReferenceTime(); + std::unique_ptr report1(new ReceiverReferenceTime()); report1->SetNtpSec(11111111); report1->SetNtpFrac(22222222); @@ -148,7 +145,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - auto report2 = ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize()); + std::unique_ptr report2( + ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize())); REQUIRE(report1->GetType() == report2->GetType()); REQUIRE(report1->GetNtpSec() == report2->GetNtpSec()); @@ -158,8 +156,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1); - packet1->AddReport(report2); + packet1->AddReport(report1.get()); + packet1->AddReport(report2.get()); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0); @@ -179,7 +177,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") packet1->Serialize(bufferPacket1); // Create a new packet out of the external buffer. - auto packet2 = ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize()); + std::unique_ptr packet2( + ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize())); REQUIRE(packet2->GetType() == packet1->GetType()); REQUIRE(packet2->GetCount() == packet1->GetCount()); @@ -194,8 +193,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create DLRR") { // Create local report and check content. - auto* report1 = new DelaySinceLastRr(); - auto* ssrcInfo1 = new DelaySinceLastRr::SsrcInfo(); + std::unique_ptr report1(new DelaySinceLastRr()); + std::unique_ptr ssrcInfo1(new DelaySinceLastRr::SsrcInfo()); ssrcInfo1->SetSsrc(1234); ssrcInfo1->SetLastReceiverReport(11111111); @@ -206,7 +205,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") REQUIRE(ssrcInfo1->GetDelaySinceLastReceiverReport() == 22222222); REQUIRE(ssrcInfo1->GetSize() == sizeof(DelaySinceLastRr::SsrcInfo::Body)); - report1->AddSsrcInfo(ssrcInfo1); + report1->AddSsrcInfo(ssrcInfo1.get()); // Serialize the report into an external buffer. uint8_t bufferReport1[256]{ 0 }; @@ -214,7 +213,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - auto report2 = DelaySinceLastRr::Parse(bufferReport1, report1->GetSize()); + std::unique_ptr report2( + DelaySinceLastRr::Parse(bufferReport1, report1->GetSize())); REQUIRE(report1->GetType() == report2->GetType()); @@ -231,8 +231,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1); - packet1->AddReport(report2); + packet1->AddReport(report1.get()); + packet1->AddReport(report2.get()); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0); @@ -252,7 +252,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") packet1->Serialize(bufferPacket1); // Create a new packet out of the external buffer. - auto packet2 = ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize()); + std::unique_ptr packet2( + ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize())); REQUIRE(packet2->GetType() == packet1->GetType()); REQUIRE(packet2->GetCount() == packet1->GetCount()); diff --git a/worker/test/src/RTC/TestRtpStreamSend.cpp b/worker/test/src/RTC/TestRtpStreamSend.cpp index 3d18323c1b..0bca387fc3 100644 --- a/worker/test/src/RTC/TestRtpStreamSend.cpp +++ b/worker/test/src/RTC/TestRtpStreamSend.cpp @@ -496,7 +496,8 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - auto* stream = new RtpStreamSend(&testRtpStreamListener, params, mid); + std::unique_ptr sharedStream1( + new RtpStreamSend(&testRtpStreamListener, params, mid)); size_t iterations = 10000000; @@ -508,36 +509,33 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") auto* packet = RtpPacket::Parse(rtpBuffer1, 1500); packet->SetSsrc(1111); - std::shared_ptr sharedPacket(packet); + std::unique_ptr sharedPacket(packet); - stream->ReceivePacket(packet, sharedPacket); + sharedStream1->ReceivePacket(packet, sharedPacket); } std::chrono::duration dur = std::chrono::system_clock::now() - start; - std::cout << "nullptr && initialized shared_ptr: \t" << dur.count() << " seconds" << std::endl; - - delete stream; + std::cout << "nullptr && initialized unique_ptr: \t" << dur.count() << " seconds" << std::endl; params.mimeType.type = RTC::RtpCodecMimeType::Type::AUDIO; - stream = new RtpStreamSend(&testRtpStreamListener, params, mid); + std::unique_ptr sharedStream2( + new RtpStreamSend(&testRtpStreamListener, params, mid)); start = std::chrono::system_clock::now(); for (size_t i = 0; i < iterations; i++) { - std::shared_ptr sharedPacket; + std::unique_ptr sharedPacket; // Create packet. auto* packet = RtpPacket::Parse(rtpBuffer1, 1500); packet->SetSsrc(1111); - stream->ReceivePacket(packet, sharedPacket); + sharedStream2->ReceivePacket(packet, sharedPacket); } dur = std::chrono::system_clock::now() - start; - std::cout << "raw && empty shared_ptr duration: \t" << dur.count() << " seconds" << std::endl; - - delete stream; + std::cout << "raw && empty unique_ptr duration: \t" << dur.count() << " seconds" << std::endl; } #endif } From f19a534fc5fa7e37eaa4dcf5a3ad8c17ef649f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Tue, 2 Jul 2024 11:10:15 +0200 Subject: [PATCH 02/17] revert wrong changes --- worker/test/src/RTC/TestRtpStreamSend.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/worker/test/src/RTC/TestRtpStreamSend.cpp b/worker/test/src/RTC/TestRtpStreamSend.cpp index 0bca387fc3..0ce0925a46 100644 --- a/worker/test/src/RTC/TestRtpStreamSend.cpp +++ b/worker/test/src/RTC/TestRtpStreamSend.cpp @@ -496,8 +496,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr sharedStream1( - new RtpStreamSend(&testRtpStreamListener, params, mid)); + std::unique_ptr stream1(new RtpStreamSend(&testRtpStreamListener, params, mid)); size_t iterations = 10000000; @@ -509,33 +508,32 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") auto* packet = RtpPacket::Parse(rtpBuffer1, 1500); packet->SetSsrc(1111); - std::unique_ptr sharedPacket(packet); + std::shared_ptr sharedPacket(packet); - sharedStream1->ReceivePacket(packet, sharedPacket); + stream1->ReceivePacket(packet, sharedPacket); } std::chrono::duration dur = std::chrono::system_clock::now() - start; - std::cout << "nullptr && initialized unique_ptr: \t" << dur.count() << " seconds" << std::endl; + std::cout << "nullptr && initialized shared_ptr: \t" << dur.count() << " seconds" << std::endl; params.mimeType.type = RTC::RtpCodecMimeType::Type::AUDIO; - std::unique_ptr sharedStream2( - new RtpStreamSend(&testRtpStreamListener, params, mid)); + std::unique_ptr stream2(new RtpStreamSend(&testRtpStreamListener, params, mid)); start = std::chrono::system_clock::now(); for (size_t i = 0; i < iterations; i++) { - std::unique_ptr sharedPacket; + std::shared_ptr sharedPacket; // Create packet. auto* packet = RtpPacket::Parse(rtpBuffer1, 1500); packet->SetSsrc(1111); - sharedStream2->ReceivePacket(packet, sharedPacket); + stream2->ReceivePacket(packet, sharedPacket); } dur = std::chrono::system_clock::now() - start; - std::cout << "raw && empty unique_ptr duration: \t" << dur.count() << " seconds" << std::endl; + std::cout << "raw && empty shared_ptr duration: \t" << dur.count() << " seconds" << std::endl; } #endif } From 730b9f38df264c3376309fb6c49ee1a1e49d41b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Tue, 2 Jul 2024 11:29:56 +0200 Subject: [PATCH 03/17] use make_unique --- worker/test/src/RTC/TestRtpStreamSend.cpp | 96 +++++++++-------------- 1 file changed, 36 insertions(+), 60 deletions(-) diff --git a/worker/test/src/RTC/TestRtpStreamSend.cpp b/worker/test/src/RTC/TestRtpStreamSend.cpp index 0ce0925a46..c3f454a6c6 100644 --- a/worker/test/src/RTC/TestRtpStreamSend.cpp +++ b/worker/test/src/RTC/TestRtpStreamSend.cpp @@ -4,20 +4,22 @@ #include "RTC/RtpStream.hpp" #include "RTC/RtpStreamSend.hpp" #include +#include #include // #define PERFORMANCE_TEST 1 using namespace RTC; -static RtpPacket* CreateRtpPacket(uint8_t* buffer, size_t len, uint16_t seq, uint32_t timestamp) +static std::unique_ptr CreateRtpPacket( + uint8_t* buffer, size_t len, uint16_t seq, uint32_t timestamp) { auto* packet = RtpPacket::Parse(buffer, len); packet->SetSequenceNumber(seq); packet->SetTimestamp(timestamp); - return packet; + return std::unique_ptr(packet); } static void SendRtpPacket(std::vector> streams, RtpPacket* packet) @@ -78,20 +80,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") SECTION("receive NACK and get retransmitted packets") { // packet1 [pt:123, seq:21006, timestamp:1533790901] - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); // packet2 [pt:123, seq:21007, timestamp:1533790901] - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); // packet3 [pt:123, seq:21008, timestamp:1533793871] - std::unique_ptr packet3( - CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); + auto packet3(CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); // packet4 [pt:123, seq:21009, timestamp:1533793871] - std::unique_ptr packet4( - CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); + auto packet4(CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); // packet5 [pt:123, seq:21010, timestamp:1533796931] - std::unique_ptr packet5( - CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); + auto packet5(CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -104,7 +101,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params, mid); // Receive all the packets (some of them not in order and/or duplicated). SendRtpPacket({ { stream.get(), params.ssrc } }, packet1.get()); @@ -146,20 +143,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") SECTION("receive NACK and get zero retransmitted packets if useNack is not set") { // packet1 [pt:123, seq:21006, timestamp:1533790901] - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); // packet2 [pt:123, seq:21007, timestamp:1533790901] - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); // packet3 [pt:123, seq:21008, timestamp:1533793871] - std::unique_ptr packet3( - CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); + auto packet3(CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); // packet4 [pt:123, seq:21009, timestamp:1533793871] - std::unique_ptr packet4( - CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); + auto packet4(CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); // packet5 [pt:123, seq:21010, timestamp:1533796931] - std::unique_ptr packet5( - CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); + auto packet5(CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -172,7 +164,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params, mid); // Receive all the packets (some of them not in order and/or duplicated). SendRtpPacket({ { stream.get(), params.ssrc } }, packet1.get()); @@ -202,20 +194,15 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") SECTION("receive NACK and get zero retransmitted packets for audio") { // packet1 [pt:123, seq:21006, timestamp:1533790901] - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); // packet2 [pt:123, seq:21007, timestamp:1533790901] - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); // packet3 [pt:123, seq:21008, timestamp:1533793871] - std::unique_ptr packet3( - CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); + auto packet3(CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, 1533793871)); // packet4 [pt:123, seq:21009, timestamp:1533793871] - std::unique_ptr packet4( - CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); + auto packet4(CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 21009, 1533793871)); // packet5 [pt:123, seq:21010, timestamp:1533796931] - std::unique_ptr packet5( - CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); + auto packet5(CreateRtpPacket(rtpBuffer5, sizeof(rtpBuffer5), 21010, 1533796931)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -228,7 +215,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params.mimeType.type = RTC::RtpCodecMimeType::Type::AUDIO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params, mid); // Receive all the packets (some of them not in order and/or duplicated). SendRtpPacket({ { stream.get(), params.ssrc } }, packet1.get()); @@ -258,11 +245,9 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") SECTION("receive NACK in different RtpStreamSend instances and get retransmitted packets") { // packet1 [pt:123, seq:21006, timestamp:1533790901] - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, 1533790901)); // packet2 [pt:123, seq:21007, timestamp:1533790901] - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, 1533790901)); // Create two RtpStreamSend instances. TestRtpStreamListener testRtpStreamListener1; @@ -334,10 +319,8 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") uint32_t diffTs = RtpStreamSend::MaxRetransmissionDelayForVideoMs * clockRate / 1000; uint32_t secondTs = firstTs + diffTs; - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs)); - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs - 1)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs - 1)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -350,7 +333,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params1, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params1, mid); // Receive all the packets. SendRtpPacket({ { stream.get(), params1.ssrc } }, packet1.get()); @@ -389,12 +372,9 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") // Send a third packet so it will clean old packets from the buffer. uint32_t thirdTs = firstTs + (2 * diffTs); - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs)); - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs)); - std::unique_ptr packet3( - CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, thirdTs)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 21006, firstTs)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 21007, secondTs)); + auto packet3(CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 21008, thirdTs)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -407,7 +387,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params1, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params1, mid); // Receive all the packets. SendRtpPacket({ { stream.get(), params1.ssrc } }, packet1.get()); @@ -439,18 +419,14 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") { // This scenario reproduce the "too bad sequence number" and "bad sequence // number" scenarios in RtpStream::UpdateSeq(). - std::unique_ptr packet1( - CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 50001, 1000001)); - std::unique_ptr packet2( - CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 50002, 1000002)); + auto packet1(CreateRtpPacket(rtpBuffer1, sizeof(rtpBuffer1), 50001, 1000001)); + auto packet2(CreateRtpPacket(rtpBuffer2, sizeof(rtpBuffer2), 50002, 1000002)); // Third packet has bad sequence number (its seq is more than MaxDropout=3000 // older than current max seq) and will be dropped. - std::unique_ptr packet3( - CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 40003, 1000003)); + auto packet3(CreateRtpPacket(rtpBuffer3, sizeof(rtpBuffer3), 40003, 1000003)); // Forth packet has seq=badSeq+1 so will be accepted and will trigger a // stream reset. - std::unique_ptr packet4( - CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 40004, 1000004)); + auto packet4(CreateRtpPacket(rtpBuffer4, sizeof(rtpBuffer4), 40004, 1000004)); // Create a RtpStreamSend instance. TestRtpStreamListener testRtpStreamListener; @@ -463,7 +439,7 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") params1.mimeType.type = RTC::RtpCodecMimeType::Type::VIDEO; std::string mid; - std::unique_ptr stream(new RtpStreamSend(&testRtpStreamListener, params1, mid)); + auto stream = std::make_unique(&testRtpStreamListener, params1, mid); SendRtpPacket({ { stream.get(), params1.ssrc } }, packet1.get()); SendRtpPacket({ { stream.get(), params1.ssrc } }, packet2.get()); From aceb9ca3dfdbc2c3404fcdfeccba3d507194f92a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 3 Jul 2024 14:31:06 +0200 Subject: [PATCH 04/17] worker/Dockerfile: enable core dumps --- worker/Dockerfile | 6 +++++- worker/test/src/RTC/RTCP/TestXr.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/worker/Dockerfile b/worker/Dockerfile index 64ae430df2..3a0dd68de8 100644 --- a/worker/Dockerfile +++ b/worker/Dockerfile @@ -6,7 +6,7 @@ RUN set -x \ && apt-get install --yes \ gcc g++ clang pkg-config bash-completion wget curl \ screen python3-pip python3-yaml pkg-config zlib1g-dev \ - libgss-dev libssl-dev libxml2-dev + libgss-dev libssl-dev libxml2-dev gdb # Install node 20. RUN set -x \ @@ -21,6 +21,10 @@ RUN set -x \ && apt-get update \ && apt-get install nodejs --yes +# Enable core dumps. +RUN set -x \ + && echo "mkdir -p /tmp/cores && chmod 777 /tmp/cores && echo \"/tmp/cores/core.%e.sig%s.%p\" > /proc/sys/kernel/core_pattern && ulimit -c unlimited" >> ~/.bashrc + # Make CC and CXX point to clang/clang++ installed above. ENV LANG="C.UTF-8" ENV CC="clang" diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index 82680a0eca..941fe7452d 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -3,6 +3,7 @@ #include "RTC/RTCP/XrDelaySinceLastRr.hpp" #include "RTC/RTCP/XrReceiverReferenceTime.hpp" #include +#include #include // std::memcmp(), std::memcpy() using namespace RTC::RTCP; From 281054c40476ab4fa0f91f68a566f7766e7eb752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 3 Jul 2024 14:46:45 +0200 Subject: [PATCH 05/17] Do not use unique_ptr for isntances whose lifecycle is managed by a packet or report class --- worker/test/src/RTC/RTCP/TestXr.cpp | 32 ++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index 941fe7452d..99010115f6 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -131,7 +131,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create RRT") { // Create local report and check content. - std::unique_ptr report1(new ReceiverReferenceTime()); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto* report1 = new ReceiverReferenceTime(); report1->SetNtpSec(11111111); report1->SetNtpFrac(22222222); @@ -146,8 +148,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - std::unique_ptr report2( - ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize())); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto report2 = ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize()); REQUIRE(report1->GetType() == report2->GetType()); REQUIRE(report1->GetNtpSec() == report2->GetNtpSec()); @@ -157,8 +160,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1.get()); - packet1->AddReport(report2.get()); + packet1->AddReport(report1); + packet1->AddReport(report2); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0); @@ -194,8 +197,12 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create DLRR") { // Create local report and check content. - std::unique_ptr report1(new DelaySinceLastRr()); - std::unique_ptr ssrcInfo1(new DelaySinceLastRr::SsrcInfo()); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto* report1 = new DelaySinceLastRr(); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the report. + auto* ssrcInfo1 = new DelaySinceLastRr::SsrcInfo(); ssrcInfo1->SetSsrc(1234); ssrcInfo1->SetLastReceiverReport(11111111); @@ -206,7 +213,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") REQUIRE(ssrcInfo1->GetDelaySinceLastReceiverReport() == 22222222); REQUIRE(ssrcInfo1->GetSize() == sizeof(DelaySinceLastRr::SsrcInfo::Body)); - report1->AddSsrcInfo(ssrcInfo1.get()); + report1->AddSsrcInfo(ssrcInfo1); // Serialize the report into an external buffer. uint8_t bufferReport1[256]{ 0 }; @@ -214,8 +221,9 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. - std::unique_ptr report2( - DelaySinceLastRr::Parse(bufferReport1, report1->GetSize())); + // NOTE: We cannot use unique_ptr here since the instance lifecycle will be + // managed by the packet. + auto report2 = DelaySinceLastRr::Parse(bufferReport1, report1->GetSize()); REQUIRE(report1->GetType() == report2->GetType()); @@ -232,8 +240,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") std::unique_ptr packet1(new ExtendedReportPacket()); packet1->SetSsrc(2222); - packet1->AddReport(report1.get()); - packet1->AddReport(report2.get()); + packet1->AddReport(report1); + packet1->AddReport(report2); REQUIRE(packet1->GetType() == Type::XR); REQUIRE(packet1->GetCount() == 0); From 5c8afb31dfef45804c9ceae6fc3c26d6711c4d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Wed, 3 Jul 2024 14:48:21 +0200 Subject: [PATCH 06/17] lint --- worker/test/src/RTC/RTCP/TestXr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index 99010115f6..3767ff6945 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -3,8 +3,8 @@ #include "RTC/RTCP/XrDelaySinceLastRr.hpp" #include "RTC/RTCP/XrReceiverReferenceTime.hpp" #include -#include #include // std::memcmp(), std::memcpy() +#include using namespace RTC::RTCP; @@ -199,7 +199,7 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") // Create local report and check content. // NOTE: We cannot use unique_ptr here since the instance lifecycle will be // managed by the packet. - auto* report1 = new DelaySinceLastRr(); + auto* report1 = new DelaySinceLastRr(); // NOTE: We cannot use unique_ptr here since the instance lifecycle will be // managed by the report. auto* ssrcInfo1 = new DelaySinceLastRr::SsrcInfo(); From da616e5080750c4851e1a278b9d4dab62386e784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 11:46:56 +0200 Subject: [PATCH 07/17] Apply changes to TestSdes.cpp --- worker/test/src/RTC/RTCP/TestSdes.cpp | 35 +++++++++------------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestSdes.cpp b/worker/test/src/RTC/RTCP/TestSdes.cpp index a875dbf2ba..b453d05fc6 100644 --- a/worker/test/src/RTC/RTCP/TestSdes.cpp +++ b/worker/test/src/RTC/RTCP/TestSdes.cpp @@ -3,6 +3,7 @@ #include "RTC/RTCP/Sdes.hpp" #include #include // std::memcmp() +#include #include using namespace RTC::RTCP; @@ -97,8 +98,8 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") { SECTION("parse packet 1") { - SdesPacket* packet = SdesPacket::Parse(buffer1, sizeof(buffer1)); - auto* header = reinterpret_cast(buffer1); + std::unique_ptr packet{ SdesPacket::Parse(buffer1, sizeof(buffer1)) }; + auto* header = reinterpret_cast(buffer1); REQUIRE(packet); REQUIRE(ntohs(header->length) == 6); @@ -164,14 +165,12 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::memcmp(chunk1Buffer, serialized1, 24) == 0); } - - delete packet; } SECTION("parse packet 2") { - SdesPacket* packet = SdesPacket::Parse(buffer2, sizeof(buffer2)); - auto* header = reinterpret_cast(buffer2); + std::unique_ptr packet{ SdesPacket::Parse(buffer2, sizeof(buffer2)) }; + auto* header = reinterpret_cast(buffer2); REQUIRE(packet); REQUIRE(ntohs(header->length) == 13); @@ -292,14 +291,12 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::memcmp(chunk2Buffer, serialized2, 24) == 0); } - - delete packet; } SECTION("parse packet 3") { - SdesPacket* packet = SdesPacket::Parse(buffer3, sizeof(buffer3)); - auto* header = reinterpret_cast(buffer3); + std::unique_ptr packet{ SdesPacket::Parse(buffer3, sizeof(buffer3)) }; + auto* header = reinterpret_cast(buffer3); REQUIRE(packet); REQUIRE(ntohs(header->length) == 3); @@ -364,8 +361,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::memcmp(chunk1Buffer, serialized1, 12) == 0); } - - delete packet; } SECTION("parsing a packet with missing null octects fails") @@ -390,7 +385,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") SdesPacket packet; // Create a chunk and an item to obtain their size. - SdesChunk* chunk = new SdesChunk(1234 /*ssrc*/); + auto chunk = std::make_unique(1234 /*ssrc*/); auto* item1 = new RTC::RTCP::SdesItem(SdesItem::Type::CNAME, item1Value.size(), item1Value.c_str()); @@ -398,8 +393,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") auto chunkSize = chunk->GetSize(); - delete chunk; - for (auto i{ 1 }; i <= count; ++i) { // Create chunk and add to packet. @@ -422,7 +415,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") // exceed 31. packet.Serialize(buffer1); - auto* packet2 = static_cast(Packet::Parse(buffer1, sizeof(buffer1))); + std::unique_ptr packet2{static_cast(Packet::Parse(buffer1, sizeof(buffer1)))}; REQUIRE(packet2 != nullptr); REQUIRE(packet2->GetCount() == count); @@ -443,11 +436,10 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::string(item->GetValue()) == item1Value); } - SdesPacket* packet3 = static_cast(packet2->GetNext()); + std::unique_ptr packet3{static_cast(packet2->GetNext())}; REQUIRE(packet3 == nullptr); - delete packet3; } SECTION("create SDES packet with more than 31 chunks") @@ -456,7 +448,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") SdesPacket packet; // Create a chunk and an item to obtain their size. - SdesChunk* chunk = new SdesChunk(1234 /*ssrc*/); + auto chunk = std::make_unique(1234 /*ssrc*/); auto* item1 = new RTC::RTCP::SdesItem(SdesItem::Type::CNAME, item1Value.size(), item1Value.c_str()); @@ -464,8 +456,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") auto chunkSize = chunk->GetSize(); - delete chunk; - for (auto i{ 1 }; i <= count; ++i) { // Create chunk and add to packet. @@ -487,7 +477,7 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") // Serialization must contain 2 SDES packets since report count exceeds 31. packet.Serialize(buffer1); - auto* packet2 = static_cast(Packet::Parse(buffer1, sizeof(buffer1))); + std::unique_ptr packet2 {static_cast(Packet::Parse(buffer1, sizeof(buffer1)))}; REQUIRE(packet2 != nullptr); REQUIRE(packet2->GetCount() == 31); @@ -529,7 +519,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::string(item->GetValue()) == item1Value); } - delete packet2; delete packet3; } From a999cd6ce4e8e0f70ec3580756ffc07a2e63f2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 11:50:20 +0200 Subject: [PATCH 08/17] Apply changes to TestRtpRetransmissionBuffer.cpp --- worker/test/src/RTC/TestRtpRetransmissionBuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/test/src/RTC/TestRtpRetransmissionBuffer.cpp b/worker/test/src/RTC/TestRtpRetransmissionBuffer.cpp index ab038ba0e7..7158509ed2 100644 --- a/worker/test/src/RTC/TestRtpRetransmissionBuffer.cpp +++ b/worker/test/src/RTC/TestRtpRetransmissionBuffer.cpp @@ -36,14 +36,14 @@ class RtpMyRetransmissionBuffer : public RtpRetransmissionBuffer }; // clang-format on - auto* packet = RtpPacket::Parse(rtpBuffer, sizeof(rtpBuffer)); + std::unique_ptr packet{ RtpPacket::Parse(rtpBuffer, sizeof(rtpBuffer)) }; packet->SetSequenceNumber(seq); packet->SetTimestamp(timestamp); std::shared_ptr sharedPacket; - RtpRetransmissionBuffer::Insert(packet, sharedPacket); + RtpRetransmissionBuffer::Insert(packet.get(), sharedPacket); } void AssertBuffer(std::vector verificationBuffer) From a457cd5c0256f9a8722389af85fbc8381bc6e462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 11:53:22 +0200 Subject: [PATCH 09/17] Apply changes to TestTransportCongestionControlServer.cpp --- worker/test/src/RTC/TestTransportCongestionControlServer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/test/src/RTC/TestTransportCongestionControlServer.cpp b/worker/test/src/RTC/TestTransportCongestionControlServer.cpp index 27512b2b37..3a02b433ba 100644 --- a/worker/test/src/RTC/TestTransportCongestionControlServer.cpp +++ b/worker/test/src/RTC/TestTransportCongestionControlServer.cpp @@ -93,7 +93,7 @@ void validate(std::vector& inputs, Te tccServer.SetMaxIncomingBitrate(150000); tccServer.TransportConnected(); - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; packet->SetTransportWideCc01ExtensionId(5); packet->SetSequenceNumber(1); @@ -116,7 +116,7 @@ void validate(std::vector& inputs, Te } packet->UpdateTransportWideCc01(input.wideSeqNumber); - tccServer.IncomingPacket(input.nowMs, packet); + tccServer.IncomingPacket(input.nowMs, packet.get()); } tccServer.FillAndSendTransportCcFeedback(); From 3b152b815cf74b902fc2aac3042a0d49fb1a3e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 12:07:33 +0200 Subject: [PATCH 10/17] .cont --- .../src/RTC/RTCP/TestFeedbackRtpTransport.cpp | 86 +++++++------------ worker/test/src/RTC/TestRtpStreamRecv.cpp | 20 ++--- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp index 0204f81480..0f6b9e579b 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp @@ -3,6 +3,7 @@ #include "RTC/RTCP/FeedbackRtpTransport.hpp" #include #include // std::memcmp() +#include using namespace RTC::RTCP; @@ -69,7 +70,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION( "create FeedbackRtpTransportPacket, small delta run length chunk and single large delta status packet") { - auto* packet = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet = std::make_unique(senderSsrc, mediaSsrc); REQUIRE(packet); @@ -141,7 +142,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet2 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet2{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet2); REQUIRE(packet2->GetBaseSequenceNumber() == 1000); @@ -155,17 +157,13 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet2->GetSize() == len2); - - delete packet2; } } - - delete packet; } SECTION("create FeedbackRtpTransportPacket, run length chunk (2)") { - auto* packet = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet = std::make_unique(senderSsrc, mediaSsrc); /* clang-format off */ std::vector inputs = @@ -209,7 +207,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet2 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet2{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet2); REQUIRE(packet2->GetBaseSequenceNumber() == 1000); @@ -223,12 +222,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet2->GetSize() == len2); - - delete packet2; } } - - delete packet; } SECTION("create FeedbackRtpTransportPacket, mixed chunks") @@ -246,7 +241,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; /* clang-format on */ - auto* packet = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet = std::make_unique(senderSsrc, mediaSsrc); packet->SetFeedbackPacketCount(1); @@ -281,7 +276,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet2 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet2{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet2); REQUIRE(packet2->GetBaseSequenceNumber() == 1000); @@ -295,12 +291,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet2->GetSize() == len2); - - delete packet2; } } - - delete packet; } SECTION("create FeedbackRtpTransportPacket, incomplete two bit vector chunk") @@ -311,7 +303,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" { 1001, 1000000700, RtcpMtu }, }; - auto* packet = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet = std::make_unique(senderSsrc, mediaSsrc); packet->SetFeedbackPacketCount(1); @@ -346,7 +338,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet2 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet2{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet2); REQUIRE(packet2->GetBaseSequenceNumber() == 1000); @@ -360,12 +353,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet2->GetSize() == len2); - - delete packet2; } } - - delete packet; } SECTION("create two sequential FeedbackRtpTransportPackets") @@ -385,7 +374,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; /* clang-format on */ - auto* packet = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet = std::make_unique(senderSsrc, mediaSsrc); packet->SetFeedbackPacketCount(1); @@ -418,7 +407,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet2 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet2{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet2); REQUIRE(packet2->GetBaseSequenceNumber() == 1000); @@ -432,8 +422,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet2->GetSize() == len2); - - delete packet2; } auto latestWideSeqNumber = packet->GetLatestSequenceNumber(); @@ -453,7 +441,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; /* clang-format on */ - auto* packet2 = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet2 = std::make_unique(senderSsrc, mediaSsrc); packet2->SetFeedbackPacketCount(2); @@ -485,7 +473,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" SECTION("parse serialized buffer") { - auto* packet3 = FeedbackRtpTransportPacket::Parse(buffer, len); + std::unique_ptr packet3{ FeedbackRtpTransportPacket::Parse( + buffer, len) }; REQUIRE(packet3); REQUIRE(packet3->GetBaseSequenceNumber() == 1008); @@ -499,12 +488,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == len2); REQUIRE(std::memcmp(buffer, buffer2, len) == 0); REQUIRE(packet3->GetSize() == len2); - - delete packet3; } - - delete packet2; - delete packet; } SECTION("parse FeedbackRtpTransportPacket, one bit vector chunk") @@ -523,7 +507,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; // clang-format on - auto* packet = FeedbackRtpTransportPacket::Parse(data, sizeof(data)); + std::unique_ptr packet{ FeedbackRtpTransportPacket::Parse( + data, sizeof(data)) }; REQUIRE(packet); REQUIRE(packet->GetSize() == sizeof(data)); @@ -544,8 +529,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == sizeof(data)); REQUIRE(std::memcmp(data, buffer, len) == 0); } - - delete packet; } SECTION("parse FeedbackRtpTransportPacket with negative reference time") @@ -561,7 +544,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; // clang-format on - auto* packet = FeedbackRtpTransportPacket::Parse(data, sizeof(data)); + std::unique_ptr packet{ FeedbackRtpTransportPacket::Parse( + data, sizeof(data)) }; REQUIRE(packet); REQUIRE(packet->GetSize() == sizeof(data)); @@ -582,8 +566,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == sizeof(data)); REQUIRE(std::memcmp(data, buffer, len) == 0); } - - delete packet; } SECTION("parse FeedbackRtpTransportPacket generated by Chrome") @@ -600,7 +582,8 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" }; // clang-format on - auto* packet = FeedbackRtpTransportPacket::Parse(data, sizeof(data)); + std::unique_ptr packet{ FeedbackRtpTransportPacket::Parse( + data, sizeof(data)) }; REQUIRE(packet); REQUIRE(packet->GetSize() == sizeof(data)); @@ -622,8 +605,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(len == sizeof(data)); REQUIRE(std::memcmp(data, buffer, len) == 0); } - - delete packet; } SECTION("parse FeedbackRtpTransportPacket generated by Chrome with libwebrtc as a reference") @@ -766,8 +747,10 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" for (const auto& packetMeta : feedbackPacketsMeta) { - auto buffer = packetMeta.buffer; - auto* feedback = FeedbackRtpTransportPacket::Parse(buffer.data(), buffer.size()); + auto buffer = packetMeta.buffer; + + std::unique_ptr feedback{ FeedbackRtpTransportPacket::Parse( + buffer.data(), buffer.size()) }; REQUIRE(feedback->GetReferenceTime() == packetMeta.baseTimeRaw); REQUIRE(feedback->GetReferenceTimestamp() == packetMeta.baseTimeMs); @@ -783,7 +766,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(static_cast(resultDelta / 4) == delta); deltasIt++; } - delete feedback; } } @@ -791,9 +773,9 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" { auto MaxBaseTime = FeedbackRtpTransportPacket::TimeWrapPeriod - FeedbackRtpTransportPacket::BaseTimeTick; - auto* packet1 = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); - auto* packet2 = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); - auto* packet3 = new FeedbackRtpTransportPacket(senderSsrc, mediaSsrc); + auto packet1 = std::make_unique(senderSsrc, mediaSsrc); + auto packet2 = std::make_unique(senderSsrc, mediaSsrc); + auto packet3 = std::make_unique(senderSsrc, mediaSsrc); packet1->SetReferenceTime(MaxBaseTime); packet2->SetReferenceTime(MaxBaseTime + FeedbackRtpTransportPacket::BaseTimeTick); @@ -813,9 +795,5 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(packet2->GetBaseDelta(packet1->GetReferenceTimestamp()) == 64); REQUIRE(packet3->GetBaseDelta(packet2->GetReferenceTimestamp()) == 64); REQUIRE(packet3->GetBaseDelta(packet1->GetReferenceTimestamp()) == 128); - - delete packet1; - delete packet2; - delete packet3; } } diff --git a/worker/test/src/RTC/TestRtpStreamRecv.cpp b/worker/test/src/RTC/TestRtpStreamRecv.cpp index feaf8e7c03..388513fc71 100644 --- a/worker/test/src/RTC/TestRtpStreamRecv.cpp +++ b/worker/test/src/RTC/TestRtpStreamRecv.cpp @@ -128,7 +128,7 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -149,25 +149,25 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck); packet->SetSequenceNumber(1); - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); packet->SetSequenceNumber(3); listener.shouldTriggerNack = true; listener.shouldTriggerPLI = false; listener.shouldTriggerFIR = false; - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); REQUIRE(listener.nackedSeqNumbers.size() == 1); REQUIRE(listener.nackedSeqNumbers[0] == 2); listener.nackedSeqNumbers.clear(); packet->SetSequenceNumber(2); - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); REQUIRE(listener.nackedSeqNumbers.size() == 0); packet->SetSequenceNumber(4); - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); REQUIRE(listener.nackedSeqNumbers.size() == 0); } @@ -178,13 +178,13 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck); packet->SetSequenceNumber(0xfffe); - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); packet->SetSequenceNumber(1); listener.shouldTriggerNack = true; listener.shouldTriggerPLI = false; listener.shouldTriggerFIR = false; - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); REQUIRE(listener.nackedSeqNumbers.size() == 2); REQUIRE(listener.nackedSeqNumbers[0] == 0xffff); @@ -198,18 +198,16 @@ SCENARIO("receive RTP packets and trigger NACK", "[rtp][rtpstream]") RtpStreamRecv rtpStream(&listener, params, SendNackDelay, UseRtpInactivityCheck); packet->SetSequenceNumber(1); - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); // Seq different is bigger than MaxNackPackets in NackGenerator, so it // triggers a key frame. packet->SetSequenceNumber(1003); listener.shouldTriggerPLI = true; listener.shouldTriggerFIR = false; - rtpStream.ReceivePacket(packet); + rtpStream.ReceivePacket(packet.get()); } // Must run the loop to wait for UV timers and close them. DepLibUV::RunLoop(); - - delete packet; } From e028f7b4e84533d3f292dbdeb2c604c1d6e17d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 12:29:14 +0200 Subject: [PATCH 11/17] cont. --- worker/test/src/RTC/RTCP/TestBye.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsAfb.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsLei.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsPli.cpp | 7 +++---- .../test/src/RTC/RTCP/TestFeedbackPsRemb.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsSli.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsTst.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp | 6 ++---- .../test/src/RTC/RTCP/TestFeedbackRtpNack.cpp | 7 +++---- .../src/RTC/RTCP/TestFeedbackRtpSrReq.cpp | 7 +++---- .../src/RTC/RTCP/TestFeedbackRtpTllei.cpp | 7 +++---- .../test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp | 14 ++++++------- worker/test/src/RTC/RTCP/TestPacket.cpp | 20 +++++-------------- .../test/src/RTC/RTCP/TestReceiverReport.cpp | 20 ++++++++----------- worker/test/src/RTC/RTCP/TestSenderReport.cpp | 15 ++++++-------- 17 files changed, 55 insertions(+), 96 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestBye.cpp b/worker/test/src/RTC/RTCP/TestBye.cpp index fa77458c35..2085e0791c 100644 --- a/worker/test/src/RTC/RTCP/TestBye.cpp +++ b/worker/test/src/RTC/RTCP/TestBye.cpp @@ -47,11 +47,11 @@ SCENARIO("RTCP BYE parsing", "[parser][rtcp][bye]") { SECTION("parse BYE packet") { - ByePacket* packet = ByePacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ ByePacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -64,8 +64,6 @@ SCENARIO("RTCP BYE parsing", "[parser][rtcp][bye]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create ByePacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp index cbea3a75cd..3d7f8227a1 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsAfb.cpp @@ -39,11 +39,11 @@ SCENARIO("RTCP Feedback PS AFB parsing", "[parser][rtcp][feedback-ps][afb]") { using namespace TestFeedbackPsAfb; - FeedbackPsAfbPacket* packet = FeedbackPsAfbPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsAfbPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -56,7 +56,5 @@ SCENARIO("RTCP Feedback PS AFB parsing", "[parser][rtcp][feedback-ps][afb]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp index 98196a2e0e..485a6382cc 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsLei.cpp @@ -41,11 +41,11 @@ SCENARIO("RTCP Feedback PS LEI parsing", "[parser][rtcp][feedback-ps][lei]") SECTION("parse FeedbackPsLeiPacket") { - FeedbackPsLeiPacket* packet = FeedbackPsLeiPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsLeiPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -58,8 +58,6 @@ SCENARIO("RTCP Feedback PS LEI parsing", "[parser][rtcp][feedback-ps][lei]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackPsLeiPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp index 3182ddcf04..c5559cd1bb 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp @@ -2,6 +2,7 @@ #include "RTC/RTCP/FeedbackPsPli.hpp" #include #include // std::memcmp() +#include using namespace RTC::RTCP; @@ -35,11 +36,11 @@ SCENARIO("RTCP Feeback RTP PLI parsing", "[parser][rtcp][feedback-ps][pli]") SECTION("parse FeedbackPsPliPacket") { - FeedbackPsPliPacket* packet = FeedbackPsPliPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsPliPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -52,8 +53,6 @@ SCENARIO("RTCP Feeback RTP PLI parsing", "[parser][rtcp][feedback-ps][pli]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackPsPliPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp index c0c9b21f88..e71eb05f95 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsRemb.cpp @@ -43,11 +43,11 @@ SCENARIO("RTCP Feedback PS parsing", "[parser][rtcp][feedback-ps][remb]") SECTION("parse FeedbackPsRembPacket") { - FeedbackPsRembPacket* packet = FeedbackPsRembPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsRembPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -60,8 +60,6 @@ SCENARIO("RTCP Feedback PS parsing", "[parser][rtcp][feedback-ps][remb]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackPsRembPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp index 796868ad50..2b5fe999af 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsRpsi.cpp @@ -49,11 +49,11 @@ SCENARIO("RTCP Feedback PS RPSI parsing", "[parser][rtcp][feedback-ps][rpsi]") SECTION("parse FeedbackPsRpsiPacket") { - FeedbackPsRpsiPacket* packet = FeedbackPsRpsiPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsRpsiPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -66,7 +66,5 @@ SCENARIO("RTCP Feedback PS RPSI parsing", "[parser][rtcp][feedback-ps][rpsi]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp index f01999a39d..d3def79324 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsSli.cpp @@ -46,11 +46,11 @@ SCENARIO("RTCP Feedback PS SLI parsing", "[parser][rtcp][feedback-ps][sli]") SECTION("parse FeedbackPsSliPacket") { - FeedbackPsSliPacket* packet = FeedbackPsSliPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsSliPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -63,7 +63,5 @@ SCENARIO("RTCP Feedback PS SLI parsing", "[parser][rtcp][feedback-ps][sli]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp index de8fc4d1ef..99427598ee 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsTst.cpp @@ -45,11 +45,11 @@ SCENARIO("RTCP Feedback PS TSTN parsing", "[parser][rtcp][feedback-ps][tstn]") SECTION("parse FeedbackPsTstPacket") { - FeedbackPsTstnPacket* packet = FeedbackPsTstnPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsTstnPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -62,8 +62,6 @@ SCENARIO("RTCP Feedback PS TSTN parsing", "[parser][rtcp][feedback-ps][tstn]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackPsTstPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp index 3067c7367c..9743091158 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsVbcm.cpp @@ -55,11 +55,11 @@ SCENARIO("RTCP Feedback PS VBCM parsing", "[parser][rtcp][feedback-ps][vbcm]") SECTION("parse FeedbackPsVbcmPacket") { - FeedbackPsVbcmPacket* packet = FeedbackPsVbcmPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsVbcmPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -72,7 +72,5 @@ SCENARIO("RTCP Feedback PS VBCM parsing", "[parser][rtcp][feedback-ps][vbcm]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp index 06c1d93dd9..1536de5130 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpEcn.cpp @@ -61,11 +61,11 @@ SCENARIO("RTCP Feeback RTP ECN parsing", "[parser][rtcp][feedback-rtp][ecn]") { using namespace TestFeedbackRtpEcn; - FeedbackRtpEcnPacket* packet = FeedbackRtpEcnPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpEcnPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -78,7 +78,5 @@ SCENARIO("RTCP Feeback RTP ECN parsing", "[parser][rtcp][feedback-rtp][ecn]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp index 64ed4ee994..2d62caa2bd 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpNack.cpp @@ -45,11 +45,12 @@ SCENARIO("RTCP Feeback RTP NACK parsing", "[parser][rtcp][feedback-rtp][nack]") SECTION("parse FeedbackRtpNackItem") { - FeedbackRtpNackPacket* packet = FeedbackRtpNackPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpNackPacket::Parse( + buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -62,8 +63,6 @@ SCENARIO("RTCP Feeback RTP NACK parsing", "[parser][rtcp][feedback-rtp][nack]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackRtpNackPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp index 8b1e4036cd..1604dfabc4 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpSrReq.cpp @@ -35,11 +35,12 @@ SCENARIO("RTCP Feeback RTP SR-REQ parsing", "[parser][rtcp][feedback-rtp][sr-req SECTION("parse FeedbackRtpSrReqPacket") { - FeedbackRtpSrReqPacket* packet = FeedbackRtpSrReqPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpSrReqPacket::Parse( + buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -52,8 +53,6 @@ SCENARIO("RTCP Feeback RTP SR-REQ parsing", "[parser][rtcp][feedback-rtp][sr-req REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackRtpSrReqPacket") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp index 654a11d251..f39ff48e7a 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTllei.cpp @@ -45,11 +45,12 @@ SCENARIO("RTCP Feeback RTP TLLEI parsing", "[parser][rtcp][feedback-rtp][tllei]" { using namespace TestFeedbackRtpTllei; - FeedbackRtpTlleiPacket* packet = FeedbackRtpTlleiPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpTlleiPacket::Parse( + buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -62,7 +63,5 @@ SCENARIO("RTCP Feeback RTP TLLEI parsing", "[parser][rtcp][feedback-rtp][tllei]" REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp index fc17fcf23f..b099aa448e 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTmmb.cpp @@ -48,11 +48,12 @@ SCENARIO("RTCP Feeback RTP TMMBR parsing", "[parser][rtcp][feedback-rtp][tmmb]") SECTION("parse FeedbackRtpTmmbrPacket") { - FeedbackRtpTmmbrPacket* packet = FeedbackRtpTmmbrPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpTmmbrPacket::Parse( + buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -64,15 +65,12 @@ SCENARIO("RTCP Feeback RTP TMMBR parsing", "[parser][rtcp][feedback-rtp][tmmb]") // represent the same content. SECTION("create a packet out of the serialized buffer") { - FeedbackRtpTmmbrPacket* packet = FeedbackRtpTmmbrPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackRtpTmmbrPacket::Parse( + buffer, sizeof(buffer)) }; - verify(packet); - - delete packet; + verify(packet.get()); } } - - delete packet; } SECTION("create FeedbackRtpTmmbrPacket") diff --git a/worker/test/src/RTC/RTCP/TestPacket.cpp b/worker/test/src/RTC/RTCP/TestPacket.cpp index 7755e0be38..48218dbb12 100644 --- a/worker/test/src/RTC/RTCP/TestPacket.cpp +++ b/worker/test/src/RTC/RTCP/TestPacket.cpp @@ -18,11 +18,9 @@ SCENARIO("RTCP parsing", "[parser][rtcp][packet]") SECTION("a RTCP packet may only contain the RTCP common header") { - Packet* packet = Packet::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ Packet::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - - delete packet; } SECTION("a too small RTCP packet should fail") @@ -30,11 +28,9 @@ SCENARIO("RTCP parsing", "[parser][rtcp][packet]") // Provide a wrong packet length. size_t length = sizeof(buffer) - 1; - Packet* packet = Packet::Parse(buffer, length); + std::unique_ptr packet{ Packet::Parse(buffer, length) }; REQUIRE_FALSE(packet); - - delete packet; } SECTION("a RTCP packet with incorrect version should fail") @@ -42,11 +38,9 @@ SCENARIO("RTCP parsing", "[parser][rtcp][packet]") // Set an incorrect version value (0). buffer[0] &= 0b00111111; - Packet* packet = Packet::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ Packet::Parse(buffer, sizeof(buffer)) }; REQUIRE_FALSE(packet); - - delete packet; } SECTION("a RTCP packet with incorrect length should fail") @@ -54,11 +48,9 @@ SCENARIO("RTCP parsing", "[parser][rtcp][packet]") // Set the packet length to zero. buffer[3] = 1; - Packet* packet = Packet::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ Packet::Parse(buffer, sizeof(buffer)) }; REQUIRE_FALSE(packet); - - delete packet; } SECTION("a RTCP packet with unknown type should fail") @@ -66,10 +58,8 @@ SCENARIO("RTCP parsing", "[parser][rtcp][packet]") // Set and unknown packet type (0). buffer[1] = 0; - Packet* packet = Packet::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ Packet::Parse(buffer, sizeof(buffer)) }; REQUIRE_FALSE(packet); - - delete packet; } } diff --git a/worker/test/src/RTC/RTCP/TestReceiverReport.cpp b/worker/test/src/RTC/RTCP/TestReceiverReport.cpp index a184856ab6..914d4c1de8 100644 --- a/worker/test/src/RTC/RTCP/TestReceiverReport.cpp +++ b/worker/test/src/RTC/RTCP/TestReceiverReport.cpp @@ -53,7 +53,7 @@ SCENARIO("RTCP RR parsing", "[parser][rtcp][rr]") { SECTION("parse RR packet with a single report") { - ReceiverReportPacket* packet = ReceiverReportPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ ReceiverReportPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet->GetCount() == 1); @@ -67,7 +67,8 @@ SCENARIO("RTCP RR parsing", "[parser][rtcp][rr]") packet->Serialize(serialized); - ReceiverReportPacket* packet2 = ReceiverReportPacket::Parse(serialized, sizeof(buffer)); + std::unique_ptr packet2{ ReceiverReportPacket::Parse( + serialized, sizeof(buffer)) }; REQUIRE(packet2->GetType() == Type::RR); REQUIRE(packet2->GetCount() == 1); @@ -81,26 +82,21 @@ SCENARIO("RTCP RR parsing", "[parser][rtcp][rr]") verify(report); - delete packet2; - SECTION("compare serialized packet with original buffer") { REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("parse RR") { - ReceiverReport* report = ReceiverReport::Parse(rrBuffer, ReceiverReport::HeaderSize); + std::unique_ptr report{ ReceiverReport::Parse( + rrBuffer, ReceiverReport::HeaderSize) }; REQUIRE(report); - verify(report); - - delete report; + verify(report.get()); } SECTION("create RR packet with more than 31 reports") @@ -132,7 +128,8 @@ SCENARIO("RTCP RR parsing", "[parser][rtcp][rr]") // Serialization must contain 2 RR packets since report count exceeds 31. packet.Serialize(buffer); - auto* packet2 = static_cast(Packet::Parse(buffer, sizeof(buffer))); + std::unique_ptr packet2{ static_cast( + Packet::Parse(buffer, sizeof(buffer))) }; REQUIRE(packet2 != nullptr); REQUIRE(packet2->GetCount() == 31); @@ -172,7 +169,6 @@ SCENARIO("RTCP RR parsing", "[parser][rtcp][rr]") REQUIRE(report->GetDelaySinceLastSenderReport() == 31 + i); } - delete packet2; delete packet3; } diff --git a/worker/test/src/RTC/RTCP/TestSenderReport.cpp b/worker/test/src/RTC/RTCP/TestSenderReport.cpp index 38f7862e8f..790160bc4f 100644 --- a/worker/test/src/RTC/RTCP/TestSenderReport.cpp +++ b/worker/test/src/RTC/RTCP/TestSenderReport.cpp @@ -2,6 +2,7 @@ #include "RTC/RTCP/SenderReport.hpp" #include #include // std::memcmp() +#include using namespace RTC::RTCP; @@ -50,7 +51,7 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") { SECTION("parse SR packet") { - SenderReportPacket* packet = SenderReportPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ SenderReportPacket::Parse(buffer, sizeof(buffer)) }; auto* report = *(packet->Begin()); @@ -67,17 +68,15 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("parse SR") { - SenderReport* report = SenderReport::Parse(srBuffer, SenderReport::HeaderSize); + std::unique_ptr report{ SenderReport::Parse(srBuffer, SenderReport::HeaderSize) }; REQUIRE(report); - verify(report); + verify(report.get()); SECTION("serialize SenderReport instance") { @@ -90,8 +89,6 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") REQUIRE(std::memcmp(srBuffer, serialized, SenderReport::HeaderSize) == 0); } } - - delete report; } SECTION("create SR packet multiple reports") @@ -122,7 +119,8 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") SenderReport* reports[count]{ nullptr }; - auto* packet2 = static_cast(Packet::Parse(buffer, sizeof(buffer))); + std::unique_ptr packet2{ static_cast( + Packet::Parse(buffer, sizeof(buffer))) }; REQUIRE(packet2 != nullptr); @@ -154,7 +152,6 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") REQUIRE(report->GetOctetCount() == i); } - delete packet2; delete packet3; delete packet4; } From deeda2ccf82e9debde7ba4ed6195bab07efc903a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 12:36:57 +0200 Subject: [PATCH 12/17] cont. --- worker/test/src/RTC/TestRtpPacketH264Svc.cpp | 76 ++++++++------------ 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/worker/test/src/RTC/TestRtpPacketH264Svc.cpp b/worker/test/src/RTC/TestRtpPacketH264Svc.cpp index e2407ff1ff..844bfe3853 100644 --- a/worker/test/src/RTC/TestRtpPacketH264Svc.cpp +++ b/worker/test/src/RTC/TestRtpPacketH264Svc.cpp @@ -26,7 +26,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -59,8 +59,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -73,10 +74,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->tlIndex == 0); REQUIRE(payloadDescriptor->hasSlIndex == false); REQUIRE(payloadDescriptor->isKeyFrame == true); - - delete payloadDescriptor; - - delete packet; } SECTION("parse I0-8.bin") @@ -90,7 +87,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -123,8 +120,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -137,10 +135,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->tlIndex == 0); REQUIRE(payloadDescriptor->hasSlIndex == false); REQUIRE(payloadDescriptor->isKeyFrame == false); - - delete payloadDescriptor; - - delete packet; } SECTION("parse I0-5.bin") @@ -154,7 +148,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -187,8 +181,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -200,10 +195,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->isKeyFrame == true); REQUIRE(payloadDescriptor->hasSlIndex == false); REQUIRE(payloadDescriptor->hasTlIndex == false); - - delete payloadDescriptor; - - delete packet; } SECTION("parse I1-15.bin") @@ -217,7 +208,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -250,8 +241,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -264,10 +256,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->tlIndex == 0); REQUIRE(payloadDescriptor->hasSlIndex == false); REQUIRE(payloadDescriptor->isKeyFrame == false); - - delete payloadDescriptor; - - delete packet; } SECTION("parse I0-14.bin") @@ -281,7 +269,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -314,8 +302,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -328,10 +317,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->tlIndex == 0); REQUIRE(payloadDescriptor->hasSlIndex == false); REQUIRE(payloadDescriptor->isKeyFrame == true); - - delete payloadDescriptor; - - delete packet; } SECTION("parse 2SL-I14.bin") @@ -345,7 +330,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -378,8 +363,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = - Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -393,10 +379,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") REQUIRE(payloadDescriptor->hasSlIndex); REQUIRE(payloadDescriptor->slIndex == 0); REQUIRE(payloadDescriptor->isKeyFrame == true); - - delete payloadDescriptor; - - delete packet; } SECTION("create and test RTP files") @@ -453,7 +435,7 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") FAIL("Failed to write RTP packet!\n"); } - RtpPacket* packet = RtpPacket::Parse(buffer2, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer2, len) }; if (!packet) { @@ -469,8 +451,9 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") // Read frame-marking. packet->ReadFrameMarking(&frameMarking, frameMarkingLen); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse( - payload, packet->GetPayloadLength(), frameMarking, frameMarkingLen); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(payload, packet->GetPayloadLength(), frameMarking, frameMarkingLen) + }; REQUIRE(payloadDescriptor); @@ -478,9 +461,6 @@ SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]") pos += bytes; rows++; - - delete payloadDescriptor; - delete packet; } nf.close(); From e1d0e7b6d00ede7dd7265bd0b2bd52b003e24ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 12:42:58 +0200 Subject: [PATCH 13/17] cont. --- worker/test/src/RTC/TestRtpPacket.cpp | 53 +++++++-------------------- 1 file changed, 14 insertions(+), 39 deletions(-) diff --git a/worker/test/src/RTC/TestRtpPacket.cpp b/worker/test/src/RTC/TestRtpPacket.cpp index e931697c9e..0afd766d9e 100644 --- a/worker/test/src/RTC/TestRtpPacket.cpp +++ b/worker/test/src/RTC/TestRtpPacket.cpp @@ -24,7 +24,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -50,8 +50,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(extenValue == nullptr); REQUIRE(packet->ReadRid(rid) == false); REQUIRE(rid == ""); - - delete packet; } SECTION("parse packet2.raw") @@ -63,7 +61,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -80,8 +78,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->GetHeaderExtensionLength() == 0); REQUIRE(packet->HasOneByteExtensions() == false); REQUIRE(packet->HasTwoBytesExtensions() == false); - - delete packet; } SECTION("parse packet3.raw") @@ -98,7 +94,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") FAIL("cannot open file"); } - RtpPacket* packet = RtpPacket::Parse(buffer, len); + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -139,7 +135,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->ReadAbsSendTime(absSendTime) == true); REQUIRE(absSendTime == 0x65341e); - auto* clonedPacket = packet->Clone(); + std::unique_ptr clonedPacket{ packet->Clone() }; std::memset(buffer, '0', sizeof(buffer)); @@ -174,9 +170,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(extenValue[2] == 0x1e); REQUIRE(clonedPacket->ReadAbsSendTime(absSendTime) == true); REQUIRE(absSendTime == 0x65341e); - - delete packet; - delete clonedPacket; } SECTION("create RtpPacket without header extension") @@ -190,7 +183,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -205,8 +198,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasOneByteExtensions() == false); REQUIRE(packet->HasTwoBytesExtensions() == false); REQUIRE(packet->GetSsrc() == 5); - - delete packet; } SECTION("create RtpPacket with One-Byte header extension") @@ -224,7 +215,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -248,8 +239,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->GetPayloadLength() == 1000); REQUIRE(packet->GetSize() == 1028); - - delete packet; } SECTION("create RtpPacket with Two-Bytes header extension") @@ -271,7 +260,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") uint8_t extenLen; uint8_t* extenValue; - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -316,8 +305,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasExtension(5) == false); REQUIRE(extenValue == nullptr); REQUIRE(extenLen == 0); - - delete packet; } SECTION("rtx encryption-decryption") @@ -340,7 +327,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") uint32_t rtxSsrc{ 6 }; uint16_t rtxSeq{ 80 }; - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -358,9 +345,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->HasOneByteExtensions() == false); REQUIRE(packet->HasTwoBytesExtensions()); - auto* rtxPacket = packet->Clone(); - - delete packet; + std::unique_ptr rtxPacket{ packet->Clone() }; std::memset(buffer, '0', sizeof(buffer)); @@ -389,8 +374,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(rtxPacket->GetHeaderExtensionLength() == 12); REQUIRE(rtxPacket->HasOneByteExtensions() == false); REQUIRE(rtxPacket->HasTwoBytesExtensions()); - - delete rtxPacket; } SECTION("create RtpPacket and apply payload shift to it") @@ -415,8 +398,8 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - size_t len = 40; - RtpPacket* packet = RtpPacket::Parse(buffer, len); + size_t len = 40; + std::unique_ptr packet{ RtpPacket::Parse(buffer, len) }; if (!packet) { @@ -504,8 +487,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->GetPayloadLength() == 1000); REQUIRE(packet->GetPayloadPadding() == 0); REQUIRE(packet->GetSize() == 1028); - - delete packet; } SECTION("set One-Byte header extensions") @@ -530,7 +511,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, 28); + std::unique_ptr packet{ RtpPacket::Parse(buffer, 28) }; std::vector extensions; uint8_t extenLen; uint8_t* extenValue; @@ -675,8 +656,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(extenValue[1] == 0x02); REQUIRE(extenValue[2] == 0x03); REQUIRE(extenValue[3] == 0x00); - - delete packet; } SECTION("set Two-Bytes header extensions") @@ -703,7 +682,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, 28); + std::unique_ptr packet{ RtpPacket::Parse(buffer, 28) }; std::vector extensions; uint8_t extenLen; uint8_t* extenValue; @@ -830,8 +809,6 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(packet->GetExtension(24, extenLen)); REQUIRE(packet->HasExtension(24) == true); REQUIRE(extenLen == 4); - - delete packet; } SECTION("read frame-marking extension") @@ -848,7 +825,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") }; // clang-format on - RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ RtpPacket::Parse(buffer, sizeof(buffer)) }; if (!packet) { @@ -882,7 +859,5 @@ SCENARIO("parse RTP packets", "[parser][rtp]") REQUIRE(frameMarking->tid == 3); REQUIRE(frameMarking->lid == 1); REQUIRE(frameMarking->tl0picidx == 5); - - delete packet; } } From df75e8e7ba2d522a1e262763163fd1340ac5808a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Thu, 4 Jul 2024 12:48:06 +0200 Subject: [PATCH 14/17] cont. --- worker/test/src/RTC/Codecs/TestH264.cpp | 5 ++- worker/test/src/RTC/Codecs/TestH264_SVC.cpp | 36 +++++++++---------- worker/test/src/RTC/Codecs/TestVP8.cpp | 10 +++--- .../test/src/RTC/RTCP/TestFeedbackPsFir.cpp | 6 ++-- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/worker/test/src/RTC/Codecs/TestH264.cpp b/worker/test/src/RTC/Codecs/TestH264.cpp index 67b573682f..47132e96cc 100644 --- a/worker/test/src/RTC/Codecs/TestH264.cpp +++ b/worker/test/src/RTC/Codecs/TestH264.cpp @@ -21,10 +21,9 @@ SCENARIO("parse H264 payload descriptor", "[codecs][h264]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ Codecs::H264::Parse( + buffer, sizeof(buffer)) }; REQUIRE(payloadDescriptor); - - delete payloadDescriptor; } } diff --git a/worker/test/src/RTC/Codecs/TestH264_SVC.cpp b/worker/test/src/RTC/Codecs/TestH264_SVC.cpp index 16c5726ac6..dc7380959d 100644 --- a/worker/test/src/RTC/Codecs/TestH264_SVC.cpp +++ b/worker/test/src/RTC/Codecs/TestH264_SVC.cpp @@ -21,7 +21,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -31,8 +33,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == true); REQUIRE(payloadDescriptor->hasTlIndex == false); REQUIRE(payloadDescriptor->hasSlIndex == false); - - delete payloadDescriptor; } SECTION("parse payload descriptor for NALU 8") @@ -49,7 +49,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -59,8 +61,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == false); REQUIRE(payloadDescriptor->hasTlIndex == false); REQUIRE(payloadDescriptor->hasSlIndex == false); - - delete payloadDescriptor; } SECTION("parse payload descriptor for NALU 1") @@ -77,7 +77,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -87,8 +89,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == false); REQUIRE(payloadDescriptor->hasTlIndex == false); REQUIRE(payloadDescriptor->hasSlIndex == false); - - delete payloadDescriptor; } SECTION("parse payload descriptor for NALU 5") @@ -105,7 +105,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -115,8 +117,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == true); REQUIRE(payloadDescriptor->hasTlIndex == false); REQUIRE(payloadDescriptor->hasSlIndex == false); - - delete payloadDescriptor; } SECTION("parse payload descriptor for NALU 14") @@ -133,7 +133,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -145,8 +147,6 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == false); REQUIRE(payloadDescriptor->hasTlIndex == true); REQUIRE(payloadDescriptor->hasSlIndex == true); - - delete payloadDescriptor; } SECTION("parse payload descriptor for NALU 20") @@ -163,7 +163,9 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ + Codecs::H264_SVC::Parse(buffer, sizeof(buffer)) + }; REQUIRE(payloadDescriptor); @@ -175,7 +177,5 @@ SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]") REQUIRE(payloadDescriptor->isKeyFrame == false); REQUIRE(payloadDescriptor->hasTlIndex == true); REQUIRE(payloadDescriptor->hasSlIndex == true); - - delete payloadDescriptor; } } diff --git a/worker/test/src/RTC/Codecs/TestVP8.cpp b/worker/test/src/RTC/Codecs/TestVP8.cpp index 545240d78c..a5b663aaea 100644 --- a/worker/test/src/RTC/Codecs/TestVP8.cpp +++ b/worker/test/src/RTC/Codecs/TestVP8.cpp @@ -38,7 +38,8 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); - const auto* payloadDescriptor = Codecs::VP8::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ Codecs::VP8::Parse( + buffer, sizeof(buffer)) }; REQUIRE(payloadDescriptor); @@ -77,8 +78,6 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]") REQUIRE(std::memcmp(buffer, originalBuffer, sizeof(buffer)) == 0); } } - - delete payloadDescriptor; } SECTION("parse payload descriptor 2") @@ -113,7 +112,8 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]") std::memcpy(buffer, originalBuffer, sizeof(buffer)); // Parse the buffer. - const auto* payloadDescriptor = Codecs::VP8::Parse(buffer, sizeof(buffer)); + std::unique_ptr payloadDescriptor{ Codecs::VP8::Parse( + buffer, sizeof(buffer)) }; REQUIRE(payloadDescriptor); @@ -152,8 +152,6 @@ SCENARIO("parse VP8 payload descriptor", "[codecs][vp8]") REQUIRE(std::memcmp(buffer, originalBuffer, sizeof(buffer)) == 0); } } - - delete payloadDescriptor; }; SECTION("parse payload descriptor. I flag set but no space for pictureId") diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp index 7bd3a71585..b5781802e9 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsFir.cpp @@ -44,11 +44,11 @@ SCENARIO("RTCP Feedback PS FIR parsing", "[parser][rtcp][feedback-ps][fir]") SECTION("parse FeedbackPsFirPacket") { - FeedbackPsFirPacket* packet = FeedbackPsFirPacket::Parse(buffer, sizeof(buffer)); + std::unique_ptr packet{ FeedbackPsFirPacket::Parse(buffer, sizeof(buffer)) }; REQUIRE(packet); - verify(packet); + verify(packet.get()); SECTION("serialize packet instance") { @@ -61,8 +61,6 @@ SCENARIO("RTCP Feedback PS FIR parsing", "[parser][rtcp][feedback-ps][fir]") REQUIRE(std::memcmp(buffer, serialized, sizeof(buffer)) == 0); } } - - delete packet; } SECTION("create FeedbackPsFirPacket") From 4a8fb44bf6b4ea48bde851bde803fbb30a8d84ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 6 Jul 2024 13:46:37 +0200 Subject: [PATCH 15/17] no need to include , already in common.hpp --- worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp | 1 - worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp | 1 - worker/test/src/RTC/RTCP/TestSdes.cpp | 1 - worker/test/src/RTC/RTCP/TestSenderReport.cpp | 1 - worker/test/src/RTC/RTCP/TestXr.cpp | 1 - worker/test/src/RTC/TestRtpStreamSend.cpp | 1 - 6 files changed, 6 deletions(-) diff --git a/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp b/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp index c5559cd1bb..762f9e5b72 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp @@ -2,7 +2,6 @@ #include "RTC/RTCP/FeedbackPsPli.hpp" #include #include // std::memcmp() -#include using namespace RTC::RTCP; diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp index 0f6b9e579b..68fc15d258 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp @@ -3,7 +3,6 @@ #include "RTC/RTCP/FeedbackRtpTransport.hpp" #include #include // std::memcmp() -#include using namespace RTC::RTCP; diff --git a/worker/test/src/RTC/RTCP/TestSdes.cpp b/worker/test/src/RTC/RTCP/TestSdes.cpp index b453d05fc6..b03df3c855 100644 --- a/worker/test/src/RTC/RTCP/TestSdes.cpp +++ b/worker/test/src/RTC/RTCP/TestSdes.cpp @@ -3,7 +3,6 @@ #include "RTC/RTCP/Sdes.hpp" #include #include // std::memcmp() -#include #include using namespace RTC::RTCP; diff --git a/worker/test/src/RTC/RTCP/TestSenderReport.cpp b/worker/test/src/RTC/RTCP/TestSenderReport.cpp index 790160bc4f..e874ba92a1 100644 --- a/worker/test/src/RTC/RTCP/TestSenderReport.cpp +++ b/worker/test/src/RTC/RTCP/TestSenderReport.cpp @@ -2,7 +2,6 @@ #include "RTC/RTCP/SenderReport.hpp" #include #include // std::memcmp() -#include using namespace RTC::RTCP; diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index 3767ff6945..b1569bddc8 100644 --- a/worker/test/src/RTC/RTCP/TestXr.cpp +++ b/worker/test/src/RTC/RTCP/TestXr.cpp @@ -4,7 +4,6 @@ #include "RTC/RTCP/XrReceiverReferenceTime.hpp" #include #include // std::memcmp(), std::memcpy() -#include using namespace RTC::RTCP; diff --git a/worker/test/src/RTC/TestRtpStreamSend.cpp b/worker/test/src/RTC/TestRtpStreamSend.cpp index c3f454a6c6..de52e87f83 100644 --- a/worker/test/src/RTC/TestRtpStreamSend.cpp +++ b/worker/test/src/RTC/TestRtpStreamSend.cpp @@ -4,7 +4,6 @@ #include "RTC/RtpStream.hpp" #include "RTC/RtpStreamSend.hpp" #include -#include #include // #define PERFORMANCE_TEST 1 From 0e6ec6fd85bbabf6e27a384d57caabad03ca2f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 6 Jul 2024 13:56:25 +0200 Subject: [PATCH 16/17] one more --- worker/test/src/RTC/TestNackGenerator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/test/src/RTC/TestNackGenerator.cpp b/worker/test/src/RTC/TestNackGenerator.cpp index bb9744188b..caaefdbe4a 100644 --- a/worker/test/src/RTC/TestNackGenerator.cpp +++ b/worker/test/src/RTC/TestNackGenerator.cpp @@ -118,7 +118,7 @@ uint8_t rtpBuffer[] = // clang-format on // [pt:123, seq:21006, timestamp:1533790901] -RtpPacket* packet = RtpPacket::Parse(rtpBuffer, sizeof(rtpBuffer)); +std::unique_ptr packet(RtpPacket::Parse(rtpBuffer, sizeof(rtpBuffer))); void validate(std::vector& inputs) { @@ -133,7 +133,7 @@ void validate(std::vector& inputs) packet->SetPayloadDescriptorHandler(tpdh); packet->SetSequenceNumber(input.seq); - nackGenerator.ReceivePacket(packet, /*isRecovered*/ false); + nackGenerator.ReceivePacket(packet.get(), /*isRecovered*/ false); listener.Check(nackGenerator); } From 42b57afb42b294c7bba0786623586ae6bd4505b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Sat, 6 Jul 2024 13:58:44 +0200 Subject: [PATCH 17/17] enable test-asan-address in CI Linux --- .github/workflows/mediasoup-worker.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mediasoup-worker.yaml b/.github/workflows/mediasoup-worker.yaml index a75f85435c..6ff7dc5ec1 100644 --- a/.github/workflows/mediasoup-worker.yaml +++ b/.github/workflows/mediasoup-worker.yaml @@ -97,12 +97,10 @@ jobs: # TODO: Maybe fix this one day. if: runner.os != 'Windows' - # TODO: Uncomment once https://github.com/versatica/mediasoup/issues/1417 - # is fixed. - # - name: invoke -r worker test-asan-address - # run: invoke -r worker test-asan-address - # # Address Sanitizer only works on Linux. - # if: runner.os == 'Linux' + - name: invoke -r worker test-asan-address + run: invoke -r worker test-asan-address + # Address Sanitizer only works on Linux. + if: runner.os == 'Linux' # TODO: Uncomment once https://github.com/versatica/mediasoup/issues/1417 # is fixed.