From bdadd572e2d77c95e767123e5277760fff0c30cf Mon Sep 17 00:00:00 2001 From: ibaker Date: Wed, 22 Jul 2020 17:05:20 +0100 Subject: [PATCH] Enable nullness checks for more easy files PiperOrigin-RevId: 322586013 --- .../google/android/exoplayer2/DefaultLoadControl.java | 3 ++- .../android/exoplayer2/mediacodec/MediaCodecInfo.java | 7 +++++-- .../android/exoplayer2/upstream/DefaultAllocator.java | 9 +++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java index 5cbe394f1d..3d3b22b570 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2; +import androidx.annotation.Nullable; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.upstream.Allocator; @@ -94,7 +95,7 @@ public class DefaultLoadControl implements LoadControl { /** Builder for {@link DefaultLoadControl}. */ public static final class Builder { - private DefaultAllocator allocator; + @Nullable private DefaultAllocator allocator; private int minBufferMs; private int maxBufferMs; private int bufferForPlaybackMs; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java index 736f941152..404066e96d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java @@ -328,7 +328,7 @@ public final class MediaCodecInfo { public boolean isSeamlessAdaptationSupported( Format oldFormat, Format newFormat, boolean isNewFormatComplete) { if (isVideo) { - return oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) + return Assertions.checkNotNull(oldFormat.sampleMimeType).equals(newFormat.sampleMimeType) && oldFormat.rotationDegrees == newFormat.rotationDegrees && (adaptive || (oldFormat.width == newFormat.width && oldFormat.height == newFormat.height)) @@ -336,14 +336,16 @@ public final class MediaCodecInfo { || Util.areEqual(oldFormat.colorInfo, newFormat.colorInfo)); } else { if (!MimeTypes.AUDIO_AAC.equals(mimeType) - || !oldFormat.sampleMimeType.equals(newFormat.sampleMimeType) + || !Assertions.checkNotNull(oldFormat.sampleMimeType).equals(newFormat.sampleMimeType) || oldFormat.channelCount != newFormat.channelCount || oldFormat.sampleRate != newFormat.sampleRate) { return false; } // Check the codec profile levels support adaptation. + @Nullable Pair oldCodecProfileLevel = MediaCodecUtil.getCodecProfileAndLevel(oldFormat); + @Nullable Pair newCodecProfileLevel = MediaCodecUtil.getCodecProfileAndLevel(newFormat); if (oldCodecProfileLevel == null || newCodecProfileLevel == null) { @@ -402,6 +404,7 @@ public final class MediaCodecInfo { * the {@link MediaCodec}'s width and height alignment requirements, or null if not a video * codec. */ + @Nullable @RequiresApi(21) public Point alignVideoSizeV21(int width, int height) { if (capabilities == null) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java index ca9cca255d..5a2ad765d9 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/DefaultAllocator.java @@ -19,6 +19,7 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Util; import java.util.Arrays; +import org.checkerframework.checker.nullness.compatqual.NullableType; /** * Default implementation of {@link Allocator}. @@ -35,7 +36,7 @@ public final class DefaultAllocator implements Allocator { private int targetBufferSize; private int allocatedCount; private int availableCount; - private Allocation[] availableAllocations; + @NullableType private Allocation[] availableAllocations; /** * Constructs an instance without creating any {@link Allocation}s up front. @@ -97,7 +98,7 @@ public final class DefaultAllocator implements Allocator { allocatedCount++; Allocation allocation; if (availableCount > 0) { - allocation = availableAllocations[--availableCount]; + allocation = Assertions.checkNotNull(availableAllocations[--availableCount]); availableAllocations[availableCount] = null; } else { allocation = new Allocation(new byte[individualAllocationSize], 0); @@ -141,11 +142,11 @@ public final class DefaultAllocator implements Allocator { int lowIndex = 0; int highIndex = availableCount - 1; while (lowIndex <= highIndex) { - Allocation lowAllocation = availableAllocations[lowIndex]; + Allocation lowAllocation = Assertions.checkNotNull(availableAllocations[lowIndex]); if (lowAllocation.data == initialAllocationBlock) { lowIndex++; } else { - Allocation highAllocation = availableAllocations[highIndex]; + Allocation highAllocation = Assertions.checkNotNull(availableAllocations[highIndex]); if (highAllocation.data != initialAllocationBlock) { highIndex--; } else {