Skip to content

Commit

Permalink
VP8: Fix and improve temporal layer selection
Browse files Browse the repository at this point in the history
Fixes versatica#989

* An old payload cannot upgrade the current temporal layer.
* Update current temporal layer to the target one.
  • Loading branch information
jmillan committed Jan 30, 2023
1 parent c942fd9 commit f021e27
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
1 change: 1 addition & 0 deletions worker/include/RTC/Codecs/VP8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ namespace RTC

private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
bool hasProcessedAnyPayload{ false };
};
};
} // namespace Codecs
Expand Down
57 changes: 38 additions & 19 deletions worker/src/RTC/Codecs/VP8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,27 @@ namespace RTC
MS_WARN_DEV("stream is supposed to have >1 temporal layers but does not have TlIndex field");
}

auto oldPictureId = false;

// clang-format off
if (
this->hasProcessedAnyPayload &&
RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan(
this->payloadDescriptor->pictureId, context->pictureIdManager.GetMaxInput())
)
// clang-format on
{
oldPictureId = true;
}
else if (!this->hasProcessedAnyPayload)
{
this->hasProcessedAnyPayload = true;
}

// Check whether pictureId and tl0PictureIndex sync is required.
// clang-format off
if (
!oldPictureId &&
context->syncRequired &&
this->payloadDescriptor->hasPictureId &&
this->payloadDescriptor->hasTl0PictureIndex
Expand All @@ -255,12 +273,10 @@ namespace RTC
// Incremental pictureId. Check the temporal layer.
// clang-format off
if (
!oldPictureId &&
this->payloadDescriptor->hasPictureId &&
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->hasTl0PictureIndex &&
!RTC::SeqManager<uint16_t, 15>::IsSeqLowerThan(
this->payloadDescriptor->pictureId,
context->pictureIdManager.GetMaxInput())
this->payloadDescriptor->hasTl0PictureIndex
)
// clang-format on
{
Expand Down Expand Up @@ -321,23 +337,26 @@ namespace RTC
return false;
}

// Update/fix current temporal layer.
// clang-format off
if (
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()
)
// clang-format on
if (!oldPictureId)
{
context->SetCurrentTemporalLayer(this->payloadDescriptor->tlIndex);
}
else if (!this->payloadDescriptor->hasTlIndex)
{
context->SetCurrentTemporalLayer(0);
}
// Update/fix current temporal layer.
// clang-format off
if (
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->tlIndex == context->GetTargetTemporalLayer()
)
// clang-format on
{
context->SetCurrentTemporalLayer(this->payloadDescriptor->tlIndex);
}
else if (!this->payloadDescriptor->hasTlIndex)
{
context->SetCurrentTemporalLayer(0);
}

if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer())
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer());
if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer())
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer());
}

// clang-format off
if (
Expand Down

0 comments on commit f021e27

Please sign in to comment.