# NalUnitTargetBuffer

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

*** ** * ** ***


```
@UnstableApi
public final class NalUnitTargetBuffer
```

<br />

*** ** * ** ***

A buffer that fills itself with data corresponding to a specific NAL unit, as it is encountered in the stream.

## Summary

| ### Public fields |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#isCompleted()` |
| `byte[]` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#nalData()` |
| `int` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#nalLength()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#NalUnitTargetBuffer(int,int)(int targetType, int initialCapacity)` Creates the buffer. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#appendToNalUnit(byte[],int,int)(byte[] data, int offset, int limit)` Called to pass stream data. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#endNalUnit(int)(int discardPadding)` Called to indicate that a NAL unit has ended. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#isCompleted()()` Returns whether the buffer currently holds a complete NAL unit of the target type. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#reset()()` Resets the buffer, clearing any data that it holds. |
| `void` | `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#startNalUnit(int)(int type)` Called to indicate that a NAL unit has started. |

## Public fields

### isCompleted

```
public boolean isCompleted
```

### nalData

```
public byte[] nalData
```

### nalLength

```
public int nalLength
```

## Public constructors

### NalUnitTargetBuffer

```
public NalUnitTargetBuffer(int targetType, int initialCapacity)
```

Creates the buffer.

| Parameters |
|---|---|
| `int targetType` | The type of the NAL unit. |
| `int initialCapacity` | The initial capacity of the buffer in bytes. |

## Public methods

### appendToNalUnit

```
public void appendToNalUnit(byte[] data, int offset, int limit)
```

Called to pass stream data. The data passed should not include the 3 byte start code.

| Parameters |
|---|---|
| `byte[] data` | Holds the data being passed. |
| `int offset` | The offset of the data in `data`. |
| `int limit` | The limit (exclusive) of the data in `data`. |

### endNalUnit

```
public boolean endNalUnit(int discardPadding)
```

Called to indicate that a NAL unit has ended.

| Parameters |
|---|---|
| `int discardPadding` | The number of excess bytes that were passed to `https://developer.android.com/reference/androidx/media3/extractor/ts/NalUnitTargetBuffer#appendToNalUnit(byte[],int,int)`, which should be discarded. |

| Returns |
|---|---|
| `boolean` | Whether the ended NAL unit is of the target type. |

### isCompleted

```
public boolean isCompleted()
```

Returns whether the buffer currently holds a complete NAL unit of the target type.

### reset

```
public void reset()
```

Resets the buffer, clearing any data that it holds.

### startNalUnit

```
public void startNalUnit(int type)
```

Called to indicate that a NAL unit has started.

| Parameters |
|---|---|
| `int type` | The type of the NAL unit. |