Search in sources :

Example 1 with TrackOutput

use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.

the class SingleSampleMediaChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException {
    BaseMediaChunkOutput output = getOutput();
    output.setSampleOffsetUs(0);
    TrackOutput trackOutput = output.track(0, trackType);
    trackOutput.format(sampleFormat);
    try {
        // Create and open the input.
        DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
        long length = dataSource.open(loadDataSpec);
        if (length != C.LENGTH_UNSET) {
            length += nextLoadPosition;
        }
        ExtractorInput extractorInput = new DefaultExtractorInput(dataSource, nextLoadPosition, length);
        // Load the sample data.
        int result = 0;
        while (result != C.RESULT_END_OF_INPUT) {
            nextLoadPosition += result;
            result = trackOutput.sampleData(extractorInput, Integer.MAX_VALUE, true);
        }
        int sampleSize = (int) nextLoadPosition;
        trackOutput.sampleMetadata(startTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
    } finally {
        DataSourceUtil.closeQuietly(dataSource);
    }
    loadCompleted = true;
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 2 with TrackOutput

use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.

the class OutputConsumerAdapterV30 method onSampleDataFound.

@Override
public void onSampleDataFound(int trackIndex, MediaParser.InputReader sampleData) throws IOException {
    ensureSpaceForTrackIndex(trackIndex);
    scratchDataReaderAdapter.input = sampleData;
    TrackOutput trackOutput = trackOutputs.get(trackIndex);
    if (trackOutput == null) {
        trackOutput = extractorOutput.track(trackIndex, C.TRACK_TYPE_UNKNOWN);
        trackOutputs.set(trackIndex, trackOutput);
    }
    trackOutput.sampleData(scratchDataReaderAdapter, (int) sampleData.getLength(), /* allowEndOfInput= */
    true);
}
Also used : TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 3 with TrackOutput

use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.

the class DvbSubtitleReader method consume.

@Override
public void consume(ParsableByteArray data) {
    if (writingSample) {
        if (bytesToCheck == 2 && !checkNextByte(data, 0x20)) {
            // Failed to check data_identifier
            return;
        }
        if (bytesToCheck == 1 && !checkNextByte(data, 0x00)) {
            // Check and discard the subtitle_stream_id
            return;
        }
        int dataPosition = data.getPosition();
        int bytesAvailable = data.bytesLeft();
        for (TrackOutput output : outputs) {
            data.setPosition(dataPosition);
            output.sampleData(data, bytesAvailable);
        }
        sampleBytesWritten += bytesAvailable;
    }
}
Also used : TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 4 with TrackOutput

use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.

the class DvbSubtitleReader method createTracks.

@Override
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
    for (int i = 0; i < outputs.length; i++) {
        DvbSubtitleInfo subtitleInfo = subtitleInfos.get(i);
        idGenerator.generateNewId();
        TrackOutput output = extractorOutput.track(idGenerator.getTrackId(), C.TRACK_TYPE_TEXT);
        output.format(new Format.Builder().setId(idGenerator.getFormatId()).setSampleMimeType(MimeTypes.APPLICATION_DVBSUBS).setInitializationData(Collections.singletonList(subtitleInfo.initializationData)).setLanguage(subtitleInfo.language).build());
        outputs[i] = output;
    }
}
Also used : DvbSubtitleInfo(com.google.android.exoplayer2.extractor.ts.TsPayloadReader.DvbSubtitleInfo) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput)

Example 5 with TrackOutput

use of androidx.media3.extractor.TrackOutput in project ExoPlayer by google.

the class SeiReader method createTracks.

public void createTracks(ExtractorOutput extractorOutput, 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);
        String formatId = channelFormat.id != null ? channelFormat.id : idGenerator.getFormatId();
        output.format(new Format.Builder().setId(formatId).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)

Aggregations

FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)70 Test (org.junit.Test)61 SeekMap (androidx.media3.extractor.SeekMap)60 Uri (android.net.Uri)50 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)38 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)31 TrackOutput (androidx.media3.extractor.TrackOutput)19 Nullable (androidx.annotation.Nullable)13 Format (androidx.media3.common.Format)11 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)11 Format (com.google.android.exoplayer2.Format)8 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)5 ParserException (com.google.android.exoplayer2.ParserException)5 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)5 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)4 SeekPoint (androidx.media3.extractor.SeekPoint)4 Metadata (androidx.media3.common.Metadata)3 Cue (androidx.media3.common.text.Cue)3 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)3 ExtractorInput (androidx.media3.extractor.ExtractorInput)3