public class RawPacket extends java.lang.Object implements ByteArrayBuffer
Modifier and Type | Class and Description |
---|---|
class |
RawPacket.HeaderExtension
Represents an RTP header extension with the RFC5285 one-byte header:
|
class |
RawPacket.HeaderExtensions
Implements an iterator over the RTP header extensions of a
RawPacket . |
Modifier and Type | Field and Description |
---|---|
static int |
EXT_HEADER_SIZE
The size of the extension header as defined by RFC 3550.
|
static int |
FIXED_HEADER_SIZE
The size of the fixed part of the RTP header as defined by RFC 3550.
|
Constructor and Description |
---|
RawPacket()
Initializes a new empty RawPacket instance.
|
RawPacket(byte[] buffer,
int offset,
int length)
Initializes a new RawPacket instance with a specific
byte array buffer.
|
Modifier and Type | Method and Description |
---|---|
void |
addExtension(byte id,
byte[] data)
Adds the given buffer as a header extension of this packet
according the rules specified in RFC 5285.
|
void |
addExtension(byte id,
byte[] data,
int len)
Adds the given buffer as a header extension of this packet
according the rules specified in RFC 5285.
|
RawPacket.HeaderExtension |
addExtension(byte id,
int len)
Adds an RTP header extension with a given ID and a given length to this
packet.
|
void |
append(byte[] data,
int len)
Append a byte array to the end of the packet.
|
long[] |
extractCsrcAudioLevels(byte csrcExtID)
Returns a map binding CSRC IDs to audio levels as reported by the remote
party that sent this packet.
|
long[] |
extractCsrcList()
Returns the list of CSRC IDs, currently encapsulated in this packet.
|
byte |
extractSsrcAudioLevel(byte ssrcExtID)
Extracts the source audio level reported by the remote party which sent
this packet and carried in this packet.
|
byte[] |
getBuffer()
Get buffer containing the content of this packet
|
int |
getCsrcCount()
Returns the number of CSRC identifiers currently included in this packet.
|
static int |
getCsrcCount(byte[] buffer,
int offset,
int length)
Returns the number of CSRC identifiers currently included in this packet.
|
boolean |
getExtensionBit()
Returns true if the extension bit of this packet has been set
and false otherwise.
|
static boolean |
getExtensionBit(byte[] buffer,
int offset,
int length)
Returns true if the extension bit of this packet has been set
and false otherwise.
|
int |
getExtensionLength()
Returns the length of the extensions currently added to this packet.
|
static int |
getExtensionLength(byte[] buffer,
int offset,
int length)
Returns the length of the extensions currently added to this packet.
|
int |
getFlags()
Gets the bitmap/flag mask that specifies the set of boolean attributes
enabled for this RawPacket.
|
RawPacket.HeaderExtension |
getHeaderExtension(byte id) |
RawPacket.HeaderExtensions |
getHeaderExtensions() |
int |
getHeaderExtensionType()
Return the define by profile part of the extension header.
|
int |
getHeaderLength()
Get RTP header length from a RTP packet
|
static int |
getHeaderLength(byte[] buffer,
int offset,
int length)
Get RTP header length from a RTP packet
|
int |
getLength()
Get the length of this packet's data
|
int |
getOffset()
Get the start offset of this packet's data inside storing buffer
|
int |
getOriginalSequenceNumber()
Gets the OSN value of an RTX packet.
|
int |
getPaddingSize()
Get RTP padding size from a RTP packet
|
static int |
getPaddingSize(byte[] buf,
int off,
int len)
Get RTP padding size from a RTP packet
|
byte[] |
getPayload()
Get the RTP payload (bytes) of this RTP packet.
|
int |
getPayloadLength()
Get RTP payload length from a RTP packet
|
int |
getPayloadLength(boolean removePadding)
Get RTP payload length from a RTP packet
|
static int |
getPayloadLength(byte[] buffer,
int offset,
int length)
Get RTP payload length from a RTP packet
|
static int |
getPayloadLength(byte[] buffer,
int offset,
int length,
boolean removePadding)
Get RTP payload length from a RTP packet
|
int |
getPayloadOffset()
Get the RTP payload offset of an RTP packet.
|
static int |
getPayloadOffset(byte[] buffer,
int offset,
int length)
Get the RTP payload offset of an RTP packet.
|
byte |
getPayloadType()
Get RTP payload type from a RTP packet
|
static int |
getPayloadType(byte[] buf,
int off,
int len)
Get RTP payload type from a RTP packet
|
static int |
getPayloadType(RawPacket pkt)
Get RTP payload type from a RTP packet
|
int |
getRTCPPacketType()
Gets the packet type of this RTCP packet.
|
long |
getRTCPSSRC()
Get RTCP SSRC from a RTCP packet
|
static long |
getRTCPSSRC(byte[] buf,
int off,
int len)
Get RTCP SSRC from a RTCP packet
|
static long |
getRTCPSSRC(ByteArrayBuffer baf)
Get RTCP SSRC from a RTCP packet
|
int |
getSequenceNumber()
Get RTP sequence number from a RTP packet
|
static int |
getSequenceNumber(byte[] buffer,
int offset,
int length)
Get RTP sequence number from a RTP packet
|
static int |
getSequenceNumber(ByteArrayBuffer baf)
Gets the RTP sequence number from a RTP packet.
|
int |
getSRTCPIndex(int authTagLen)
Get SRTCP sequence number from a SRTCP packet
|
int |
getSSRC()
Get RTP SSRC from a RTP packet
|
static int |
getSSRC(byte[] buffer,
int offset,
int length)
Get RTP SSRC from a RTP packet
|
long |
getSSRCAsLong()
Returns a
long representation of the SSRC of this RTP packet. |
static long |
getSSRCAsLong(byte[] buffer,
int offset,
int length)
Returns a
long representation of the SSRC of this RTP packet. |
long |
getTimestamp()
Returns the timestamp for this RTP RawPacket.
|
static long |
getTimestamp(byte[] buf,
int off,
int len)
Gets the RTP timestamp for an RTP buffer.
|
static long |
getTimestamp(ByteArrayBuffer baf)
Gets the RTP timestamp for an RTP buffer.
|
int |
getVersion()
Gets the value of the "version" field of an RTP packet.
|
static int |
getVersion(byte[] buffer,
int offset,
int length)
Gets the value of the "version" field of an RTP packet.
|
static int |
getVersion(ByteArrayBuffer baf)
Gets the value of the "version" field of an RTP packet.
|
void |
grow(int howMuch)
Grows the internal buffer of this
RawPacket . |
boolean |
isInvalid()
Perform checks on the packet represented by this instance and
return true if it is found to be invalid.
|
static boolean |
isInvalid(byte[] buffer,
int offset,
int length)
Perform checks on the packet represented by this instance and
return true if it is found to be invalid.
|
boolean |
isPacketMarked()
Test whether the RTP Marker bit is set
|
static boolean |
isPacketMarked(byte[] buffer,
int offset,
int length)
Test whether the RTP Marker bit is set
|
static boolean |
isPacketMarked(ByteArrayBuffer baf)
Test whether the RTP Marker bit is set
|
static RawPacket |
makeRTP(long ssrc,
int pt,
int seqNum,
long ts,
int len)
Makes a new RTP
RawPacket filled with padding with the specified
parameters. |
byte |
readByte(int off)
Read a byte from this packet at specified offset
|
int |
readInt(int off)
Read a integer from this packet at specified offset
|
byte[] |
readRegion(int off,
int len)
Read a byte region from specified offset with specified length
|
void |
readRegionToBuff(int off,
int len,
byte[] outBuff)
Read a byte region from specified offset with specified length in given
buffer
|
int |
readUint16AsInt(int off)
Read an unsigned short at specified offset as a int
|
long |
readUint32AsLong(int off)
Read a 32-bit unsigned integer from this packet at the specified offset.
|
void |
removeExtension()
Removes the extension from the packet and its header.
|
void |
setBuffer(byte[] buffer) |
void |
setCsrcList(long[] newCsrcList)
Replaces the existing CSRC list (even if empty) with newCsrcList
and updates the CC (CSRC count) field of this RawPacket
accordingly.
|
void |
setFlags(int flags)
Sets the bitmap/flag mask that specifies the set of boolean attributes
enabled for this RawPacket.
|
void |
setLength(int length)
Sets the length of the data in the buffer.
|
void |
setMarker(boolean marker)
Sets or resets the marker bit of this packet according to the
marker parameter.
|
void |
setOffset(int offset)
Sets the offset of the data in the buffer.
|
void |
setOriginalSequenceNumber(int sequenceNumber)
Sets the OSN value of an RTX packet.
|
boolean |
setPaddingSize(int len)
Sets the padding length for this RTP packet.
|
void |
setPayloadType(byte payload)
Sets the payload type of this packet.
|
static void |
setSequenceNumber(byte[] buffer,
int offset,
int seq)
Set sequence number for an RTP buffer
|
static void |
setSequenceNumber(ByteArrayBuffer baf,
int dstSeqNum)
Sets the sequence number of an RTP packet.
|
void |
setSequenceNumber(int seq)
Set the RTP sequence number of an RTP packet
|
void |
setSSRC(int ssrc)
Set the SSRC of this packet
|
static void |
setTimestamp(byte[] buf,
int off,
int len,
long ts)
Set the RTP timestamp for an RTP buffer.
|
static void |
setTimestamp(ByteArrayBuffer baf,
long ts)
Sets the RTP timestamp of an RTP packet.
|
void |
setTimestamp(long timestamp)
Set the timestamp value of the RTP Packet
|
boolean |
setVersion()
Sets the RTP version in this RTP packet.
|
void |
shrink(int len)
Shrink the buffer of this packet by specified length
|
java.lang.String |
toString() |
void |
writeByte(int off,
byte b)
Write a byte to this packet at specified offset
|
void |
writeInt(int off,
int data)
Set an integer at specified offset in network order.
|
void |
writeShort(int off,
short val)
Write a short to this packet at the specified offset.
|
public static final int EXT_HEADER_SIZE
public static final int FIXED_HEADER_SIZE
public RawPacket()
public RawPacket(byte[] buffer, int offset, int length)
buffer
- the byte array to be the buffer of the new
instanceoffset
- the offset in buffer at which the actual data to
be represented by the new instance startslength
- the number of bytes in buffer which
constitute the actual data to be represented by the new instancepublic static RawPacket makeRTP(long ssrc, int pt, int seqNum, long ts, int len)
RawPacket
filled with padding with the specified
parameters. Note that because we're creating a packet filled with
padding, the length must not exceed 12 + 0xFF.ssrc
- the SSRC of the RTP packet to make.pt
- the payload type of the RTP packet to make.seqNum
- the sequence number of the RTP packet to make.ts
- the RTP timestamp of the RTP packet to make.len
- the length of the RTP packet to make.RawPacket
that was created.public static int getVersion(ByteArrayBuffer baf)
public static int getVersion(byte[] buffer, int offset, int length)
public static boolean isPacketMarked(ByteArrayBuffer baf)
baf
- public static boolean isPacketMarked(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public static boolean isInvalid(byte[] buffer, int offset, int length)
public static long getRTCPSSRC(ByteArrayBuffer baf)
long
.public static long getRTCPSSRC(byte[] buf, int off, int len)
public void addExtension(byte id, byte[] data)
getHeaderExtensions()
, or while manipulating the state of this
RawPacket
.id
- the ID with which to add the extension.data
- the buffer containing the extension data.public void addExtension(byte id, byte[] data, int len)
getHeaderExtensions()
, or while manipulating the state of this
RawPacket
.id
- the ID with which to add the extension.data
- the buffer containing the extension data.len
- the length of the extension.public RawPacket.HeaderExtension addExtension(byte id, int len)
getHeaderExtensions()
, or while manipulating the state of this
RawPacket
.id
- the ID of the extension to add.len
- the length in bytes of the extension to add.public void append(byte[] data, int len)
data
- byte array to appendlen
- the number of bytes to appendpublic long[] extractCsrcAudioLevels(byte csrcExtID)
csrcExtID
- the ID of the extension that's transporting csrc audio
levels in the session that this RawPacket belongs to.public long[] extractCsrcList()
public byte extractSsrcAudioLevel(byte ssrcExtID)
ssrcExtID
- the ID of the extension that's transporting ssrc audio
levels in the session that this RawPacket belongs topublic byte[] getBuffer()
getBuffer
in interface ByteArrayBuffer
public int getCsrcCount()
public static int getCsrcCount(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public boolean getExtensionBit()
public static boolean getExtensionBit(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public int getExtensionLength()
public RawPacket.HeaderExtensions getHeaderExtensions()
RawPacket
's RTP header extensions.public static int getExtensionLength(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public int getFlags()
public int getHeaderExtensionType()
public int getHeaderLength()
public static int getHeaderLength(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public int getLength()
getLength
in interface ByteArrayBuffer
public int getOffset()
getOffset
in interface ByteArrayBuffer
public int getVersion()
public int getPaddingSize()
public static int getPaddingSize(byte[] buf, int off, int len)
public byte[] getPayload()
public int getPayloadLength(boolean removePadding)
public int getPayloadLength()
public static int getPayloadLength(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public static int getPayloadLength(byte[] buffer, int offset, int length, boolean removePadding)
buffer
- offset
- length
- removePadding
- public int getPayloadOffset()
public static int getPayloadOffset(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public byte getPayloadType()
public static int getPayloadType(byte[] buf, int off, int len)
public static int getPayloadType(RawPacket pkt)
public long getRTCPSSRC()
public int getRTCPPacketType()
public int getSequenceNumber()
public static int getSequenceNumber(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public static int getSequenceNumber(ByteArrayBuffer baf)
baf
- the ByteArrayBuffer
that contains the RTP packet.public static void setSequenceNumber(byte[] buffer, int offset, int seq)
buffer
- offset
- seq
- public static void setSequenceNumber(ByteArrayBuffer baf, int dstSeqNum)
baf
- the ByteArrayBuffer
that contains the RTP packet.dstSeqNum
- the sequence number to set in the RTP packet.public static void setTimestamp(byte[] buf, int off, int len, long ts)
buf
- the byte array that holds the RTP packet.off
- the offset in buffer at which the actual RTP data
begins.len
- the number of bytes in buffer which
constitute the actual RTP data.ts
- the timestamp to set in the RTP buffer.public static void setTimestamp(ByteArrayBuffer baf, long ts)
ByteArrayBuffer
that contains the RTP packet.ts
- the timestamp to set in the RTP packet.public int getSRTCPIndex(int authTagLen)
authTagLen
- authentication tag lengthpublic int getSSRC()
public static int getSSRC(byte[] buffer, int offset, int length)
buffer
- offset
- length
- public long getSSRCAsLong()
long
representation of the SSRC of this RTP packet.long
representation of the SSRC of this RTP packet.public static long getSSRCAsLong(byte[] buffer, int offset, int length)
long
representation of the SSRC of this RTP packet.buffer
- offset
- length
- long
representation of the SSRC of this RTP packet.public long getTimestamp()
public static long getTimestamp(byte[] buf, int off, int len)
buf
- the byte array that holds the RTP packet.off
- the offset in buffer at which the actual RTP data
begins.len
- the number of bytes in buffer which
constitute the actual RTP data.public static long getTimestamp(ByteArrayBuffer baf)
baf
- the ByteArrayBuffer
that contains the RTP packet.public void grow(int howMuch)
RawPacket
.
This will change the data buffer of this packet but not the length of the
valid data. Use this to grow the internal buffer to avoid buffer
re-allocations when appending data.howMuch
- the number of bytes by which this RawPacket
is to
growpublic boolean isInvalid()
isInvalid
in interface ByteArrayBuffer
public boolean isPacketMarked()
public byte readByte(int off)
off
- start offset of the bytepublic int readInt(int off)
off
- start offset of the integer to be readpublic long readUint32AsLong(int off)
off
- start offset of the integer to be read.public byte[] readRegion(int off, int len)
off
- start offset of the region to be readlen
- length of the region to be readpublic void readRegionToBuff(int off, int len, byte[] outBuff)
off
- start offset of the region to be readlen
- length of the region to be readoutBuff
- output bufferpublic void writeShort(int off, short val)
off
- val
- public int readUint16AsInt(int off)
off
- start offset of the unsigned shortpublic void removeExtension()
public void setBuffer(byte[] buffer)
buffer
- the buffer to setpublic void setCsrcList(long[] newCsrcList)
newCsrcList
- the list of CSRC identifiers that we'd like to set for
this RawPacket.public void setFlags(int flags)
flags
- the bitmap/flag mask that specifies the set of boolean
attributes enabled for this RawPacketpublic void setLength(int length)
ByteArrayBuffer
setLength
in interface ByteArrayBuffer
length
- the length to setpublic void setMarker(boolean marker)
marker
- true if we are to raise the marker bit and
false otherwise.public void setOffset(int offset)
ByteArrayBuffer
setOffset
in interface ByteArrayBuffer
offset
- the offset to setpublic void setPayloadType(byte payload)
payload
- the RTP payload type describing the content of this
packet.public void setSequenceNumber(int seq)
seq
- the sequence number to set (only the least-significant 16bits
are used)public void setSSRC(int ssrc)
ssrc
- SSRC to setpublic void setTimestamp(long timestamp)
timestamp
- : the RTP Timestamppublic void shrink(int len)
len
- length to shrinkpublic void writeByte(int off, byte b)
off
- start offset of the byteb
- byte to writepublic void writeInt(int off, int data)
off
- Offset into the bufferdata
- The integer to store in the packetpublic int getOriginalSequenceNumber()
public void setOriginalSequenceNumber(int sequenceNumber)
sequenceNumber
- the new OSN value of this RTX packet.public boolean setPaddingSize(int len)
len
- the padding length.public boolean setVersion()
public java.lang.String toString()
toString
in class java.lang.Object
public RawPacket.HeaderExtension getHeaderExtension(byte id)
id
- RawPacket
with the given ID,
or null if the packet doesn't have one.
WARNING: This method should not be used while iterating over the
extensions with getHeaderExtensions()
, because it uses the same
iterator.
Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under Apache license.