Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VP8: do not forward RTP packets which payload contains a higher temporal layer than current one. #1009

Draft
wants to merge 2 commits into
base: v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion worker/src/RTC/Codecs/VP8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ namespace RTC
// clang-format off
if (
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()
this->payloadDescriptor->tlIndex == context->GetTargetTemporalLayer()
Copy link
Contributor

@vpalmisano vpalmisano Feb 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to keep the packets with temporal layer <= target ?

Suggested change
this->payloadDescriptor->tlIndex == context->GetTargetTemporalLayer()
this->payloadDescriptor->tlIndex <= context->GetTargetTemporalLayer()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must only upgrade the temporal layer with a packet whose temporal layer is the target one.

)
// clang-format on
{
Expand All @@ -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())
jmillan marked this conversation as resolved.
Show resolved Hide resolved
{
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);
}
}