From ea4415238d9b875acec70a1a7032c53f59b031a8 Mon Sep 17 00:00:00 2001 From: cmoore Date: Thu, 14 Sep 2023 17:32:33 -0400 Subject: [PATCH] Add ability to set sequence number for cases where sequence number is not generated locally. For example webrtc media servers. --- src/net/RTP/MediaStream.cs | 18 ++++++++++++++++-- src/net/RTP/RTPSession.cs | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/net/RTP/MediaStream.cs b/src/net/RTP/MediaStream.cs index 3231961ff..e23e3ff49 100644 --- a/src/net/RTP/MediaStream.cs +++ b/src/net/RTP/MediaStream.cs @@ -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()) { @@ -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; @@ -393,6 +393,20 @@ protected void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloa } } + /// + /// Allows additional control for sending raw RTP payloads. No framing or other processing is carried out. + /// + /// The media type of the RTP packet being sent. Must be audio or video. + /// The RTP packet payload. + /// The timestamp to set on the RTP header. + /// The value to set on the RTP header marker bit, should be 0 or 1. + /// The payload ID to set in the RTP header. + /// The RTP sequence number + public void SendRtpRaw(byte[] data, uint timestamp, int markerBit, int payloadType, ushort seqNum) + { + SendRtpRaw(data, timestamp, markerBit, payloadType, false, seqNum); + } + /// /// Allows additional control for sending raw RTP payloads. No framing or other processing is carried out. /// diff --git a/src/net/RTP/RTPSession.cs b/src/net/RTP/RTPSession.cs index 0c3fbd4fb..01aca0dd0 100644 --- a/src/net/RTP/RTPSession.cs +++ b/src/net/RTP/RTPSession.cs @@ -2403,6 +2403,27 @@ private MediaStream GetMediaStream(RTCPCompoundPacket rtcpPkt) return null; } + /// + /// Allows additional control for sending raw RTP payloads (on the primary one). No framing or other processing is carried out. + /// + /// The media type of the RTP packet being sent. Must be audio or video. + /// The RTP packet payload. + /// The timestamp to set on the RTP header. + /// The value to set on the RTP header marker bit, should be 0 or 1. + /// The payload ID to set in the RTP header. + /// The sequence number of the packet. + 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); + } + } + /// /// Allows additional control for sending raw RTP payloads (on the primary one). No framing or other processing is carried out. ///