Fix HLS module API nullability issues and add package-level non-null-by-default

PiperOrigin-RevId: 262124441
This commit is contained in:
tonihei 2019-08-07 14:42:47 +01:00 committed by Oliver Woodman
parent 074b6f8ebd
commit 58d4fd93dd
14 changed files with 90 additions and 25 deletions

View File

@ -41,6 +41,7 @@ android {
dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
implementation project(modulePrefix + 'library-core')
testImplementation project(modulePrefix + 'testutils-robolectric')
}

View File

@ -105,7 +105,8 @@ import javax.crypto.spec.SecretKeySpec;
}
@Override
public final @Nullable Uri getUri() {
@Nullable
public final Uri getUri() {
return upstream.getUri();
}

View File

@ -84,11 +84,11 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
@Override
public Result createExtractor(
Extractor previousExtractor,
@Nullable Extractor previousExtractor,
Uri uri,
Format format,
List<Format> muxedCaptionFormats,
DrmInitData drmInitData,
@Nullable List<Format> muxedCaptionFormats,
@Nullable DrmInitData drmInitData,
TimestampAdjuster timestampAdjuster,
Map<String, List<String>> responseHeaders,
ExtractorInput extractorInput)

View File

@ -59,10 +59,8 @@ import java.util.Map;
clear();
}
/**
* The chunk to be loaded next.
*/
public Chunk chunk;
/** The chunk to be loaded next. */
@Nullable public Chunk chunk;
/**
* Indicates that the end of the stream has been reached.
@ -70,7 +68,7 @@ import java.util.Map;
public boolean endOfStream;
/** Indicates that the chunk source is waiting for the referred playlist to be refreshed. */
public Uri playlistUrl;
@Nullable public Uri playlistUrl;
/**
* Clears the holder.
@ -138,7 +136,7 @@ import java.util.Map;
HlsDataSourceFactory dataSourceFactory,
@Nullable TransferListener mediaTransferListener,
TimestampAdjusterProvider timestampAdjusterProvider,
List<Format> muxedCaptionFormats) {
@Nullable List<Format> muxedCaptionFormats) {
this.extractorFactory = extractorFactory;
this.playlistTracker = playlistTracker;
this.playlistUrls = playlistUrls;

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.hls;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.extractor.Extractor;
@ -82,11 +83,11 @@ public interface HlsExtractorFactory {
* @throws IOException If an I/O error is encountered while sniffing.
*/
Result createExtractor(
Extractor previousExtractor,
@Nullable Extractor previousExtractor,
Uri uri,
Format format,
List<Format> muxedCaptionFormats,
DrmInitData drmInitData,
@Nullable List<Format> muxedCaptionFormats,
@Nullable DrmInitData drmInitData,
TimestampAdjuster timestampAdjuster,
Map<String, List<String>> responseHeaders,
ExtractorInput sniffingExtractorInput)

View File

@ -54,6 +54,7 @@ import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/**
* A {@link MediaPeriod} that loads an HLS stream.
@ -249,8 +250,12 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
}
@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
public long selectTracks(
@NullableType TrackSelection[] selections,
boolean[] mayRetainStreamFlags,
@NullableType SampleStream[] streams,
boolean[] streamResetFlags,
long positionUs) {
// Map each selection and stream onto a child period index.
int[] streamChildIndices = new int[selections.length];
int[] selectionChildIndices = new int[selections.length];

View File

@ -110,7 +110,7 @@ public final class HlsMediaSource extends BaseMediaSource
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
public Factory setTag(Object tag) {
public Factory setTag(@Nullable Object tag) {
Assertions.checkState(!isCreateCalled);
this.tag = tag;
return this;

View File

@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.source.hls;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
@ -49,7 +50,7 @@ public final class WebvttExtractor implements Extractor {
private static final int HEADER_MIN_LENGTH = 6 /* "WEBVTT" */;
private static final int HEADER_MAX_LENGTH = 3 /* optional Byte Order Mark */ + HEADER_MIN_LENGTH;
private final String language;
@Nullable private final String language;
private final TimestampAdjuster timestampAdjuster;
private final ParsableByteArray sampleDataWrapper;
@ -58,7 +59,7 @@ public final class WebvttExtractor implements Extractor {
private byte[] sampleData;
private int sampleSize;
public WebvttExtractor(String language, TimestampAdjuster timestampAdjuster) {
public WebvttExtractor(@Nullable String language, TimestampAdjuster timestampAdjuster) {
this.language = language;
this.timestampAdjuster = timestampAdjuster;
this.sampleDataWrapper = new ParsableByteArray();

View File

@ -0,0 +1,19 @@
/*
* 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.source.hls.offline;
import com.google.android.exoplayer2.util.NonNullApi;

View File

@ -0,0 +1,19 @@
/*
* 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.source.hls;
import com.google.android.exoplayer2.util.NonNullApi;

View File

@ -172,6 +172,7 @@ public final class DefaultHlsPlaylistTracker
}
@Override
@Nullable
public HlsMediaPlaylist getPlaylistSnapshot(Uri url, boolean isForPlayback) {
HlsMediaPlaylist snapshot = playlistBundles.get(url).getPlaylistSnapshot();
if (snapshot != null && isForPlayback) {
@ -448,7 +449,7 @@ public final class DefaultHlsPlaylistTracker
private final Loader mediaPlaylistLoader;
private final ParsingLoadable<HlsPlaylist> mediaPlaylistLoadable;
private HlsMediaPlaylist playlistSnapshot;
@Nullable private HlsMediaPlaylist playlistSnapshot;
private long lastSnapshotLoadMs;
private long lastSnapshotChangeMs;
private long earliestNextLoadTimeMs;
@ -467,6 +468,7 @@ public final class DefaultHlsPlaylistTracker
mediaPlaylistParser);
}
@Nullable
public HlsMediaPlaylist getPlaylistSnapshot() {
return playlistSnapshot;
}

View File

@ -174,7 +174,7 @@ public final class HlsMasterPlaylist extends HlsPlaylist {
* The format of the audio muxed in the variants. May be null if the playlist does not declare any
* muxed audio.
*/
public final Format muxedAudioFormat;
@Nullable public final Format muxedAudioFormat;
/**
* The format of the closed captions declared by the playlist. May be empty if the playlist
* explicitly declares no captions are available, or null if the playlist does not declare any
@ -208,7 +208,7 @@ public final class HlsMasterPlaylist extends HlsPlaylist {
List<Rendition> audios,
List<Rendition> subtitles,
List<Rendition> closedCaptions,
Format muxedAudioFormat,
@Nullable Format muxedAudioFormat,
List<Format> muxedCaptionFormats,
boolean hasIndependentSegments,
Map<String, String> variableDefinitions,

View File

@ -16,7 +16,6 @@
package com.google.android.exoplayer2.source.hls.playlist;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmInitData;
@ -95,8 +94,8 @@ public final class HlsMediaPlaylist extends HlsPlaylist {
String uri,
long byterangeOffset,
long byterangeLength,
String fullSegmentEncryptionKeyUri,
String encryptionIV) {
@Nullable String fullSegmentEncryptionKeyUri,
@Nullable String encryptionIV) {
this(
uri,
/* initializationSegment= */ null,
@ -154,7 +153,7 @@ public final class HlsMediaPlaylist extends HlsPlaylist {
}
@Override
public int compareTo(@NonNull Long relativeStartTimeUs) {
public int compareTo(Long relativeStartTimeUs) {
return this.relativeStartTimeUs > relativeStartTimeUs
? 1 : (this.relativeStartTimeUs < relativeStartTimeUs ? -1 : 0);
}

View File

@ -0,0 +1,19 @@
/*
* 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.source.hls.playlist;
import com.google.android.exoplayer2.util.NonNullApi;