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

Add ability to set sequence number for cases where sequence number is not generated locally. #995

Merged
merged 1 commit into from
Oct 2, 2023
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
18 changes: 16 additions & 2 deletions src/net/RTP/MediaStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected Boolean CheckIfCanSendRtpRaw()
return true;
}

protected void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloadType, Boolean checkDone)
protected void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloadType, Boolean checkDone, ushort? seqNum = null)
{
if (checkDone || CheckIfCanSendRtpRaw())
{
Expand All @@ -361,7 +361,7 @@ protected void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloa

RTPPacket rtpPacket = new RTPPacket(data.Length + srtpProtectionLength);
rtpPacket.Header.SyncSource = LocalTrack.Ssrc;
rtpPacket.Header.SequenceNumber = LocalTrack.GetNextSeqNum();
rtpPacket.Header.SequenceNumber = seqNum ?? LocalTrack.GetNextSeqNum();
rtpPacket.Header.Timestamp = timestamp;
rtpPacket.Header.MarkerBit = markerBit;
rtpPacket.Header.PayloadType = payloadType;
Expand Down Expand Up @@ -393,6 +393,20 @@ protected void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloa
}
}

/// <summary>
/// Allows additional control for sending raw RTP payloads. No framing or other processing is carried out.
/// </summary>
/// <param name="mediaType">The media type of the RTP packet being sent. Must be audio or video.</param>
/// <param name="payload">The RTP packet payload.</param>
/// <param name="timestamp">The timestamp to set on the RTP header.</param>
/// <param name="markerBit">The value to set on the RTP header marker bit, should be 0 or 1.</param>
/// <param name="payloadTypeID">The payload ID to set in the RTP header.</param>
/// <param name="seqNum"> The RTP sequence number </param>
public void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloadType, ushort seqNum)
{
SendRtpRaw(data, timestamp, markerBit, payloadType, false, seqNum);
}

/// <summary>
/// Allows additional control for sending raw RTP payloads. No framing or other processing is carried out.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions src/net/RTP/RTPSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,27 @@ private MediaStream GetMediaStream(RTCPCompoundPacket rtcpPkt)
return null;
}

/// <summary>
/// Allows additional control for sending raw RTP payloads (on the primary one). No framing or other processing is carried out.
/// </summary>
/// <param name="mediaType">The media type of the RTP packet being sent. Must be audio or video.</param>
/// <param name="payload">The RTP packet payload.</param>
/// <param name="timestamp">The timestamp to set on the RTP header.</param>
/// <param name="markerBit">The value to set on the RTP header marker bit, should be 0 or 1.</param>
/// <param name="payloadTypeID">The payload ID to set in the RTP header.</param>
/// <param name="seqNum">The sequence number of the packet.</param>
public void SendRtpRaw(SDPMediaTypesEnum mediaType, byte[] payload, uint timestamp, int markerBit, int payloadTypeID, ushort seqNum)
{
if (mediaType == SDPMediaTypesEnum.audio)
{
AudioStream.SendRtpRaw(payload, timestamp, markerBit, payloadTypeID, seqNum);
}
else if (mediaType == SDPMediaTypesEnum.video)
{
VideoStream?.SendRtpRaw(payload, timestamp, markerBit, payloadTypeID, seqNum);
}
}

/// <summary>
/// Allows additional control for sending raw RTP payloads (on the primary one). No framing or other processing is carried out.
/// </summary>
Expand Down
Loading