Search in sources :

Example 26 with Assertions.checkState

use of com.google.android.exoplayer2.util.Assertions.checkState in project ExoPlayer by google.

the class HlsMediaPeriod method selectTracks.

@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    // Map each selection and stream onto a child period index.
    int[] streamChildIndices = new int[selections.length];
    int[] selectionChildIndices = new int[selections.length];
    for (int i = 0; i < selections.length; i++) {
        streamChildIndices[i] = streams[i] == null ? C.INDEX_UNSET : streamWrapperIndices.get(streams[i]);
        selectionChildIndices[i] = C.INDEX_UNSET;
        if (selections[i] != null) {
            TrackGroup trackGroup = selections[i].getTrackGroup();
            for (int j = 0; j < sampleStreamWrappers.length; j++) {
                if (sampleStreamWrappers[j].getTrackGroups().indexOf(trackGroup) != C.INDEX_UNSET) {
                    selectionChildIndices[i] = j;
                    break;
                }
            }
        }
    }
    boolean forceReset = false;
    streamWrapperIndices.clear();
    // Select tracks for each child, copying the resulting streams back into a new streams array.
    SampleStream[] newStreams = new SampleStream[selections.length];
    @NullableType SampleStream[] childStreams = new SampleStream[selections.length];
    @NullableType ExoTrackSelection[] childSelections = new ExoTrackSelection[selections.length];
    int newEnabledSampleStreamWrapperCount = 0;
    HlsSampleStreamWrapper[] newEnabledSampleStreamWrappers = new HlsSampleStreamWrapper[sampleStreamWrappers.length];
    for (int i = 0; i < sampleStreamWrappers.length; i++) {
        for (int j = 0; j < selections.length; j++) {
            childStreams[j] = streamChildIndices[j] == i ? streams[j] : null;
            childSelections[j] = selectionChildIndices[j] == i ? selections[j] : null;
        }
        HlsSampleStreamWrapper sampleStreamWrapper = sampleStreamWrappers[i];
        boolean wasReset = sampleStreamWrapper.selectTracks(childSelections, mayRetainStreamFlags, childStreams, streamResetFlags, positionUs, forceReset);
        boolean wrapperEnabled = false;
        for (int j = 0; j < selections.length; j++) {
            SampleStream childStream = childStreams[j];
            if (selectionChildIndices[j] == i) {
                // Assert that the child provided a stream for the selection.
                Assertions.checkNotNull(childStream);
                newStreams[j] = childStream;
                wrapperEnabled = true;
                streamWrapperIndices.put(childStream, i);
            } else if (streamChildIndices[j] == i) {
                // Assert that the child cleared any previous stream.
                Assertions.checkState(childStream == null);
            }
        }
        if (wrapperEnabled) {
            newEnabledSampleStreamWrappers[newEnabledSampleStreamWrapperCount] = sampleStreamWrapper;
            if (newEnabledSampleStreamWrapperCount++ == 0) {
                // The first enabled wrapper is always allowed to initialize timestamp adjusters. Note
                // that the first wrapper will correspond to a variant, or else an audio rendition, or
                // else a text rendition, in that order.
                sampleStreamWrapper.setIsTimestampMaster(true);
                if (wasReset || enabledSampleStreamWrappers.length == 0 || sampleStreamWrapper != enabledSampleStreamWrappers[0]) {
                    // The wrapper responsible for initializing the timestamp adjusters was reset or
                    // changed. We need to reset the timestamp adjuster provider and all other wrappers.
                    timestampAdjusterProvider.reset();
                    forceReset = true;
                }
            } else {
                // Additional wrappers are also allowed to initialize timestamp adjusters if they contain
                // audio or video, since they are expected to contain dense samples. Text wrappers are not
                // permitted except in the case above in which no variant or audio rendition wrappers are
                // enabled.
                sampleStreamWrapper.setIsTimestampMaster(i < audioVideoSampleStreamWrapperCount);
            }
        }
    }
    // Copy the new streams back into the streams array.
    System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
    // Update the local state.
    enabledSampleStreamWrappers = Util.nullSafeArrayCopy(newEnabledSampleStreamWrappers, newEnabledSampleStreamWrapperCount);
    compositeSequenceableLoader = compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(enabledSampleStreamWrappers);
    return positionUs;
}
Also used : ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) SampleStream(com.google.android.exoplayer2.source.SampleStream)

Example 27 with Assertions.checkState

use of com.google.android.exoplayer2.util.Assertions.checkState in project ExoPlayer by google.

the class BundledHlsMediaChunkExtractor method recreate.

@Override
public HlsMediaChunkExtractor recreate() {
    Assertions.checkState(!isReusable());
    Extractor newExtractorInstance;
    if (extractor instanceof WebvttExtractor) {
        newExtractorInstance = new WebvttExtractor(multivariantPlaylistFormat.language, timestampAdjuster);
    } else if (extractor instanceof AdtsExtractor) {
        newExtractorInstance = new AdtsExtractor();
    } else if (extractor instanceof Ac3Extractor) {
        newExtractorInstance = new Ac3Extractor();
    } else if (extractor instanceof Ac4Extractor) {
        newExtractorInstance = new Ac4Extractor();
    } else if (extractor instanceof Mp3Extractor) {
        newExtractorInstance = new Mp3Extractor();
    } else {
        throw new IllegalStateException("Unexpected extractor type for recreation: " + extractor.getClass().getSimpleName());
    }
    return new BundledHlsMediaChunkExtractor(newExtractorInstance, multivariantPlaylistFormat, timestampAdjuster);
}
Also used : AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) FragmentedMp4Extractor(com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor) Extractor(com.google.android.exoplayer2.extractor.Extractor) TsExtractor(com.google.android.exoplayer2.extractor.ts.TsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor) Mp3Extractor(com.google.android.exoplayer2.extractor.mp3.Mp3Extractor) Ac4Extractor(com.google.android.exoplayer2.extractor.ts.Ac4Extractor) AdtsExtractor(com.google.android.exoplayer2.extractor.ts.AdtsExtractor) Ac3Extractor(com.google.android.exoplayer2.extractor.ts.Ac3Extractor)

Example 28 with Assertions.checkState

use of com.google.android.exoplayer2.util.Assertions.checkState in project ExoPlayer by google.

the class DefaultHlsPlaylistTracker method start.

// HlsPlaylistTracker implementation.
@Override
public void start(Uri initialPlaylistUri, EventDispatcher eventDispatcher, PrimaryPlaylistListener primaryPlaylistListener) {
    this.playlistRefreshHandler = Util.createHandlerForCurrentLooper();
    this.eventDispatcher = eventDispatcher;
    this.primaryPlaylistListener = primaryPlaylistListener;
    ParsingLoadable<HlsPlaylist> multivariantPlaylistLoadable = new ParsingLoadable<>(dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST), initialPlaylistUri, C.DATA_TYPE_MANIFEST, playlistParserFactory.createPlaylistParser());
    Assertions.checkState(initialPlaylistLoader == null);
    initialPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MultivariantPlaylist");
    long elapsedRealtime = initialPlaylistLoader.startLoading(multivariantPlaylistLoadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(multivariantPlaylistLoadable.type));
    eventDispatcher.loadStarted(new LoadEventInfo(multivariantPlaylistLoadable.loadTaskId, multivariantPlaylistLoadable.dataSpec, elapsedRealtime), multivariantPlaylistLoadable.type);
}
Also used : LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) ParsingLoadable(com.google.android.exoplayer2.upstream.ParsingLoadable) Loader(com.google.android.exoplayer2.upstream.Loader)

Example 29 with Assertions.checkState

use of com.google.android.exoplayer2.util.Assertions.checkState in project ExoPlayer by google.

the class DecoderVideoRenderer method render.

// BaseRenderer implementation.
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (outputStreamEnded) {
        return;
    }
    if (inputFormat == null) {
        // We don't have a format yet, so try and read one.
        FormatHolder formatHolder = getFormatHolder();
        flagsOnlyBuffer.clear();
        @ReadDataResult int result = readSource(formatHolder, flagsOnlyBuffer, FLAG_REQUIRE_FORMAT);
        if (result == C.RESULT_FORMAT_READ) {
            onInputFormatChanged(formatHolder);
        } else if (result == C.RESULT_BUFFER_READ) {
            // End of stream read having not read a format.
            Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
            inputStreamEnded = true;
            outputStreamEnded = true;
            return;
        } else {
            // We still don't have a format and can't make progress without one.
            return;
        }
    }
    // If we don't have a decoder yet, we need to instantiate one.
    maybeInitDecoder();
    if (decoder != null) {
        try {
            // Rendering loop.
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {
            }
            while (feedInputBuffer()) {
            }
            TraceUtil.endSection();
        } catch (DecoderException e) {
            Log.e(TAG, "Video codec error", e);
            eventDispatcher.videoCodecError(e);
            throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODING_FAILED);
        }
        decoderCounters.ensureUpdated();
    }
}
Also used : DecoderException(com.google.android.exoplayer2.decoder.DecoderException) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 30 with Assertions.checkState

use of com.google.android.exoplayer2.util.Assertions.checkState in project ExoPlayer by google.

the class PlayerWrapper method skipToPlaylistItem.

public boolean skipToPlaylistItem(@IntRange(from = 0) int index) {
    Timeline timeline = player.getCurrentTimeline();
    Assertions.checkState(!timeline.isEmpty());
    // Use checkState() instead of checkIndex() for throwing IllegalStateException.
    // checkIndex() throws IndexOutOfBoundsException which maps the RESULT_ERROR_BAD_VALUE
    // but RESULT_ERROR_INVALID_STATE with IllegalStateException is expected here.
    Assertions.checkState(0 <= index && index < timeline.getWindowCount());
    int currentIndex = player.getCurrentMediaItemIndex();
    if (currentIndex == index || !player.isCommandAvailable(COMMAND_SEEK_TO_MEDIA_ITEM)) {
        return false;
    }
    player.seekToDefaultPosition(index);
    return true;
}
Also used : Timeline(com.google.android.exoplayer2.Timeline)

Aggregations

Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)4 Player (com.google.android.exoplayer2.Player)4 FormatHolder (com.google.android.exoplayer2.FormatHolder)3 Timeline (com.google.android.exoplayer2.Timeline)3 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)3 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 Segment (com.google.android.exoplayer2.testutil.FakeDataSet.FakeData.Segment)3 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)3 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)3 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)3 SuppressLint (android.annotation.SuppressLint)2 Uri (android.net.Uri)2 GLSurfaceView (android.opengl.GLSurfaceView)2 SurfaceView (android.view.SurfaceView)2 TextureView (android.view.TextureView)2 DecoderException (com.google.android.exoplayer2.decoder.DecoderException)2 SchemeData (com.google.android.exoplayer2.drm.DrmInitData.SchemeData)2 Extractor (com.google.android.exoplayer2.extractor.Extractor)2