Commit c027b4e7 by andrewlewis Committed by Oliver Woodman

Turn on nullness checker for playback stats

The nullness checker complains about Integers with @IntDef annotations
so replace pairs with custom pair types for the timed event records in
PlaybackStats.

PiperOrigin-RevId: 284731834
parent 70ba4b19
......@@ -16,7 +16,6 @@
package com.google.android.exoplayer2.analytics;
import android.os.SystemClock;
import android.util.Pair;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
......@@ -25,6 +24,9 @@ import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.Timeline.Period;
import com.google.android.exoplayer2.analytics.PlaybackStats.EventTimeAndException;
import com.google.android.exoplayer2.analytics.PlaybackStats.EventTimeAndFormat;
import com.google.android.exoplayer2.analytics.PlaybackStats.EventTimeAndPlaybackState;
import com.google.android.exoplayer2.analytics.PlaybackStats.PlaybackState;
import com.google.android.exoplayer2.source.LoadEventInfo;
import com.google.android.exoplayer2.source.MediaLoadData;
......@@ -42,7 +44,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
* {@link AnalyticsListener} to gather {@link PlaybackStats} from the player.
......@@ -433,12 +434,12 @@ public final class PlaybackStatsListener
// Final stats.
private final boolean keepHistory;
private final long[] playbackStateDurationsMs;
private final List<Pair<EventTime, @PlaybackState Integer>> playbackStateHistory;
private final List<EventTimeAndPlaybackState> playbackStateHistory;
private final List<long[]> mediaTimeHistory;
private final List<Pair<EventTime, @NullableType Format>> videoFormatHistory;
private final List<Pair<EventTime, @NullableType Format>> audioFormatHistory;
private final List<Pair<EventTime, Exception>> fatalErrorHistory;
private final List<Pair<EventTime, Exception>> nonFatalErrorHistory;
private final List<EventTimeAndFormat> videoFormatHistory;
private final List<EventTimeAndFormat> audioFormatHistory;
private final List<EventTimeAndException> fatalErrorHistory;
private final List<EventTimeAndException> nonFatalErrorHistory;
private final boolean isAd;
private long firstReportedTimeMs;
......@@ -589,7 +590,7 @@ public final class PlaybackStatsListener
public void onFatalError(EventTime eventTime, Exception error) {
fatalErrorCount++;
if (keepHistory) {
fatalErrorHistory.add(Pair.create(eventTime, error));
fatalErrorHistory.add(new EventTimeAndException(eventTime, error));
}
hasFatalError = true;
isInterruptedByAd = false;
......@@ -743,7 +744,7 @@ public final class PlaybackStatsListener
public void onNonFatalError(EventTime eventTime, Exception error) {
nonFatalErrorCount++;
if (keepHistory) {
nonFatalErrorHistory.add(Pair.create(eventTime, error));
nonFatalErrorHistory.add(new EventTimeAndException(eventTime, error));
}
}
......@@ -776,9 +777,9 @@ public final class PlaybackStatsListener
: playbackStateDurationsMs[PlaybackStats.PLAYBACK_STATE_JOINING_FOREGROUND];
boolean hasBackgroundJoin =
playbackStateDurationsMs[PlaybackStats.PLAYBACK_STATE_JOINING_BACKGROUND] > 0;
List<Pair<EventTime, @NullableType Format>> videoHistory =
List<EventTimeAndFormat> videoHistory =
isFinal ? videoFormatHistory : new ArrayList<>(videoFormatHistory);
List<Pair<EventTime, @NullableType Format>> audioHistory =
List<EventTimeAndFormat> audioHistory =
isFinal ? audioFormatHistory : new ArrayList<>(audioFormatHistory);
return new PlaybackStats(
/* playbackCount= */ 1,
......@@ -864,7 +865,7 @@ public final class PlaybackStatsListener
currentPlaybackState = newPlaybackState;
currentPlaybackStateStartTimeMs = eventTime.realtimeMs;
if (keepHistory) {
playbackStateHistory.add(Pair.create(eventTime, currentPlaybackState));
playbackStateHistory.add(new EventTimeAndPlaybackState(eventTime, currentPlaybackState));
}
}
......@@ -973,7 +974,7 @@ public final class PlaybackStatsListener
}
currentVideoFormat = newFormat;
if (keepHistory) {
videoFormatHistory.add(Pair.create(eventTime, currentVideoFormat));
videoFormatHistory.add(new EventTimeAndFormat(eventTime, currentVideoFormat));
}
}
......@@ -989,7 +990,7 @@ public final class PlaybackStatsListener
}
currentAudioFormat = newFormat;
if (keepHistory) {
audioFormatHistory.add(Pair.create(eventTime, currentAudioFormat));
audioFormatHistory.add(new EventTimeAndFormat(eventTime, currentAudioFormat));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment