use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class AdtsExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectSamples.
@Test
public void seeking_handlesSeekingBackward_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 = 0;
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 ConstantBitrateSeekerTest method assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame.
private static void assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(String fileName, FakeTrackOutput trackOutput, long targetSeekTimeUs, int firstFrameIndexAfterSeek) throws IOException {
FakeTrackOutput expectedTrackOutput = getExpectedTrackOutput(fileName);
int exactFrameIndex = getFrameIndex(expectedTrackOutput, targetSeekTimeUs);
boolean foundPreviousFrame = exactFrameIndex != 0 && Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex - 1));
boolean foundExactFrame = Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex));
boolean foundNextFrame = exactFrameIndex != expectedTrackOutput.getSampleCount() - 1 && Arrays.equals(trackOutput.getSampleData(firstFrameIndexAfterSeek), expectedTrackOutput.getSampleData(exactFrameIndex + 1));
assertThat(foundPreviousFrame || foundExactFrame || foundNextFrame).isTrue();
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput in project ExoPlayer by google.
the class ConstantBitrateSeekerTest method seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame.
@Test
public void seeking_variableFrameSize_seeksNearlyExactlyToCorrectFrame() throws IOException {
String fileName = VARIABLE_FRAME_SIZE_TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 1_234_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
assertFirstFrameAfterSeekIsWithin1FrameOfExactFrame(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeTrackOutput 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.FakeTrackOutput 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);
}
Aggregations