Search in sources :

Example 26 with DefaultExtractorInput

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

the class PsExtractorSeekTest method getExtractorInputFromPosition.

private ExtractorInput getExtractorInputFromPosition(long position) throws IOException {
    DataSpec dataSpec = new DataSpec(Uri.parse("asset:///" + PS_FILE_PATH), position, C.LENGTH_UNSET);
    dataSource.open(dataSpec);
    return new DefaultExtractorInput(dataSource, position, totalInputLength);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput)

Example 27 with DefaultExtractorInput

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

the class TestUtil method getExtractorInputFromPosition.

/**
 * Returns an {@link ExtractorInput} to read from the given input at given position.
 */
public static ExtractorInput getExtractorInputFromPosition(DataSource dataSource, long position, Uri uri) throws IOException {
    DataSpec dataSpec = new DataSpec(uri, position, C.LENGTH_UNSET);
    long length = dataSource.open(dataSpec);
    if (length != C.LENGTH_UNSET) {
        length += position;
    }
    return new DefaultExtractorInput(dataSource, position, length);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput)

Example 28 with DefaultExtractorInput

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

the class ContainerMediaChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException {
    if (nextLoadPosition == 0) {
        // Configure the output and set it as the target for the extractor wrapper.
        BaseMediaChunkOutput output = getOutput();
        output.setSampleOffsetUs(sampleOffsetUs);
        chunkExtractor.init(getTrackOutputProvider(output), clippedStartTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedStartTimeUs - sampleOffsetUs), clippedEndTimeUs == C.TIME_UNSET ? C.TIME_UNSET : (clippedEndTimeUs - sampleOffsetUs));
    }
    try {
        // Create and open the input.
        DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.position, dataSource.open(loadDataSpec));
        // Load and decode the sample data.
        try {
            while (!loadCanceled && chunkExtractor.read(input)) {
            }
        } finally {
            nextLoadPosition = input.getPosition() - dataSpec.position;
        }
    } finally {
        DataSourceUtil.closeQuietly(dataSource);
    }
    loadCompleted = !loadCanceled;
}
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)

Example 29 with DefaultExtractorInput

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

the class InitializationChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException {
    if (nextLoadPosition == 0) {
        chunkExtractor.init(trackOutputProvider, /* startTimeUs= */
        C.TIME_UNSET, /* endTimeUs= */
        C.TIME_UNSET);
    }
    try {
        // Create and open the input.
        DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.position, dataSource.open(loadDataSpec));
        // Load and decode the initialization data.
        try {
            while (!loadCanceled && chunkExtractor.read(input)) {
            }
        } finally {
            nextLoadPosition = input.getPosition() - dataSpec.position;
        }
    } finally {
        DataSourceUtil.closeQuietly(dataSource);
    }
}
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)

Example 30 with DefaultExtractorInput

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

the class RtpDataLoadable method load.

@Override
public void load() throws IOException {
    @Nullable RtpDataChannel dataChannel = null;
    try {
        dataChannel = rtpDataChannelFactory.createAndOpenDataChannel(trackId);
        String transport = dataChannel.getTransport();
        RtpDataChannel finalDataChannel = dataChannel;
        playbackThreadHandler.post(() -> eventListener.onTransportReady(transport, finalDataChannel));
        // Sets up the extractor.
        ExtractorInput extractorInput = new DefaultExtractorInput(checkNotNull(dataChannel), /* position= */
        0, /* length= */
        C.LENGTH_UNSET);
        extractor = new RtpExtractor(rtspMediaTrack.payloadFormat, trackId);
        extractor.init(output);
        while (!loadCancelled) {
            if (pendingSeekPositionUs != C.TIME_UNSET) {
                extractor.seek(nextRtpTimestamp, pendingSeekPositionUs);
                pendingSeekPositionUs = C.TIME_UNSET;
            }
            @Extractor.ReadResult int readResult = extractor.read(extractorInput, /* seekPosition= */
            new PositionHolder());
            if (readResult == Extractor.RESULT_END_OF_INPUT) {
                // Loading is finished.
                break;
            }
        }
    } finally {
        DataSourceUtil.closeQuietly(dataChannel);
    }
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) Nullable(androidx.annotation.Nullable)

Aggregations

FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)20 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)18 Test (org.junit.Test)14 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)10 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)7 IOException (java.io.IOException)4 EOFException (java.io.EOFException)3 Nullable (androidx.annotation.Nullable)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 InterruptedIOException (java.io.InterruptedIOException)1 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1