use of com.google.android.exoplayer2.extractor.Extractor 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.extractor.Extractor in project ExoPlayer by google.
the class AdtsExtractorSeekTest method adtsExtractorReads_returnSeekableSeekMap.
@Test
public void adtsExtractorReads_returnSeekableSeekMap() throws IOException {
String fileName = TEST_FILE;
Uri fileUri = TestUtil.buildAssetUri(fileName);
expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
AdtsExtractor extractor = createAdtsExtractor();
SeekMap seekMap = TestUtil.extractSeekMap(extractor, new FakeExtractorOutput(), dataSource, fileUri);
assertThat(seekMap).isNotNull();
assertThat(seekMap.getDurationUs()).isEqualTo(FILE_DURATION_US);
assertThat(seekMap.isSeekable()).isTrue();
}
use of com.google.android.exoplayer2.extractor.Extractor in project ExoPlayer by google.
the class ConstantBitrateSeekerTest method mp3ExtractorReads_returnSeekableCbrSeeker.
@Test
public void mp3ExtractorReads_returnSeekableCbrSeeker() throws IOException {
Uri fileUri = TestUtil.buildAssetUri(CONSTANT_FRAME_SIZE_TEST_FILE);
SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
assertThat(seekMap.getClass()).isEqualTo(ConstantBitrateSeeker.class);
assertThat(seekMap.getDurationUs()).isEqualTo(2_784_000);
assertThat(seekMap.isSeekable()).isTrue();
}
use of com.google.android.exoplayer2.extractor.Extractor 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.extractor.Extractor in project ExoPlayer by google.
the class ExtractorAsserts method assertAllBehaviors.
/**
* Asserts that an extractor behaves correctly given valid input data:
*
* <ul>
* <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
* {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
* <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
* boolean, boolean)} with all possible combinations of "simulate" parameters.
* </ul>
*
* @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
* class which is to be tested.
* @param file The path to the input sample.
* @param dumpFilesPrefix The dump files prefix appended to the dump files path.
* @throws IOException If reading from the input fails.
*/
public static void assertAllBehaviors(ExtractorFactory factory, String file, String dumpFilesPrefix) throws IOException {
// Check behavior prior to initialization.
Extractor extractor = factory.create();
extractor.seek(0, 0);
extractor.release();
// Assert output.
Context context = ApplicationProvider.getApplicationContext();
byte[] fileData = TestUtil.getByteArray(context, file);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, false, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, false, true, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, false, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, false);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, true, true, true, true);
assertOutput(factory.create(), dumpFilesPrefix, fileData, context, false, false, false, false, false);
}
Aggregations