mirror of
https://github.com/androidx/media.git
synced 2025-05-06 23:20:42 +08:00
Fix HLS module API nullability issues and add package-level non-null-by-default
PiperOrigin-RevId: 262124441
This commit is contained in:
parent
074b6f8ebd
commit
58d4fd93dd
@ -41,6 +41,7 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'androidx.annotation:annotation:1.1.0'
|
implementation 'androidx.annotation:annotation:1.1.0'
|
||||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||||
|
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||||
implementation project(modulePrefix + 'library-core')
|
implementation project(modulePrefix + 'library-core')
|
||||||
testImplementation project(modulePrefix + 'testutils-robolectric')
|
testImplementation project(modulePrefix + 'testutils-robolectric')
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,8 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final @Nullable Uri getUri() {
|
@Nullable
|
||||||
|
public final Uri getUri() {
|
||||||
return upstream.getUri();
|
return upstream.getUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +84,11 @@ public final class DefaultHlsExtractorFactory implements HlsExtractorFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result createExtractor(
|
public Result createExtractor(
|
||||||
Extractor previousExtractor,
|
@Nullable Extractor previousExtractor,
|
||||||
Uri uri,
|
Uri uri,
|
||||||
Format format,
|
Format format,
|
||||||
List<Format> muxedCaptionFormats,
|
@Nullable List<Format> muxedCaptionFormats,
|
||||||
DrmInitData drmInitData,
|
@Nullable DrmInitData drmInitData,
|
||||||
TimestampAdjuster timestampAdjuster,
|
TimestampAdjuster timestampAdjuster,
|
||||||
Map<String, List<String>> responseHeaders,
|
Map<String, List<String>> responseHeaders,
|
||||||
ExtractorInput extractorInput)
|
ExtractorInput extractorInput)
|
||||||
|
@ -59,10 +59,8 @@ import java.util.Map;
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** The chunk to be loaded next. */
|
||||||
* The chunk to be loaded next.
|
@Nullable public Chunk chunk;
|
||||||
*/
|
|
||||||
public Chunk chunk;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the end of the stream has been reached.
|
* Indicates that the end of the stream has been reached.
|
||||||
@ -70,7 +68,7 @@ import java.util.Map;
|
|||||||
public boolean endOfStream;
|
public boolean endOfStream;
|
||||||
|
|
||||||
/** Indicates that the chunk source is waiting for the referred playlist to be refreshed. */
|
/** Indicates that the chunk source is waiting for the referred playlist to be refreshed. */
|
||||||
public Uri playlistUrl;
|
@Nullable public Uri playlistUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the holder.
|
* Clears the holder.
|
||||||
@ -138,7 +136,7 @@ import java.util.Map;
|
|||||||
HlsDataSourceFactory dataSourceFactory,
|
HlsDataSourceFactory dataSourceFactory,
|
||||||
@Nullable TransferListener mediaTransferListener,
|
@Nullable TransferListener mediaTransferListener,
|
||||||
TimestampAdjusterProvider timestampAdjusterProvider,
|
TimestampAdjusterProvider timestampAdjusterProvider,
|
||||||
List<Format> muxedCaptionFormats) {
|
@Nullable List<Format> muxedCaptionFormats) {
|
||||||
this.extractorFactory = extractorFactory;
|
this.extractorFactory = extractorFactory;
|
||||||
this.playlistTracker = playlistTracker;
|
this.playlistTracker = playlistTracker;
|
||||||
this.playlistUrls = playlistUrls;
|
this.playlistUrls = playlistUrls;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.source.hls;
|
package com.google.android.exoplayer2.source.hls;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData;
|
import com.google.android.exoplayer2.drm.DrmInitData;
|
||||||
import com.google.android.exoplayer2.extractor.Extractor;
|
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.
|
* @throws IOException If an I/O error is encountered while sniffing.
|
||||||
*/
|
*/
|
||||||
Result createExtractor(
|
Result createExtractor(
|
||||||
Extractor previousExtractor,
|
@Nullable Extractor previousExtractor,
|
||||||
Uri uri,
|
Uri uri,
|
||||||
Format format,
|
Format format,
|
||||||
List<Format> muxedCaptionFormats,
|
@Nullable List<Format> muxedCaptionFormats,
|
||||||
DrmInitData drmInitData,
|
@Nullable DrmInitData drmInitData,
|
||||||
TimestampAdjuster timestampAdjuster,
|
TimestampAdjuster timestampAdjuster,
|
||||||
Map<String, List<String>> responseHeaders,
|
Map<String, List<String>> responseHeaders,
|
||||||
ExtractorInput sniffingExtractorInput)
|
ExtractorInput sniffingExtractorInput)
|
||||||
|
@ -54,6 +54,7 @@ import java.util.HashSet;
|
|||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MediaPeriod} that loads an HLS stream.
|
* A {@link MediaPeriod} that loads an HLS stream.
|
||||||
@ -249,8 +250,12 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags,
|
public long selectTracks(
|
||||||
SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
|
@NullableType TrackSelection[] selections,
|
||||||
|
boolean[] mayRetainStreamFlags,
|
||||||
|
@NullableType SampleStream[] streams,
|
||||||
|
boolean[] streamResetFlags,
|
||||||
|
long positionUs) {
|
||||||
// Map each selection and stream onto a child period index.
|
// Map each selection and stream onto a child period index.
|
||||||
int[] streamChildIndices = new int[selections.length];
|
int[] streamChildIndices = new int[selections.length];
|
||||||
int[] selectionChildIndices = new int[selections.length];
|
int[] selectionChildIndices = new int[selections.length];
|
||||||
|
@ -110,7 +110,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||||||
* @return This factory, for convenience.
|
* @return This factory, for convenience.
|
||||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
* @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);
|
Assertions.checkState(!isCreateCalled);
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
return this;
|
return this;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.hls;
|
package com.google.android.exoplayer2.source.hls;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
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_MIN_LENGTH = 6 /* "WEBVTT" */;
|
||||||
private static final int HEADER_MAX_LENGTH = 3 /* optional Byte Order Mark */ + HEADER_MIN_LENGTH;
|
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 TimestampAdjuster timestampAdjuster;
|
||||||
private final ParsableByteArray sampleDataWrapper;
|
private final ParsableByteArray sampleDataWrapper;
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ public final class WebvttExtractor implements Extractor {
|
|||||||
private byte[] sampleData;
|
private byte[] sampleData;
|
||||||
private int sampleSize;
|
private int sampleSize;
|
||||||
|
|
||||||
public WebvttExtractor(String language, TimestampAdjuster timestampAdjuster) {
|
public WebvttExtractor(@Nullable String language, TimestampAdjuster timestampAdjuster) {
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.timestampAdjuster = timestampAdjuster;
|
this.timestampAdjuster = timestampAdjuster;
|
||||||
this.sampleDataWrapper = new ParsableByteArray();
|
this.sampleDataWrapper = new ParsableByteArray();
|
||||||
|
@ -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;
|
@ -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;
|
@ -172,6 +172,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public HlsMediaPlaylist getPlaylistSnapshot(Uri url, boolean isForPlayback) {
|
public HlsMediaPlaylist getPlaylistSnapshot(Uri url, boolean isForPlayback) {
|
||||||
HlsMediaPlaylist snapshot = playlistBundles.get(url).getPlaylistSnapshot();
|
HlsMediaPlaylist snapshot = playlistBundles.get(url).getPlaylistSnapshot();
|
||||||
if (snapshot != null && isForPlayback) {
|
if (snapshot != null && isForPlayback) {
|
||||||
@ -448,7 +449,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
private final Loader mediaPlaylistLoader;
|
private final Loader mediaPlaylistLoader;
|
||||||
private final ParsingLoadable<HlsPlaylist> mediaPlaylistLoadable;
|
private final ParsingLoadable<HlsPlaylist> mediaPlaylistLoadable;
|
||||||
|
|
||||||
private HlsMediaPlaylist playlistSnapshot;
|
@Nullable private HlsMediaPlaylist playlistSnapshot;
|
||||||
private long lastSnapshotLoadMs;
|
private long lastSnapshotLoadMs;
|
||||||
private long lastSnapshotChangeMs;
|
private long lastSnapshotChangeMs;
|
||||||
private long earliestNextLoadTimeMs;
|
private long earliestNextLoadTimeMs;
|
||||||
@ -467,6 +468,7 @@ public final class DefaultHlsPlaylistTracker
|
|||||||
mediaPlaylistParser);
|
mediaPlaylistParser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public HlsMediaPlaylist getPlaylistSnapshot() {
|
public HlsMediaPlaylist getPlaylistSnapshot() {
|
||||||
return playlistSnapshot;
|
return playlistSnapshot;
|
||||||
}
|
}
|
||||||
|
@ -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
|
* The format of the audio muxed in the variants. May be null if the playlist does not declare any
|
||||||
* muxed audio.
|
* 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
|
* 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
|
* 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> audios,
|
||||||
List<Rendition> subtitles,
|
List<Rendition> subtitles,
|
||||||
List<Rendition> closedCaptions,
|
List<Rendition> closedCaptions,
|
||||||
Format muxedAudioFormat,
|
@Nullable Format muxedAudioFormat,
|
||||||
List<Format> muxedCaptionFormats,
|
List<Format> muxedCaptionFormats,
|
||||||
boolean hasIndependentSegments,
|
boolean hasIndependentSegments,
|
||||||
Map<String, String> variableDefinitions,
|
Map<String, String> variableDefinitions,
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package com.google.android.exoplayer2.source.hls.playlist;
|
package com.google.android.exoplayer2.source.hls.playlist;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData;
|
import com.google.android.exoplayer2.drm.DrmInitData;
|
||||||
@ -95,8 +94,8 @@ public final class HlsMediaPlaylist extends HlsPlaylist {
|
|||||||
String uri,
|
String uri,
|
||||||
long byterangeOffset,
|
long byterangeOffset,
|
||||||
long byterangeLength,
|
long byterangeLength,
|
||||||
String fullSegmentEncryptionKeyUri,
|
@Nullable String fullSegmentEncryptionKeyUri,
|
||||||
String encryptionIV) {
|
@Nullable String encryptionIV) {
|
||||||
this(
|
this(
|
||||||
uri,
|
uri,
|
||||||
/* initializationSegment= */ null,
|
/* initializationSegment= */ null,
|
||||||
@ -154,7 +153,7 @@ public final class HlsMediaPlaylist extends HlsPlaylist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NonNull Long relativeStartTimeUs) {
|
public int compareTo(Long relativeStartTimeUs) {
|
||||||
return this.relativeStartTimeUs > relativeStartTimeUs
|
return this.relativeStartTimeUs > relativeStartTimeUs
|
||||||
? 1 : (this.relativeStartTimeUs < relativeStartTimeUs ? -1 : 0);
|
? 1 : (this.relativeStartTimeUs < relativeStartTimeUs ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
Loading…
x
Reference in New Issue
Block a user