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);
}
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");
}
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();
}
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);
}
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);
}
Aggregations