Search in sources :

Example 36 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class TsExtractorTest method testCustomPesReader.

public void testCustomPesReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    FakeExtractorOutput output = new FakeExtractorOutput();
    tsExtractor.init(output);
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    CustomEsReader reader = factory.esReader;
    assertEquals(2, reader.packetsRead);
    TrackOutput trackOutput = reader.getTrackOutput();
    assertTrue(trackOutput == output.trackOutputs.get(257));
    assertEquals(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) TimestampAdjuster(com.google.android.exoplayer2.util.TimestampAdjuster) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput)

Example 37 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToZero.

@Test
public void seeking_seekTable_handlesSeekToZero() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 38 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingBackward.

@Test
public void seeking_seekTable_handlesSeekingBackward() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 1_234_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 987_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 39 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingBackward.

@Test
public void seeking_binarySearch_handlesSeekingBackward() throws IOException {
    String fileName = TEST_FILE_BINARY_SEARCH;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 1_234_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 987_00;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 40 with FakeTrackOutput

use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.

the class FlacExtractorSeekTest method assertFirstFrameAfterSeekContainsTargetSeekTime.

private static void assertFirstFrameAfterSeekContainsTargetSeekTime(String fileName, FakeTrackOutput trackOutput, long targetSeekTimeUs, int firstFrameIndexAfterSeek) throws IOException {
    FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
    int expectedFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
    trackOutput.assertSample(firstFrameIndexAfterSeek, expectedTrackOutput.getSampleData(expectedFrameIndex), expectedTrackOutput.getSampleTimeUs(expectedFrameIndex), expectedTrackOutput.getSampleFlags(expectedFrameIndex), expectedTrackOutput.getSampleCryptoData(expectedFrameIndex));
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput)

Aggregations

FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)71 Test (org.junit.Test)60 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)58 Uri (android.net.Uri)50 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)32 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)6 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)5 Format (com.google.android.exoplayer2.Format)4 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)3 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)3 WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)3 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1 IOException (java.io.IOException)1 Before (org.junit.Before)1