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

Handle sequence numbers rolling over to zero in AbstractRtpSession #1

Merged
merged 1 commit into from
May 28, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public abstract class AbstractRtpSession implements RtpSession, TimerTask {
protected static final boolean AUTOMATED_RTCP_HANDLING = true;
protected static final boolean TRY_TO_UPDATE_ON_EVERY_SDES = true;
protected static final int PARTICIPANT_DATABASE_CLEANUP = 10;
protected static final int SEQUENCE_NUMBER_WRAP_BOUND = 32767;
protected static final int MAX_SEQUENCE_NUMBER_FOR_WRAP = 1000;

// configuration --------------------------------------------------------------------------------------------------

Expand All @@ -103,6 +105,8 @@ public abstract class AbstractRtpSession implements RtpSession, TimerTask {
protected boolean automatedRtcpHandling;
protected boolean tryToUpdateOnEverySdes;
protected int participantDatabaseCleanup;
protected int sequenceNumberWrapBound;
protected int maxSequenceNumberForWrap;

// internal vars --------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -182,6 +186,8 @@ public AbstractRtpSession(String id, int payloadType, RtpParticipant local, Hash
this.automatedRtcpHandling = AUTOMATED_RTCP_HANDLING;
this.tryToUpdateOnEverySdes = TRY_TO_UPDATE_ON_EVERY_SDES;
this.participantDatabaseCleanup = PARTICIPANT_DATABASE_CLEANUP;
this.sequenceNumberWrapBound = SEQUENCE_NUMBER_WRAP_BOUND;
this.maxSequenceNumberForWrap = MAX_SEQUENCE_NUMBER_FOR_WRAP;
}

// RtpSession -----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -464,7 +470,7 @@ public void dataPacketReceived(SocketAddress origin, DataPacket packet) {
}

// Should the packet be discarded due to out of order SN?
if ((participant.getLastSequenceNumber() >= packet.getSequenceNumber()) && this.discardOutOfOrder) {
if (isSequenceNumberOutOfOrder(participant.getLastSequenceNumber(), packet.getSequenceNumber()) && this.discardOutOfOrder) {
LOG.trace("Discarded out of order packet from {} in session with id {} (last SN was {}, packet SN was {}).",
participant, this.id, participant.getLastSequenceNumber(), packet.getSequenceNumber());
return;
Expand All @@ -480,6 +486,14 @@ public void dataPacketReceived(SocketAddress origin, DataPacket packet) {
}
}

private boolean isSequenceNumberOutOfOrder(int previousSequenceNumber, int sequenceNumber) {
if (previousSequenceNumber >= sequenceNumberWrapBound && sequenceNumber <= maxSequenceNumberForWrap) {
return false;
} else {
return previousSequenceNumber >= sequenceNumber;
}
}

// ControlPacketReceiver ------------------------------------------------------------------------------------------

@Override
Expand Down