use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame.
@Test
public void handlePendingSeek_handlesRandomSeeks_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 numSeek = 100;
for (long i = 0; i < numSeek; i++) {
long targetSeekTimeUs = random.nextInt(DURATION_US + 1);
int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainsTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame.
@Test
public void handlePendingSeek_handlesSeekingToPositionInFile_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 targetSeekTimeUs = 987_000;
int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainsTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class PsExtractorSeekTest method seekToTimeUs.
/**
* Seeks to the given seek time and keeps reading from input until we can extract at least one
* frame from the seek position, or until end-of-input is reached.
*
* @return The index of the first extracted frame written to the given {@code trackOutput} after
* the seek is completed, or -1 if the seek is completed without any extracted frame.
*/
private int seekToTimeUs(PsExtractor psExtractor, SeekMap seekMap, long seekTimeUs, FakeTrackOutput trackOutput) throws IOException {
int numSampleBeforeSeek = trackOutput.getSampleCount();
SeekMap.SeekPoints seekPoints = seekMap.getSeekPoints(seekTimeUs);
long initialSeekLoadPosition = seekPoints.first.position;
psExtractor.seek(initialSeekLoadPosition, seekTimeUs);
positionHolder.position = C.POSITION_UNSET;
ExtractorInput extractorInput = getExtractorInputFromPosition(initialSeekLoadPosition);
int extractorReadResult = Extractor.RESULT_CONTINUE;
while (true) {
try {
// Keep reading until we can read at least one frame after seek
while (extractorReadResult == Extractor.RESULT_CONTINUE && trackOutput.getSampleCount() == numSampleBeforeSeek) {
extractorReadResult = psExtractor.read(extractorInput, positionHolder);
}
} finally {
DataSourceUtil.closeQuietly(dataSource);
}
if (extractorReadResult == Extractor.RESULT_SEEK) {
extractorInput = getExtractorInputFromPosition(positionHolder.position);
extractorReadResult = Extractor.RESULT_CONTINUE;
} else if (extractorReadResult == Extractor.RESULT_END_OF_INPUT) {
return -1;
} else if (trackOutput.getSampleCount() > numSampleBeforeSeek) {
// First index after seek = num sample before seek.
return numSampleBeforeSeek;
}
}
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class AdtsExtractorSeekTest method seeking_handlesSeekingForward_extractsCorrectSamples.
@Test
public void seeking_handlesSeekingForward_extractsCorrectSamples() throws IOException {
String fileName = TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AdtsExtractor extractor = createAdtsExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long firstSeekTimeUs = 980_000;
TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
long targetSeekTimeUs = 1_200_000;
int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedSampleIndex).isNotEqualTo(-1);
assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class AdtsExtractorSeekTest method seeking_handlesRandomSeeks_extractsCorrectSamples.
@Test
public void seeking_handlesRandomSeeks_extractsCorrectSamples() throws IOException {
String fileName = TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AdtsExtractor extractor = createAdtsExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long numSeek = 100;
for (long i = 0; i < numSeek; i++) {
long targetSeekTimeUs = random.nextInt(FILE_DURATION_US + 1);
int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedSampleIndex).isNotEqualTo(-1);
assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
}
Aggregations