Search in sources :

Example 66 with FakeTrackOutput

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

the class TsExtractorSeekTest method handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long firstSeekTimeUs = 987_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 67 with FakeTrackOutput

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

the class TsExtractorSeekTest method handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long targetSeekTimeUs = 987_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 68 with FakeTrackOutput

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

the class SubtitleExtractorTest method extractor_seekBetweenReads_outputsCues.

@Test
public void extractor_seekBetweenReads_outputsCues() throws Exception {
    CueDecoder decoder = new CueDecoder();
    FakeExtractorOutput output = new FakeExtractorOutput();
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(Util.getUtf8Bytes(TEST_DATA)).setSimulatePartialReads(true).build();
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).build());
    extractor.init(output);
    FakeTrackOutput trackOutput = output.trackOutputs.get(0);
    assertThat(extractor.read(input, null)).isNotEqualTo(Extractor.RESULT_END_OF_INPUT);
    extractor.seek((int) output.seekMap.getSeekPoints(2_345_000L).first.position, 2_345_000L);
    input.setPosition((int) output.seekMap.getSeekPoints(2_345_000L).first.position);
    trackOutput.clear();
    while (extractor.read(input, null) != Extractor.RESULT_END_OF_INPUT) {
    }
    assertThat(trackOutput.lastFormat.sampleMimeType).isEqualTo(MimeTypes.TEXT_EXOPLAYER_CUES);
    assertThat(trackOutput.lastFormat.codecs).isEqualTo(MimeTypes.TEXT_VTT);
    assertThat(trackOutput.getSampleCount()).isEqualTo(4);
    // Check sample timestamps.
    assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(2_345_000L);
    assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(2_600_000L);
    assertThat(trackOutput.getSampleTimeUs(2)).isEqualTo(3_456_000L);
    assertThat(trackOutput.getSampleTimeUs(3)).isEqualTo(4_567_000L);
    // Check sample content.
    List<Cue> cues0 = decoder.decode(trackOutput.getSampleData(0));
    assertThat(cues0).hasSize(1);
    assertThat(cues0.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    List<Cue> cues1 = decoder.decode(trackOutput.getSampleData(1));
    assertThat(cues1).hasSize(2);
    assertThat(cues1.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    assertThat(cues1.get(1).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues2 = decoder.decode(trackOutput.getSampleData(2));
    assertThat(cues2).hasSize(1);
    assertThat(cues2.get(0).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues3 = decoder.decode(trackOutput.getSampleData(3));
    assertThat(cues3).isEmpty();
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Format(com.google.android.exoplayer2.Format) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 69 with FakeTrackOutput

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

the class SubtitleExtractorTest method extractor_seekAfterExtracting_outputsCues.

@Test
public void extractor_seekAfterExtracting_outputsCues() throws Exception {
    CueDecoder decoder = new CueDecoder();
    FakeExtractorOutput output = new FakeExtractorOutput();
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(Util.getUtf8Bytes(TEST_DATA)).setSimulatePartialReads(true).build();
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).build());
    extractor.init(output);
    FakeTrackOutput trackOutput = output.trackOutputs.get(0);
    while (extractor.read(input, null) != Extractor.RESULT_END_OF_INPUT) {
    }
    extractor.seek((int) output.seekMap.getSeekPoints(2_445_000L).first.position, 2_445_000L);
    input.setPosition((int) output.seekMap.getSeekPoints(2_445_000L).first.position);
    trackOutput.clear();
    while (extractor.read(input, null) != Extractor.RESULT_END_OF_INPUT) {
    }
    assertThat(trackOutput.lastFormat.sampleMimeType).isEqualTo(MimeTypes.TEXT_EXOPLAYER_CUES);
    assertThat(trackOutput.lastFormat.codecs).isEqualTo(MimeTypes.TEXT_VTT);
    assertThat(trackOutput.getSampleCount()).isEqualTo(4);
    // Check sample timestamps.
    assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(2_345_000L);
    assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(2_600_000L);
    assertThat(trackOutput.getSampleTimeUs(2)).isEqualTo(3_456_000L);
    assertThat(trackOutput.getSampleTimeUs(3)).isEqualTo(4_567_000L);
    // Check sample content.
    List<Cue> cues0 = decoder.decode(trackOutput.getSampleData(0));
    assertThat(cues0).hasSize(1);
    assertThat(cues0.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    List<Cue> cues1 = decoder.decode(trackOutput.getSampleData(1));
    assertThat(cues1).hasSize(2);
    assertThat(cues1.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    assertThat(cues1.get(1).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues2 = decoder.decode(trackOutput.getSampleData(2));
    assertThat(cues2).hasSize(1);
    assertThat(cues2.get(0).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues3 = decoder.decode(trackOutput.getSampleData(3));
    assertThat(cues3).isEmpty();
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Format(com.google.android.exoplayer2.Format) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 70 with FakeTrackOutput

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

the class SubtitleExtractorTest method extractor_outputsCues.

@Test
public void extractor_outputsCues() throws Exception {
    CueDecoder decoder = new CueDecoder();
    FakeExtractorOutput output = new FakeExtractorOutput();
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(Util.getUtf8Bytes(TEST_DATA)).setSimulatePartialReads(true).build();
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).build());
    extractor.init(output);
    while (extractor.read(input, null) != Extractor.RESULT_END_OF_INPUT) {
    }
    FakeTrackOutput trackOutput = output.trackOutputs.get(0);
    assertThat(trackOutput.lastFormat.sampleMimeType).isEqualTo(MimeTypes.TEXT_EXOPLAYER_CUES);
    assertThat(trackOutput.lastFormat.codecs).isEqualTo(MimeTypes.TEXT_VTT);
    assertThat(trackOutput.getSampleCount()).isEqualTo(6);
    // Check sample timestamps.
    assertThat(trackOutput.getSampleTimeUs(0)).isEqualTo(0L);
    assertThat(trackOutput.getSampleTimeUs(1)).isEqualTo(1_234_000L);
    assertThat(trackOutput.getSampleTimeUs(2)).isEqualTo(2_345_000L);
    assertThat(trackOutput.getSampleTimeUs(3)).isEqualTo(2_600_000L);
    assertThat(trackOutput.getSampleTimeUs(4)).isEqualTo(3_456_000L);
    assertThat(trackOutput.getSampleTimeUs(5)).isEqualTo(4_567_000L);
    // Check sample content.
    List<Cue> cues0 = decoder.decode(trackOutput.getSampleData(0));
    assertThat(cues0).hasSize(1);
    assertThat(cues0.get(0).text.toString()).isEqualTo("This is the first subtitle.");
    List<Cue> cues1 = decoder.decode(trackOutput.getSampleData(1));
    assertThat(cues1).isEmpty();
    List<Cue> cues2 = decoder.decode(trackOutput.getSampleData(2));
    assertThat(cues2).hasSize(1);
    assertThat(cues2.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    List<Cue> cues3 = decoder.decode(trackOutput.getSampleData(3));
    assertThat(cues3).hasSize(2);
    assertThat(cues3.get(0).text.toString()).isEqualTo("This is the second subtitle.");
    assertThat(cues3.get(1).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues4 = decoder.decode(trackOutput.getSampleData(4));
    assertThat(cues4).hasSize(1);
    assertThat(cues4.get(0).text.toString()).isEqualTo("This is the third subtitle.");
    List<Cue> cues5 = decoder.decode(trackOutput.getSampleData(5));
    assertThat(cues5).isEmpty();
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) Format(com.google.android.exoplayer2.Format) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

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