# RtpPacket

Artifact: [androidx.media3:media3-exoplayer-rtsp](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/rtsp/RtpPacket.java+class:androidx.media3.exoplayer.rtsp.RtpPacket)

*** ** * ** ***


```
@UnstableApi
public final class RtpPacket
```

<br />

*** ** * ** ***

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
```

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket.Builder` Builder class for an `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#CSRC_SIZE() = 4` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#MAX_SEQUENCE_NUMBER() = 65535` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#MAX_SIZE() = 65507` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#MIN_HEADER_SIZE() = 12` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#MIN_SEQUENCE_NUMBER() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#RTP_VERSION() = 2` |

| ### Public fields |
|---|---|
| `final byte[]` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#csrc()` The RTP CSRC fields (Optional, up to 15 items). |
| `final byte` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#csrcCount()` The RTP CSRC count field (Word 0, bits 4-7). |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#extension()` The RTP extension bit (Word 0, bit 3). |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#marker()` The RTP marker bit (Word 0, bit 8). |
| `final boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#padding()` The RTP padding bit (Word 0, bit 2). |
| `final byte[]` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#payloadData()` |
| `final byte` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#payloadType()` The RTP CSRC count field (Word 0, bits 9-15). |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#sequenceNumber()` The RTP sequence number field (Word 0, bits 16-31). |
| `final int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#ssrc()` The RTP SSRC field (Word 2). |
| `final long` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#timestamp()` The RTP timestamp field (Word 1). |
| `final byte` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#version()` The RTP version field (Word 0, bits 0-1), should always be 2. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html o)` |
| `static int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#getNextSequenceNumber(int)(int sequenceNumber)` Returns the next sequence number of the `sequenceNumber`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#getPreviousSequenceNumber(int)(int sequenceNumber)` Returns the previous sequence number from the `sequenceNumber`. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#hashCode()()` |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#parse(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray packetBuffer)` Creates an `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` from a `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray`. |
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#parse(byte[],int)(byte[] buffer, int length)` Creates an `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` from a byte array. |
| `https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#toString()()` |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#writeToBuffer(byte[],int,int)(byte[] target, int offset, int length)` Writes the data in an RTP packet to a target buffer. |

## Constants

### CSRC_SIZE

```
public static final int CSRC_SIZE = 4
```

### MAX_SEQUENCE_NUMBER

```
public static final int MAX_SEQUENCE_NUMBER = 65535
```

### MAX_SIZE

```
public static final int MAX_SIZE = 65507
```

### MIN_HEADER_SIZE

```
public static final int MIN_HEADER_SIZE = 12
```

### MIN_SEQUENCE_NUMBER

```
public static final int MIN_SEQUENCE_NUMBER = 0
```

### RTP_VERSION

```
public static final int RTP_VERSION = 2
```

## Public fields

### csrc

```
public final byte[] csrc
```

The RTP CSRC fields (Optional, up to 15 items).

### csrcCount

```
public final byte csrcCount
```

The RTP CSRC count field (Word 0, bits 4-7).

### extension

```
public final boolean extension
```

The RTP extension bit (Word 0, bit 3).

### marker

```
public final boolean marker
```

The RTP marker bit (Word 0, bit 8).

### padding

```
public final boolean padding
```

The RTP padding bit (Word 0, bit 2).

### payloadData

```
public final byte[] payloadData
```

### 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).

### ssrc

```
public final int ssrc
```

The RTP SSRC field (Word 2).

### timestamp

```
public final long timestamp
```

The RTP timestamp field (Word 1).

### version

```
public final byte version
```

The RTP version field (Word 0, bits 0-1), should always be 2.

## Public methods

### equals

```
public boolean equals(@Nullable Object o)
```

### getNextSequenceNumber

```
public static int getNextSequenceNumber(int sequenceNumber)
```

Returns the next sequence number of the `sequenceNumber`.

### getPreviousSequenceNumber

```
public static int getPreviousSequenceNumber(int sequenceNumber)
```

Returns the previous sequence number from the `sequenceNumber`.

### hashCode

```
public int hashCode()
```

### parse

```
public static @Nullable RtpPacket parse(ParsableByteArray packetBuffer)
```

Creates an `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` from a `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray packetBuffer` | The buffer that contains the RTP packet data. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` | The built `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket`. |

### parse

```
public static @Nullable RtpPacket parse(byte[] buffer, int length)
```

Creates an `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` from a byte array.

| Parameters |
|---|---|
| `byte[] buffer` | The buffer that contains the RTP packet data. |
| `int length` | The length of the RTP packet. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket` | The built `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket`. |

### toString

```
public String toString()
```

### 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 `https://developer.android.com/reference/androidx/media3/exoplayer/rtsp/RtpPacket#MAX_SIZE()`.

| Parameters |
|---|---|
| `byte[] target` | A target byte buffer to which the packet data is copied. |
| `int offset` | The offset into the target array at which to write. |
| `int length` | The maximum number of bytes that can be written. |

| Returns |
|---|---|
| `int` | The number of bytes written, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if there is not enough space to write the packet. |