Search in sources :

Example 11 with DataSource

use of com.google.android.exoplayer2.upstream.DataSource in project ExoPlayer by google.

the class DashMediaSource method prepareSource.

// MediaSource implementation.
@Override
public void prepareSource(ExoPlayer player, boolean isTopLevelSource, Listener listener) {
    sourceListener = listener;
    if (sideloadedManifest) {
        loaderErrorThrower = new LoaderErrorThrower.Dummy();
        processManifest(false);
    } else {
        dataSource = manifestDataSourceFactory.createDataSource();
        loader = new Loader("Loader:DashMediaSource");
        loaderErrorThrower = loader;
        handler = new Handler();
        startLoadingManifest();
    }
}
Also used : LoaderErrorThrower(com.google.android.exoplayer2.upstream.LoaderErrorThrower) Loader(com.google.android.exoplayer2.upstream.Loader) Handler(android.os.Handler)

Example 12 with DataSource

use of com.google.android.exoplayer2.upstream.DataSource in project ExoPlayer by google.

the class ContainerMediaChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public final void load() throws IOException, InterruptedException {
    DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
    try {
        // Create and open the input.
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
        if (bytesLoaded == 0) {
            // Configure the output and set it as the target for the extractor wrapper.
            BaseMediaChunkOutput output = getOutput();
            output.setSampleOffsetUs(sampleOffsetUs);
            extractorWrapper.init(output);
        }
        // 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, null);
            }
            Assertions.checkState(result != Extractor.RESULT_SEEK);
        } 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) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Example 13 with DataSource

use of com.google.android.exoplayer2.upstream.DataSource in project ExoPlayer by google.

the class InitializationChunk method load.

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
    DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
    try {
        // Create and open the input.
        ExtractorInput input = new DefaultExtractorInput(dataSource, loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
        if (bytesLoaded == 0) {
            extractorWrapper.init(null);
        }
        // Load and decode the initialization data.
        try {
            Extractor extractor = extractorWrapper.extractor;
            int result = Extractor.RESULT_CONTINUE;
            while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
                result = extractor.read(input, null);
            }
            Assertions.checkState(result != Extractor.RESULT_SEEK);
        } finally {
            bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
        }
    } finally {
        Util.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) Extractor(com.google.android.exoplayer2.extractor.Extractor)

Example 14 with DataSource

use of com.google.android.exoplayer2.upstream.DataSource in project ExoPlayer by google.

the class DashUtil method loadInitializationData.

/**
   * Loads initialization data for the {@code representation} and optionally index data then
   * returns a {@link ChunkExtractorWrapper} which contains the output.
   *
   * @param dataSource The source from which the data should be loaded.
   * @param representation The representation which initialization chunk belongs to.
   * @param loadIndex Whether to load index data too.
   * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
   *     initialization or (if requested) index data exists.
   * @throws IOException Thrown when there is an error while loading.
   * @throws InterruptedException Thrown if the thread was interrupted.
   */
private static ChunkExtractorWrapper loadInitializationData(DataSource dataSource, Representation representation, boolean loadIndex) throws IOException, InterruptedException {
    RangedUri initializationUri = representation.getInitializationUri();
    if (initializationUri == null) {
        return null;
    }
    ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(representation.format);
    RangedUri requestUri;
    if (loadIndex) {
        RangedUri indexUri = representation.getIndexUri();
        if (indexUri == null) {
            return null;
        }
        // It's common for initialization and index data to be stored adjacently. Attempt to merge
        // the two requests together to request both at once.
        requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
        if (requestUri == null) {
            loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
            requestUri = indexUri;
        }
    } else {
        requestUri = initializationUri;
    }
    loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
    return extractorWrapper;
}
Also used : ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri)

Example 15 with DataSource

use of com.google.android.exoplayer2.upstream.DataSource in project ExoPlayer by google.

the class DashUtil method loadInitializationData.

private static void loadInitializationData(DataSource dataSource, Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri) throws IOException, InterruptedException {
    DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl), requestUri.start, requestUri.length, representation.getCacheKey());
    InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
    extractorWrapper);
    initializationChunk.load();
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Aggregations

DataSpec (com.google.android.exoplayer2.upstream.DataSpec)12 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)5 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)5 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)4 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)3 Extractor (com.google.android.exoplayer2.extractor.Extractor)2 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)2 ChunkExtractorWrapper (com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper)2 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)2 InitializationChunk (com.google.android.exoplayer2.source.chunk.InitializationChunk)2 DataSource (com.google.android.exoplayer2.upstream.DataSource)2 DataSourceInputStream (com.google.android.exoplayer2.upstream.DataSourceInputStream)2 Uri (android.net.Uri)1 Handler (android.os.Handler)1 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)1 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)1 Format (com.google.android.exoplayer2.Format)1 AudioAttributes (com.google.android.exoplayer2.audio.AudioAttributes)1 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)1 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)1