Source package: Add some missing nullness annotations

Plus a bit of misc warning cleanup whilst I was there

PiperOrigin-RevId: 295415657
This commit is contained in:
olly 2020-02-16 10:19:46 +00:00 committed by Ian Baker
parent 0257e895d0
commit ed210bca4e
13 changed files with 35 additions and 37 deletions

View File

@ -106,7 +106,7 @@ public abstract class BaseMediaSource implements MediaSource {
*/ */
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher( protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(
MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) { MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) {
Assertions.checkArgument(mediaPeriodId != null); Assertions.checkNotNull(mediaPeriodId);
return eventDispatcher.withParameters(/* windowIndex= */ 0, mediaPeriodId, mediaTimeOffsetMs); return eventDispatcher.withParameters(/* windowIndex= */ 0, mediaPeriodId, mediaTimeOffsetMs);
} }
@ -145,7 +145,7 @@ public abstract class BaseMediaSource implements MediaSource {
MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) { MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) {
Looper looper = Looper.myLooper(); Looper looper = Looper.myLooper();
Assertions.checkArgument(this.looper == null || this.looper == looper); Assertions.checkArgument(this.looper == null || this.looper == looper);
Timeline timeline = this.timeline; @Nullable Timeline timeline = this.timeline;
mediaSourceCallers.add(caller); mediaSourceCallers.add(caller);
if (this.looper == null) { if (this.looper == null) {
this.looper = looper; this.looper = looper;

View File

@ -174,7 +174,7 @@ public final class ClippingMediaPeriod implements MediaPeriod, MediaPeriod.Callb
@Override @Override
public long seekToUs(long positionUs) { public long seekToUs(long positionUs) {
pendingInitialDiscontinuityPositionUs = C.TIME_UNSET; pendingInitialDiscontinuityPositionUs = C.TIME_UNSET;
for (ClippingSampleStream sampleStream : sampleStreams) { for (@Nullable ClippingSampleStream sampleStream : sampleStreams) {
if (sampleStream != null) { if (sampleStream != null) {
sampleStream.clearSentEos(); sampleStream.clearSentEos();
} }

View File

@ -317,7 +317,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
/** Updates the event dispatcher and returns whether the event should be dispatched. */ /** Updates the event dispatcher and returns whether the event should be dispatched. */
private boolean maybeUpdateEventDispatcher( private boolean maybeUpdateEventDispatcher(
int childWindowIndex, @Nullable MediaPeriodId childMediaPeriodId) { int childWindowIndex, @Nullable MediaPeriodId childMediaPeriodId) {
MediaPeriodId mediaPeriodId = null; @Nullable MediaPeriodId mediaPeriodId = null;
if (childMediaPeriodId != null) { if (childMediaPeriodId != null) {
mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, childMediaPeriodId); mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, childMediaPeriodId);
if (mediaPeriodId == null) { if (mediaPeriodId == null) {

View File

@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -468,7 +467,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) { public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid); Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid)); MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid); @Nullable MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
if (holder == null) { if (holder == null) {
// Stale event. The media source has already been removed. // Stale event. The media source has already been removed.
holder = new MediaSourceHolder(new DummyMediaSource(), useLazyPreparation); holder = new MediaSourceHolder(new DummyMediaSource(), useLazyPreparation);
@ -555,7 +554,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
@Nullable Handler handler, @Nullable Handler handler,
@Nullable Runnable onCompletionAction) { @Nullable Runnable onCompletionAction) {
Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Assertions.checkArgument((handler == null) == (onCompletionAction == null));
Handler playbackThreadHandler = this.playbackThreadHandler; @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
for (MediaSource mediaSource : mediaSources) { for (MediaSource mediaSource : mediaSources) {
Assertions.checkNotNull(mediaSource); Assertions.checkNotNull(mediaSource);
} }
@ -565,6 +564,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
} }
mediaSourcesPublic.addAll(index, mediaSourceHolders); mediaSourcesPublic.addAll(index, mediaSourceHolders);
if (playbackThreadHandler != null && !mediaSources.isEmpty()) { if (playbackThreadHandler != null && !mediaSources.isEmpty()) {
@Nullable
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
playbackThreadHandler playbackThreadHandler
.obtainMessage(MSG_ADD, new MessageData<>(index, mediaSourceHolders, callbackAction)) .obtainMessage(MSG_ADD, new MessageData<>(index, mediaSourceHolders, callbackAction))
@ -581,9 +581,10 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
@Nullable Handler handler, @Nullable Handler handler,
@Nullable Runnable onCompletionAction) { @Nullable Runnable onCompletionAction) {
Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Assertions.checkArgument((handler == null) == (onCompletionAction == null));
Handler playbackThreadHandler = this.playbackThreadHandler; @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
Util.removeRange(mediaSourcesPublic, fromIndex, toIndex); Util.removeRange(mediaSourcesPublic, fromIndex, toIndex);
if (playbackThreadHandler != null) { if (playbackThreadHandler != null) {
@Nullable
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
playbackThreadHandler playbackThreadHandler
.obtainMessage(MSG_REMOVE, new MessageData<>(fromIndex, toIndex, callbackAction)) .obtainMessage(MSG_REMOVE, new MessageData<>(fromIndex, toIndex, callbackAction))
@ -600,9 +601,10 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
@Nullable Handler handler, @Nullable Handler handler,
@Nullable Runnable onCompletionAction) { @Nullable Runnable onCompletionAction) {
Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Assertions.checkArgument((handler == null) == (onCompletionAction == null));
Handler playbackThreadHandler = this.playbackThreadHandler; @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
mediaSourcesPublic.add(newIndex, mediaSourcesPublic.remove(currentIndex)); mediaSourcesPublic.add(newIndex, mediaSourcesPublic.remove(currentIndex));
if (playbackThreadHandler != null) { if (playbackThreadHandler != null) {
@Nullable
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
playbackThreadHandler playbackThreadHandler
.obtainMessage(MSG_MOVE, new MessageData<>(currentIndex, newIndex, callbackAction)) .obtainMessage(MSG_MOVE, new MessageData<>(currentIndex, newIndex, callbackAction))
@ -616,7 +618,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
private void setPublicShuffleOrder( private void setPublicShuffleOrder(
ShuffleOrder shuffleOrder, @Nullable Handler handler, @Nullable Runnable onCompletionAction) { ShuffleOrder shuffleOrder, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
Assertions.checkArgument((handler == null) == (onCompletionAction == null)); Assertions.checkArgument((handler == null) == (onCompletionAction == null));
Handler playbackThreadHandler = this.playbackThreadHandler; @Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
if (playbackThreadHandler != null) { if (playbackThreadHandler != null) {
int size = getSize(); int size = getSize();
if (shuffleOrder.getLength() != size) { if (shuffleOrder.getLength() != size) {
@ -625,6 +627,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
.cloneAndClear() .cloneAndClear()
.cloneAndInsert(/* insertionIndex= */ 0, /* insertionCount= */ size); .cloneAndInsert(/* insertionIndex= */ 0, /* insertionCount= */ size);
} }
@Nullable
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction); HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
playbackThreadHandler playbackThreadHandler
.obtainMessage( .obtainMessage(
@ -772,9 +775,6 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
} }
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) { private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
if (mediaSourceHolder == null) {
throw new IllegalArgumentException();
}
if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) { if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) {
MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1); MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1);
int windowOffsetUpdate = int windowOffsetUpdate =
@ -947,7 +947,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
@Override @Override
protected int getChildIndexByChildUid(Object childUid) { protected int getChildIndexByChildUid(Object childUid) {
Integer index = childIndexByUid.get(childUid); @Nullable Integer index = childIndexByUid.get(childUid);
return index == null ? C.INDEX_UNSET : index; return index == null ? C.INDEX_UNSET : index;
} }
@ -1002,7 +1002,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
} }
@Override @Override
public void maybeThrowSourceInfoRefreshError() throws IOException { public void maybeThrowSourceInfoRefreshError() {
// Do nothing. // Do nothing.
} }

View File

@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.FormatHolder; import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import java.io.IOException;
/** /**
* An empty {@link SampleStream}. * An empty {@link SampleStream}.
@ -31,7 +30,7 @@ public final class EmptySampleStream implements SampleStream {
} }
@Override @Override
public void maybeThrowError() throws IOException { public void maybeThrowError() {
// Do nothing. // Do nothing.
} }
@ -46,5 +45,4 @@ public final class EmptySampleStream implements SampleStream {
public int skipData(long positionUs) { public int skipData(long positionUs) {
return 0; return 0;
} }
} }

View File

@ -71,7 +71,7 @@ import java.util.Map;
} }
@Override @Override
public long open(DataSpec dataSpec) throws IOException { public long open(DataSpec dataSpec) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -103,7 +103,7 @@ import java.util.Map;
} }
@Override @Override
public void close() throws IOException { public void close() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -107,6 +107,7 @@ public final class LoopingMediaSource extends CompositeMediaSource<Void> {
@Override @Override
public void releasePeriod(MediaPeriod mediaPeriod) { public void releasePeriod(MediaPeriod mediaPeriod) {
maskingMediaSource.releasePeriod(mediaPeriod); maskingMediaSource.releasePeriod(mediaPeriod);
@Nullable
MediaPeriodId childMediaPeriodId = mediaPeriodToChildMediaPeriodId.remove(mediaPeriod); MediaPeriodId childMediaPeriodId = mediaPeriodToChildMediaPeriodId.remove(mediaPeriod);
if (childMediaPeriodId != null) { if (childMediaPeriodId != null) {
childMediaPeriodIdToMediaPeriodId.remove(childMediaPeriodId); childMediaPeriodIdToMediaPeriodId.remove(childMediaPeriodId);
@ -123,7 +124,8 @@ public final class LoopingMediaSource extends CompositeMediaSource<Void> {
} }
@Override @Override
protected @Nullable MediaPeriodId getMediaPeriodIdForChildMediaPeriodId( @Nullable
protected MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
Void id, MediaPeriodId mediaPeriodId) { Void id, MediaPeriodId mediaPeriodId) {
return loopCount != Integer.MAX_VALUE return loopCount != Integer.MAX_VALUE
? childMediaPeriodIdToMediaPeriodId.get(mediaPeriodId) ? childMediaPeriodIdToMediaPeriodId.get(mediaPeriodId)

View File

@ -26,7 +26,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
/** /**
* A {@link MediaSource} that masks the {@link Timeline} with a placeholder until the actual media * A {@link MediaSource} that masks the {@link Timeline} with a placeholder until the actual media
@ -59,7 +58,7 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
this.useLazyPreparation = useLazyPreparation && mediaSource.isSingleWindow(); this.useLazyPreparation = useLazyPreparation && mediaSource.isSingleWindow();
window = new Timeline.Window(); window = new Timeline.Window();
period = new Timeline.Period(); period = new Timeline.Period();
Timeline initialTimeline = mediaSource.getInitialTimeline(); @Nullable Timeline initialTimeline = mediaSource.getInitialTimeline();
if (initialTimeline != null) { if (initialTimeline != null) {
timeline = timeline =
MaskingTimeline.createWithRealTimeline( MaskingTimeline.createWithRealTimeline(
@ -92,7 +91,7 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
@Override @Override
@SuppressWarnings("MissingSuperCall") @SuppressWarnings("MissingSuperCall")
public void maybeThrowSourceInfoRefreshError() throws IOException { public void maybeThrowSourceInfoRefreshError() {
// Do nothing. Source info refresh errors will be thrown when calling // Do nothing. Source info refresh errors will be thrown when calling
// MaskingMediaPeriod.maybeThrowPrepareError. // MaskingMediaPeriod.maybeThrowPrepareError.
} }

View File

@ -221,7 +221,8 @@ public interface MediaSourceEventListener {
* @param eventListener The listener to be added. * @param eventListener The listener to be added.
*/ */
public void addEventListener(Handler handler, MediaSourceEventListener eventListener) { public void addEventListener(Handler handler, MediaSourceEventListener eventListener) {
Assertions.checkArgument(handler != null && eventListener != null); Assertions.checkNotNull(handler);
Assertions.checkNotNull(eventListener);
listenerAndHandlers.add(new ListenerAndHandler(handler, eventListener)); listenerAndHandlers.add(new ListenerAndHandler(handler, eventListener));
} }

View File

@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import java.io.IOException;
/** /**
* Provides one period that loads data from a {@link Uri} and extracted using an {@link Extractor}. * Provides one period that loads data from a {@link Uri} and extracted using an {@link Extractor}.
@ -245,7 +244,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
} }
@Override @Override
public void maybeThrowSourceInfoRefreshError() throws IOException { public void maybeThrowSourceInfoRefreshError() {
// Do nothing. // Do nothing.
} }

View File

@ -24,6 +24,7 @@ import com.google.android.exoplayer2.source.SampleQueue.SampleExtrasHolder;
import com.google.android.exoplayer2.upstream.Allocation; import com.google.android.exoplayer2.upstream.Allocation;
import com.google.android.exoplayer2.upstream.Allocator; import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -246,11 +247,11 @@ import java.nio.ByteBuffer;
} }
// Write the clear and encrypted subsample sizes. // Write the clear and encrypted subsample sizes.
int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData; @Nullable int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData;
if (clearDataSizes == null || clearDataSizes.length < subsampleCount) { if (clearDataSizes == null || clearDataSizes.length < subsampleCount) {
clearDataSizes = new int[subsampleCount]; clearDataSizes = new int[subsampleCount];
} }
int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData; @Nullable int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData;
if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) { if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) {
encryptedDataSizes = new int[subsampleCount]; encryptedDataSizes = new int[subsampleCount];
} }
@ -270,7 +271,7 @@ import java.nio.ByteBuffer;
} }
// Populate the cryptoInfo. // Populate the cryptoInfo.
CryptoData cryptoData = extrasHolder.cryptoData; CryptoData cryptoData = Util.castNonNull(extrasHolder.cryptoData);
buffer.cryptoInfo.set( buffer.cryptoInfo.set(
subsampleCount, subsampleCount,
clearDataSizes, clearDataSizes,

View File

@ -104,7 +104,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
@Override @Override
public void maybeThrowPrepareError() throws IOException { public void maybeThrowPrepareError() {
// Do nothing. // Do nothing.
} }
@ -394,7 +394,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
@Override @Override
public void load() throws IOException, InterruptedException { public void load() throws IOException {
// We always load from the beginning, so reset bytesRead to 0. // We always load from the beginning, so reset bytesRead to 0.
dataSource.resetBytesRead(); dataSource.resetBytesRead();
try { try {
@ -415,7 +415,5 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Util.closeQuietly(dataSource); Util.closeQuietly(dataSource);
} }
} }
} }
} }

View File

@ -256,8 +256,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
Format format, Format format,
long durationUs, long durationUs,
int minLoadableRetryCount, int minLoadableRetryCount,
Handler eventHandler, @Nullable Handler eventHandler,
EventListener eventListener, @Nullable EventListener eventListener,
int eventSourceId, int eventSourceId,
boolean treatLoadErrorsAsEndOfStream) { boolean treatLoadErrorsAsEndOfStream) {
this( this(
@ -313,7 +313,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
} }
@Override @Override
public void maybeThrowSourceInfoRefreshError() throws IOException { public void maybeThrowSourceInfoRefreshError() {
// Do nothing. // Do nothing.
} }