Class RtpPacket
- java.lang.Object
-
- com.google.android.exoplayer2.source.rtsp.RtpPacket
-
public final class RtpPacket extends Object
Represents the header and the payload of an RTP packet.Not supported parsing at the moment: header extension and CSRC.
Structure of an RTP header (RFC3550, Section 5.1).
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |V=2|P|X| CC |M| PT | sequence number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | synchronization source (SSRC) identifier | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | contributing source (CSRC) identifiers | | .... | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | Profile-specific extension ID | Extension header length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Extension header | | .... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3 2 1 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRtpPacket.BuilderBuilder class for anRtpPacket
-
Field Summary
Fields Modifier and Type Field Description byte[]csrcThe RTP CSRC fields (Optional, up to 15 items).static intCSRC_SIZEbytecsrcCountThe RTP CSRC count field (Word 0, bits 4-7).booleanextensionThe RTP extension bit (Word 0, bit 3).booleanmarkerThe RTP marker bit (Word 0, bit 8).static intMAX_SEQUENCE_NUMBERstatic intMAX_SIZEstatic intMIN_HEADER_SIZEstatic intMIN_SEQUENCE_NUMBERbooleanpaddingThe RTP padding bit (Word 0, bit 2).byte[]payloadDatabytepayloadTypeThe RTP CSRC count field (Word 0, bits 9-15).static intRTP_VERSIONintsequenceNumberThe RTP sequence number field (Word 0, bits 16-31).intssrcThe RTP SSRC field (Word 2).longtimestampThe RTP timestamp field (Word 1).byteversionThe RTP version field (Word 0, bits 0-1), should always be 2.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static intgetNextSequenceNumber(int sequenceNumber)Returns the next sequence number of thesequenceNumber.static intgetPreviousSequenceNumber(int sequenceNumber)Returns the previous sequence number from thesequenceNumber.inthashCode()static RtpPacketparse(byte[] buffer, int length)Creates anRtpPacketfrom a byte array.static RtpPacketparse(ParsableByteArray packetBuffer)Creates anRtpPacketfrom aParsableByteArray.StringtoString()intwriteToBuffer(byte[] target, int offset, int length)Writes the data in an RTP packet to a target buffer.
-
-
-
Field Detail
-
RTP_VERSION
public static final int RTP_VERSION
- See Also:
- Constant Field Values
-
MAX_SIZE
public static final int MAX_SIZE
- See Also:
- Constant Field Values
-
MIN_HEADER_SIZE
public static final int MIN_HEADER_SIZE
- See Also:
- Constant Field Values
-
MIN_SEQUENCE_NUMBER
public static final int MIN_SEQUENCE_NUMBER
- See Also:
- Constant Field Values
-
MAX_SEQUENCE_NUMBER
public static final int MAX_SEQUENCE_NUMBER
- See Also:
- Constant Field Values
-
CSRC_SIZE
public static final int CSRC_SIZE
- See Also:
- Constant Field Values
-
version
public final byte version
The RTP version field (Word 0, bits 0-1), should always be 2.- See Also:
- Constant Field Values
-
padding
public final boolean padding
The RTP padding bit (Word 0, bit 2).
-
extension
public final boolean extension
The RTP extension bit (Word 0, bit 3).
-
csrcCount
public final byte csrcCount
The RTP CSRC count field (Word 0, bits 4-7).
-
marker
public final boolean marker
The RTP marker bit (Word 0, bit 8).
-
payloadType
public final byte payloadType
The RTP CSRC count field (Word 0, bits 9-15).
-
sequenceNumber
public final int sequenceNumber
The RTP sequence number field (Word 0, bits 16-31).
-
timestamp
public final long timestamp
The RTP timestamp field (Word 1).
-
ssrc
public final int ssrc
The RTP SSRC field (Word 2).
-
csrc
public final byte[] csrc
The RTP CSRC fields (Optional, up to 15 items).
-
payloadData
public final byte[] payloadData
-
-
Method Detail
-
getNextSequenceNumber
public static int getNextSequenceNumber(int sequenceNumber)
Returns the next sequence number of thesequenceNumber.
-
getPreviousSequenceNumber
public static int getPreviousSequenceNumber(int sequenceNumber)
Returns the previous sequence number from thesequenceNumber.
-
parse
@Nullable public static RtpPacket parse(ParsableByteArray packetBuffer)
Creates anRtpPacketfrom aParsableByteArray.- Parameters:
packetBuffer- The buffer that contains the RTP packet data.- Returns:
- The built
RtpPacket.
-
parse
@Nullable public static RtpPacket parse(byte[] buffer, int length)
Creates anRtpPacketfrom a byte array.- Parameters:
buffer- The buffer that contains the RTP packet data.length- The length of the RTP packet.- Returns:
- The built
RtpPacket.
-
writeToBuffer
public int writeToBuffer(byte[] target, int offset, int length)Writes the data in an RTP packet to a target buffer.The size of the target buffer and the length argument should be big enough so that the entire RTP packet could fit. That is, if there is not enough space to store the entire RTP packet, no bytes will be written. The maximum size of an RTP packet is defined as
MAX_SIZE.- Parameters:
target- A target byte buffer to which the packet data is copied.offset- The offset into the target array at which to write.length- The maximum number of bytes that can be written.- Returns:
- The number of bytes written, or
C.LENGTH_UNSETif there is not enough space to write the packet.
-
-