Search in sources :

Example 6 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacMetadataReaderTest method readMetadataBlock_lastMetadataBlock_isTrue.

@Test
public void readMetadataBlock_lastMetadataBlock_isTrue() throws Exception {
    ExtractorInput input = buildExtractorInput("media/flac/bear_one_metadata_block.flac");
    input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
    boolean result = FlacMetadataReader.readMetadataBlock(input, new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null));
    assertThat(result).isTrue();
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 7 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacFrameReader method checkFrameHeaderFromPeek.

/**
 * Checks whether the given FLAC frame header is valid and, if so, writes the frame first sample
 * number in {@code sampleNumberHolder}.
 *
 * <p>The {@code input} peek position is left unchanged.
 *
 * @param input The input to get the data from, whose peek position must correspond to the frame
 *     header.
 * @param flacStreamMetadata The stream metadata.
 * @param frameStartMarker The frame start marker of the stream.
 * @param sampleNumberHolder The holder used to contain the sample number.
 * @return Whether the frame header is valid.
 */
public static boolean checkFrameHeaderFromPeek(ExtractorInput input, FlacStreamMetadata flacStreamMetadata, int frameStartMarker, SampleNumberHolder sampleNumberHolder) throws IOException {
    long originalPeekPosition = input.getPeekPosition();
    byte[] frameStartBytes = new byte[2];
    input.peekFully(frameStartBytes, 0, 2);
    int frameStart = (frameStartBytes[0] & 0xFF) << 8 | (frameStartBytes[1] & 0xFF);
    if (frameStart != frameStartMarker) {
        input.resetPeekPosition();
        input.advancePeekPosition((int) (originalPeekPosition - input.getPosition()));
        return false;
    }
    ParsableByteArray scratch = new ParsableByteArray(FlacConstants.MAX_FRAME_HEADER_SIZE);
    System.arraycopy(frameStartBytes, /* srcPos= */
    0, scratch.getData(), /* destPos= */
    0, /* length= */
    2);
    int totalBytesPeeked = ExtractorUtil.peekToLength(input, scratch.getData(), 2, FlacConstants.MAX_FRAME_HEADER_SIZE - 2);
    scratch.setLimit(totalBytesPeeked);
    input.resetPeekPosition();
    input.advancePeekPosition((int) (originalPeekPosition - input.getPosition()));
    return checkAndReadFrameHeader(scratch, flacStreamMetadata, frameStartMarker, sampleNumberHolder);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 8 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacFrameReader method getFirstSampleNumber.

/**
 * Returns the number of the first sample in the given frame.
 *
 * <p>The read position of {@code input} is left unchanged.
 *
 * <p>If no exception is thrown, the peek position is aligned with the read position. Otherwise,
 * there is no guarantee on the peek position.
 *
 * @param input Input stream to get the sample number from (starting from the read position).
 * @return The frame first sample number.
 * @throws ParserException If an error occurs parsing the sample number.
 * @throws IOException If peeking from the input fails.
 */
public static long getFirstSampleNumber(ExtractorInput input, FlacStreamMetadata flacStreamMetadata) throws IOException {
    input.resetPeekPosition();
    input.advancePeekPosition(1);
    byte[] blockingStrategyByte = new byte[1];
    input.peekFully(blockingStrategyByte, 0, 1);
    boolean isBlockSizeVariable = (blockingStrategyByte[0] & 1) == 1;
    input.advancePeekPosition(2);
    int maxUtf8SampleNumberSize = isBlockSizeVariable ? 7 : 6;
    ParsableByteArray scratch = new ParsableByteArray(maxUtf8SampleNumberSize);
    int totalBytesPeeked = ExtractorUtil.peekToLength(input, scratch.getData(), 0, maxUtf8SampleNumberSize);
    scratch.setLimit(totalBytesPeeked);
    input.resetPeekPosition();
    SampleNumberHolder sampleNumberHolder = new SampleNumberHolder();
    if (!checkAndReadFirstSampleNumber(scratch, flacStreamMetadata, isBlockSizeVariable, sampleNumberHolder)) {
        throw ParserException.createForMalformedContainer(/* message= */
        null, /* cause= */
        null);
    }
    return sampleNumberHolder.sampleNumber;
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray)

Example 9 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacFrameReaderTest method checkAndReadFrameHeader_validData_isTrue.

@Test
public void checkAndReadFrameHeader_validData_isTrue() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
    ParsableByteArray scratch = new ParsableByteArray(FlacConstants.MAX_FRAME_HEADER_SIZE);
    input.read(scratch.getData(), 0, FlacConstants.MAX_FRAME_HEADER_SIZE);
    boolean result = FlacFrameReader.checkAndReadFrameHeader(scratch, streamMetadataHolder.flacStreamMetadata, frameStartMarker, new SampleNumberHolder());
    assertThat(result).isTrue();
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) SampleNumberHolder(com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 10 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata in project ExoPlayer by google.

the class FlacFrameReaderTest method checkFrameHeaderFromPeek_validData_isTrue.

@Test
public void checkFrameHeaderFromPeek_validData_isTrue() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
    boolean result = FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, frameStartMarker, new SampleNumberHolder());
    assertThat(result).isTrue();
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) SampleNumberHolder(com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 FlacStreamMetadataHolder (com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder)16 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)16 SampleNumberHolder (com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder)9 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)7 Metadata (com.google.android.exoplayer2.metadata.Metadata)5 Nullable (androidx.annotation.Nullable)4 ArrayList (java.util.ArrayList)4 FlacStreamMetadata (com.google.android.exoplayer2.extractor.FlacStreamMetadata)3 VorbisComment (com.google.android.exoplayer2.metadata.vorbis.VorbisComment)3 Format (com.google.android.exoplayer2.Format)2 OutputFrameHolder (com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder)1 SeekTable (com.google.android.exoplayer2.extractor.FlacStreamMetadata.SeekTable)1 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 PictureFrame (com.google.android.exoplayer2.metadata.flac.PictureFrame)1 ParsableBitArray (com.google.android.exoplayer2.util.ParsableBitArray)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)1