Skip to content

Commit

Permalink
Remove some more core classes from nullness blacklist
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 283366568
  • Loading branch information
ojw28 committed Dec 6, 2019
1 parent ab1d54d commit 9256632
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MediaClock;
import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

/**
* A {@link Renderer} implementation whose track type is {@link C#TRACK_TYPE_NONE} and does not
* consume data from its {@link SampleStream}.
*/
public abstract class NoSampleRenderer implements Renderer, RendererCapabilities {

private RendererConfiguration configuration;
@MonotonicNonNull private RendererConfiguration configuration;
private int index;
private int state;
private SampleStream stream;
@Nullable private SampleStream stream;
private boolean streamIsFinal;

@Override
Expand Down Expand Up @@ -285,8 +286,10 @@ protected void onReset() {
// Methods to be called by subclasses.

/**
* Returns the configuration set when the renderer was most recently enabled.
* Returns the configuration set when the renderer was most recently enabled, or {@code null} if
* the renderer has never been enabled.
*/
@Nullable
protected final RendererConfiguration getConfiguration() {
return configuration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.audio;

import static com.google.android.exoplayer2.util.Util.castNonNull;

import android.os.Handler;
import android.os.SystemClock;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -105,8 +107,8 @@ public EventDispatcher(@Nullable Handler handler,
* Invokes {@link AudioRendererEventListener#onAudioEnabled(DecoderCounters)}.
*/
public void enabled(final DecoderCounters decoderCounters) {
if (listener != null) {
handler.post(() -> listener.onAudioEnabled(decoderCounters));
if (handler != null) {
handler.post(() -> castNonNull(listener).onAudioEnabled(decoderCounters));
}
}

Expand All @@ -115,20 +117,21 @@ public void enabled(final DecoderCounters decoderCounters) {
*/
public void decoderInitialized(final String decoderName,
final long initializedTimestampMs, final long initializationDurationMs) {
if (listener != null) {
if (handler != null) {
handler.post(
() ->
listener.onAudioDecoderInitialized(
decoderName, initializedTimestampMs, initializationDurationMs));
castNonNull(listener)
.onAudioDecoderInitialized(
decoderName, initializedTimestampMs, initializationDurationMs));
}
}

/**
* Invokes {@link AudioRendererEventListener#onAudioInputFormatChanged(Format)}.
*/
public void inputFormatChanged(final Format format) {
if (listener != null) {
handler.post(() -> listener.onAudioInputFormatChanged(format));
if (handler != null) {
handler.post(() -> castNonNull(listener).onAudioInputFormatChanged(format));
}
}

Expand All @@ -137,9 +140,11 @@ public void inputFormatChanged(final Format format) {
*/
public void audioTrackUnderrun(final int bufferSize, final long bufferSizeMs,
final long elapsedSinceLastFeedMs) {
if (listener != null) {
if (handler != null) {
handler.post(
() -> listener.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs));
() ->
castNonNull(listener)
.onAudioSinkUnderrun(bufferSize, bufferSizeMs, elapsedSinceLastFeedMs));
}
}

Expand All @@ -148,11 +153,11 @@ public void audioTrackUnderrun(final int bufferSize, final long bufferSizeMs,
*/
public void disabled(final DecoderCounters counters) {
counters.ensureUpdated();
if (listener != null) {
if (handler != null) {
handler.post(
() -> {
counters.ensureUpdated();
listener.onAudioDisabled(counters);
castNonNull(listener).onAudioDisabled(counters);
});
}
}
Expand All @@ -161,11 +166,9 @@ public void disabled(final DecoderCounters counters) {
* Invokes {@link AudioRendererEventListener#onAudioSessionId(int)}.
*/
public void audioSessionId(final int audioSessionId) {
if (listener != null) {
handler.post(() -> listener.onAudioSessionId(audioSessionId));
if (handler != null) {
handler.post(() -> castNonNull(listener).onAudioSessionId(audioSessionId));
}
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.MimeTypes;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* An MPEG audio frame header.
Expand Down Expand Up @@ -195,7 +196,7 @@ public static boolean populateHeader(int headerData, MpegAudioHeader header) {
/** MPEG audio header version. */
public int version;
/** The mime type. */
public String mimeType;
@Nullable public String mimeType;
/** Size of the frame associated with this header, in bytes. */
public int frameSize;
/** Sample rate in samples per second. */
Expand Down Expand Up @@ -223,5 +224,4 @@ private void setValues(
this.bitrate = bitrate;
this.samplesPerFrame = samplesPerFrame;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.extractor.wav;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.audio.WavUtil;
Expand All @@ -39,6 +40,7 @@
* @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
* supported WAV format.
*/
@Nullable
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
Assertions.checkNotNull(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.metadata;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.metadata.emsg.EventMessageDecoder;
import com.google.android.exoplayer2.metadata.icy.IcyDecoder;
Expand Down Expand Up @@ -62,7 +63,7 @@ public interface MetadataDecoderFactory {

@Override
public boolean supportsFormat(Format format) {
String mimeType = format.sampleMimeType;
@Nullable String mimeType = format.sampleMimeType;
return MimeTypes.APPLICATION_ID3.equals(mimeType)
|| MimeTypes.APPLICATION_EMSG.equals(mimeType)
|| MimeTypes.APPLICATION_SCTE35.equals(mimeType)
Expand All @@ -71,19 +72,23 @@ public boolean supportsFormat(Format format) {

@Override
public MetadataDecoder createDecoder(Format format) {
switch (format.sampleMimeType) {
case MimeTypes.APPLICATION_ID3:
return new Id3Decoder();
case MimeTypes.APPLICATION_EMSG:
return new EventMessageDecoder();
case MimeTypes.APPLICATION_SCTE35:
return new SpliceInfoDecoder();
case MimeTypes.APPLICATION_ICY:
return new IcyDecoder();
default:
throw new IllegalArgumentException(
"Attempted to create decoder for unsupported format");
@Nullable String mimeType = format.sampleMimeType;
if (mimeType != null) {
switch (mimeType) {
case MimeTypes.APPLICATION_ID3:
return new Id3Decoder();
case MimeTypes.APPLICATION_EMSG:
return new EventMessageDecoder();
case MimeTypes.APPLICATION_SCTE35:
return new SpliceInfoDecoder();
case MimeTypes.APPLICATION_ICY:
return new IcyDecoder();
default:
break;
}
}
throw new IllegalArgumentException(
"Attempted to create decoder for unsupported MIME type: " + mimeType);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.text;

import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.text.cea.Cea608Decoder;
import com.google.android.exoplayer2.text.cea.Cea708Decoder;
Expand Down Expand Up @@ -74,7 +75,7 @@ public interface SubtitleDecoderFactory {

@Override
public boolean supportsFormat(Format format) {
String mimeType = format.sampleMimeType;
@Nullable String mimeType = format.sampleMimeType;
return MimeTypes.TEXT_VTT.equals(mimeType)
|| MimeTypes.TEXT_SSA.equals(mimeType)
|| MimeTypes.APPLICATION_TTML.equals(mimeType)
Expand All @@ -90,32 +91,36 @@ public boolean supportsFormat(Format format) {

@Override
public SubtitleDecoder createDecoder(Format format) {
switch (format.sampleMimeType) {
case MimeTypes.TEXT_VTT:
return new WebvttDecoder();
case MimeTypes.TEXT_SSA:
return new SsaDecoder(format.initializationData);
case MimeTypes.APPLICATION_MP4VTT:
return new Mp4WebvttDecoder();
case MimeTypes.APPLICATION_TTML:
return new TtmlDecoder();
case MimeTypes.APPLICATION_SUBRIP:
return new SubripDecoder();
case MimeTypes.APPLICATION_TX3G:
return new Tx3gDecoder(format.initializationData);
case MimeTypes.APPLICATION_CEA608:
case MimeTypes.APPLICATION_MP4CEA608:
return new Cea608Decoder(format.sampleMimeType, format.accessibilityChannel);
case MimeTypes.APPLICATION_CEA708:
return new Cea708Decoder(format.accessibilityChannel, format.initializationData);
case MimeTypes.APPLICATION_DVBSUBS:
return new DvbDecoder(format.initializationData);
case MimeTypes.APPLICATION_PGS:
return new PgsDecoder();
default:
throw new IllegalArgumentException(
"Attempted to create decoder for unsupported format");
@Nullable String mimeType = format.sampleMimeType;
if (mimeType != null) {
switch (mimeType) {
case MimeTypes.TEXT_VTT:
return new WebvttDecoder();
case MimeTypes.TEXT_SSA:
return new SsaDecoder(format.initializationData);
case MimeTypes.APPLICATION_MP4VTT:
return new Mp4WebvttDecoder();
case MimeTypes.APPLICATION_TTML:
return new TtmlDecoder();
case MimeTypes.APPLICATION_SUBRIP:
return new SubripDecoder();
case MimeTypes.APPLICATION_TX3G:
return new Tx3gDecoder(format.initializationData);
case MimeTypes.APPLICATION_CEA608:
case MimeTypes.APPLICATION_MP4CEA608:
return new Cea608Decoder(mimeType, format.accessibilityChannel);
case MimeTypes.APPLICATION_CEA708:
return new Cea708Decoder(format.accessibilityChannel, format.initializationData);
case MimeTypes.APPLICATION_DVBSUBS:
return new DvbDecoder(format.initializationData);
case MimeTypes.APPLICATION_PGS:
return new PgsDecoder();
default:
break;
}
}
throw new IllegalArgumentException(
"Attempted to create decoder for unsupported MIME type: " + mimeType);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public boolean isRetry() {

private final ExecutorService downloadExecutorService;

private LoadTask<? extends Loadable> currentTask;
private IOException fatalError;
@Nullable private LoadTask<? extends Loadable> currentTask;
@Nullable private IOException fatalError;

/**
* @param threadName A name for the loader's thread.
Expand Down Expand Up @@ -242,39 +242,34 @@ public void clearFatalError() {
*/
public <T extends Loadable> long startLoading(
T loadable, Callback<T> callback, int defaultMinRetryCount) {
Looper looper = Looper.myLooper();
Assertions.checkState(looper != null);
Looper looper = Assertions.checkStateNotNull(Looper.myLooper());
fatalError = null;
long startTimeMs = SystemClock.elapsedRealtime();
new LoadTask<>(looper, loadable, callback, defaultMinRetryCount, startTimeMs).start(0);
return startTimeMs;
}

/**
* Returns whether the {@link Loader} is currently loading a {@link Loadable}.
*/
/** Returns whether the loader is currently loading. */
public boolean isLoading() {
return currentTask != null;
}

/**
* Cancels the current load. This method should only be called when a load is in progress.
* Cancels the current load.
*
* @throws IllegalStateException If the loader is not currently loading.
*/
public void cancelLoading() {
currentTask.cancel(false);
Assertions.checkStateNotNull(currentTask).cancel(false);
}

/**
* Releases the {@link Loader}. This method should be called when the {@link Loader} is no longer
* required.
*/
/** Releases the loader. This method should be called when the loader is no longer required. */
public void release() {
release(null);
}

/**
* Releases the {@link Loader}. This method should be called when the {@link Loader} is no longer
* required.
* Releases the loader. This method should be called when the loader is no longer required.
*
* @param callback An optional callback to be called on the loading thread once the loader has
* been released.
Expand Down Expand Up @@ -325,10 +320,10 @@ private final class LoadTask<T extends Loadable> extends Handler implements Runn
private final long startTimeMs;

@Nullable private Loader.Callback<T> callback;
private IOException currentError;
@Nullable private IOException currentError;
private int errorCount;

private volatile Thread executorThread;
@Nullable private volatile Thread executorThread;
private volatile boolean canceled;
private volatile boolean released;

Expand Down Expand Up @@ -368,14 +363,16 @@ public void cancel(boolean released) {
} else {
canceled = true;
loadable.cancelLoad();
Thread executorThread = this.executorThread;
if (executorThread != null) {
executorThread.interrupt();
}
}
if (released) {
finish();
long nowMs = SystemClock.elapsedRealtime();
callback.onLoadCanceled(loadable, nowMs, nowMs - startTimeMs, true);
Assertions.checkNotNull(callback)
.onLoadCanceled(loadable, nowMs, nowMs - startTimeMs, true);
// If loading, this task will be referenced from a GC root (the loading thread) until
// cancellation completes. The time taken for cancellation to complete depends on the
// implementation of the Loadable that the task is loading. We null the callback reference
Expand Down Expand Up @@ -450,6 +447,7 @@ public void handleMessage(Message msg) {
finish();
long nowMs = SystemClock.elapsedRealtime();
long durationMs = nowMs - startTimeMs;
Loader.Callback<T> callback = Assertions.checkNotNull(this.callback);
if (canceled) {
callback.onLoadCanceled(loadable, nowMs, durationMs, false);
return;
Expand Down Expand Up @@ -492,7 +490,7 @@ public void handleMessage(Message msg) {

private void execute() {
currentError = null;
downloadExecutorService.execute(currentTask);
downloadExecutorService.execute(Assertions.checkNotNull(currentTask));
}

private void finish() {
Expand Down
Loading

0 comments on commit 9256632

Please sign in to comment.