Search in sources :

Example 1 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class DownloadHelper method runTrackSelection.

/**
 * Runs the track selection for a given period index with the current parameters. The selected
 * tracks will be added to {@link #trackSelectionsByPeriodAndRenderer}.
 */
@RequiresNonNull({ "trackGroupArrays", "trackSelectionsByPeriodAndRenderer", "mediaPreparer", "mediaPreparer.timeline" })
private TrackSelectorResult runTrackSelection(int periodIndex) {
    try {
        TrackSelectorResult trackSelectorResult = trackSelector.selectTracks(rendererCapabilities, trackGroupArrays[periodIndex], new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)), mediaPreparer.timeline);
        for (int i = 0; i < trackSelectorResult.length; i++) {
            @Nullable ExoTrackSelection newSelection = trackSelectorResult.selections[i];
            if (newSelection == null) {
                continue;
            }
            List<ExoTrackSelection> existingSelectionList = trackSelectionsByPeriodAndRenderer[periodIndex][i];
            boolean mergedWithExistingSelection = false;
            for (int j = 0; j < existingSelectionList.size(); j++) {
                ExoTrackSelection existingSelection = existingSelectionList.get(j);
                if (existingSelection.getTrackGroup().equals(newSelection.getTrackGroup())) {
                    // Merge with existing selection.
                    scratchSet.clear();
                    for (int k = 0; k < existingSelection.length(); k++) {
                        scratchSet.put(existingSelection.getIndexInTrackGroup(k), 0);
                    }
                    for (int k = 0; k < newSelection.length(); k++) {
                        scratchSet.put(newSelection.getIndexInTrackGroup(k), 0);
                    }
                    int[] mergedTracks = new int[scratchSet.size()];
                    for (int k = 0; k < scratchSet.size(); k++) {
                        mergedTracks[k] = scratchSet.keyAt(k);
                    }
                    existingSelectionList.set(j, new DownloadTrackSelection(existingSelection.getTrackGroup(), mergedTracks));
                    mergedWithExistingSelection = true;
                    break;
                }
            }
            if (!mergedWithExistingSelection) {
                existingSelectionList.add(newSelection);
            }
        }
        return trackSelectorResult;
    } catch (ExoPlaybackException e) {
        // DefaultTrackSelector does not throw exceptions during track selection.
        throw new UnsupportedOperationException(e);
    }
}
Also used : TrackSelectorResult(com.google.android.exoplayer2.trackselection.TrackSelectorResult) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 2 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class DefaultAnalyticsCollector method generateEventTime.

/**
 * Returns a new {@link EventTime} for the specified timeline, window and media period id.
 */
@RequiresNonNull("player")
protected final EventTime generateEventTime(Timeline timeline, int windowIndex, @Nullable MediaPeriodId mediaPeriodId) {
    if (timeline.isEmpty()) {
        // Ensure media period id is only reported together with a valid timeline.
        mediaPeriodId = null;
    }
    long realtimeMs = clock.elapsedRealtime();
    long eventPositionMs;
    boolean isInCurrentWindow = timeline.equals(player.getCurrentTimeline()) && windowIndex == player.getCurrentMediaItemIndex();
    if (mediaPeriodId != null && mediaPeriodId.isAd()) {
        boolean isCurrentAd = isInCurrentWindow && player.getCurrentAdGroupIndex() == mediaPeriodId.adGroupIndex && player.getCurrentAdIndexInAdGroup() == mediaPeriodId.adIndexInAdGroup;
        // Assume start position of 0 for future ads.
        eventPositionMs = isCurrentAd ? player.getCurrentPosition() : 0;
    } else if (isInCurrentWindow) {
        eventPositionMs = player.getContentPosition();
    } else {
        // Assume default start position for future content windows. If timeline is not available yet,
        // assume start position of 0.
        eventPositionMs = timeline.isEmpty() ? 0 : timeline.getWindow(windowIndex, window).getDefaultPositionMs();
    }
    @Nullable MediaPeriodId currentMediaPeriodId = mediaPeriodQueueTracker.getCurrentPlayerMediaPeriod();
    return new EventTime(realtimeMs, timeline, windowIndex, mediaPeriodId, eventPositionMs, player.getCurrentTimeline(), player.getCurrentMediaItemIndex(), currentMediaPeriodId, player.getCurrentPosition(), player.getTotalBufferedDuration());
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 3 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class DefaultPlaybackSessionManager method updateCurrentSession.

@RequiresNonNull("listener")
private void updateCurrentSession(EventTime eventTime) {
    if (eventTime.timeline.isEmpty()) {
        // Clear current session if the Timeline is empty.
        currentSessionId = null;
        return;
    }
    @Nullable SessionDescriptor previousSessionDescriptor = sessions.get(currentSessionId);
    SessionDescriptor currentSessionDescriptor = getOrAddSession(eventTime.windowIndex, eventTime.mediaPeriodId);
    currentSessionId = currentSessionDescriptor.sessionId;
    updateSessions(eventTime);
    if (eventTime.mediaPeriodId != null && eventTime.mediaPeriodId.isAd() && (previousSessionDescriptor == null || previousSessionDescriptor.windowSequenceNumber != eventTime.mediaPeriodId.windowSequenceNumber || previousSessionDescriptor.adMediaPeriodId == null || previousSessionDescriptor.adMediaPeriodId.adGroupIndex != eventTime.mediaPeriodId.adGroupIndex || previousSessionDescriptor.adMediaPeriodId.adIndexInAdGroup != eventTime.mediaPeriodId.adIndexInAdGroup)) {
        // New ad playback started. Find corresponding content session and notify ad playback started.
        MediaPeriodId contentMediaPeriodId = new MediaPeriodId(eventTime.mediaPeriodId.periodUid, eventTime.mediaPeriodId.windowSequenceNumber);
        SessionDescriptor contentSession = getOrAddSession(eventTime.windowIndex, contentMediaPeriodId);
        listener.onAdPlaybackStarted(eventTime, contentSession.sessionId, currentSessionDescriptor.sessionId);
    }
}
Also used : MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 4 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class CastPlayer method updatePlaybackRateAndNotifyIfChanged.

@RequiresNonNull("remoteMediaClient")
private void updatePlaybackRateAndNotifyIfChanged(@Nullable ResultCallback<?> resultCallback) {
    if (playbackParameters.acceptsUpdate(resultCallback)) {
        @Nullable MediaStatus mediaStatus = remoteMediaClient.getMediaStatus();
        float speed = mediaStatus != null ? (float) mediaStatus.getPlaybackRate() : PlaybackParameters.DEFAULT.speed;
        if (speed > 0.0f) {
            // Set the speed if not paused.
            setPlaybackParametersAndNotifyIfChanged(new PlaybackParameters(speed));
        }
        playbackParameters.clearPendingResultCallback();
    }
}
Also used : Nullable(androidx.annotation.Nullable) MediaStatus(com.google.android.gms.cast.MediaStatus) PlaybackParameters(com.google.android.exoplayer2.PlaybackParameters) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 5 with RequiresNonNull

use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.

the class TransformerActivity method startTransformation.

@RequiresNonNull({ "playerView", "debugTextView", "informationTextView", "progressIndicator", "transformationStopwatch", "progressViewGroup", "debugFrame" })
private void startTransformation() {
    requestTransformerPermission();
    Intent intent = getIntent();
    Uri uri = checkNotNull(intent.getData());
    try {
        externalCacheFile = createExternalCacheFile("transformer-output.mp4");
        String filePath = externalCacheFile.getAbsolutePath();
        @Nullable Bundle bundle = intent.getExtras();
        Transformer transformer = createTransformer(bundle, filePath);
        transformationStopwatch.start();
        transformer.startTransformation(MediaItem.fromUri(uri), filePath);
        this.transformer = transformer;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    informationTextView.setText(R.string.transformation_started);
    playerView.setVisibility(View.GONE);
    Handler mainHandler = new Handler(getMainLooper());
    ProgressHolder progressHolder = new ProgressHolder();
    mainHandler.post(new Runnable() {

        @Override
        public void run() {
            if (transformer != null && transformer.getProgress(progressHolder) != Transformer.PROGRESS_STATE_NO_TRANSFORMATION) {
                progressIndicator.setProgress(progressHolder.progress);
                informationTextView.setText(getString(R.string.transformation_timer, transformationStopwatch.elapsed(TimeUnit.SECONDS)));
                mainHandler.postDelayed(/* r= */
                this, /* delayMillis= */
                500);
            }
        }
    });
}
Also used : Transformer(com.google.android.exoplayer2.transformer.Transformer) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable) ProgressHolder(com.google.android.exoplayer2.transformer.ProgressHolder) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)43 Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)10 SuppressLint (android.annotation.SuppressLint)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 TextPaint (android.text.TextPaint)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 Transformer (com.google.android.exoplayer2.transformer.Transformer)2 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)2 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)2 SpecialBlock (org.checkerframework.dataflow.cfg.block.SpecialBlock)2 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)2