use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class TestUtil method extractSeekMap.
/**
* Reads from the given input using the given {@link Extractor}, until it can produce the {@link
* SeekMap} and all of the track formats have been identified, or until the extractor encounters
* EOF.
*
* @param extractor The {@link Extractor} to extractor from input.
* @param output The {@link FakeTrackOutput} to store the extracted {@link SeekMap} and track.
* @param dataSource The {@link DataSource} that will be used to read from the input.
* @param uri The Uri of the input.
* @return The extracted {@link SeekMap}.
* @throws IOException If an error occurred reading from the input, or if the extractor finishes
* reading from input without extracting any {@link SeekMap}.
*/
public static SeekMap extractSeekMap(Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri) throws IOException {
ExtractorInput input = getExtractorInputFromPosition(dataSource, /* position= */
0, uri);
extractor.init(output);
PositionHolder positionHolder = new PositionHolder();
int readResult = Extractor.RESULT_CONTINUE;
while (true) {
try {
// Keep reading until we get the seek map and the track information.
while (readResult == Extractor.RESULT_CONTINUE && (output.seekMap == null || !output.tracksEnded)) {
readResult = extractor.read(input, positionHolder);
}
for (int i = 0; i < output.trackOutputs.size(); i++) {
int trackId = output.trackOutputs.keyAt(i);
while (readResult == Extractor.RESULT_CONTINUE && output.trackOutputs.get(trackId).lastFormat == null) {
readResult = extractor.read(input, positionHolder);
}
}
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
if (readResult == Extractor.RESULT_SEEK) {
input = getExtractorInputFromPosition(dataSource, positionHolder.position, uri);
readResult = Extractor.RESULT_CONTINUE;
} else if (readResult == Extractor.RESULT_END_OF_INPUT) {
throw new IOException("EOF encountered without seekmap");
}
if (output.seekMap != null) {
return output.seekMap;
}
}
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame.
@Test
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
PsExtractor extractor = new PsExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = extractSeekMapAndTracks(extractor, extractorOutput);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
long firstSeekTimeUs = 987_000;
seekToTimeUs(extractor, seekMap, firstSeekTimeUs, trackOutput);
long targetSeekTimeUs = 0;
int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainsTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method readInputFileOnce.
private void readInputFileOnce(PsExtractor extractor, FakeExtractorOutput extractorOutput) throws IOException {
extractor.init(extractorOutput);
int readResult = Extractor.RESULT_CONTINUE;
ExtractorInput input = getExtractorInputFromPosition(0);
while (readResult != Extractor.RESULT_END_OF_INPUT) {
try {
while (readResult == Extractor.RESULT_CONTINUE) {
readResult = extractor.read(input, positionHolder);
}
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
if (readResult == Extractor.RESULT_SEEK) {
input = getExtractorInputFromPosition(positionHolder.position);
readResult = Extractor.RESULT_CONTINUE;
}
}
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method psExtractorReads_nonSeekTableFile_returnSeekableSeekMap.
@Test
public void psExtractorReads_nonSeekTableFile_returnSeekableSeekMap() throws IOException {
PsExtractor extractor = new PsExtractor();
SeekMap seekMap = extractSeekMapAndTracks(extractor, new FakeExtractorOutput());
assertThat(seekMap).isNotNull();
assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
assertThat(seekMap.isSeekable()).isTrue();
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method handlePendingSeek_handlesSeekToEoF.
@Test
public void handlePendingSeek_handlesSeekToEoF() throws IOException, InterruptedException {
PsExtractor extractor = new PsExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = extractSeekMapAndTracks(extractor, extractorOutput);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
long targetSeekTimeUs = seekMap.getDurationUs();
int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
// Assert that this seek will return a position at end of stream, without any frame.
assertThat(extractedFrameIndex).isEqualTo(-1);
}
Aggregations