Skip to content

Commit

Permalink
VP8: do not forward RTP packets which payload contains a higher tempo…
Browse files Browse the repository at this point in the history
…ral layer than current one. (#1009)

Worker: VP8, do not send frames with temporal layer higher than the current one

Fixes #989


---------

Co-authored-by: Iñaki Baz Castillo <[email protected]>
  • Loading branch information
jmillan and ibc authored Jan 29, 2025
1 parent 4638d83 commit b5d8517
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
8 changes: 7 additions & 1 deletion worker/src/RTC/Codecs/VP8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ namespace RTC
// clang-format off
if (
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()
this->payloadDescriptor->tlIndex == context->GetTargetTemporalLayer()
)
// clang-format on
{
Expand All @@ -375,6 +375,12 @@ namespace RTC
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 &&
Expand Down
64 changes: 64 additions & 0 deletions worker/test/src/RTC/Codecs/TestVP8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit b5d8517

Please sign in to comment.