Search in sources :

Example 16 with ExtractorInput

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

the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageInputShorterThanPeekLength.

public void testSkipToNextPageInputShorterThanPeekLength() throws Exception {
    FakeExtractorInput extractorInput = TestData.createInput(TestUtil.joinByteArrays(new byte[] { 'x', 'O', 'g', 'g', 'S' }), false);
    skipToNextPage(extractorInput);
    assertEquals(1, extractorInput.getPosition());
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 17 with ExtractorInput

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

the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageOverlap.

public void testSkipToNextPageOverlap() throws Exception {
    FakeExtractorInput extractorInput = TestData.createInput(TestUtil.joinByteArrays(TestUtil.buildTestData(2046, random), new byte[] { 'O', 'g', 'g', 'S' }, TestUtil.buildTestData(4000, random)), false);
    skipToNextPage(extractorInput);
    assertEquals(2046, extractorInput.getPosition());
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 18 with ExtractorInput

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

the class DefaultOggSeekerUtilMethodsTest method testSkipToNextPageNoMatch.

public void testSkipToNextPageNoMatch() throws Exception {
    FakeExtractorInput extractorInput = TestData.createInput(new byte[] { 'g', 'g', 'S', 'O', 'g', 'g' }, false);
    try {
        skipToNextPage(extractorInput);
        fail();
    } catch (EOFException e) {
    // expected
    }
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) EOFException(java.io.EOFException)

Example 19 with ExtractorInput

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

the class VorbisReaderTest method testReadSetupHeadersWithIOExceptions.

public void testReadSetupHeadersWithIOExceptions() throws IOException, InterruptedException {
    byte[] data = TestData.getVorbisHeaderPages();
    ExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(true).setSimulateUnknownLength(true).setSimulatePartialReads(true).build();
    VorbisReader reader = new VorbisReader();
    VorbisReader.VorbisSetup vorbisSetup = readSetupHeaders(reader, input);
    assertNotNull(vorbisSetup.idHeader);
    assertNotNull(vorbisSetup.commentHeader);
    assertNotNull(vorbisSetup.setupHeaderData);
    assertNotNull(vorbisSetup.modes);
    assertEquals(45, vorbisSetup.commentHeader.length);
    assertEquals(30, vorbisSetup.idHeader.data.length);
    assertEquals(3597, vorbisSetup.setupHeaderData.length);
    assertEquals(-1, vorbisSetup.idHeader.bitrateMax);
    assertEquals(-1, vorbisSetup.idHeader.bitrateMin);
    assertEquals(66666, vorbisSetup.idHeader.bitrateNominal);
    assertEquals(512, vorbisSetup.idHeader.blockSize0);
    assertEquals(1024, vorbisSetup.idHeader.blockSize1);
    assertEquals(2, vorbisSetup.idHeader.channels);
    assertTrue(vorbisSetup.idHeader.framingFlag);
    assertEquals(22050, vorbisSetup.idHeader.sampleRate);
    assertEquals(0, vorbisSetup.idHeader.version);
    assertEquals("Xiph.Org libVorbis I 20030909", vorbisSetup.commentHeader.vendor);
    assertEquals(1, vorbisSetup.iLogModes);
    assertEquals(data[data.length - 1], vorbisSetup.setupHeaderData[vorbisSetup.setupHeaderData.length - 1]);
    assertFalse(vorbisSetup.modes[0].blockFlag);
    assertTrue(vorbisSetup.modes[1].blockFlag);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) VorbisSetup(com.google.android.exoplayer2.extractor.ogg.VorbisReader.VorbisSetup) ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 20 with ExtractorInput

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

the class HlsMediaChunk method peekId3PrivTimestamp.

/**
   * Peek the presentation timestamp of the first sample in the chunk from an ID3 PRIV as defined
   * in the HLS spec, version 20, Section 3.4. Returns {@link C#TIME_UNSET} if the frame is not
   * found. This method only modifies the peek position.
   *
   * @param input The {@link ExtractorInput} to obtain the PRIV frame from.
   * @return The parsed, adjusted timestamp in microseconds
   * @throws IOException If an error occurred peeking from the input.
   * @throws InterruptedException If the thread was interrupted.
   */
private long peekId3PrivTimestamp(ExtractorInput input) throws IOException, InterruptedException {
    input.resetPeekPosition();
    if (!input.peekFully(id3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH, true)) {
        return C.TIME_UNSET;
    }
    id3Data.reset(Id3Decoder.ID3_HEADER_LENGTH);
    int id = id3Data.readUnsignedInt24();
    if (id != Id3Decoder.ID3_TAG) {
        return C.TIME_UNSET;
    }
    // version(2), flags(1).
    id3Data.skipBytes(3);
    int id3Size = id3Data.readSynchSafeInt();
    int requiredCapacity = id3Size + Id3Decoder.ID3_HEADER_LENGTH;
    if (requiredCapacity > id3Data.capacity()) {
        byte[] data = id3Data.data;
        id3Data.reset(requiredCapacity);
        System.arraycopy(data, 0, id3Data.data, 0, Id3Decoder.ID3_HEADER_LENGTH);
    }
    if (!input.peekFully(id3Data.data, Id3Decoder.ID3_HEADER_LENGTH, id3Size, true)) {
        return C.TIME_UNSET;
    }
    Metadata metadata = id3Decoder.decode(id3Data.data, id3Size);
    if (metadata == null) {
        return C.TIME_UNSET;
    }
    int metadataLength = metadata.length();
    for (int i = 0; i < metadataLength; i++) {
        Metadata.Entry frame = metadata.get(i);
        if (frame instanceof PrivFrame) {
            PrivFrame privFrame = (PrivFrame) frame;
            if (PRIV_TIMESTAMP_FRAME_OWNER.equals(privFrame.owner)) {
                System.arraycopy(privFrame.privateData, 0, id3Data.data, 0, 8);
                id3Data.reset(8);
                return id3Data.readLong();
            }
        }
    }
    return C.TIME_UNSET;
}
Also used : Metadata(com.google.android.exoplayer2.metadata.Metadata) PrivFrame(com.google.android.exoplayer2.metadata.id3.PrivFrame)

Aggregations

ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)20 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)19 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)12 ParserException (com.google.android.exoplayer2.ParserException)8 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)5 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)4 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)3 Format (com.google.android.exoplayer2.Format)2 Extractor (com.google.android.exoplayer2.extractor.Extractor)2 ContainerAtom (com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom)2 EOFException (java.io.EOFException)2 LeafAtom (com.google.android.exoplayer2.extractor.mp4.Atom.LeafAtom)1 VorbisSetup (com.google.android.exoplayer2.extractor.ogg.VorbisReader.VorbisSetup)1 TrackIdGenerator (com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 PrivFrame (com.google.android.exoplayer2.metadata.id3.PrivFrame)1 SimulatedIOException (com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)1 FlacStreamInfo (com.google.android.exoplayer2.util.FlacStreamInfo)1 ParsableBitArray (com.google.android.exoplayer2.util.ParsableBitArray)1