Search in sources :

Example 1 with FakeExtractorInput

use of androidx.media3.test.utils.FakeExtractorInput in project media by androidx.

the class AmrExtractorNonParameterizedTest method read_amrWb_returnEndOfInput_ifInputEncountersEoF.

@Test
public void read_amrWb_returnEndOfInput_ifInputEncountersEoF() throws IOException {
    AmrExtractor amrExtractor = setupAmrExtractorWithOutput();
    byte[] amrFrame = newWideBandAmrFrameWithType(5);
    byte[] data = joinData(amrSignatureWb(), amrFrame);
    FakeExtractorInput input = fakeExtractorInputWithData(data);
    // Read 1st frame, which will put the input at EoF.
    amrExtractor.read(input, new PositionHolder());
    int result = amrExtractor.read(input, new PositionHolder());
    assertThat(result).isEqualTo(Extractor.RESULT_END_OF_INPUT);
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) PositionHolder(androidx.media3.extractor.PositionHolder) Test(org.junit.Test)

Example 2 with FakeExtractorInput

use of androidx.media3.test.utils.FakeExtractorInput in project media by androidx.

the class Id3PeekerTest method peekId3Data_returnId3TagAccordingToGivenPredicate_ifId3TagPresent.

@Test
public void peekId3Data_returnId3TagAccordingToGivenPredicate_ifId3TagPresent() throws IOException {
    Id3Peeker id3Peeker = new Id3Peeker();
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(getByteArray(ApplicationProvider.getApplicationContext(), "media/id3/comm_apic.id3")).build();
    @Nullable Metadata metadata = id3Peeker.peekId3Data(input, (majorVersion, id0, id1, id2, id3) -> id0 == 'C' && id1 == 'O' && id2 == 'M' && id3 == 'M');
    assertThat(metadata).isNotNull();
    assertThat(metadata.length()).isEqualTo(1);
    CommentFrame commentFrame = (CommentFrame) metadata.get(0);
    assertThat(commentFrame.language).isEqualTo("eng");
    assertThat(commentFrame.description).isEqualTo("description");
    assertThat(commentFrame.text).isEqualTo("text");
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) Metadata(androidx.media3.common.Metadata) CommentFrame(androidx.media3.extractor.metadata.id3.CommentFrame) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 3 with FakeExtractorInput

use of androidx.media3.test.utils.FakeExtractorInput in project media by androidx.

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(androidx.media3.test.utils.FakeExtractorInput) Cue(androidx.media3.common.text.Cue) Format(androidx.media3.common.Format) FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) WebvttDecoder(androidx.media3.extractor.text.webvtt.WebvttDecoder) FakeExtractorOutput(androidx.media3.test.utils.FakeExtractorOutput) Test(org.junit.Test)

Example 4 with FakeExtractorInput

use of androidx.media3.test.utils.FakeExtractorInput in project media by androidx.

the class PsDurationReaderTest method readDuration_returnsCorrectDuration.

@Test
public void readDuration_returnsCorrectDuration() throws IOException {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "media/ts/sample_h262_mpeg_audio.ps")).build();
    int result = Extractor.RESULT_CONTINUE;
    while (!tsDurationReader.isDurationReadFinished()) {
        result = tsDurationReader.readDuration(input, seekPositionHolder);
        if (result == Extractor.RESULT_SEEK) {
            input.setPosition((int) seekPositionHolder.position);
        }
    }
    assertThat(result).isNotEqualTo(Extractor.RESULT_END_OF_INPUT);
    assertThat(tsDurationReader.getDurationUs()).isEqualTo(766);
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) Test(org.junit.Test)

Example 5 with FakeExtractorInput

use of androidx.media3.test.utils.FakeExtractorInput in project media by androidx.

the class DefaultOggSeekerTest method readGranuleOfLastPage.

@Test
public void readGranuleOfLastPage() throws IOException {
    // This test stream has three headers with granule numbers 20000, 40000 and 60000.
    byte[] data = getByteArray(ApplicationProvider.getApplicationContext(), "media/ogg/three_headers");
    FakeExtractorInput input = createInput(data, /* simulateUnknownLength= */
    false);
    assertReadGranuleOfLastPage(input, 60000);
}
Also used : FakeExtractorInput(androidx.media3.test.utils.FakeExtractorInput) Test(org.junit.Test)

Aggregations

FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)43 Test (org.junit.Test)41 PositionHolder (androidx.media3.extractor.PositionHolder)12 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)7 ParserException (androidx.media3.common.ParserException)5 WebvttDecoder (androidx.media3.extractor.text.webvtt.WebvttDecoder)5 Format (androidx.media3.common.Format)4 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)4 Nullable (androidx.annotation.Nullable)3 Metadata (androidx.media3.common.Metadata)3 Cue (androidx.media3.common.text.Cue)3 TimestampAdjuster (androidx.media3.common.util.TimestampAdjuster)2 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)1 SeekMap (androidx.media3.extractor.SeekMap)1 TrackOutput (androidx.media3.extractor.TrackOutput)1 ApicFrame (androidx.media3.extractor.metadata.id3.ApicFrame)1 CommentFrame (androidx.media3.extractor.metadata.id3.CommentFrame)1 SimulatedIOException (androidx.media3.test.utils.FakeExtractorInput.SimulatedIOException)1 EOFException (java.io.EOFException)1