# TrackOutput

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/TrackOutput.java+class:androidx.media3.extractor.TrackOutput)

*** ** * ** ***

<br />

```
@UnstableApi
public interface TrackOutput
```

<br />

Known direct subclasses [DiscardingTrackOutput](https://developer.android.com/reference/androidx/media3/extractor/DiscardingTrackOutput), [FakeTrackOutput](https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput), [ForwardingTrackOutput](https://developer.android.com/reference/androidx/media3/extractor/ForwardingTrackOutput), [PlayerEmsgHandler.PlayerTrackEmsgHandler](https://developer.android.com/reference/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler), [SampleQueue](https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleQueue)

|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/DiscardingTrackOutput` | A `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput` that consumes and discards all reported samples. |
| `https://developer.android.com/reference/androidx/media3/test/utils/FakeTrackOutput` | A fake `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput`. |
| `https://developer.android.com/reference/androidx/media3/extractor/ForwardingTrackOutput` | An overridable `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput` implementation forwarding all methods to another track output. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/dash/PlayerEmsgHandler.PlayerTrackEmsgHandler` | Handles emsg messages for a specific track for the player. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/source/SampleQueue` | A queue of media samples. |

*** ** * ** ***

Receives track level data extracted by an `https://developer.android.com/reference/androidx/media3/extractor/Extractor`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.CryptoData` Holds data required to decrypt a sample. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.SampleDataPart` Defines the part of the sample data to which a call to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean)` corresponds. |

| ### Constants |
|---|---|
| `default static final int` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_ENCRYPTION() = 1` Sample encryption data. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_MAIN() = 0` Main media sample data. |
| `default static final int` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#SAMPLE_DATA_PART_SUPPLEMENTAL() = 2` Sample supplemental data. |

| ### Public methods |
|---|---|
| `default void` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#durationUs(long)(long durationUs)` Called to set the duration of the track in microseconds. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#format(androidx.media3.common.Format)(https://developer.android.com/reference/androidx/media3/common/Format format)` Called when the `https://developer.android.com/reference/androidx/media3/common/Format` of the track has been extracted from the stream. |
| `default void` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data, int length)` Equivalent to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int,int)` sampleData(data, length, SAMPLE_DATA_PART_MAIN)}. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int,int)( https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data, int length, @https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.SampleDataPart int sampleDataPart )` Called to write sample data to the output. |
| `default int` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean)(https://developer.android.com/reference/androidx/media3/common/DataReader input, int length, boolean allowEndOfInput)` Equivalent to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean,int)`. |
| `abstract int` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean,int)( https://developer.android.com/reference/androidx/media3/common/DataReader input, int length, boolean allowEndOfInput, @https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.SampleDataPart int sampleDataPart )` Called to write sample data to the output. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleMetadata(long,int,int,int,androidx.media3.extractor.TrackOutput.CryptoData)( long timeUs, @https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flags, int size, int offset, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.CryptoData cryptoData )` Called when metadata associated with a sample has been extracted from the stream. |

## Constants

### SAMPLE_DATA_PART_ENCRYPTION

```
default static final int SAMPLE_DATA_PART_ENCRYPTION = 1
```

Sample encryption data.

The format for encryption information is:

- (1 byte) `encryption_signal_byte`: Most significant bit signals whether the encryption data contains subsample encryption data. The remaining bits contain ` initialization_vector_size`.
- (`initialization_vector_size` bytes) Initialization vector.
- If subsample encryption data is present, as per `encryption_signal_byte`, the encryption data also contains:
  - (2 bytes) `subsample_encryption_data_length`.
  - (`subsample_encryption_data_length * 6` bytes) Subsample encryption data (repeated `subsample_encryption_data_length` times:
    - (2 bytes) Size of a clear section in sample.
    - (4 bytes) Size of an encryption section in sample.

### SAMPLE_DATA_PART_MAIN

```
default static final int SAMPLE_DATA_PART_MAIN = 0
```

Main media sample data.

### SAMPLE_DATA_PART_SUPPLEMENTAL

```
default static final int SAMPLE_DATA_PART_SUPPLEMENTAL = 2
```

Sample supplemental data.

If a sample contains supplemental data, the format of the entire sample data will be:

- If the sample has the `https://developer.android.com/reference/androidx/media3/common/C#BUFFER_FLAG_ENCRYPTED()` flag set, all encryption information.
- (4 bytes) `sample_data_size`: The size of the actual sample data, not including supplemental data or encryption information.
- (`sample_data_size` bytes): The media sample data.
- (remaining bytes) The supplemental data.

## Public methods

### durationUs

```
default void durationUs(long durationUs)
```

Called to set the duration of the track in microseconds.

| Parameters |
|---|---|
| `long durationUs` | The duration of the track in microseconds. |

### format

```
abstract void format(Format format)
```

Called when the `https://developer.android.com/reference/androidx/media3/common/Format` of the track has been extracted from the stream.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The extracted `https://developer.android.com/reference/androidx/media3/common/Format`. |

### sampleData

```
default void sampleData(ParsableByteArray data, int length)
```

Equivalent to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int,int)` sampleData(data, length, SAMPLE_DATA_PART_MAIN)}.

### sampleData

```
abstract void sampleData(
    ParsableByteArray data,
    int length,
    @TrackOutput.SampleDataPart int sampleDataPart
)
```

Called to write sample data to the output.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data` | A `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray` from which to read the sample data. |
| `int length` | The number of bytes to read, starting from `data.getPosition()`. |
| `@https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.SampleDataPart int sampleDataPart` | The part of the sample data to which this call corresponds. |

### sampleData

```
default int sampleData(DataReader input, int length, boolean allowEndOfInput)
```

Equivalent to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean,int)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### sampleData

```
abstract int sampleData(
    DataReader input,
    int length,
    boolean allowEndOfInput,
    @TrackOutput.SampleDataPart int sampleDataPart
)
```

Called to write sample data to the output.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/DataReader input` | A `https://developer.android.com/reference/androidx/media3/common/DataReader` from which to read the sample data. |
| `int length` | The maximum length to read from the input. |
| `boolean allowEndOfInput` | True if encountering the end of the input having read no data is allowed, and should result in `https://developer.android.com/reference/androidx/media3/common/C#RESULT_END_OF_INPUT()` being returned. False if it should be considered an error, causing an `https://developer.android.com/reference/java/io/EOFException.html` to be thrown. |
| `@https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.SampleDataPart int sampleDataPart` | The part of the sample data to which this call corresponds. |

| Returns |
|---|---|
| `int` | The number of bytes appended. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the input. |

### sampleMetadata

```
abstract void sampleMetadata(
    long timeUs,
    @C.BufferFlags int flags,
    int size,
    int offset,
    @Nullable TrackOutput.CryptoData cryptoData
)
```

Called when metadata associated with a sample has been extracted from the stream.

The corresponding sample data will have already been passed to the output via calls to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean)` or `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int)`.

| Parameters |
|---|---|
| `long timeUs` | The media timestamp associated with the sample, in microseconds. |
| `@https://developer.android.com/reference/androidx/media3/common/C.BufferFlags int flags` | Flags associated with the sample. See `C.BUFFER_FLAG_*`. |
| `int size` | The size of the sample data, in bytes. |
| `int offset` | The number of bytes that have been passed to `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.DataReader,int,boolean)` or `https://developer.android.com/reference/androidx/media3/extractor/TrackOutput#sampleData(androidx.media3.common.util.ParsableByteArray,int)` since the last byte belonging to the sample whose metadata is being passed. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/extractor/TrackOutput.CryptoData cryptoData` | The encryption data required to decrypt the sample. May be null. |