Search in sources :

Example 11 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

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 : DefaultExtractorInput(androidx.media3.extractor.DefaultExtractorInput) ExtractorInput(androidx.media3.extractor.ExtractorInput) DataSpec(androidx.media3.datasource.DataSpec) DefaultExtractorInput(androidx.media3.extractor.DefaultExtractorInput)

Example 12 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

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(androidx.media3.extractor.ExtractorInput) DefaultExtractorInput(androidx.media3.extractor.DefaultExtractorInput) DataSpec(androidx.media3.datasource.DataSpec) DefaultExtractorInput(androidx.media3.extractor.DefaultExtractorInput)

Example 13 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class IcyDataSource method readMetadata.

/**
 * Reads an ICY stream metadata block, passing it to {@link #listener} unless the block is empty.
 *
 * @return True if the block was extracted, including if its length byte indicated a length of
 *     zero. False if the end of the stream was reached.
 * @throws IOException If an error occurs reading from the wrapped {@link DataSource}.
 */
private boolean readMetadata() throws IOException {
    int bytesRead = upstream.read(metadataLengthByteHolder, 0, 1);
    if (bytesRead == C.RESULT_END_OF_INPUT) {
        return false;
    }
    int metadataLength = (metadataLengthByteHolder[0] & 0xFF) << 4;
    if (metadataLength == 0) {
        return true;
    }
    int offset = 0;
    int lengthRemaining = metadataLength;
    byte[] metadata = new byte[metadataLength];
    while (lengthRemaining > 0) {
        bytesRead = upstream.read(metadata, offset, lengthRemaining);
        if (bytesRead == C.RESULT_END_OF_INPUT) {
            return false;
        }
        offset += bytesRead;
        lengthRemaining -= bytesRead;
    }
    // Discard trailing zero bytes.
    while (metadataLength > 0 && metadata[metadataLength - 1] == 0) {
        metadataLength--;
    }
    if (metadataLength > 0) {
        listener.onIcyMetadata(new ParsableByteArray(metadata, metadataLength));
    }
    return true;
}
Also used : ParsableByteArray(androidx.media3.common.util.ParsableByteArray)

Example 14 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class DashMediaSource method prepareSourceInternal.

@Override
protected void prepareSourceInternal(@Nullable TransferListener mediaTransferListener) {
    this.mediaTransferListener = mediaTransferListener;
    drmSessionManager.prepare();
    drmSessionManager.setPlayer(/* playbackLooper= */
    Looper.myLooper(), getPlayerId());
    if (sideloadedManifest) {
        processManifest(false);
    } else {
        dataSource = manifestDataSourceFactory.createDataSource();
        loader = new Loader("DashMediaSource");
        handler = Util.createHandlerForCurrentLooper();
        startLoadingManifest();
    }
}
Also used : Loader(androidx.media3.exoplayer.upstream.Loader) SequenceableLoader(androidx.media3.exoplayer.source.SequenceableLoader)

Example 15 with DataSource

use of androidx.media3.datasource.DataSource in project media by androidx.

the class DashUtil method loadInitializationData.

private static void loadInitializationData(DataSource dataSource, Representation representation, int baseUrlIndex, ChunkExtractor chunkExtractor, RangedUri requestUri) throws IOException {
    DataSpec dataSpec = DashUtil.buildDataSpec(representation, representation.baseUrls.get(baseUrlIndex).url, requestUri, /* flags= */
    0);
    InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
    chunkExtractor);
    initializationChunk.load();
}
Also used : InitializationChunk(androidx.media3.exoplayer.source.chunk.InitializationChunk) DataSpec(androidx.media3.datasource.DataSpec)

Aggregations

Test (org.junit.Test)101 Uri (android.net.Uri)72 SeekMap (androidx.media3.extractor.SeekMap)65 DataSpec (androidx.media3.datasource.DataSpec)56 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)50 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)29 DataSource (androidx.media3.datasource.DataSource)25 Nullable (androidx.annotation.Nullable)13 IOException (java.io.IOException)13 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)12 ExtractorInput (androidx.media3.extractor.ExtractorInput)10 FakeDataSource (androidx.media3.test.utils.FakeDataSource)10 StatsDataSource (androidx.media3.datasource.StatsDataSource)8 FakeDataSet (androidx.media3.test.utils.FakeDataSet)7 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)5 Representation (androidx.media3.exoplayer.dash.manifest.Representation)5 Before (org.junit.Before)5 Format (androidx.media3.common.Format)3 DataSourceInputStream (androidx.media3.datasource.DataSourceInputStream)3 FileDataSource (androidx.media3.datasource.FileDataSource)3