Class RtpPacket
Class for handling Real Time Protocol (RTP) network packets. See RFC 3550.
Inherited Members
Namespace: SipLib.Rtp
Assembly: SipLib.dll
Syntax
public class RtpPacket
Constructors
| Edit this page View SourceRtpPacket()
Constructs a RTP packet containing only a RTP packet header without a payload.
Declaration
public RtpPacket()
RtpPacket(byte[])
Constructs a RTP packet from an array of bytes.
Use this constructor to encapsulate the raw bytes received in a UDP packet. You can then access the RTP packet header fields using the properties of the new RtpPacket object. Use the GetPayloadBytes() method to get a byte array containing the media bytes.
Declaration
public RtpPacket(byte[] SrcBytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | SrcBytes | Byte array to "attach" to. Must be at least MIN_PACKET_LENGTH bytes long. |
RtpPacket(int)
Creates an new RTP packet given the length of the payload in bytes. The RTP header will be 12 bytes.
Declaration
public RtpPacket(int PayloadLength)
Parameters
Type | Name | Description |
---|---|---|
int | PayloadLength | Number of bytes in the payload. |
RtpPacket(int, int)
Creates a new RtpPacket given the payload length and the RTP packet header length.
Declaration
public RtpPacket(int PayloadLength, int headerLength)
Parameters
Type | Name | Description |
---|---|---|
int | PayloadLength | Length of the packet payload in bytes. May be 0 is only sending an RTP packet header. |
int | headerLength | Length of the RTP packet header in bytes. Must be at least 12. The headerLength can be calculated as: 12 + 4 * (number of CSRCs). |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the headerLength is less than the minimum RTP packet header length of 12. |
Fields
| Edit this page View SourceCSRC_LENGTH
Length of each CSRC in bytes
Declaration
public const int CSRC_LENGTH = 4
Field Value
Type | Description |
---|---|
int |
MIN_PACKET_LENGTH
Minimum RTP packet length. This assumes that CSRCs are included.
Declaration
public const int MIN_PACKET_LENGTH = 12
Field Value
Type | Description |
---|---|
int |
Properties
| Edit this page View SourceCSRCs
Gets a list of CSRCs (contributing source identifiers) for this RTP packet.
Declaration
public List<uint>? CSRCs { get; }
Property Value
Type | Description |
---|---|
List<uint> |
CsrcCount
Gets or sets the CSRC Count.
Declaration
public int CsrcCount { get; set; }
Property Value
Type | Description |
---|---|
int |
HeaderLength
Gets the length of the RTP packet header.
Declaration
public int HeaderLength { get; }
Property Value
Type | Description |
---|---|
int |
Marker
Gets or sets the M (marker) bit.
Declaration
public bool Marker { get; set; }
Property Value
Type | Description |
---|---|
bool |
PacketBytes
Gets the entire packet byte array
Declaration
public byte[]? PacketBytes { get; }
Property Value
Type | Description |
---|---|
byte[] |
Padding
Gets or sets the Padding bit.
Declaration
public bool Padding { get; set; }
Property Value
Type | Description |
---|---|
bool |
Payload
Gets or sets the payload of the RTP packet. The getter returns a copy of the payload bytes.
Declaration
public byte[]? Payload { get; set; }
Property Value
Type | Description |
---|---|
byte[] |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown by if the input packet is longer than the allocated payload length for this RTP packet. |
PayloadLength
Gets the number of bytes in the RTP packet payload.
Declaration
public int PayloadLength { get; }
Property Value
Type | Description |
---|---|
int |
PayloadType
Gets or sets the Payload Type (PT) field in the RTP header. The Payload Type must be between 0 and 127.
Declaration
public int PayloadType { get; set; }
Property Value
Type | Description |
---|---|
int |
SSRC
Gets or sets the synchronization source identifier (SSRC).
Declaration
public uint SSRC { get; set; }
Property Value
Type | Description |
---|---|
uint |
SequenceNumber
Gets or sets the Sequence Number field of the RTP packet header.
Declaration
public ushort SequenceNumber { get; set; }
Property Value
Type | Description |
---|---|
ushort |
Timestamp
Gets or sets the Timestamp field of the RTP packet header.
Declaration
public uint Timestamp { get; set; }
Property Value
Type | Description |
---|---|
uint |
Version
Gets the Version field.
Declaration
public int Version { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceGetCSRC(int)
Gets a CSRC specified by its index.
Declaration
public uint GetCSRC(int Idx)
Parameters
Type | Name | Description |
---|---|---|
int | Idx | Index of the CSRC to get. |
Returns
Type | Description |
---|---|
uint | Returns the specified CSRC. Returns 0 if the index is out range. |
GetHeaderBytes()
Gets only the bytes from the header portion of the RTP packet.
Declaration
public byte[] GetHeaderBytes()
Returns
Type | Description |
---|---|
byte[] | Returns a byte array containing the header bytes. |
GetPayloadBytes()
Strips out the RTP packet header and returns new byte array containing the packet payload.
Declaration
public byte[]? GetPayloadBytes()
Returns
Type | Description |
---|---|
byte[] | Returns null if there is no payload or a new byte array containing the payload bytes if there is a payload for the RTP packet. |
SetCSRC(int, uint)
Sets a CSRC value.
Declaration
public void SetCSRC(int Idx, uint CSRC)
Parameters
Type | Name | Description |
---|---|---|
int | Idx | Index of the CSRC to set. |
uint | CSRC | CSRC value. |
SetPayloadBytes(byte[])
Sets the payload bytes in the packet.
Declaration
public void SetPayloadBytes(byte[] payloadBytes)
Parameters
Type | Name | Description |
---|---|---|
byte[] | payloadBytes | Contains the payload bytes. The length must be equal to PayloadLength |