Commit 313bd109 by tonihei Committed by Oliver Woodman

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

PiperOrigin-RevId: 262306255
parent 70b912c2
...@@ -41,6 +41,7 @@ android { ...@@ -41,6 +41,7 @@ android {
dependencies { dependencies {
implementation project(modulePrefix + 'library-core') implementation project(modulePrefix + 'library-core')
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.annotation:annotation:1.1.0'
testImplementation project(modulePrefix + 'testutils-robolectric') testImplementation project(modulePrefix + 'testutils-robolectric')
} }
......
...@@ -38,6 +38,7 @@ import com.google.android.exoplayer2.upstream.TransferListener; ...@@ -38,6 +38,7 @@ import com.google.android.exoplayer2.upstream.TransferListener;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/** A SmoothStreaming {@link MediaPeriod}. */ /** A SmoothStreaming {@link MediaPeriod}. */
/* package */ final class SsMediaPeriod /* package */ final class SsMediaPeriod
...@@ -120,8 +121,12 @@ import java.util.List; ...@@ -120,8 +121,12 @@ import java.util.List;
} }
@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) {
ArrayList<ChunkSampleStream<SsChunkSource>> sampleStreamsList = new ArrayList<>(); ArrayList<ChunkSampleStream<SsChunkSource>> sampleStreamsList = new ArrayList<>();
for (int i = 0; i < selections.length; i++) { for (int i = 0; i < selections.length; i++) {
if (streams[i] != null) { if (streams[i] != null) {
......
...@@ -115,7 +115,7 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -115,7 +115,7 @@ public final class SsMediaSource 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;
...@@ -370,8 +370,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -370,8 +370,8 @@ public final class SsMediaSource extends BaseMediaSource
public SsMediaSource( public SsMediaSource(
SsManifest manifest, SsManifest manifest,
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifest, manifest,
chunkSourceFactory, chunkSourceFactory,
...@@ -395,8 +395,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -395,8 +395,8 @@ public final class SsMediaSource extends BaseMediaSource
SsManifest manifest, SsManifest manifest,
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, int minLoadableRetryCount,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifest, manifest,
/* manifestUri= */ null, /* manifestUri= */ null,
...@@ -431,8 +431,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -431,8 +431,8 @@ public final class SsMediaSource extends BaseMediaSource
Uri manifestUri, Uri manifestUri,
DataSource.Factory manifestDataSourceFactory, DataSource.Factory manifestDataSourceFactory,
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifestUri, manifestUri,
manifestDataSourceFactory, manifestDataSourceFactory,
...@@ -466,8 +466,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -466,8 +466,8 @@ public final class SsMediaSource extends BaseMediaSource
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, int minLoadableRetryCount,
long livePresentationDelayMs, long livePresentationDelayMs,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this(manifestUri, manifestDataSourceFactory, new SsManifestParser(), chunkSourceFactory, this(manifestUri, manifestDataSourceFactory, new SsManifestParser(), chunkSourceFactory,
minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener); minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener);
} }
...@@ -496,8 +496,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -496,8 +496,8 @@ public final class SsMediaSource extends BaseMediaSource
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, int minLoadableRetryCount,
long livePresentationDelayMs, long livePresentationDelayMs,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
/* manifest= */ null, /* manifest= */ null,
manifestUri, manifestUri,
...@@ -515,10 +515,10 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -515,10 +515,10 @@ public final class SsMediaSource extends BaseMediaSource
} }
private SsMediaSource( private SsMediaSource(
SsManifest manifest, @Nullable SsManifest manifest,
Uri manifestUri, @Nullable Uri manifestUri,
DataSource.Factory manifestDataSourceFactory, @Nullable DataSource.Factory manifestDataSourceFactory,
ParsingLoadable.Parser<? extends SsManifest> manifestParser, @Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser,
SsChunkSource.Factory chunkSourceFactory, SsChunkSource.Factory chunkSourceFactory,
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
DrmSessionManager<?> drmSessionManager, DrmSessionManager<?> drmSessionManager,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.smoothstreaming.manifest; package com.google.android.exoplayer2.source.smoothstreaming.manifest;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox; import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox;
...@@ -69,7 +70,7 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -69,7 +70,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
public final int maxHeight; public final int maxHeight;
public final int displayWidth; public final int displayWidth;
public final int displayHeight; public final int displayHeight;
public final String language; @Nullable public final String language;
public final Format[] formats; public final Format[] formats;
public final int chunkCount; public final int chunkCount;
...@@ -80,9 +81,20 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -80,9 +81,20 @@ public class SsManifest implements FilterableManifest<SsManifest> {
private final long[] chunkStartTimesUs; private final long[] chunkStartTimesUs;
private final long lastChunkDurationUs; private final long lastChunkDurationUs;
public StreamElement(String baseUri, String chunkTemplate, int type, String subType, public StreamElement(
long timescale, String name, int maxWidth, int maxHeight, int displayWidth, String baseUri,
int displayHeight, String language, Format[] formats, List<Long> chunkStartTimes, String chunkTemplate,
int type,
String subType,
long timescale,
String name,
int maxWidth,
int maxHeight,
int displayWidth,
int displayHeight,
@Nullable String language,
Format[] formats,
List<Long> chunkStartTimes,
long lastChunkDuration) { long lastChunkDuration) {
this( this(
baseUri, baseUri,
...@@ -102,10 +114,22 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -102,10 +114,22 @@ public class SsManifest implements FilterableManifest<SsManifest> {
Util.scaleLargeTimestamp(lastChunkDuration, C.MICROS_PER_SECOND, timescale)); Util.scaleLargeTimestamp(lastChunkDuration, C.MICROS_PER_SECOND, timescale));
} }
private StreamElement(String baseUri, String chunkTemplate, int type, String subType, private StreamElement(
long timescale, String name, int maxWidth, int maxHeight, int displayWidth, String baseUri,
int displayHeight, String language, Format[] formats, List<Long> chunkStartTimes, String chunkTemplate,
long[] chunkStartTimesUs, long lastChunkDurationUs) { int type,
String subType,
long timescale,
String name,
int maxWidth,
int maxHeight,
int displayWidth,
int displayHeight,
@Nullable String language,
Format[] formats,
List<Long> chunkStartTimes,
long[] chunkStartTimesUs,
long lastChunkDurationUs) {
this.baseUri = baseUri; this.baseUri = baseUri;
this.chunkTemplate = chunkTemplate; this.chunkTemplate = chunkTemplate;
this.type = type; this.type = type;
...@@ -208,7 +232,7 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -208,7 +232,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
public final boolean isLive; public final boolean isLive;
/** Content protection information, or null if the content is not protected. */ /** Content protection information, or null if the content is not protected. */
public final ProtectionElement protectionElement; @Nullable public final ProtectionElement protectionElement;
/** The contained stream elements. */ /** The contained stream elements. */
public final StreamElement[] streamElements; public final StreamElement[] streamElements;
...@@ -249,7 +273,7 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -249,7 +273,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
long dvrWindowLength, long dvrWindowLength,
int lookAheadCount, int lookAheadCount,
boolean isLive, boolean isLive,
ProtectionElement protectionElement, @Nullable ProtectionElement protectionElement,
StreamElement[] streamElements) { StreamElement[] streamElements) {
this( this(
majorVersion, majorVersion,
...@@ -273,7 +297,7 @@ public class SsManifest implements FilterableManifest<SsManifest> { ...@@ -273,7 +297,7 @@ public class SsManifest implements FilterableManifest<SsManifest> {
long dvrWindowLengthUs, long dvrWindowLengthUs,
int lookAheadCount, int lookAheadCount,
boolean isLive, boolean isLive,
ProtectionElement protectionElement, @Nullable ProtectionElement protectionElement,
StreamElement[] streamElements) { StreamElement[] streamElements) {
this.majorVersion = majorVersion; this.majorVersion = majorVersion;
this.minorVersion = minorVersion; this.minorVersion = minorVersion;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.smoothstreaming.manifest; package com.google.android.exoplayer2.source.smoothstreaming.manifest;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.Nullable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64; import android.util.Base64;
import android.util.Pair; import android.util.Pair;
...@@ -40,6 +41,7 @@ import java.util.Collections; ...@@ -40,6 +41,7 @@ import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.compatqual.NullableType;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
...@@ -94,10 +96,10 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> { ...@@ -94,10 +96,10 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
private final String baseUri; private final String baseUri;
private final String tag; private final String tag;
private final ElementParser parent; @Nullable private final ElementParser parent;
private final List<Pair<String, Object>> normalizedAttributes; private final List<Pair<String, @NullableType Object>> normalizedAttributes;
public ElementParser(ElementParser parent, String baseUri, String tag) { public ElementParser(@Nullable ElementParser parent, String baseUri, String tag) {
this.parent = parent; this.parent = parent;
this.baseUri = baseUri; this.baseUri = baseUri;
this.tag = tag; this.tag = tag;
...@@ -174,24 +176,25 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> { ...@@ -174,24 +176,25 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
* Stash an attribute that may be normalized at this level. In other words, an attribute that * Stash an attribute that may be normalized at this level. In other words, an attribute that
* may have been pulled up from the child elements because its value was the same in all * may have been pulled up from the child elements because its value was the same in all
* children. * children.
* <p> *
* Stashing an attribute allows child element parsers to retrieve the values of normalized * <p>Stashing an attribute allows child element parsers to retrieve the values of normalized
* attributes using {@link #getNormalizedAttribute(String)}. * attributes using {@link #getNormalizedAttribute(String)}.
* *
* @param key The name of the attribute. * @param key The name of the attribute.
* @param value The value of the attribute. * @param value The value of the attribute.
*/ */
protected final void putNormalizedAttribute(String key, Object value) { protected final void putNormalizedAttribute(String key, @Nullable Object value) {
normalizedAttributes.add(Pair.create(key, value)); normalizedAttributes.add(Pair.create(key, value));
} }
/** /**
* Attempt to retrieve a stashed normalized attribute. If there is no stashed attribute with * Attempt to retrieve a stashed normalized attribute. If there is no stashed attribute with the
* the provided name, the parent element parser will be queried, and so on up the chain. * provided name, the parent element parser will be queried, and so on up the chain.
* *
* @param key The name of the attribute. * @param key The name of the attribute.
* @return The stashed value, or null if the attribute was not be found. * @return The stashed value, or null if the attribute was not be found.
*/ */
@Nullable
protected final Object getNormalizedAttribute(String key) { protected final Object getNormalizedAttribute(String key) {
for (int i = 0; i < normalizedAttributes.size(); i++) { for (int i = 0; i < normalizedAttributes.size(); i++) {
Pair<String, Object> pair = normalizedAttributes.get(i); Pair<String, Object> pair = normalizedAttributes.get(i);
...@@ -340,7 +343,7 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> { ...@@ -340,7 +343,7 @@ public class SsManifestParser implements ParsingLoadable.Parser<SsManifest> {
private long dvrWindowLength; private long dvrWindowLength;
private int lookAheadCount; private int lookAheadCount;
private boolean isLive; private boolean isLive;
private ProtectionElement protectionElement; @Nullable private ProtectionElement protectionElement;
public SmoothStreamingMediaParser(ElementParser parent, String baseUri) { public SmoothStreamingMediaParser(ElementParser parent, String baseUri) {
super(parent, baseUri, TAG); super(parent, baseUri, TAG);
......
/*
* 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.smoothstreaming.manifest;
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.source.smoothstreaming.offline;
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.source.smoothstreaming;
import com.google.android.exoplayer2.util.NonNullApi;
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