Search in sources :

Example 71 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class AdtsExtractor method init.

@Override
public void init(ExtractorOutput output) {
    this.extractorOutput = output;
    reader.createTracks(output, new TrackIdGenerator(0, 1));
    output.endTracks();
}
Also used : TrackIdGenerator(com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)

Example 72 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class UserDataReader method createTracks.

public void createTracks(ExtractorOutput extractorOutput, TsPayloadReader.TrackIdGenerator idGenerator) {
    for (int i = 0; i < outputs.length; i++) {
        idGenerator.generateNewId();
        TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
        Format channelFormat = closedCaptionFormats.get(i);
        @Nullable String channelMimeType = channelFormat.sampleMimeType;
        Assertions.checkArgument(MimeTypes.APPLICATION_CEA608.equals(channelMimeType) || MimeTypes.APPLICATION_CEA708.equals(channelMimeType), "Invalid closed caption mime type provided: " + channelMimeType);
        output.format(new Format.Builder().setId(idGenerator.getFormatId()).setSampleMimeType(channelMimeType).setSelectionFlags(channelFormat.selectionFlags).setLanguage(channelFormat.language).setAccessibilityChannel(channelFormat.accessibilityChannel).setInitializationData(channelFormat.initializationData).build());
        outputs[i] = output;
    }
}
Also used : Format(com.google.android.exoplayer2.Format) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) Nullable(androidx.annotation.Nullable)

Example 73 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class ExtractorAsserts method assertOutput.

/**
 * Asserts that an extractor consumes valid input data successfully under the specified
 * conditions.
 *
 * @param extractor The {@link Extractor} to be tested.
 * @param dumpFilesPrefix The dump files prefix prepended to the dump files path.
 * @param data Content of the input file.
 * @param context To be used to load the sample file.
 * @param sniffFirst Whether to sniff the data by calling {@link Extractor#sniff(ExtractorInput)}
 *     prior to consuming it.
 * @param simulateIOErrors Whether to simulate IO errors.
 * @param simulateUnknownLength Whether to simulate unknown input length.
 * @param simulatePartialReads Whether to simulate partial reads.
 * @throws IOException If reading from the input fails.
 */
private static void assertOutput(Extractor extractor, String dumpFilesPrefix, byte[] data, Context context, boolean deduplicateConsecutiveFormats, boolean sniffFirst, boolean simulateIOErrors, boolean simulateUnknownLength, boolean simulatePartialReads) throws IOException {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(simulateIOErrors).setSimulateUnknownLength(simulateUnknownLength).setSimulatePartialReads(simulatePartialReads).build();
    if (sniffFirst) {
        assertSniff(extractor, input, /* expectedResult= */
        true);
        input.resetPeekPosition();
    }
    FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true, deduplicateConsecutiveFormats);
    if (simulateUnknownLength) {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
    } else {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
    }
    // Seeking to (timeUs=0, position=0) should always work, and cause the same data to be output.
    extractorOutput.clearTrackOutputs();
    input.reset();
    consumeTestData(extractor, input, /* timeUs= */
    0, extractorOutput, false);
    if (simulateUnknownLength) {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
    } else {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
    }
    SeekMap seekMap = Assertions.checkNotNull(extractorOutput.seekMap);
    long durationUs = seekMap.getDurationUs();
    // Only seek to the timeUs=0 if the SeekMap is unseekable or the duration is unknown.
    int numberSeekTests = seekMap.isSeekable() && durationUs != C.TIME_UNSET ? 4 : 1;
    for (int j = 0; j < numberSeekTests; j++) {
        long timeUs = durationUs * j / 3;
        long position = seekMap.getSeekPoints(timeUs).first.position;
        if (timeUs == 0 && position == 0) {
            // Already tested.
            continue;
        }
        input.reset();
        input.setPosition((int) position);
        extractorOutput.clearTrackOutputs();
        consumeTestData(extractor, input, timeUs, extractorOutput, false);
        if (simulateUnknownLength && timeUs == 0) {
            DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
        } else {
            DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + '.' + j + DUMP_EXTENSION);
        }
    }
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

Example 74 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput 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)

Example 75 with ExtractorOutput

use of com.google.android.exoplayer2.extractor.ExtractorOutput in project ExoPlayer by google.

the class AmrExtractorSeekTest method seeking_handlesRandomSeeks_extractsCorrectFrames_forWideBandAmr.

@Test
public void seeking_handlesRandomSeeks_extractsCorrectFrames_forWideBandAmr() throws IOException, InterruptedException {
    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 numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(NARROW_BAND_FILE_DURATION_US + 1);
        int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
        assertThat(extractedFrameIndex).isNotEqualTo(-1);
        assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
    }
}
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)

Aggregations

SeekMap (com.google.android.exoplayer2.extractor.SeekMap)79 Test (org.junit.Test)66 Uri (android.net.Uri)59 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)57 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)31 Nullable (androidx.annotation.Nullable)12 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)9 Format (com.google.android.exoplayer2.Format)6 TrackIdGenerator (com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)6 Metadata (com.google.android.exoplayer2.metadata.Metadata)6 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)5 Extractor (com.google.android.exoplayer2.extractor.Extractor)4 OutputFrameHolder (com.google.android.exoplayer2.ext.flac.FlacBinarySearchSeeker.OutputFrameHolder)3 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)3 ExtractorOutput (com.google.android.exoplayer2.extractor.ExtractorOutput)3 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)3 Before (org.junit.Before)3 CallSuper (androidx.annotation.CallSuper)2 Format (androidx.media3.common.Format)2 Metadata (androidx.media3.common.Metadata)2