# FlacFrameReader

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/extractor/FlacFrameReader "View this page in Java")

<br />

```
@UnstableApi
class FlacFrameReader
```

<br />

*** ** * ** ***

Reads and peeks FLAC frame elements according to RFC 9639.

## Summary

|                                                                                 ### Nested types                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[FlacFrameReader.SampleNumberHolder](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder) Holds a sample number. |

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [checkAndReadFrameHeader](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader#checkAndReadFrameHeader(androidx.media3.common.util.ParsableByteArray,androidx.media3.extractor.FlacStreamMetadata,int,androidx.media3.extractor.FlacFrameReader.SampleNumberHolder))`(` ` data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!,` ` flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!,` ` frameStartMarker: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` sampleNumberHolder: `[FlacFrameReader.SampleNumberHolder](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder)`!` `)` Checks whether the given FLAC frame header is valid and, if so, reads it and writes the frame first sample number in`sampleNumberHolder`. |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [checkFrameHeaderFromPeek](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader#checkFrameHeaderFromPeek(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.FlacStreamMetadata,int,androidx.media3.extractor.FlacFrameReader.SampleNumberHolder))`(` ` input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!,` ` flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!,` ` frameStartMarker: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` sampleNumberHolder: `[FlacFrameReader.SampleNumberHolder](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder)`!` `)` Checks whether the given FLAC frame header is valid and, if so, writes the frame first sample number in`sampleNumberHolder`.                        |
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | [getFirstSampleNumber](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader#getFirstSampleNumber(androidx.media3.extractor.ExtractorInput,androidx.media3.extractor.FlacStreamMetadata))`(` ` input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!,` ` flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!` `)` Returns the number of the first sample in the given frame.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [readFrameBlockSizeSamplesFromKey](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader#readFrameBlockSizeSamplesFromKey(androidx.media3.common.util.ParsableByteArray,int))`(` ` data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!,` ` blockSizeKey: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Reads the given block size.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |

## Public functions

### checkAndReadFrameHeader

```
java-static fun checkAndReadFrameHeader(
    data: ParsableByteArray!,
    flacStreamMetadata: FlacStreamMetadata!,
    frameStartMarker: Int,
    sampleNumberHolder: FlacFrameReader.SampleNumberHolder!
): Boolean
```

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                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| `data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!`                                               | The array to read the data from, whose position must correspond to the frame header. |
| `flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!`                                 | The stream metadata.                                                                 |
| `frameStartMarker: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                            | The frame start marker of the stream.                                                |
| `sampleNumberHolder: `[FlacFrameReader.SampleNumberHolder](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder)`!` | The holder used to contain the sample number.                                        |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the frame header is valid. |

### checkFrameHeaderFromPeek

```
java-static fun checkFrameHeaderFromPeek(
    input: ExtractorInput!,
    flacStreamMetadata: FlacStreamMetadata!,
    frameStartMarker: Int,
    sampleNumberHolder: FlacFrameReader.SampleNumberHolder!
): Boolean
```

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                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| `input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!`                                                      | The input to get the data from, whose peek position must correspond to the frame header. |
| `flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!`                                 | The stream metadata.                                                                     |
| `frameStartMarker: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                            | The frame start marker of the stream.                                                    |
| `sampleNumberHolder: `[FlacFrameReader.SampleNumberHolder](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacFrameReader.SampleNumberHolder)`!` | The holder used to contain the sample number.                                            |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the frame header is valid. |

|                                         Throws                                          |
|-----------------------------------------------------------------------------------------|---|
| [java.io.IOException](https://developer.android.com/reference/java/io/IOException.html) |   |

### getFirstSampleNumber

```
java-static fun getFirstSampleNumber(
    input: ExtractorInput!,
    flacStreamMetadata: FlacStreamMetadata!
): Long
```

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                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|
| `input: `[ExtractorInput](https://developer.android.com/reference/kotlin/androidx/media3/extractor/ExtractorInput)`!`                      | Input stream to get the sample number from (starting from the read position). |
| `flacStreamMetadata: `[FlacStreamMetadata](https://developer.android.com/reference/kotlin/androidx/media3/extractor/FlacStreamMetadata)`!` | The FLAC metadata of the stream.                                              |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|--------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The frame first sample number. |

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

### readFrameBlockSizeSamplesFromKey

```
java-static fun readFrameBlockSizeSamplesFromKey(
    data: ParsableByteArray!,
    blockSizeKey: Int
): Int
```

Reads the given block size.  

|                                                          Parameters                                                          |
|------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| `data: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!` | The array to read the data from, whose position must correspond to the block size bits. |
| `blockSizeKey: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                  | The key in the block size lookup table.                                                 |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The block size in samples, or -1 if the`blockSizeKey`is invalid. |