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. 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/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/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/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") 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..762f9e5b72 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackPsPli.cpp @@ -35,11 +35,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 +52,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/TestFeedbackRtpTransport.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp index 0204f81480..68fc15d258 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp @@ -69,7 +69,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 +141,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 +156,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 +206,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 +221,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 +240,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 +275,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 +290,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 +302,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 +337,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 +352,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 +373,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 +406,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 +421,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 +440,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 +472,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 +487,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 +506,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 +528,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 +543,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 +565,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 +581,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 +604,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 +746,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 +765,6 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" REQUIRE(static_cast(resultDelta / 4) == delta); deltasIt++; } - delete feedback; } } @@ -791,9 +772,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 +794,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/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/TestSdes.cpp b/worker/test/src/RTC/RTCP/TestSdes.cpp index a875dbf2ba..b03df3c855 100644 --- a/worker/test/src/RTC/RTCP/TestSdes.cpp +++ b/worker/test/src/RTC/RTCP/TestSdes.cpp @@ -97,8 +97,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 +164,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 +290,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 +360,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 +384,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 +392,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 +414,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 +435,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 +447,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 +455,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 +476,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 +518,6 @@ SCENARIO("RTCP SDES parsing", "[parser][rtcp][sdes]") REQUIRE(std::string(item->GetValue()) == item1Value); } - delete packet2; delete packet3; } diff --git a/worker/test/src/RTC/RTCP/TestSenderReport.cpp b/worker/test/src/RTC/RTCP/TestSenderReport.cpp index 38f7862e8f..e874ba92a1 100644 --- a/worker/test/src/RTC/RTCP/TestSenderReport.cpp +++ b/worker/test/src/RTC/RTCP/TestSenderReport.cpp @@ -50,7 +50,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 +67,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 +88,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 +118,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 +151,6 @@ SCENARIO("RTCP SR parsing", "[parser][rtcp][sr]") REQUIRE(report->GetOctetCount() == i); } - delete packet2; delete packet3; delete packet4; } diff --git a/worker/test/src/RTC/RTCP/TestXr.cpp b/worker/test/src/RTC/RTCP/TestXr.cpp index b047d32389..b1569bddc8 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,6 +130,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create RRT") { // 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 ReceiverReferenceTime(); report1->SetNtpSec(11111111); @@ -148,6 +147,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. + // 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()); @@ -179,7 +180,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,7 +196,11 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") SECTION("create DLRR") { // Create local report and check content. - auto* report1 = new DelaySinceLastRr(); + // 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); @@ -214,6 +220,8 @@ SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]") report1->Serialize(bufferReport1); // Create a new report out of the external buffer. + // 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()); @@ -252,7 +260,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/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); } 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; } } 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(); 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) 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; } diff --git a/worker/test/src/RTC/TestRtpStreamSend.cpp b/worker/test/src/RTC/TestRtpStreamSend.cpp index 3d18323c1b..de52e87f83 100644 --- a/worker/test/src/RTC/TestRtpStreamSend.cpp +++ b/worker/test/src/RTC/TestRtpStreamSend.cpp @@ -10,14 +10,15 @@ 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 +79,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 +100,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 +142,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 +163,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 +193,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 +214,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 +244,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 +318,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 +332,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 +371,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 +386,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 +418,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 +438,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()); @@ -496,7 +471,7 @@ 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 stream1(new RtpStreamSend(&testRtpStreamListener, params, mid)); size_t iterations = 10000000; @@ -510,16 +485,14 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") std::shared_ptr sharedPacket(packet); - stream->ReceivePacket(packet, sharedPacket); + stream1->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; - params.mimeType.type = RTC::RtpCodecMimeType::Type::AUDIO; - stream = new RtpStreamSend(&testRtpStreamListener, params, mid); + std::unique_ptr stream2(new RtpStreamSend(&testRtpStreamListener, params, mid)); start = std::chrono::system_clock::now(); @@ -531,13 +504,11 @@ SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp][nack]") auto* packet = RtpPacket::Parse(rtpBuffer1, 1500); packet->SetSsrc(1111); - stream->ReceivePacket(packet, sharedPacket); + stream2->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; } #endif } 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();