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