use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class AmrExtractorSeekTest method seeking_handlesSeekToEoF_extractsLastFrame_forNarrowBandAmr.
@Test
public void seeking_handlesSeekToEoF_extractsLastFrame_forNarrowBandAmr() throws IOException {
String fileName = NARROW_BAND_AMR_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AmrExtractor extractor = createAmrExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = seekMap.getDurationUs();
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class AmrExtractorSeekTest method seeking_handlesSeekToEoF_extractsLastFrame_forWideBandAmr.
@Test
public void seeking_handlesSeekToEoF_extractsLastFrame_forWideBandAmr() throws IOException {
String fileName = WIDE_BAND_AMR_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AmrExtractor extractor = createAmrExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = seekMap.getDurationUs();
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class AmrExtractorSeekTest method seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forNarrowBandAmr.
@Test
public void seeking_handlesSeekingToPositionInFile_extractsCorrectFrame_forNarrowBandAmr() throws IOException {
String fileName = NARROW_BAND_AMR_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AmrExtractor extractor = createAmrExtractor();
FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
long targetSeekTimeUs = 980_000;
int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class AmrExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectFrames_forNarrowBandAmr.
@Test
public void seeking_handlesSeekingBackward_extractsCorrectFrames_forNarrowBandAmr() throws IOException {
String fileName = NARROW_BAND_AMR_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AmrExtractor extractor = createAmrExtractor();
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 extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
assertThat(extractedFrameIndex).isNotEqualTo(-1);
assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.
the class TestUtil method extractAllSamplesFromFile.
/**
* Extracts all samples from the given file into a {@link FakeTrackOutput}.
*
* @param extractor The {@link Extractor} to extractor from input.
* @param context A {@link Context}.
* @param fileName The name of the input file.
* @return The {@link FakeTrackOutput} containing the extracted samples.
* @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 FakeExtractorOutput extractAllSamplesFromFile(Extractor extractor, Context context, String fileName) throws IOException {
byte[] data = TestUtil.getByteArray(context, fileName);
FakeExtractorOutput expectedOutput = new FakeExtractorOutput();
extractor.init(expectedOutput);
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
PositionHolder positionHolder = new PositionHolder();
int readResult = Extractor.RESULT_CONTINUE;
while (readResult != Extractor.RESULT_END_OF_INPUT) {
while (readResult == Extractor.RESULT_CONTINUE) {
readResult = extractor.read(input, positionHolder);
}
if (readResult == Extractor.RESULT_SEEK) {
input.setPosition((int) positionHolder.position);
readResult = Extractor.RESULT_CONTINUE;
}
}
return expectedOutput;
}
Aggregations