Search in sources :

Example 6 with SampleNumberHolder

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

the class FlacFrameReaderTest method checkAndReadFrameHeader_validData_updatesPosition.

@Test
public void checkAndReadFrameHeader_validData_updatesPosition() 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);
    FlacFrameReader.checkAndReadFrameHeader(scratch, streamMetadataHolder.flacStreamMetadata, frameStartMarker, new SampleNumberHolder());
    assertThat(scratch.getPosition()).isEqualTo(FlacConstants.MIN_FRAME_HEADER_SIZE);
}
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 7 with SampleNumberHolder

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

the class FlacFrameReaderTest method checkFrameHeaderFromPeek_validData_doesNotUpdatePositions.

@Test
public void checkFrameHeaderFromPeek_validData_doesNotUpdatePositions() throws Exception {
    String file = "media/flac/bear_one_metadata_block.flac";
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame(file, streamMetadataHolder);
    int frameStartMarker = FlacMetadataReader.getFrameStartMarker(input);
    long peekPosition = input.getPosition();
    // Set read position to 0.
    input = buildExtractorInput(file);
    input.advancePeekPosition((int) peekPosition);
    FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, frameStartMarker, 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 8 with SampleNumberHolder

use of com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder 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 9 with SampleNumberHolder

use of com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder 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 10 with SampleNumberHolder

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

the class FlacFrameReaderTest method checkFrameHeaderFromPeek_invalidData_isFalse.

@Test
public void checkFrameHeaderFromPeek_invalidData_isFalse() throws Exception {
    FlacStreamMetadataHolder streamMetadataHolder = new FlacStreamMetadataHolder(/* flacStreamMetadata= */
    null);
    ExtractorInput input = buildExtractorInputReadingFromFirstFrame("media/flac/bear_one_metadata_block.flac", streamMetadataHolder);
    // The first bytes of the frame are not equal to the frame start marker.
    boolean result = FlacFrameReader.checkFrameHeaderFromPeek(input, streamMetadataHolder.flacStreamMetadata, /* frameStartMarker= */
    -1, new SampleNumberHolder());
    assertThat(result).isFalse();
}
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

SampleNumberHolder (com.google.android.exoplayer2.extractor.FlacFrameReader.SampleNumberHolder)9 FlacStreamMetadataHolder (com.google.android.exoplayer2.extractor.FlacMetadataReader.FlacStreamMetadataHolder)9 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)9 Test (org.junit.Test)9 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)6