Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -4,6 +4,7 @@

- libuv: Update to v1.51.0 ([PR #1543](https://github.com/versatica/mediasoup/pull/1543)).
- libsrtp: Update to v3.0.0-beta version in our fork ([PR #1544](https://github.com/versatica/mediasoup/pull/1544)).
- `XxxxConsumer.cpp`: Only drop packets in RTP sequence manager when they belong to current spatial layer ([PR #1549](https://github.com/versatica/mediasoup/pull/1549)).

### 3.16.0

Expand Down
2 changes: 0 additions & 2 deletions worker/include/RTC/RtcLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ namespace RTC
NOT_A_KEYFRAME,
EMPTY_PAYLOAD,
SPATIAL_LAYER_MISMATCH,
TOO_HIGH_TIMESTAMP_EXTRA_NEEDED,
PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH,
DROPPED_BY_CODEC,
SEND_RTP_STREAM_DISCARDED,
};

static absl::flat_hash_map<DropReason, std::string> dropReason2String;
Expand Down
38 changes: 21 additions & 17 deletions worker/src/RTC/PipeConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,30 @@ namespace RTC
packet->logger.consumerId = this->id;
#endif

auto ssrc = this->mapMappedSsrcSsrc.at(packet->GetSsrc());
auto* rtpStream = this->mapSsrcRtpStream.at(ssrc);
auto& syncRequired = this->mapRtpStreamSyncRequired.at(rtpStream);
auto& rtpSeqManager = this->mapRtpStreamRtpSeqManager.at(rtpStream);

if (!IsActive())
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
#endif

rtpSeqManager->Drop(packet->GetSequenceNumber());

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())
{
// NOTE: No need to drop the packet in the RTP sequence manager since here
// we are blocking all packets but the key frame that would trigger sync
// below.

return;
}

Expand All @@ -243,34 +261,20 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
#endif

return;
}

auto ssrc = this->mapMappedSsrcSsrc.at(packet->GetSsrc());
auto* rtpStream = this->mapSsrcRtpStream.at(ssrc);
auto& syncRequired = this->mapRtpStreamSyncRequired.at(rtpStream);
auto& rtpSeqManager = this->mapRtpStreamRtpSeqManager.at(rtpStream);

// If we need to sync, support key frames and this is not a key frame, ignore
// the packet.
if (syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif
rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

// 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

rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

Expand Down
2 changes: 0 additions & 2 deletions worker/src/RTC/RtcLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ namespace RTC
{ 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" },
{ RtpPacket::DropReason::DROPPED_BY_CODEC, "DroppedByCodec" },
{ RtpPacket::DropReason::SEND_RTP_STREAM_DISCARDED, "SendRtpStreamDiscarded" },
};
// clang-format on

Expand Down
48 changes: 23 additions & 25 deletions worker/src/RTC/SimpleConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ namespace RTC
return;
}

// If we need to sync, support key frames and this is not a key frame, ignore
// the packet.
if (this->syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
{
// NOTE: No need to drop the packet in the RTP sequence manager since here
// we are blocking all packets but the key frame that would trigger sync
// below.

return;
}

auto payloadType = packet->GetPayloadType();

// NOTE: This may happen if this Consumer supports just some codecs of those
Expand All @@ -342,6 +353,18 @@ namespace RTC
return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

bool marker;

// Process the payload if needed. Drop packet if necessary.
Expand All @@ -362,31 +385,6 @@ namespace RTC
return;
}

// If we need to sync, support key frames and this is not a key frame, ignore
// the packet.
if (this->syncRequired && this->keyFrameSupported && !packet->IsKeyFrame())
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

// Whether this is the first packet after re-sync.
const bool isSyncPacket = this->syncRequired;

Expand Down
89 changes: 56 additions & 33 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,24 +732,36 @@ namespace RTC
packet->logger.consumerId = this->id;
#endif

auto spatialLayer = this->mapMappedSsrcSpatialLayer.at(packet->GetSsrc());

if (!IsActive())
{
// Only drop the packet in the RTP sequence manager if it belongs to the
// current spatial layer.
if (spatialLayer == this->currentSpatialLayer)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
this->rtpSeqManager->Drop(packet->GetSequenceNumber());
}

return;
}

if (this->targetTemporalLayer == -1)
{
// Only drop the packet in the RTP sequence manager if it belongs to the
// current spatial layer.
if (spatialLayer == this->currentSpatialLayer)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
this->rtpSeqManager->Drop(packet->GetSequenceNumber());
}

return;
}
Expand All @@ -760,16 +772,22 @@ namespace RTC
// in the corresponding Producer.
if (!this->supportedCodecPayloadTypes[payloadType])
{
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);
// Only drop the packet in the RTP sequence manager if it belongs to the
// current spatial layer.
if (spatialLayer == this->currentSpatialLayer)
{
MS_DEBUG_DEV("payload type not supported [payloadType:%" PRIu8 "]", payloadType);

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

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
}

return;
}

auto spatialLayer = this->mapMappedSsrcSpatialLayer.at(packet->GetSsrc());
bool shouldSwitchCurrentSpatialLayer{ false };

// Check whether this is the packet we are waiting for in order to update
Expand All @@ -779,11 +797,8 @@ namespace RTC
// Ignore if not a key frame.
if (!packet->IsKeyFrame())
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
// NOTE: Don't drop the packet in the RTP sequence manager since this
// packet doesn't belong to the current spatial layer.

return;
}
Expand All @@ -798,34 +813,44 @@ namespace RTC
// drop it.
else if (spatialLayer != this->currentSpatialLayer)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::SPATIAL_LAYER_MISMATCH);
#endif
// NOTE: Don't drop the packet in the RTP sequence manager since this
// packet doesn't belong to the current spatial layer.

return;
}

// If we need to sync and this is not a key frame, ignore the packet.
// NOTE: syncRequired is true if packet is a key frame of the target spatial
// layer or if transport just connected or consumer resumed.
if (this->syncRequired && !packet->IsKeyFrame())
{
// Only drop the packet in the RTP sequence manager if it belongs to the
// current spatial layer.
if (spatialLayer == this->currentSpatialLayer)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
this->rtpSeqManager->Drop(packet->GetSequenceNumber());
}

return;
}

// If the packet belongs to current spatial layer being sent and packet does
// not have payload other than padding, then drop it.
if (spatialLayer == this->currentSpatialLayer && packet->GetPayloadLength() == 0)
// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
// Only drop the packet in the RTP sequence manager if it belongs to the
// current spatial layer.
if (spatialLayer == this->currentSpatialLayer)
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::EMPTY_PAYLOAD);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
this->rtpSeqManager->Drop(packet->GetSequenceNumber());
}

return;
}
Expand All @@ -834,7 +859,7 @@ namespace RTC
const bool isSyncPacket = this->syncRequired;

// Sync sequence number and timestamp if required.
if (isSyncPacket && (this->spatialLayerToSync == -1 || this->spatialLayerToSync == spatialLayer))
if (isSyncPacket && (this->spatialLayerToSync == -1 || spatialLayer == this->spatialLayerToSync))
{
if (packet->IsKeyFrame())
{
Expand Down Expand Up @@ -941,11 +966,8 @@ namespace RTC
this->syncRequired = false;
this->spatialLayerToSync = -1;

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

this->rtpSeqManager->Drop(packet->GetSequenceNumber());
// NOTE: Don't drop the packet in the RTP sequence manager since this
// packet doesn't belong to the current spatial layer.

return;
}
Expand Down Expand Up @@ -983,7 +1005,10 @@ namespace RTC

if (!shouldSwitchCurrentSpatialLayer && this->checkingForOldPacketsInSpatialLayer)
{
// If this is a packet previous to the spatial layer switch, ignore the packet.
// If this is a packet previous to the spatial layer switch, ignore the
// packet.
// NOTE: We drop it in RTP sequence manager because this packet belongs
// to current spatial layer.
if (SeqManager<uint16_t>::IsSeqLowerThan(
packet->GetSequenceNumber(), this->snReferenceSpatialLayer))
{
Expand Down Expand Up @@ -1034,6 +1059,8 @@ namespace RTC
auto previousTemporalLayer = this->encodingContext->GetCurrentTemporalLayer();

// Rewrite payload if needed. Drop packet if necessary.
// NOTE: We drop it in RTP sequence manager because this packet belongs
// to current spatial layer.
if (!packet->ProcessPayload(this->encodingContext.get(), marker))
{
#ifdef MS_RTC_LOGGER_RTP
Expand Down Expand Up @@ -1112,10 +1139,6 @@ namespace RTC
origSsrc,
origSeq,
origTimestamp);

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

// Restore packet fields.
Expand Down
22 changes: 10 additions & 12 deletions worker/src/RTC/SvcConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,16 @@ namespace RTC
return;
}

// If we need to sync and this is not a key frame, ignore the packet.
if (this->syncRequired && !packet->IsKeyFrame())
{
// NOTE: No need to drop the packet in the RTP sequence manager since here
// we are blocking all packets but the key frame that would trigger sync
// below.

return;
}

auto payloadType = packet->GetPayloadType();

// NOTE: This may happen if this Consumer supports just some codecs of those
Expand All @@ -684,18 +694,6 @@ namespace RTC
return;
}

// If we need to sync and this is not a key frame, ignore the packet.
if (this->syncRequired && !packet->IsKeyFrame())
{
#ifdef MS_RTC_LOGGER_RTP
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

this->rtpSeqManager->Drop(packet->GetSequenceNumber());

return;
}

// Packets with only padding are not forwarded.
if (packet->GetPayloadLength() == 0)
{
Expand Down