Search in sources :

Example 1 with DefaultExtractorInput

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

the class HlsMediaChunk method maybeLoadInitData.

// Internal loading methods.
private void maybeLoadInitData() throws IOException, InterruptedException {
    if (previousExtractor == extractor || initLoadCompleted || initDataSpec == null) {
        // According to spec, for packed audio, initDataSpec is expected to be null.
        return;
    }
    DataSpec initSegmentDataSpec = Util.getRemainderDataSpec(initDataSpec, initSegmentBytesLoaded);
    try {
        ExtractorInput input = new DefaultExtractorInput(initDataSource, initSegmentDataSpec.absoluteStreamPosition, initDataSource.open(initSegmentDataSpec));
        try {
            int result = Extractor.RESULT_CONTINUE;
            while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
                result = extractor.read(input, null);
            }
        } finally {
            initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition);
        }
    } finally {
        Util.closeQuietly(dataSource);
    }
    initLoadCompleted = 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)

Example 2 with DefaultExtractorInput

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

the class HlsMediaChunk method loadMedia.

private void loadMedia() throws IOException, InterruptedException {
    // If we previously fed part of this chunk to the extractor, we need to skip it this time. For
    // encrypted content we need to skip the data by reading it through the source, so as to ensure
    // correct decryption of the remainder of the chunk. For clear content, we can request the
    // remainder of the chunk directly.
    DataSpec loadDataSpec;
    boolean skipLoadedBytes;
    if (isEncrypted) {
        loadDataSpec = dataSpec;
        skipLoadedBytes = bytesLoaded != 0;
    } else {
        loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
        skipLoadedBytes = false;
    }
    if (!isMasterTimestampSource) {
        timestampAdjuster.waitUntilInitialized();
    } else if (timestampAdjuster.getFirstSampleTimestampUs() == TimestampAdjuster.DO_NOT_OFFSET) {
        // We're the master and we haven't set the desired first sample timestamp yet.
        timestampAdjuster.setFirstSampleTimestampUs(startTimeUs);
    }
    try {
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
        if (extractor == null) {
            // Media segment format is packed audio.
            long id3Timestamp = peekId3PrivTimestamp(input);
            extractor = buildPackedAudioExtractor(id3Timestamp != C.TIME_UNSET ? timestampAdjuster.adjustTsTimestamp(id3Timestamp) : startTimeUs);
        }
        if (skipLoadedBytes) {
            input.skipFully(bytesLoaded);
        }
        try {
            int result = Extractor.RESULT_CONTINUE;
            while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
                result = extractor.read(input, null);
            }
        } finally {
            bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
        }
    } finally {
        Util.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)

Example 3 with DefaultExtractorInput

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

the class BundledExtractorsAdapter method init.

@Override
public void init(DataReader dataReader, Uri uri, Map<String, List<String>> responseHeaders, long position, long length, ExtractorOutput output) throws IOException {
    ExtractorInput extractorInput = new DefaultExtractorInput(dataReader, position, length);
    this.extractorInput = extractorInput;
    if (extractor != null) {
        return;
    }
    Extractor[] extractors = extractorsFactory.createExtractors(uri, responseHeaders);
    if (extractors.length == 1) {
        this.extractor = extractors[0];
    } else {
        for (Extractor extractor : extractors) {
            try {
                if (extractor.sniff(extractorInput)) {
                    this.extractor = extractor;
                    break;
                }
            } catch (EOFException e) {
            // Do nothing.
            } finally {
                Assertions.checkState(this.extractor != null || extractorInput.getPosition() == position);
                extractorInput.resetPeekPosition();
            }
        }
        if (extractor == null) {
            throw new UnrecognizedInputFormatException("None of the available extractors (" + Util.getCommaDelimitedSimpleClassNames(extractors) + ") could read the stream.", Assertions.checkNotNull(uri));
        }
    }
    extractor.init(output);
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) EOFException(java.io.EOFException) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) Extractor(com.google.android.exoplayer2.extractor.Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)

Example 4 with DefaultExtractorInput

use of androidx.media3.extractor.DefaultExtractorInput 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 5 with DefaultExtractorInput

use of androidx.media3.extractor.DefaultExtractorInput in project Telegram-FOSS by Telegram-FOSS-Team.

the class ContainerMediaChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {
    if (nextLoadPosition == 0) {
        // Configure the output and set it as the target for the extractor wrapper.
        BaseMediaChunkOutput output = getOutput();
        output.setSampleOffsetUs(sampleOffsetUs);
        extractorWrapper.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.absoluteStreamPosition, dataSource.open(loadDataSpec));
        // Load and decode the sample data.
        try {
            Extractor extractor = extractorWrapper.extractor;
            int result = Extractor.RESULT_CONTINUE;
            while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
                result = extractor.read(input, DUMMY_POSITION_HOLDER);
            }
            Assertions.checkState(result != Extractor.RESULT_SEEK);
        } finally {
            nextLoadPosition = input.getPosition() - dataSpec.absoluteStreamPosition;
        }
    } finally {
        Util.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) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Aggregations

DataSpec (androidx.media3.datasource.DataSpec)15 FakeDataSource (androidx.media3.test.utils.FakeDataSource)14 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)14 Test (org.junit.Test)14 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)10 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)10 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)8 ExtractorInput (androidx.media3.extractor.ExtractorInput)5 Extractor (com.google.android.exoplayer2.extractor.Extractor)3 EOFException (java.io.EOFException)3 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)3 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)3 Nullable (androidx.annotation.Nullable)2 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 Extractor (androidx.media3.extractor.Extractor)1 PositionHolder (androidx.media3.extractor.PositionHolder)1 TrackOutput (androidx.media3.extractor.TrackOutput)1 Mp3Extractor (androidx.media3.extractor.mp3.Mp3Extractor)1