Verify MediaSources passed to set/addMediaSources are non-null.

Even though they are annotated as non-null, Java users can pass in null values.
So we should verify the input to fail fast.

PiperOrigin-RevId: 306425487
This commit is contained in:
tonihei 2020-04-14 14:19:36 +01:00 committed by Ian Baker
parent 76ad0bc4ff
commit 6a491e1294

View File

@ -397,6 +397,9 @@ import java.util.concurrent.TimeoutException;
@Override @Override
public void addMediaSources(int index, List<MediaSource> mediaSources) { public void addMediaSources(int index, List<MediaSource> mediaSources) {
Assertions.checkArgument(index >= 0); Assertions.checkArgument(index >= 0);
for (int i = 0; i < mediaSources.size(); i++) {
Assertions.checkArgument(mediaSources.get(i) != null);
}
int currentWindowIndex = getCurrentWindowIndex(); int currentWindowIndex = getCurrentWindowIndex();
long currentPositionMs = getCurrentPosition(); long currentPositionMs = getCurrentPosition();
Timeline oldTimeline = getCurrentTimeline(); Timeline oldTimeline = getCurrentTimeline();
@ -966,10 +969,13 @@ import java.util.concurrent.TimeoutException;
} }
private void setMediaSourcesInternal( private void setMediaSourcesInternal(
List<MediaSource> mediaItems, List<MediaSource> mediaSources,
int startWindowIndex, int startWindowIndex,
long startPositionMs, long startPositionMs,
boolean resetToDefaultPosition) { boolean resetToDefaultPosition) {
for (int i = 0; i < mediaSources.size(); i++) {
Assertions.checkArgument(mediaSources.get(i) != null);
}
int currentWindowIndex = getCurrentWindowIndexInternal(); int currentWindowIndex = getCurrentWindowIndexInternal();
long currentPositionMs = getCurrentPosition(); long currentPositionMs = getCurrentPosition();
pendingOperationAcks++; pendingOperationAcks++;
@ -978,7 +984,7 @@ import java.util.concurrent.TimeoutException;
/* fromIndex= */ 0, /* toIndexExclusive= */ mediaSourceHolders.size()); /* fromIndex= */ 0, /* toIndexExclusive= */ mediaSourceHolders.size());
} }
List<MediaSourceList.MediaSourceHolder> holders = List<MediaSourceList.MediaSourceHolder> holders =
addMediaSourceHolders(/* index= */ 0, mediaItems); addMediaSourceHolders(/* index= */ 0, mediaSources);
PlaybackInfo playbackInfo = maskTimeline(); PlaybackInfo playbackInfo = maskTimeline();
Timeline timeline = playbackInfo.timeline; Timeline timeline = playbackInfo.timeline;
if (!timeline.isEmpty() && startWindowIndex >= timeline.getWindowCount()) { if (!timeline.isEmpty() && startWindowIndex >= timeline.getWindowCount()) {