# FlacFrameReader

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

*** ** * ** ***


```
@UnstableApi
public final class FlacFrameReader
```

<br />

*** ** * ** ***

Reads and peeks FLAC frame elements according to RFC 9639.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder` Holds a sample number. |

| ### Public methods |
|---|---|
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader#checkAndReadFrameHeader(androidx.media3.common.util.ParsableByteArray,androidx.media3.extractor.FlacStreamMetadata,int,androidx.media3.extractor.FlacFrameReader.SampleNumberHolder)( https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data, https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata, int frameStartMarker, https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder sampleNumberHolder )` Checks whether the given FLAC frame header is valid and, if so, reads it and writes the frame first sample number in `sampleNumberHolder`. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader#checkFrameHeaderFromPeek(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.FlacStreamMetadata,int,androidx.media3.extractor.FlacFrameReader.SampleNumberHolder)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata, int frameStartMarker, https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder sampleNumberHolder )` Checks whether the given FLAC frame header is valid and, if so, writes the frame first sample number in `sampleNumberHolder`. |
| `static long` | `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader#getFirstSampleNumber(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.FlacStreamMetadata)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata )` Returns the number of the first sample in the given frame. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader#readFrameBlockSizeSamplesFromKey(androidx.media3.common.util.ParsableByteArray,int)( https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data, int blockSizeKey )` Reads the given block size. |

## Public methods

### checkAndReadFrameHeader

```
public static boolean checkAndReadFrameHeader(
    ParsableByteArray data,
    FlacStreamMetadata flacStreamMetadata,
    int frameStartMarker,
    FlacFrameReader.SampleNumberHolder sampleNumberHolder
)
```

Checks whether the given FLAC frame header is valid and, if so, reads it and writes the frame first sample number in `sampleNumberHolder`.

If the header is valid, the position of `data` is moved to the byte following it. Otherwise, there is no guarantee on the position.

If `data` contains enough data, the subframe header following the header is also checked for validity, to reduce the risk of a false-positive frame header match.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data` | The array to read the data from, whose position must correspond to the frame header. |
| `https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata` | The stream metadata. |
| `int frameStartMarker` | The frame start marker of the stream. |
| `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder sampleNumberHolder` | The holder used to contain the sample number. |

| Returns |
|---|---|
| `boolean` | Whether the frame header is valid. |

### checkFrameHeaderFromPeek

```
public static boolean checkFrameHeaderFromPeek(
    ExtractorInput input,
    FlacStreamMetadata flacStreamMetadata,
    int frameStartMarker,
    FlacFrameReader.SampleNumberHolder sampleNumberHolder
)
```

Checks whether the given FLAC frame header is valid and, if so, writes the frame first sample number in `sampleNumberHolder`.

The `input` peek position is left unchanged.

If `input` contains enough data, the subframe header following the header is also checked for validity, to reduce the risk of a false-positive frame header match.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | The input to get the data from, whose peek position must correspond to the frame header. |
| `https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata` | The stream metadata. |
| `int frameStartMarker` | The frame start marker of the stream. |
| `https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder sampleNumberHolder` | The holder used to contain the sample number. |

| Returns |
|---|---|
| `boolean` | Whether the frame header is valid. |

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

### getFirstSampleNumber

```
public static long getFirstSampleNumber(
    ExtractorInput input,
    FlacStreamMetadata flacStreamMetadata
)
```

Returns the number of the first sample in the given frame.

The read position of `input` is left unchanged.

If no exception is thrown, the peek position is aligned with the read position. Otherwise, there is no guarantee on the peek position.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | Input stream to get the sample number from (starting from the read position). |
| `https://developer.android.com/reference/androidx/media3/extractor/FlacStreamMetadata flacStreamMetadata` | The FLAC metadata of the stream. |

| Returns |
|---|---|
| `long` | The frame first sample number. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | If an error occurs parsing the sample number. |
| `https://developer.android.com/reference/java/io/IOException.html` | If peeking from the input fails. |

### readFrameBlockSizeSamplesFromKey

```
public static int readFrameBlockSizeSamplesFromKey(
    ParsableByteArray data,
    int blockSizeKey
)
```

Reads the given block size.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data` | The array to read the data from, whose position must correspond to the block size bits. |
| `int blockSizeKey` | The key in the block size lookup table. |

| Returns |
|---|---|
| `int` | The block size in samples, or -1 if the `blockSizeKey` is invalid. |