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

Fix spatial layer switch with unordered packets #823

Merged
merged 7 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions worker/include/RTC/SimulcastConsumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ namespace RTC
int16_t targetTemporalLayer{ -1 };
int16_t currentSpatialLayer{ -1 };
int16_t tsReferenceSpatialLayer{ -1 }; // Used for RTP TS sync.
uint16_t snReferenceSpatialLayer{ 0 };
bool checkingForOldPacketsInSpatialLayer{ false };
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
uint32_t tsOffset{ 0u }; // RTP Timestamp offset.
bool keyFrameForTsOffsetRequested{ false };
Expand Down
26 changes: 23 additions & 3 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace RTC
static constexpr uint64_t StreamMinActiveMs{ 2000u }; // In ms.
static constexpr uint64_t BweDowngradeConservativeMs{ 10000u }; // In ms.
static constexpr uint64_t BweDowngradeMinActiveMs{ 8000u }; // In ms.
static constexpr uint16_t MaxSequenceNumberGap{ 100u };

/* Instance methods. */

Expand Down Expand Up @@ -823,13 +824,31 @@ namespace RTC
this->keyFrameForTsOffsetRequested = false;
}

if (!shouldSwitchCurrentSpatialLayer && this->checkingForOldPacketsInSpatialLayer)
jcague marked this conversation as resolved.
Show resolved Hide resolved
{
// If this is a packet previous to the spatial layer switch, ignore the packet
jcague marked this conversation as resolved.
Show resolved Hide resolved
if (SeqManager<uint16_t>::IsSeqLowerThan(
packet->GetSequenceNumber(), this->snReferenceSpatialLayer))
{
return;
}
else if (SeqManager<uint16_t>::IsSeqHigherThan(
packet->GetSequenceNumber(), this->snReferenceSpatialLayer + MaxSequenceNumberGap))
{
this->checkingForOldPacketsInSpatialLayer = false;
}
}

bool marker{ false };

if (shouldSwitchCurrentSpatialLayer)
{
// Update current spatial layer.
this->currentSpatialLayer = this->targetSpatialLayer;

this->snReferenceSpatialLayer = packet->GetSequenceNumber();
this->checkingForOldPacketsInSpatialLayer = true;

// Update target and current temporal layer.
this->encodingContext->SetTargetTemporalLayer(this->targetTemporalLayer);
this->encodingContext->SetCurrentTemporalLayer(packet->GetTemporalLayer());
Expand Down Expand Up @@ -1092,9 +1111,10 @@ namespace RTC
{
MS_TRACE();

this->syncRequired = true;
this->spatialLayerToSync = -1;
this->keyFrameForTsOffsetRequested = false;
this->syncRequired = true;
this->spatialLayerToSync = -1;
this->keyFrameForTsOffsetRequested = false;
this->checkingForOldPacketsInSpatialLayer = false;

if (IsActive())
MayChangeLayers();
Expand Down