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

Ignore RTP packets with empty payload #1403

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### NEXT

- `SimulcastConsumer`: Fix increase layer when current layer has not receive SR ([PR #1098](https://github.com/versatica/mediasoup/pull/1098) by @penguinol).
- Ignore RTP packets with empty payload ([PR #1403](https://github.com/versatica/mediasoup/pull/1403), credits to @ggarber).

### 3.14.6

Expand Down
1 change: 1 addition & 0 deletions worker/include/RTC/RtcLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace RTC
INVALID_TARGET_LAYER,
UNSUPPORTED_PAYLOAD_TYPE,
NOT_A_KEYFRAME,
EMPTY_PAYLOAD,
SPATIAL_LAYER_MISMATCH,
TOO_HIGH_TIMESTAMP_EXTRA_NEEDED,
PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH,
Expand Down
12 changes: 12 additions & 0 deletions worker/src/RTC/PipeConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ namespace RTC
auto& syncRequired = this->mapRtpStreamSyncRequired.at(rtpStream);
auto& rtpSeqManager = this->mapRtpStreamRtpSeqManager.at(rtpStream);

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
rtpSeqManager.Drop(packet->GetSequenceNumber());

#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

return;
}

// If we need to sync, support key frames and this is not a key frame, ignore
// the packet.
if (syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
Expand Down
1 change: 1 addition & 0 deletions worker/src/RTC/RtcLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace RTC
{ RtpPacket::DropReason::INVALID_TARGET_LAYER, "InvalidTargetLayer" },
{ RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE, "UnsupportedPayloadType" },
{ RtpPacket::DropReason::NOT_A_KEYFRAME, "NotAKeyframe" },
{ RtpPacket::DropReason::EMPTY_PAYLOAD, "EmptyPayload" },
{ RtpPacket::DropReason::SPATIAL_LAYER_MISMATCH, "SpatialLayerMismatch" },
{ RtpPacket::DropReason::TOO_HIGH_TIMESTAMP_EXTRA_NEEDED, "TooHighTimestampExtraNeeded" },
{ RtpPacket::DropReason::PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH, "PacketPreviousToSpatialLayerSwitch" },
Expand Down
14 changes: 14 additions & 0 deletions worker/src/RTC/RtpStreamRecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ namespace RTC
// Calculate Jitter.
CalculateJitter(packet->GetTimestamp());

// Padding only packet, do not consider it for counter increase nor
// stream activation.
if (packet->GetPayloadLength() == 0)
{
return true;
}

// Increase transmission counter.
this->transmissionCounter.Update(packet);

Expand Down Expand Up @@ -413,6 +420,13 @@ namespace RTC
// NACKed packet.
if (this->nackGenerator->ReceivePacket(packet, /*isRecovered*/ true))
{
// Padding only packet, do not consider it for counter increase nor
// stream activation.
if (packet->GetPayloadLength() == 0)
{
return true;
}

// Mark the packet as repaired.
RTC::RtpStream::PacketRepaired(packet);

Expand Down
12 changes: 12 additions & 0 deletions worker/src/RTC/SimpleConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,18 @@ namespace RTC
return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
this->rtpSeqManager.Drop(packet->GetSequenceNumber());

#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

return;
}

auto payloadType = packet->GetPayloadType();

// NOTE: This may happen if this Consumer supports just some codecs of those
Expand Down
12 changes: 12 additions & 0 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,18 @@ namespace RTC
return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
this->rtpSeqManager.Drop(packet->GetSequenceNumber());

#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

return;
}

if (this->targetTemporalLayer == -1)
{
#ifdef MS_RTC_LOGGER_RTP
Expand Down
12 changes: 12 additions & 0 deletions worker/src/RTC/SvcConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ namespace RTC
return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
this->rtpSeqManager.Drop(packet->GetSequenceNumber());

#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

return;
}

// clang-format off
if (
this->encodingContext->GetTargetSpatialLayer() == -1 ||
Expand Down
Loading