Commit 0e331239 by tonihei Committed by Andrew Lewis

Turn on non-null-by-default for some core library packages.

And add missing some missing annotations to the publicly visible API of these
packages.

PiperOrigin-RevId: 263134804
parent 860aa2f9
Showing with 314 additions and 57 deletions
......@@ -24,6 +24,7 @@ import com.google.android.exoplayer2.decoder.SimpleOutputBuffer;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer;
import java.util.List;
......@@ -106,7 +107,7 @@ import java.util.List;
return new FfmpegDecoderException("Error resetting (see logcat).");
}
}
ByteBuffer inputData = inputBuffer.data;
ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
int inputSize = inputData.limit();
ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, outputBufferSize);
int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, outputBufferSize);
......@@ -132,8 +133,8 @@ import java.util.List;
}
hasOutputFormat = true;
}
outputBuffer.data.position(0);
outputBuffer.data.limit(result);
outputData.position(0);
outputData.limit(result);
return null;
}
......
......@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer;
import com.google.android.exoplayer2.util.FlacStreamMetadata;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
......@@ -101,7 +102,7 @@ import java.util.List;
if (reset) {
decoderJni.flush();
}
decoderJni.setData(inputBuffer.data);
decoderJni.setData(Util.castNonNull(inputBuffer.data));
ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, maxOutputBufferSize);
try {
decoderJni.decodeSample(outputData);
......
......@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.decoder.SimpleOutputBuffer;
import com.google.android.exoplayer2.drm.DecryptionException;
import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
......@@ -165,7 +166,7 @@ import java.util.List;
// any other time, skip number of samples as specified by seek preroll.
skipSamples = (inputBuffer.timeUs == 0) ? headerSkipSamples : headerSeekPreRollSamples;
}
ByteBuffer inputData = inputBuffer.data;
ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
int result = inputBuffer.isEncrypted()
? opusSecureDecode(nativeDecoderContext, inputBuffer.timeUs, inputData, inputData.limit(),
......@@ -185,7 +186,7 @@ import java.util.List;
}
}
ByteBuffer outputData = outputBuffer.data;
ByteBuffer outputData = Util.castNonNull(outputBuffer.data);
outputData.position(0);
outputData.limit(result);
if (skipSamples > 0) {
......
......@@ -22,6 +22,7 @@ import com.google.android.exoplayer2.decoder.CryptoInfo;
import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.drm.DecryptionException;
import com.google.android.exoplayer2.drm.ExoMediaCrypto;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoDecoderInputBuffer;
import java.nio.ByteBuffer;
......@@ -118,7 +119,7 @@ import java.nio.ByteBuffer;
@Nullable
protected VpxDecoderException decode(
VideoDecoderInputBuffer inputBuffer, VpxOutputBuffer outputBuffer, boolean reset) {
ByteBuffer inputData = inputBuffer.data;
ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
int inputSize = inputData.limit();
CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
final long result = inputBuffer.isEncrypted()
......
......@@ -65,6 +65,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
}
@Override
@Nullable
public MediaClock getMediaClock() {
return null;
}
......@@ -105,6 +106,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
}
@Override
@Nullable
public final SampleStream getStream() {
return stream;
}
......
......@@ -49,6 +49,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
}
@Override
@Nullable
public MediaClock getMediaClock() {
return null;
}
......@@ -113,6 +114,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
}
@Override
@Nullable
public final SampleStream getStream() {
return stream;
}
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.util.MediaClock;
import java.io.IOException;
......@@ -87,11 +88,12 @@ public interface Renderer extends PlayerMessage.Target {
/**
* If the renderer advances its own playback position then this method returns a corresponding
* {@link MediaClock}. If provided, the player will use the returned {@link MediaClock} as its
* source of time during playback. A player may have at most one renderer that returns a
* {@link MediaClock} from this method.
* source of time during playback. A player may have at most one renderer that returns a {@link
* MediaClock} from this method.
*
* @return The {@link MediaClock} tracking the playback position of the renderer, or null.
*/
@Nullable
MediaClock getMediaClock();
/**
......@@ -147,9 +149,8 @@ public interface Renderer extends PlayerMessage.Target {
void replaceStream(Format[] formats, SampleStream stream, long offsetUs)
throws ExoPlaybackException;
/**
* Returns the {@link SampleStream} being consumed, or null if the renderer is disabled.
*/
/** Returns the {@link SampleStream} being consumed, or null if the renderer is disabled. */
@Nullable
SampleStream getStream();
/**
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.analytics;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -156,7 +156,7 @@ public final class Ac3Util {
* @return The AC-3 format parsed from data in the header.
*/
public static Format parseAc3AnnexFFormat(
ParsableByteArray data, String trackId, String language, DrmInitData drmInitData) {
ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData) {
int fscod = (data.readUnsignedByte() & 0xC0) >> 6;
int sampleRate = SAMPLE_RATE_BY_FSCOD[fscod];
int nextByte = data.readUnsignedByte();
......@@ -189,7 +189,7 @@ public final class Ac3Util {
* @return The E-AC-3 format parsed from data in the header.
*/
public static Format parseEAc3AnnexFFormat(
ParsableByteArray data, String trackId, String language, DrmInitData drmInitData) {
ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData) {
data.skipBytes(2); // data_rate, num_ind_sub
// Read the first independent substream.
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.audio;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
......@@ -95,7 +96,7 @@ public final class Ac4Util {
* @return The AC-4 format parsed from data in the header.
*/
public static Format parseAc4AnnexEFormat(
ParsableByteArray data, String trackId, String language, DrmInitData drmInitData) {
ParsableByteArray data, String trackId, String language, @Nullable DrmInitData drmInitData) {
data.skipBytes(1); // ac4_dsi_version, bitstream_version[0:5]
int sampleRate = ((data.readUnsignedByte() & 0x20) >> 5 == 1) ? 48000 : 44100;
return Format.createAudioSampleFormat(
......
......@@ -92,7 +92,7 @@ public final class AudioAttributes {
public final @C.AudioFlags int flags;
public final @C.AudioUsage int usage;
private @Nullable android.media.AudioAttributes audioAttributesV21;
@Nullable private android.media.AudioAttributes audioAttributesV21;
private AudioAttributes(@C.AudioContentType int contentType, @C.AudioFlags int flags,
@C.AudioUsage int usage) {
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.audio;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.util.MimeTypes;
......@@ -80,7 +81,7 @@ public final class DtsUtil {
* @return The DTS format parsed from data in the header.
*/
public static Format parseDtsFormat(
byte[] frame, String trackId, String language, DrmInitData drmInitData) {
byte[] frame, String trackId, @Nullable String language, @Nullable DrmInitData drmInitData) {
ParsableBitArray frameBits = getNormalizedFrameHeader(frame);
frameBits.skipBits(32 + 1 + 5 + 1 + 7 + 14); // SYNC, FTYPE, SHORT, CPF, NBLKS, FSIZE
int amode = frameBits.readBits(6);
......
......@@ -300,8 +300,10 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, Format format)
protected int supportsFormat(
MediaCodecSelector mediaCodecSelector,
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
Format format)
throws DecoderQueryException {
String mimeType = format.sampleMimeType;
if (!MimeTypes.isAudio(mimeType)) {
......@@ -386,7 +388,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
MediaCodecInfo codecInfo,
MediaCodec codec,
Format format,
MediaCrypto crypto,
@Nullable MediaCrypto crypto,
float codecOperatingRate) {
codecMaxInputSize = getCodecMaxInputSize(codecInfo, format, getStreamFormats());
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.util.NonNullApi;
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.database;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.decoder;
import androidx.annotation.Nullable;
/**
* A media decoder.
*
......@@ -37,6 +39,7 @@ public interface Decoder<I, O, E extends Exception> {
* @return The input buffer, which will have been cleared, or null if a buffer isn't available.
* @throws E If a decoder error has occurred.
*/
@Nullable
I dequeueInputBuffer() throws E;
/**
......@@ -53,6 +56,7 @@ public interface Decoder<I, O, E extends Exception> {
* @return The output buffer, or null if an output buffer isn't available.
* @throws E If a decoder error has occurred.
*/
@Nullable
O dequeueOutputBuffer() throws E;
/**
......
......@@ -16,11 +16,13 @@
package com.google.android.exoplayer2.decoder;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.ByteBuffer;
import org.checkerframework.checker.nullness.qual.EnsuresNonNull;
/**
* Holds input for a decoder.
......@@ -58,10 +60,8 @@ public class DecoderInputBuffer extends Buffer {
*/
public final CryptoInfo cryptoInfo;
/**
* The buffer's data, or {@code null} if no data has been set.
*/
public ByteBuffer data;
/** The buffer's data, or {@code null} if no data has been set. */
@Nullable public ByteBuffer data;
/**
* The time at which the sample should be presented.
......@@ -101,6 +101,7 @@ public class DecoderInputBuffer extends Buffer {
* @throws IllegalStateException If there is insufficient capacity to accommodate the write and
* the buffer replacement mode of the holder is {@link #BUFFER_REPLACEMENT_MODE_DISABLED}.
*/
@EnsuresNonNull("data")
public void ensureSpaceForWrite(int length) {
if (data == null) {
data = createReplacementByteBuffer(length);
......
......@@ -86,6 +86,7 @@ public abstract class SimpleDecoder<
}
@Override
@Nullable
public final I dequeueInputBuffer() throws E {
synchronized (lock) {
maybeThrowException();
......@@ -108,6 +109,7 @@ public abstract class SimpleDecoder<
}
@Override
@Nullable
public final O dequeueOutputBuffer() throws E {
synchronized (lock) {
maybeThrowException();
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.decoder;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
......@@ -25,7 +26,7 @@ public class SimpleOutputBuffer extends OutputBuffer {
private final SimpleDecoder<?, SimpleOutputBuffer, ?> owner;
public ByteBuffer data;
@Nullable public ByteBuffer data;
public SimpleOutputBuffer(SimpleDecoder<?, SimpleOutputBuffer, ?> owner) {
this.owner = owner;
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.decoder;
import com.google.android.exoplayer2.util.NonNullApi;
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.drm;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -452,12 +452,14 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* @param mediaCodecSelector The decoder selector.
* @param drmSessionManager The renderer's {@link DrmSessionManager}.
* @param format The format.
* @return The extent to which the renderer is capable of supporting the given format. See
* {@link #supportsFormat(Format)} for more detail.
* @return The extent to which the renderer is capable of supporting the given format. See {@link
* #supportsFormat(Format)} for more detail.
* @throws DecoderQueryException If there was an error querying decoders.
*/
protected abstract int supportsFormat(MediaCodecSelector mediaCodecSelector,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, Format format)
protected abstract int supportsFormat(
MediaCodecSelector mediaCodecSelector,
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
Format format)
throws DecoderQueryException;
/**
......@@ -487,7 +489,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
MediaCodecInfo codecInfo,
MediaCodec codec,
Format format,
MediaCrypto crypto,
@Nullable MediaCrypto crypto,
float codecOperatingRate);
protected final void maybeInitCodec() throws ExoPlaybackException {
......
......@@ -239,6 +239,7 @@ public final class MediaCodecUtil {
* @return A pair (profile constant, level constant) if the codec of the {@code format} is
* well-formed and recognized, or null otherwise.
*/
@Nullable
public static Pair<Integer, Integer> getCodecProfileAndLevel(Format format) {
if (format.codecs == null) {
return null;
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.mediacodec;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -29,7 +29,7 @@ public final class EventMessageDecoder implements MetadataDecoder {
@SuppressWarnings("ByteBufferBackingArray")
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
byte[] data = buffer.array();
int size = buffer.limit();
return new Metadata(decode(new ParsableByteArray(data, size)));
......
......@@ -20,6 +20,7 @@ import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoder;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer;
......@@ -39,7 +40,7 @@ public final class IcyDecoder implements MetadataDecoder {
@Nullable
@SuppressWarnings("ByteBufferBackingArray")
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
byte[] data = buffer.array();
int length = buffer.limit();
return decode(Util.fromUtf8Bytes(data, 0, length));
......
......@@ -20,6 +20,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoder;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.ParsableBitArray;
import com.google.android.exoplayer2.util.ParsableByteArray;
......@@ -99,7 +100,7 @@ public final class Id3Decoder implements MetadataDecoder {
@Override
@Nullable
public Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
ByteBuffer buffer = Assertions.checkNotNull(inputBuffer.data);
return decode(buffer.array(), buffer.limit());
}
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2;
import com.google.android.exoplayer2.util.NonNullApi;
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.scheduler;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -220,9 +220,9 @@ public final class SilenceMediaSource extends BaseMediaSource {
int bytesToWrite = (int) Math.min(SILENCE_SAMPLE.length, bytesRemaining);
buffer.ensureSpaceForWrite(bytesToWrite);
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
buffer.data.put(SILENCE_SAMPLE, /* offset= */ 0, bytesToWrite);
buffer.timeUs = getAudioPositionUs(positionBytes);
buffer.addFlag(C.BUFFER_FLAG_KEY_FRAME);
positionBytes += bytesToWrite;
return C.RESULT_BUFFER_READ;
}
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.trackselection;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -15,7 +15,6 @@
*/
package com.google.android.exoplayer2.util;
import androidx.annotation.NonNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -189,12 +188,12 @@ public final class AtomicFile {
}
@Override
public void write(@NonNull byte[] b) throws IOException {
public void write(byte[] b) throws IOException {
fileOutputStream.write(b);
}
@Override
public void write(@NonNull byte[] b, int off, int len) throws IOException {
public void write(byte[] b, int off, int len) throws IOException {
fileOutputStream.write(b, off, len);
}
}
......
......@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.util;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.Nullable;
/**
* An interface to call through to a {@link Handler}. Instances must be created by calling {@link
......@@ -32,13 +33,13 @@ public interface HandlerWrapper {
Message obtainMessage(int what);
/** @see Handler#obtainMessage(int, Object) */
Message obtainMessage(int what, Object obj);
Message obtainMessage(int what, @Nullable Object obj);
/** @see Handler#obtainMessage(int, int, int) */
Message obtainMessage(int what, int arg1, int arg2);
/** @see Handler#obtainMessage(int, int, int, Object) */
Message obtainMessage(int what, int arg1, int arg2, Object obj);
Message obtainMessage(int what, int arg1, int arg2, @Nullable Object obj);
/** @see Handler#sendEmptyMessage(int) */
boolean sendEmptyMessage(int what);
......@@ -50,7 +51,7 @@ public interface HandlerWrapper {
void removeMessages(int what);
/** @see Handler#removeCallbacksAndMessages(Object) */
void removeCallbacksAndMessages(Object token);
void removeCallbacksAndMessages(@Nullable Object token);
/** @see Handler#post(Runnable) */
boolean post(Runnable runnable);
......
......@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.util;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.Nullable;
/** The standard implementation of {@link HandlerWrapper}. */
/* package */ final class SystemHandlerWrapper implements HandlerWrapper {
......@@ -38,7 +39,7 @@ import android.os.Message;
}
@Override
public Message obtainMessage(int what, Object obj) {
public Message obtainMessage(int what, @Nullable Object obj) {
return handler.obtainMessage(what, obj);
}
......@@ -48,7 +49,7 @@ import android.os.Message;
}
@Override
public Message obtainMessage(int what, int arg1, int arg2, Object obj) {
public Message obtainMessage(int what, int arg1, int arg2, @Nullable Object obj) {
return handler.obtainMessage(what, arg1, arg2, obj);
}
......@@ -68,7 +69,7 @@ import android.os.Message;
}
@Override
public void removeCallbacksAndMessages(Object token) {
public void removeCallbacksAndMessages(@Nullable Object token) {
handler.removeCallbacksAndMessages(token);
}
......
......@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.util;
import android.net.Uri;
import androidx.annotation.Nullable;
import android.text.TextUtils;
/**
......@@ -69,19 +70,19 @@ public final class UriUtil {
* @param baseUri The base URI.
* @param referenceUri The reference URI to resolve.
*/
public static Uri resolveToUri(String baseUri, String referenceUri) {
public static Uri resolveToUri(@Nullable String baseUri, @Nullable String referenceUri) {
return Uri.parse(resolve(baseUri, referenceUri));
}
/**
* Performs relative resolution of a {@code referenceUri} with respect to a {@code baseUri}.
* <p>
* The resolution is performed as specified by RFC-3986.
*
* <p>The resolution is performed as specified by RFC-3986.
*
* @param baseUri The base URI.
* @param referenceUri The reference URI to resolve.
*/
public static String resolve(String baseUri, String referenceUri) {
public static String resolve(@Nullable String baseUri, @Nullable String referenceUri) {
StringBuilder uri = new StringBuilder();
// Map null onto empty string, to make the following logic simpler.
......
......@@ -252,14 +252,14 @@ public final class Util {
/**
* Tests whether an {@code items} array contains an object equal to {@code item}, according to
* {@link Object#equals(Object)}.
* <p>
* If {@code item} is null then true is returned if and only if {@code items} contains null.
*
* <p>If {@code item} is null then true is returned if and only if {@code items} contains null.
*
* @param items The array of items to search.
* @param item The item to search for.
* @return True if the array contains an object equal to the item being searched for.
*/
public static boolean contains(Object[] items, Object item) {
public static boolean contains(@NullableType Object[] items, @Nullable Object item) {
for (Object arrayItem : items) {
if (areEqual(arrayItem, item)) {
return true;
......@@ -1486,7 +1486,7 @@ public final class Util {
* @return The content type.
*/
@C.ContentType
public static int inferContentType(Uri uri, String overrideExtension) {
public static int inferContentType(Uri uri, @Nullable String overrideExtension) {
return TextUtils.isEmpty(overrideExtension)
? inferContentType(uri)
: inferContentType("." + overrideExtension);
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.util;
......@@ -308,8 +308,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
}
@Override
protected int supportsFormat(MediaCodecSelector mediaCodecSelector,
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager, Format format)
protected int supportsFormat(
MediaCodecSelector mediaCodecSelector,
@Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
Format format)
throws DecoderQueryException {
String mimeType = format.sampleMimeType;
if (!MimeTypes.isVideo(mimeType)) {
......@@ -601,7 +603,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
MediaCodecInfo codecInfo,
MediaCodec codec,
Format format,
MediaCrypto crypto,
@Nullable MediaCrypto crypto,
float codecOperatingRate) {
String codecMimeType = codecInfo.codecMimeType;
codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
......
......@@ -544,9 +544,10 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer {
/**
* Dequeues output buffer.
*
* @return Dequeued video decoder output buffer.
* @return Dequeued video decoder output buffer, or null if an output buffer isn't available.
* @throws VideoDecoderException If an error occurs while dequeuing the output buffer.
*/
@Nullable
protected abstract VideoDecoderOutputBuffer dequeueOutputBuffer() throws VideoDecoderException;
/** Clears output buffer. */
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.video;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -93,7 +93,7 @@ public class CameraMotionRenderer extends BaseRenderer {
buffer.flip();
lastTimestampUs = buffer.timeUs;
if (listener != null) {
float[] rotation = parseMetadata(buffer.data);
float[] rotation = parseMetadata(Util.castNonNull(buffer.data));
if (rotation != null) {
Util.castNonNull(listener).onCameraMotion(lastTimestampUs - offsetUs, rotation);
}
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.video.spherical;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -115,9 +115,9 @@ import java.io.IOException;
byte[] serializedEvent = eventMessageEncoder.encode(eventStream.events[sampleIndex]);
if (serializedEvent != null) {
buffer.ensureSpaceForWrite(serializedEvent.length);
buffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
buffer.data.put(serializedEvent);
buffer.timeUs = eventTimesUs[sampleIndex];
buffer.setFlags(C.BUFFER_FLAG_KEY_FRAME);
return C.RESULT_BUFFER_READ;
} else {
return C.RESULT_NOTHING_READ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment