mirror of
https://github.com/androidx/media.git
synced 2025-05-13 18:50:02 +08:00
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:
parent
0257e895d0
commit
ed210bca4e
@ -106,7 +106,7 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
*/
|
||||
protected final MediaSourceEventListener.EventDispatcher createEventDispatcher(
|
||||
MediaPeriodId mediaPeriodId, long mediaTimeOffsetMs) {
|
||||
Assertions.checkArgument(mediaPeriodId != null);
|
||||
Assertions.checkNotNull(mediaPeriodId);
|
||||
return eventDispatcher.withParameters(/* windowIndex= */ 0, mediaPeriodId, mediaTimeOffsetMs);
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) {
|
||||
Looper looper = Looper.myLooper();
|
||||
Assertions.checkArgument(this.looper == null || this.looper == looper);
|
||||
Timeline timeline = this.timeline;
|
||||
@Nullable Timeline timeline = this.timeline;
|
||||
mediaSourceCallers.add(caller);
|
||||
if (this.looper == null) {
|
||||
this.looper = looper;
|
||||
|
@ -174,7 +174,7 @@ public final class ClippingMediaPeriod implements MediaPeriod, MediaPeriod.Callb
|
||||
@Override
|
||||
public long seekToUs(long positionUs) {
|
||||
pendingInitialDiscontinuityPositionUs = C.TIME_UNSET;
|
||||
for (ClippingSampleStream sampleStream : sampleStreams) {
|
||||
for (@Nullable ClippingSampleStream sampleStream : sampleStreams) {
|
||||
if (sampleStream != null) {
|
||||
sampleStream.clearSentEos();
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||
/** Updates the event dispatcher and returns whether the event should be dispatched. */
|
||||
private boolean maybeUpdateEventDispatcher(
|
||||
int childWindowIndex, @Nullable MediaPeriodId childMediaPeriodId) {
|
||||
MediaPeriodId mediaPeriodId = null;
|
||||
@Nullable MediaPeriodId mediaPeriodId = null;
|
||||
if (childMediaPeriodId != null) {
|
||||
mediaPeriodId = getMediaPeriodIdForChildMediaPeriodId(id, childMediaPeriodId);
|
||||
if (mediaPeriodId == null) {
|
||||
|
@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -468,7 +467,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
|
||||
Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
|
||||
MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
|
||||
MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
|
||||
@Nullable MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
|
||||
if (holder == null) {
|
||||
// Stale event. The media source has already been removed.
|
||||
holder = new MediaSourceHolder(new DummyMediaSource(), useLazyPreparation);
|
||||
@ -555,7 +554,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
@Nullable Handler handler,
|
||||
@Nullable Runnable onCompletionAction) {
|
||||
Assertions.checkArgument((handler == null) == (onCompletionAction == null));
|
||||
Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
@Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
for (MediaSource mediaSource : mediaSources) {
|
||||
Assertions.checkNotNull(mediaSource);
|
||||
}
|
||||
@ -565,6 +564,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
}
|
||||
mediaSourcesPublic.addAll(index, mediaSourceHolders);
|
||||
if (playbackThreadHandler != null && !mediaSources.isEmpty()) {
|
||||
@Nullable
|
||||
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
|
||||
playbackThreadHandler
|
||||
.obtainMessage(MSG_ADD, new MessageData<>(index, mediaSourceHolders, callbackAction))
|
||||
@ -581,9 +581,10 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
@Nullable Handler handler,
|
||||
@Nullable Runnable onCompletionAction) {
|
||||
Assertions.checkArgument((handler == null) == (onCompletionAction == null));
|
||||
Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
@Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
Util.removeRange(mediaSourcesPublic, fromIndex, toIndex);
|
||||
if (playbackThreadHandler != null) {
|
||||
@Nullable
|
||||
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
|
||||
playbackThreadHandler
|
||||
.obtainMessage(MSG_REMOVE, new MessageData<>(fromIndex, toIndex, callbackAction))
|
||||
@ -600,9 +601,10 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
@Nullable Handler handler,
|
||||
@Nullable Runnable onCompletionAction) {
|
||||
Assertions.checkArgument((handler == null) == (onCompletionAction == null));
|
||||
Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
@Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
mediaSourcesPublic.add(newIndex, mediaSourcesPublic.remove(currentIndex));
|
||||
if (playbackThreadHandler != null) {
|
||||
@Nullable
|
||||
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
|
||||
playbackThreadHandler
|
||||
.obtainMessage(MSG_MOVE, new MessageData<>(currentIndex, newIndex, callbackAction))
|
||||
@ -616,7 +618,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
private void setPublicShuffleOrder(
|
||||
ShuffleOrder shuffleOrder, @Nullable Handler handler, @Nullable Runnable onCompletionAction) {
|
||||
Assertions.checkArgument((handler == null) == (onCompletionAction == null));
|
||||
Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
@Nullable Handler playbackThreadHandler = this.playbackThreadHandler;
|
||||
if (playbackThreadHandler != null) {
|
||||
int size = getSize();
|
||||
if (shuffleOrder.getLength() != size) {
|
||||
@ -625,6 +627,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
.cloneAndClear()
|
||||
.cloneAndInsert(/* insertionIndex= */ 0, /* insertionCount= */ size);
|
||||
}
|
||||
@Nullable
|
||||
HandlerAndRunnable callbackAction = createOnCompletionAction(handler, onCompletionAction);
|
||||
playbackThreadHandler
|
||||
.obtainMessage(
|
||||
@ -772,9 +775,6 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
}
|
||||
|
||||
private void updateMediaSourceInternal(MediaSourceHolder mediaSourceHolder, Timeline timeline) {
|
||||
if (mediaSourceHolder == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (mediaSourceHolder.childIndex + 1 < mediaSourceHolders.size()) {
|
||||
MediaSourceHolder nextHolder = mediaSourceHolders.get(mediaSourceHolder.childIndex + 1);
|
||||
int windowOffsetUpdate =
|
||||
@ -947,7 +947,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
|
||||
@Override
|
||||
protected int getChildIndexByChildUid(Object childUid) {
|
||||
Integer index = childIndexByUid.get(childUid);
|
||||
@Nullable Integer index = childIndexByUid.get(childUid);
|
||||
return index == null ? C.INDEX_UNSET : index;
|
||||
}
|
||||
|
||||
@ -1002,7 +1002,7 @@ public final class ConcatenatingMediaSource extends CompositeMediaSource<MediaSo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
public void maybeThrowSourceInfoRefreshError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.FormatHolder;
|
||||
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An empty {@link SampleStream}.
|
||||
@ -31,7 +30,7 @@ public final class EmptySampleStream implements SampleStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowError() throws IOException {
|
||||
public void maybeThrowError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@ -46,5 +45,4 @@ public final class EmptySampleStream implements SampleStream {
|
||||
public int skipData(long positionUs) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ import java.util.Map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long open(DataSpec dataSpec) throws IOException {
|
||||
public long open(DataSpec dataSpec) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ import java.util.Map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
public void close() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,7 @@ public final class LoopingMediaSource extends CompositeMediaSource<Void> {
|
||||
@Override
|
||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||
maskingMediaSource.releasePeriod(mediaPeriod);
|
||||
@Nullable
|
||||
MediaPeriodId childMediaPeriodId = mediaPeriodToChildMediaPeriodId.remove(mediaPeriod);
|
||||
if (childMediaPeriodId != null) {
|
||||
childMediaPeriodIdToMediaPeriodId.remove(childMediaPeriodId);
|
||||
@ -123,7 +124,8 @@ public final class LoopingMediaSource extends CompositeMediaSource<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
|
||||
@Nullable
|
||||
protected MediaPeriodId getMediaPeriodIdForChildMediaPeriodId(
|
||||
Void id, MediaPeriodId mediaPeriodId) {
|
||||
return loopCount != Integer.MAX_VALUE
|
||||
? childMediaPeriodIdToMediaPeriodId.get(mediaPeriodId)
|
||||
|
@ -26,7 +26,6 @@ import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
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
|
||||
@ -59,7 +58,7 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
|
||||
this.useLazyPreparation = useLazyPreparation && mediaSource.isSingleWindow();
|
||||
window = new Timeline.Window();
|
||||
period = new Timeline.Period();
|
||||
Timeline initialTimeline = mediaSource.getInitialTimeline();
|
||||
@Nullable Timeline initialTimeline = mediaSource.getInitialTimeline();
|
||||
if (initialTimeline != null) {
|
||||
timeline =
|
||||
MaskingTimeline.createWithRealTimeline(
|
||||
@ -92,7 +91,7 @@ public final class MaskingMediaSource extends CompositeMediaSource<Void> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("MissingSuperCall")
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
public void maybeThrowSourceInfoRefreshError() {
|
||||
// Do nothing. Source info refresh errors will be thrown when calling
|
||||
// MaskingMediaPeriod.maybeThrowPrepareError.
|
||||
}
|
||||
|
@ -221,7 +221,8 @@ public interface MediaSourceEventListener {
|
||||
* @param eventListener The listener to be added.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
|
||||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||
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}.
|
||||
@ -245,7 +244,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
public void maybeThrowSourceInfoRefreshError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
@ -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.Allocator;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -246,11 +247,11 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
|
||||
// Write the clear and encrypted subsample sizes.
|
||||
int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData;
|
||||
@Nullable int[] clearDataSizes = buffer.cryptoInfo.numBytesOfClearData;
|
||||
if (clearDataSizes == null || clearDataSizes.length < subsampleCount) {
|
||||
clearDataSizes = new int[subsampleCount];
|
||||
}
|
||||
int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData;
|
||||
@Nullable int[] encryptedDataSizes = buffer.cryptoInfo.numBytesOfEncryptedData;
|
||||
if (encryptedDataSizes == null || encryptedDataSizes.length < subsampleCount) {
|
||||
encryptedDataSizes = new int[subsampleCount];
|
||||
}
|
||||
@ -270,7 +271,7 @@ import java.nio.ByteBuffer;
|
||||
}
|
||||
|
||||
// Populate the cryptoInfo.
|
||||
CryptoData cryptoData = extrasHolder.cryptoData;
|
||||
CryptoData cryptoData = Util.castNonNull(extrasHolder.cryptoData);
|
||||
buffer.cryptoInfo.set(
|
||||
subsampleCount,
|
||||
clearDataSizes,
|
||||
|
@ -104,7 +104,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowPrepareError() throws IOException {
|
||||
public void maybeThrowPrepareError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@ -394,7 +394,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() throws IOException, InterruptedException {
|
||||
public void load() throws IOException {
|
||||
// We always load from the beginning, so reset bytesRead to 0.
|
||||
dataSource.resetBytesRead();
|
||||
try {
|
||||
@ -415,7 +415,5 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
Util.closeQuietly(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -256,8 +256,8 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
|
||||
Format format,
|
||||
long durationUs,
|
||||
int minLoadableRetryCount,
|
||||
Handler eventHandler,
|
||||
EventListener eventListener,
|
||||
@Nullable Handler eventHandler,
|
||||
@Nullable EventListener eventListener,
|
||||
int eventSourceId,
|
||||
boolean treatLoadErrorsAsEndOfStream) {
|
||||
this(
|
||||
@ -313,7 +313,7 @@ public final class SingleSampleMediaSource extends BaseMediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void maybeThrowSourceInfoRefreshError() throws IOException {
|
||||
public void maybeThrowSourceInfoRefreshError() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user