Search in sources :

Example 16 with FlacStreamMetadataHolder

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

the class FlacFrameReaderTest method getFirstSampleNumber_returnsSampleNumber.

@Test
public void getFirstSampleNumber_returnsSampleNumber() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    // Skip first frame.
    input.skip(5030);
    long result = FlacFrameReader.getFirstSampleNumber(input, streamMetadataHolder.flacStreamMetadata);
    assertThat(result).isEqualTo(4096);
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Example 17 with FlacStreamMetadataHolder

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

the class FlacFrameReaderTest method buildExtractorInputReadingFromFirstFrame.

private ExtractorInput buildExtractorInputReadingFromFirstFrame(String file, FlacStreamMetadataHolder streamMetadataHolder) throws IOException {
    ExtractorInput input = buildExtractorInput(file);
    input.skipFully(FlacConstants.STREAM_MARKER_SIZE);
    boolean lastMetadataBlock = false;
    while (!lastMetadataBlock) {
        lastMetadataBlock = FlacMetadataReader.readMetadataBlock(input, streamMetadataHolder);
    }
    return input;
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 18 with FlacStreamMetadataHolder

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

the class FlacFrameReaderTest method checkFrameHeaderFromPeek_validData_writesSampleNumber.

@Test
public void checkFrameHeaderFromPeek_validData_writesSampleNumber() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
    // Skip first frame.
    input.skip(5030);
    SampleNumberHolder sampleNumberHolder = new SampleNumberHolder();
    FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, frameStartMarker, sampleNumberHolder);
    assertThat(sampleNumberHolder.sampleNumber).isEqualTo(4096);
}
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)

Example 19 with FlacStreamMetadataHolder

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

the class FlacFrameReaderTest method checkFrameHeaderFromPeek_invalidData_doesNotUpdatePositions.

@Test
public void checkFrameHeaderFromPeek_invalidData_doesNotUpdatePositions() throws Exception {
    String file = "media/flac/bear_one_metadata_block.flac";
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame(file, streamMetadataHolder);
    long peekPosition = input.getPosition();
    // Set read position to 0.
    input = buildExtractorInput(file);
    input.advancePeekPosition((int) peekPosition);
    // The first bytes of the frame are not equal to the frame start marker.
    FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, /* frameStartMarker= */
    -1, new SampleNumberHolder());
    assertThat(input.getPosition()).isEqualTo(0);
    assertThat(input.getPeekPosition()).isEqualTo(peekPosition);
}
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)

Example 20 with FlacStreamMetadataHolder

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

the class FlacFrameReaderTest method getFirstSampleNumber_doesNotUpdateReadPositionAndAlignsPeekPosition.

@Test
public void getFirstSampleNumber_doesNotUpdateReadPositionAndAlignsPeekPosition() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    long initialReadPosition = input.getPosition();
    // Advance peek position after block size bits.
    input.advancePeekPosition(FlacConstants.MAX_FRAME_HEADER_SIZE);
    FlacFrameReader.getFirstSampleNumber(input, streamMetadataHolder.flacStreamMetadata);
    assertThat(input.getPosition()).isEqualTo(initialReadPosition);
    assertThat(input.getPeekPosition()).isEqualTo(input.getPosition());
}
Also used : FlacStreamMetadataHolder(com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Test(org.junit.Test)

Aggregations

FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)21 FlacStreamMetadataHolder (com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder)20 Test (org.junit.Test)20 SampleNumberHolder (com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder)9 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)5 Metadata (com.google.android.exoplayer2.metadata.Metadata)2 PictureFrame (com.google.android.exoplayer2.metadata.flac.PictureFrame)2 Nullable (androidx.annotation.Nullable)1 VorbisComment (com.google.android.exoplayer2.metadata.vorbis.VorbisComment)1 ParsableBitArray (com.google.android.exoplayer2.util.ParsableBitArray)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1