From 969f33338b1c0268a95e204270f79312caad892a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Tue, 31 Jan 2023 17:32:05 +0100 Subject: [PATCH 1/3] Worker: VP8, do not send frames with temporal layer higher than the current one Fixes #989 --- worker/src/RTC/Codecs/VP8.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/worker/src/RTC/Codecs/VP8.cpp b/worker/src/RTC/Codecs/VP8.cpp index 3d5a2139ca..9136df0ab2 100644 --- a/worker/src/RTC/Codecs/VP8.cpp +++ b/worker/src/RTC/Codecs/VP8.cpp @@ -325,7 +325,7 @@ namespace RTC // clang-format off if ( this->payloadDescriptor->hasTlIndex && - this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer() + this->payloadDescriptor->tlIndex == context->GetTargetTemporalLayer() ) // clang-format on { @@ -339,6 +339,12 @@ namespace RTC if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer()) context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer()); + // Do not send tlIndex higher than current one. + if (this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()) + { + return false; + } + // clang-format off if ( this->payloadDescriptor->hasPictureId && From c1db7684e6efb323f5ccc67f5fc41b071438c7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Wed, 1 Feb 2023 16:34:43 +0100 Subject: [PATCH 2/3] Add tests --- worker/test/src/RTC/Codecs/TestVP8.cpp | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/worker/test/src/RTC/Codecs/TestVP8.cpp b/worker/test/src/RTC/Codecs/TestVP8.cpp index 9675fb2e51..676ab514d4 100644 --- a/worker/test/src/RTC/Codecs/TestVP8.cpp +++ b/worker/test/src/RTC/Codecs/TestVP8.cpp @@ -322,4 +322,68 @@ SCENARIO("process VP8 payload descriptor", "[codecs][vp8]") forwarded = ProcessPacket(context, 1, 0, 1); REQUIRE_FALSE(forwarded); } + + SECTION("old packets with higher temporal layer than current are dropped") + { + RTC::Codecs::EncodingContext::Params params; + params.spatialLayers = 0; + params.temporalLayers = 2; + Codecs::VP8::EncodingContext context(params); + context.SyncRequired(); + + context.SetCurrentTemporalLayer(0); + context.SetTargetTemporalLayer(0); + + // Frame 1. + auto forwarded = ProcessPacket(context, 1, 0, 0); + REQUIRE(forwarded); + REQUIRE(forwarded->pictureId == 1); + REQUIRE(forwarded->tlIndex == 0); + REQUIRE(forwarded->tl0PictureIndex == 1); + + // Frame 2. + forwarded = ProcessPacket(context, 2, 0, 0); + REQUIRE(forwarded); + REQUIRE(forwarded->pictureId == 2); + REQUIRE(forwarded->tlIndex == 0); + REQUIRE(forwarded->tl0PictureIndex == 1); + + // Frame 3. Old packet with higher temporal layer than current. + forwarded = ProcessPacket(context, 0, 0, 1); + REQUIRE_FALSE(forwarded); + REQUIRE(context.GetCurrentTemporalLayer() == 0); + } + + SECTION("packets with higher temporal layer than current are dropped") + { + RTC::Codecs::EncodingContext::Params params; + params.spatialLayers = 0; + params.temporalLayers = 2; + Codecs::VP8::EncodingContext context(params); + context.SyncRequired(); + + context.SetCurrentTemporalLayer(0); + context.SetTargetTemporalLayer(0); + + // Frame 1. + auto forwarded = ProcessPacket(context, 1, 0, 0); + REQUIRE(forwarded); + REQUIRE(forwarded->pictureId == 1); + REQUIRE(forwarded->tlIndex == 0); + REQUIRE(forwarded->tl0PictureIndex == 1); + + // Frame 2. + forwarded = ProcessPacket(context, 2, 0, 0); + REQUIRE(forwarded); + REQUIRE(forwarded->pictureId == 2); + REQUIRE(forwarded->tlIndex == 0); + REQUIRE(forwarded->tl0PictureIndex == 1); + + context.SetTargetTemporalLayer(2); + + // Frame 3. Old packet with higher temporal layer than current. + forwarded = ProcessPacket(context, 3, 0, 1); + REQUIRE_FALSE(forwarded); + REQUIRE(context.GetCurrentTemporalLayer() == 0); + } } From 1020149e5d39d908211d5e2f99f45770726b1291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Wed, 29 Jan 2025 12:46:17 +0100 Subject: [PATCH 3/3] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1703bc8af..82dc749a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### NEXT +- `Worker`: Drop VP8 packets with a higher temporal layer than the current one ([PR #1009](https://github.com/versatica/mediasoup/pull/1009)). + ### 3.15.3 - Node: Expose `Index` interface in `types.indexTypes` or via `import { Index as MediasoupIndex } from 'mediasoup/lib/indexTypes'` ([PR #1485](https://github.com/versatica/mediasoup/pull/1485)).