Skip to content

Commit

Permalink
Consumer: Fix sequence number gap (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmillan authored Feb 24, 2025
1 parent 8327893 commit 13a7804
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### NEXT

- `Consumer`: Fix sequence number gap ([PR #1494](https://github.com/versatica/mediasoup/pull/1494)).

### 3.15.4

- `Worker`: Drop VP8 packets with a higher temporal layer than the current one ([PR #1009](https://github.com/versatica/mediasoup/pull/1009)).
Expand Down
3 changes: 3 additions & 0 deletions worker/include/Channel/ChannelSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ namespace Channel
};

public:
#ifdef MS_TEST
explicit ChannelSocket();
#endif
explicit ChannelSocket(int consumerFd, int producerFd);
explicit ChannelSocket(
ChannelReadFn channelReadFn,
Expand Down
1 change: 1 addition & 0 deletions worker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ test_sources = [
'test/src/RTC/TestRtpStreamSend.cpp',
'test/src/RTC/TestRtpStreamRecv.cpp',
'test/src/RTC/TestSeqManager.cpp',
'test/src/RTC/TestSimpleConsumer.cpp',
'test/src/RTC/TestTrendCalculator.cpp',
'test/src/RTC/TestRtpEncodingParameters.cpp',
'test/src/RTC/TestTransportCongestionControlServer.cpp',
Expand Down
9 changes: 8 additions & 1 deletion worker/src/Channel/ChannelSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ namespace Channel

/* Instance methods. */

#ifdef MS_TEST
ChannelSocket::ChannelSocket()
{
MS_TRACE_STD();
}
#endif

ChannelSocket::ChannelSocket(int consumerFd, int producerFd)
: consumerSocket(new ConsumerSocket(consumerFd, MessageMaxLen, this)),
producerSocket(new ProducerSocket(producerFd, MessageMaxLen))
Expand Down Expand Up @@ -256,7 +263,7 @@ namespace Channel
{
this->channelWriteFn(payload, payloadLen, this->channelWriteCtx);
}
else
else if (this->producerSocket)
{
this->producerSocket->Write(payload, payloadLen);
}
Expand Down
12 changes: 10 additions & 2 deletions worker/src/RTC/SimpleConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
#endif

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

return;
}

Expand All @@ -335,6 +337,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
#endif

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

return;
}

Expand All @@ -355,6 +359,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::DROPPED_BY_CODEC);
#endif

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

return;
}

Expand All @@ -366,18 +372,20 @@ namespace RTC
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)
{
this->rtpSeqManager->Drop(packet->GetSequenceNumber());

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

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

return;
}

Expand Down
19 changes: 15 additions & 4 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
#endif

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

return;
}

Expand All @@ -745,6 +747,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
#endif

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

return;
}

Expand Down Expand Up @@ -777,6 +781,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

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

return;
}

Expand Down Expand Up @@ -804,19 +810,20 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::NOT_A_KEYFRAME);
#endif

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)
{
this->rtpSeqManager->Drop(packet->GetSequenceNumber());

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

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

return;
}

Expand Down Expand Up @@ -935,6 +942,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::TOO_HIGH_TIMESTAMP_EXTRA_NEEDED);
#endif

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

return;
}

Expand Down Expand Up @@ -980,6 +989,8 @@ namespace RTC
RtcLogger::RtpPacket::DropReason::PACKET_PREVIOUS_TO_SPATIAL_LAYER_SWITCH);
#endif

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

return;
}
else if (SeqManager<uint16_t>::IsSeqHigherThan(
Expand Down Expand Up @@ -1022,12 +1033,12 @@ namespace RTC
// Rewrite payload if needed. Drop packet if necessary.
if (!packet->ProcessPayload(this->encodingContext.get(), marker))
{
this->rtpSeqManager->Drop(packet->GetSequenceNumber());

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

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

return;
}

Expand Down
12 changes: 10 additions & 2 deletions worker/src/RTC/SvcConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::CONSUMER_INACTIVE);
#endif

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

return;
}

Expand All @@ -659,6 +661,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::INVALID_TARGET_LAYER);
#endif

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

return;
}

Expand All @@ -674,6 +678,8 @@ namespace RTC
packet->logger.Dropped(RtcLogger::RtpPacket::DropReason::UNSUPPORTED_PAYLOAD_TYPE);
#endif

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

return;
}

Expand All @@ -684,18 +690,20 @@ namespace RTC
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)
{
this->rtpSeqManager->Drop(packet->GetSequenceNumber());

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

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

return;
}

Expand Down
Loading

0 comments on commit 13a7804

Please sign in to comment.