Remove more classes from nullness blacklist

PiperOrigin-RevId: 256202135
This commit is contained in:
olly 2019-07-02 19:15:08 +01:00 committed by Toni
parent 7408b4355a
commit 7964e51e0e
9 changed files with 47 additions and 29 deletions

View File

@ -20,6 +20,7 @@ import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.cast.framework.CastOptions; import com.google.android.gms.cast.framework.CastOptions;
import com.google.android.gms.cast.framework.OptionsProvider; import com.google.android.gms.cast.framework.OptionsProvider;
import com.google.android.gms.cast.framework.SessionProvider; import com.google.android.gms.cast.framework.SessionProvider;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -58,7 +59,7 @@ public final class DefaultCastOptionsProvider implements OptionsProvider {
@Override @Override
public List<SessionProvider> getAdditionalSessionProviders(Context context) { public List<SessionProvider> getAdditionalSessionProviders(Context context) {
return null; return Collections.emptyList();
} }
} }

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.flac; package com.google.android.exoplayer2.ext.flac;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
@ -94,6 +95,7 @@ import java.util.List;
} }
@Override @Override
@Nullable
protected FlacDecoderException decode( protected FlacDecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {

View File

@ -15,9 +15,11 @@
*/ */
package com.google.android.exoplayer2.ext.flac; package com.google.android.exoplayer2.ext.flac;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.ExtractorInput; import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.util.FlacStreamInfo; import com.google.android.exoplayer2.util.FlacStreamInfo;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -37,15 +39,16 @@ import java.nio.ByteBuffer;
} }
} }
private static final int TEMP_BUFFER_SIZE = 8192; // The same buffer size which libflac has private static final int TEMP_BUFFER_SIZE = 8192; // The same buffer size as libflac.
private final long nativeDecoderContext; private final long nativeDecoderContext;
private ByteBuffer byteBufferData; @Nullable private ByteBuffer byteBufferData;
private ExtractorInput extractorInput; @Nullable private ExtractorInput extractorInput;
@Nullable private byte[] tempBuffer;
private boolean endOfExtractorInput; private boolean endOfExtractorInput;
private byte[] tempBuffer;
@SuppressWarnings("nullness:method.invocation.invalid")
public FlacDecoderJni() throws FlacDecoderException { public FlacDecoderJni() throws FlacDecoderException {
if (!FlacLibrary.isAvailable()) { if (!FlacLibrary.isAvailable()) {
throw new FlacDecoderException("Failed to load decoder native libraries."); throw new FlacDecoderException("Failed to load decoder native libraries.");
@ -58,7 +61,8 @@ import java.nio.ByteBuffer;
/** /**
* Sets data to be parsed by libflac. * Sets data to be parsed by libflac.
* @param byteBufferData Source {@link ByteBuffer} *
* @param byteBufferData Source {@link ByteBuffer}.
*/ */
public void setData(ByteBuffer byteBufferData) { public void setData(ByteBuffer byteBufferData) {
this.byteBufferData = byteBufferData; this.byteBufferData = byteBufferData;
@ -68,7 +72,8 @@ import java.nio.ByteBuffer;
/** /**
* Sets data to be parsed by libflac. * Sets data to be parsed by libflac.
* @param extractorInput Source {@link ExtractorInput} *
* @param extractorInput Source {@link ExtractorInput}.
*/ */
public void setData(ExtractorInput extractorInput) { public void setData(ExtractorInput extractorInput) {
this.byteBufferData = null; this.byteBufferData = null;
@ -90,15 +95,15 @@ import java.nio.ByteBuffer;
/** /**
* Reads up to {@code length} bytes from the data source. * Reads up to {@code length} bytes from the data source.
* <p> *
* This method blocks until at least one byte of data can be read, the end of the input is * <p>This method blocks until at least one byte of data can be read, the end of the input is
* detected or an exception is thrown. * detected or an exception is thrown.
* <p> *
* This method is called from the native code. * <p>This method is called from the native code.
* *
* @param target A target {@link ByteBuffer} into which data should be written. * @param target A target {@link ByteBuffer} into which data should be written.
* @return Returns the number of bytes read, or -1 on failure. It's not an error if this returns * @return Returns the number of bytes read, or -1 on failure. If all of the data has already been
* zero; it just means all the data read from the source. * read from the source, then 0 is returned.
*/ */
public int read(ByteBuffer target) throws IOException, InterruptedException { public int read(ByteBuffer target) throws IOException, InterruptedException {
int byteCount = target.remaining(); int byteCount = target.remaining();
@ -106,18 +111,20 @@ import java.nio.ByteBuffer;
byteCount = Math.min(byteCount, byteBufferData.remaining()); byteCount = Math.min(byteCount, byteBufferData.remaining());
int originalLimit = byteBufferData.limit(); int originalLimit = byteBufferData.limit();
byteBufferData.limit(byteBufferData.position() + byteCount); byteBufferData.limit(byteBufferData.position() + byteCount);
target.put(byteBufferData); target.put(byteBufferData);
byteBufferData.limit(originalLimit); byteBufferData.limit(originalLimit);
} else if (extractorInput != null) { } else if (extractorInput != null) {
ExtractorInput extractorInput = this.extractorInput;
byte[] tempBuffer = Util.castNonNull(this.tempBuffer);
byteCount = Math.min(byteCount, TEMP_BUFFER_SIZE); byteCount = Math.min(byteCount, TEMP_BUFFER_SIZE);
int read = readFromExtractorInput(0, byteCount); int read = readFromExtractorInput(extractorInput, tempBuffer, /* offset= */ 0, byteCount);
if (read < 4) { if (read < 4) {
// Reading less than 4 bytes, most of the time, happens because of getting the bytes left in // Reading less than 4 bytes, most of the time, happens because of getting the bytes left in
// the buffer of the input. Do another read to reduce the number of calls to this method // the buffer of the input. Do another read to reduce the number of calls to this method
// from the native code. // from the native code.
read += readFromExtractorInput(read, byteCount - read); read +=
readFromExtractorInput(
extractorInput, tempBuffer, read, /* length= */ byteCount - read);
} }
byteCount = read; byteCount = read;
target.put(tempBuffer, 0, byteCount); target.put(tempBuffer, 0, byteCount);
@ -234,7 +241,8 @@ import java.nio.ByteBuffer;
flacRelease(nativeDecoderContext); flacRelease(nativeDecoderContext);
} }
private int readFromExtractorInput(int offset, int length) private int readFromExtractorInput(
ExtractorInput extractorInput, byte[] tempBuffer, int offset, int length)
throws IOException, InterruptedException { throws IOException, InterruptedException {
int read = extractorInput.read(tempBuffer, offset, length); int read = extractorInput.read(tempBuffer, offset, length);
if (read == C.RESULT_END_OF_INPUT) { if (read == C.RESULT_END_OF_INPUT) {

View File

@ -39,6 +39,7 @@ android {
dependencies { dependencies {
implementation project(modulePrefix + 'library-core') implementation project(modulePrefix + 'library-core')
implementation 'androidx.annotation:annotation:1.0.2'
testImplementation project(modulePrefix + 'testutils-robolectric') testImplementation project(modulePrefix + 'testutils-robolectric')
androidTestImplementation 'androidx.test:runner:' + androidXTestVersion androidTestImplementation 'androidx.test:runner:' + androidXTestVersion
androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion androidTestImplementation 'androidx.test.ext:junit:' + androidXTestVersion

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.opus; package com.google.android.exoplayer2.ext.opus;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
@ -150,6 +151,7 @@ import java.util.List;
} }
@Override @Override
@Nullable
protected OpusDecoderException decode( protected OpusDecoderException decode(
DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) { DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
if (reset) { if (reset) {

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.opus; package com.google.android.exoplayer2.ext.opus;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.util.LibraryLoader; import com.google.android.exoplayer2.util.LibraryLoader;
@ -30,7 +31,7 @@ public final class OpusLibrary {
} }
private static final LibraryLoader LOADER = new LibraryLoader("opusV2JNI"); private static final LibraryLoader LOADER = new LibraryLoader("opusV2JNI");
private static Class<? extends ExoMediaCrypto> exoMediaCryptoType; @Nullable private static Class<? extends ExoMediaCrypto> exoMediaCryptoType;
private OpusLibrary() {} private OpusLibrary() {}
@ -56,9 +57,8 @@ public final class OpusLibrary {
return LOADER.isAvailable(); return LOADER.isAvailable();
} }
/** /** Returns the version of the underlying library if available, or null otherwise. */
* Returns the version of the underlying library if available, or null otherwise. @Nullable
*/
public static String getVersion() { public static String getVersion() {
return isAvailable() ? opusGetVersion() : null; return isAvailable() ? opusGetVersion() : null;
} }

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.vp9; package com.google.android.exoplayer2.ext.vp9;
import androidx.annotation.Nullable;
import android.view.Surface; import android.view.Surface;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.CryptoInfo; import com.google.android.exoplayer2.decoder.CryptoInfo;
@ -120,8 +121,9 @@ import java.nio.ByteBuffer;
} }
@Override @Override
protected VpxDecoderException decode(VpxInputBuffer inputBuffer, VpxOutputBuffer outputBuffer, @Nullable
boolean reset) { protected VpxDecoderException decode(
VpxInputBuffer inputBuffer, VpxOutputBuffer outputBuffer, boolean reset) {
ByteBuffer inputData = inputBuffer.data; ByteBuffer inputData = inputBuffer.data;
int inputSize = inputData.limit(); int inputSize = inputData.limit();
CryptoInfo cryptoInfo = inputBuffer.cryptoInfo; CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;

View File

@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.ext.vp9; package com.google.android.exoplayer2.ext.vp9;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayerLibraryInfo; import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.drm.ExoMediaCrypto; import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.util.LibraryLoader; import com.google.android.exoplayer2.util.LibraryLoader;
@ -30,7 +31,7 @@ public final class VpxLibrary {
} }
private static final LibraryLoader LOADER = new LibraryLoader("vpx", "vpxV2JNI"); private static final LibraryLoader LOADER = new LibraryLoader("vpx", "vpxV2JNI");
private static Class<? extends ExoMediaCrypto> exoMediaCryptoType; @Nullable private static Class<? extends ExoMediaCrypto> exoMediaCryptoType;
private VpxLibrary() {} private VpxLibrary() {}
@ -56,9 +57,8 @@ public final class VpxLibrary {
return LOADER.isAvailable(); return LOADER.isAvailable();
} }
/** /** Returns the version of the underlying library if available, or null otherwise. */
* Returns the version of the underlying library if available, or null otherwise. @Nullable
*/
public static String getVersion() { public static String getVersion() {
return isAvailable() ? vpxGetVersion() : null; return isAvailable() ? vpxGetVersion() : null;
} }
@ -67,6 +67,7 @@ public final class VpxLibrary {
* Returns the configuration string with which the underlying library was built if available, or * Returns the configuration string with which the underlying library was built if available, or
* null otherwise. * null otherwise.
*/ */
@Nullable
public static String getBuildConfig() { public static String getBuildConfig() {
return isAvailable() ? vpxGetBuildConfig() : null; return isAvailable() ? vpxGetBuildConfig() : null;
} }

View File

@ -301,5 +301,6 @@ public abstract class SimpleDecoder<
* @param reset Whether the decoder must be reset before decoding. * @param reset Whether the decoder must be reset before decoding.
* @return A decoder exception if an error occurred, or null if decoding was successful. * @return A decoder exception if an error occurred, or null if decoding was successful.
*/ */
protected abstract @Nullable E decode(I inputBuffer, O outputBuffer, boolean reset); @Nullable
protected abstract E decode(I inputBuffer, O outputBuffer, boolean reset);
} }