FlacFrameReader


@UnstableApi
class FlacFrameReader


Reads and peeks FLAC frame elements according to the FLAC format specification.

Summary

Nested types

Holds a sample number.

Public functions

java-static Boolean
checkAndReadFrameHeader(
    data: ParsableByteArray!,
    flacStreamMetadata: FlacStreamMetadata!,
    frameStartMarker: Int,
    sampleNumberHolder: 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
checkFrameHeaderFromPeek(
    input: ExtractorInput!,
    flacStreamMetadata: FlacStreamMetadata!,
    frameStartMarker: Int,
    sampleNumberHolder: 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
getFirstSampleNumber(
    input: ExtractorInput!,
    flacStreamMetadata: FlacStreamMetadata!
)

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

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

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.

Parameters
data: ParsableByteArray!

The array to read the data from, whose position must correspond to the frame header.

flacStreamMetadata: FlacStreamMetadata!

The stream metadata.

frameStartMarker: Int

The frame start marker of the stream.

sampleNumberHolder: FlacFrameReader.SampleNumberHolder!

The holder used to contain the sample number.

Returns
Boolean

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.

Parameters
input: ExtractorInput!

The input to get the data from, whose peek position must correspond to the frame header.

flacStreamMetadata: FlacStreamMetadata!

The stream metadata.

frameStartMarker: Int

The frame start marker of the stream.

sampleNumberHolder: FlacFrameReader.SampleNumberHolder!

The holder used to contain the sample number.

Returns
Boolean

Whether the frame header is valid.

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!

Input stream to get the sample number from (starting from the read position).

flacStreamMetadata: FlacStreamMetadata!

The FLAC metadata of the stream.

Returns
Long

The frame first sample number.

Throws
androidx.media3.common.ParserException

If an error occurs parsing the sample number.

java.io.IOException

If peeking from the input fails.

readFrameBlockSizeSamplesFromKey

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

Reads the given block size.

Parameters
data: ParsableByteArray!

The array to read the data from, whose position must correspond to the block size bits.

blockSizeKey: Int

The key in the block size lookup table.

Returns
Int

The block size in samples, or -1 if the blockSizeKey is invalid.