Search in sources :

Example 91 with Extractor

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);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 92 with Extractor

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();
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 93 with Extractor

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();
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 94 with Extractor

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);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 95 with Extractor

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);
}
Also used : Context(android.content.Context) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Aggregations

Test (org.junit.Test)87 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)74 Uri (android.net.Uri)66 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)59 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)44 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)14 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)12 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)11 Extractor (com.google.android.exoplayer2.extractor.Extractor)11 Nullable (androidx.annotation.Nullable)9 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)9 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)8 WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)8 Format (com.google.android.exoplayer2.Format)7 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)7 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)7 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)7 TsExtractor (com.google.android.exoplayer2.extractor.ts.TsExtractor)7 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)5 MatroskaExtractor (com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)5