Search in sources :

Example 11 with FlacStreamMetadata

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

the class FlacFrameReaderTest method checkAndReadFrameHeader_invalidData_isFalse.

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

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata 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 13 with FlacStreamMetadata

use of com.google.android.exoplayer2.extractor.FlacStreamMetadata 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 14 with FlacStreamMetadata

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

the class FlacStreamMetadataTest method parseInvalidVorbisComment.

@Test
public void parseInvalidVorbisComment() {
    ArrayList<String> commentsList = new ArrayList<>();
    commentsList.add("TitleSong");
    commentsList.add("Artist=Singer");
    Metadata metadata = new FlacStreamMetadata(/* minBlockSizeSamples= */
    0, /* maxBlockSizeSamples= */
    0, /* minFrameSize= */
    0, /* maxFrameSize= */
    0, /* sampleRate= */
    0, /* channels= */
    0, /* bitsPerSample= */
    0, /* totalSamples= */
    0, commentsList, /* pictureFrames= */
    new ArrayList<>()).getMetadataCopyWithAppendedEntriesFrom(/* other= */
    null);
    assertThat(metadata.length()).isEqualTo(1);
    VorbisComment commentFrame = (VorbisComment) metadata.get(0);
    assertThat(commentFrame.key).isEqualTo("Artist");
    assertThat(commentFrame.value).isEqualTo("Singer");
}
Also used : ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) VorbisComment(com.google.android.exoplayer2.metadata.vorbis.VorbisComment) Test(org.junit.Test)

Example 15 with FlacStreamMetadata

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

the class FlacStreamMetadataTest method parseVorbisComments.

@Test
public void parseVorbisComments() {
    ArrayList<String> commentsList = new ArrayList<>();
    commentsList.add("Title=Song");
    commentsList.add("Artist=Singer");
    Metadata metadata = new FlacStreamMetadata(/* minBlockSizeSamples= */
    0, /* maxBlockSizeSamples= */
    0, /* minFrameSize= */
    0, /* maxFrameSize= */
    0, /* sampleRate= */
    0, /* channels= */
    0, /* bitsPerSample= */
    0, /* totalSamples= */
    0, commentsList, /* pictureFrames= */
    new ArrayList<>()).getMetadataCopyWithAppendedEntriesFrom(/* other= */
    null);
    assertThat(metadata.length()).isEqualTo(2);
    VorbisComment commentFrame = (VorbisComment) metadata.get(0);
    assertThat(commentFrame.key).isEqualTo("Title");
    assertThat(commentFrame.value).isEqualTo("Song");
    commentFrame = (VorbisComment) metadata.get(1);
    assertThat(commentFrame.key).isEqualTo("Artist");
    assertThat(commentFrame.value).isEqualTo("Singer");
}
Also used : ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) VorbisComment(com.google.android.exoplayer2.metadata.vorbis.VorbisComment) 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