Search in sources :

Example 1 with SubtitleExtractor

use of com.google.android.exoplayer2.text.SubtitleExtractor in project ExoPlayer by google.

the class SubtitleExtractorTest method read_afterRelease_fails.

@Test
public void read_afterRelease_fails() {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(new byte[0]).build();
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().build());
    FakeExtractorOutput output = new FakeExtractorOutput();
    extractor.init(output);
    extractor.release();
    assertThrows(IllegalStateException.class, () -> extractor.read(input, null));
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 2 with SubtitleExtractor

use of com.google.android.exoplayer2.text.SubtitleExtractor in project ExoPlayer by google.

the class SubtitleExtractorTest method read_withoutInit_fails.

@Test
public void read_withoutInit_fails() {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(new byte[0]).build();
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().build());
    assertThrows(IllegalStateException.class, () -> extractor.read(input, null));
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) Test(org.junit.Test)

Example 3 with SubtitleExtractor

use of com.google.android.exoplayer2.text.SubtitleExtractor 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 4 with SubtitleExtractor

use of com.google.android.exoplayer2.text.SubtitleExtractor in project ExoPlayer by google.

the class SubtitleExtractorTest method seek_withoutInit_fails.

@Test
public void seek_withoutInit_fails() {
    SubtitleExtractor extractor = new SubtitleExtractor(new WebvttDecoder(), new Format.Builder().build());
    assertThrows(IllegalStateException.class, () -> extractor.seek(0, 0));
}
Also used : WebvttDecoder(com.google.android.exoplayer2.text.webvtt.WebvttDecoder) Test(org.junit.Test)

Example 5 with SubtitleExtractor

use of com.google.android.exoplayer2.text.SubtitleExtractor 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)

Aggregations

WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)8 Test (org.junit.Test)8 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)6 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)5 Format (com.google.android.exoplayer2.Format)4 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)3 Nullable (androidx.annotation.Nullable)1 MediaItem (com.google.android.exoplayer2.MediaItem)1 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)1 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)1 SubtitleExtractor (com.google.android.exoplayer2.text.SubtitleExtractor)1