Commit 074b6f8e by tonihei Committed by Oliver Woodman

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

PiperOrigin-RevId: 262123595
parent 79e962c5
...@@ -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')
} }
......
...@@ -60,6 +60,7 @@ import java.util.IdentityHashMap; ...@@ -60,6 +60,7 @@ import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/** A DASH {@link MediaPeriod}. */ /** A DASH {@link MediaPeriod}. */
/* package */ final class DashMediaPeriod /* package */ final class DashMediaPeriod
...@@ -245,8 +246,12 @@ import java.util.regex.Pattern; ...@@ -245,8 +246,12 @@ import java.util.regex.Pattern;
} }
@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) {
int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections); int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections);
releaseDisabledStreams(selections, mayRetainStreamFlags, streams); releaseDisabledStreams(selections, mayRetainStreamFlags, streams);
releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex); releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex);
......
...@@ -130,7 +130,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -130,7 +130,7 @@ public final class DashMediaSource 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;
...@@ -430,8 +430,8 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -430,8 +430,8 @@ public final class DashMediaSource extends BaseMediaSource {
public DashMediaSource( public DashMediaSource(
DashManifest manifest, DashManifest manifest,
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.Factory chunkSourceFactory,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifest, manifest,
chunkSourceFactory, chunkSourceFactory,
...@@ -455,8 +455,8 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -455,8 +455,8 @@ public final class DashMediaSource extends BaseMediaSource {
DashManifest manifest, DashManifest manifest,
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, int minLoadableRetryCount,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifest, manifest,
/* manifestUri= */ null, /* manifestUri= */ null,
...@@ -492,8 +492,8 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -492,8 +492,8 @@ public final class DashMediaSource extends BaseMediaSource {
Uri manifestUri, Uri manifestUri,
DataSource.Factory manifestDataSourceFactory, DataSource.Factory manifestDataSourceFactory,
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.Factory chunkSourceFactory,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifestUri, manifestUri,
manifestDataSourceFactory, manifestDataSourceFactory,
...@@ -529,8 +529,8 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -529,8 +529,8 @@ public final class DashMediaSource extends BaseMediaSource {
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, int minLoadableRetryCount,
long livePresentationDelayMs, long livePresentationDelayMs,
Handler eventHandler, @Nullable Handler eventHandler,
MediaSourceEventListener eventListener) { @Nullable MediaSourceEventListener eventListener) {
this( this(
manifestUri, manifestUri,
manifestDataSourceFactory, manifestDataSourceFactory,
...@@ -569,8 +569,8 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -569,8 +569,8 @@ public final class DashMediaSource extends BaseMediaSource {
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.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,
...@@ -591,10 +591,10 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -591,10 +591,10 @@ public final class DashMediaSource extends BaseMediaSource {
} }
private DashMediaSource( private DashMediaSource(
DashManifest manifest, @Nullable DashManifest manifest,
Uri manifestUri, @Nullable Uri manifestUri,
DataSource.Factory manifestDataSourceFactory, @Nullable DataSource.Factory manifestDataSourceFactory,
ParsingLoadable.Parser<? extends DashManifest> manifestParser, @Nullable ParsingLoadable.Parser<? extends DashManifest> manifestParser,
DashChunkSource.Factory chunkSourceFactory, DashChunkSource.Factory chunkSourceFactory,
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
DrmSessionManager<?> drmSessionManager, DrmSessionManager<?> drmSessionManager,
......
...@@ -66,7 +66,8 @@ public final class DashUtil { ...@@ -66,7 +66,8 @@ public final class DashUtil {
* @throws IOException Thrown when there is an error while loading. * @throws IOException Thrown when there is an error while loading.
* @throws InterruptedException Thrown if the thread was interrupted. * @throws InterruptedException Thrown if the thread was interrupted.
*/ */
public static @Nullable DrmInitData loadDrmInitData(DataSource dataSource, Period period) @Nullable
public static DrmInitData loadDrmInitData(DataSource dataSource, Period period)
throws IOException, InterruptedException { throws IOException, InterruptedException {
int primaryTrackType = C.TRACK_TYPE_VIDEO; int primaryTrackType = C.TRACK_TYPE_VIDEO;
Representation representation = getFirstRepresentation(period, primaryTrackType); Representation representation = getFirstRepresentation(period, primaryTrackType);
...@@ -95,7 +96,8 @@ public final class DashUtil { ...@@ -95,7 +96,8 @@ public final class DashUtil {
* @throws IOException Thrown when there is an error while loading. * @throws IOException Thrown when there is an error while loading.
* @throws InterruptedException Thrown if the thread was interrupted. * @throws InterruptedException Thrown if the thread was interrupted.
*/ */
public static @Nullable Format loadSampleFormat( @Nullable
public static Format loadSampleFormat(
DataSource dataSource, int trackType, Representation representation) DataSource dataSource, int trackType, Representation representation)
throws IOException, InterruptedException { throws IOException, InterruptedException {
ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType, ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType,
...@@ -116,7 +118,8 @@ public final class DashUtil { ...@@ -116,7 +118,8 @@ public final class DashUtil {
* @throws IOException Thrown when there is an error while loading. * @throws IOException Thrown when there is an error while loading.
* @throws InterruptedException Thrown if the thread was interrupted. * @throws InterruptedException Thrown if the thread was interrupted.
*/ */
public static @Nullable ChunkIndex loadChunkIndex( @Nullable
public static ChunkIndex loadChunkIndex(
DataSource dataSource, int trackType, Representation representation) DataSource dataSource, int trackType, Representation representation)
throws IOException, InterruptedException { throws IOException, InterruptedException {
ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType, ChunkExtractorWrapper extractorWrapper = loadInitializationData(dataSource, trackType,
...@@ -138,7 +141,8 @@ public final class DashUtil { ...@@ -138,7 +141,8 @@ public final class DashUtil {
* @throws IOException Thrown when there is an error while loading. * @throws IOException Thrown when there is an error while loading.
* @throws InterruptedException Thrown if the thread was interrupted. * @throws InterruptedException Thrown if the thread was interrupted.
*/ */
private static @Nullable ChunkExtractorWrapper loadInitializationData( @Nullable
private static ChunkExtractorWrapper loadInitializationData(
DataSource dataSource, int trackType, Representation representation, boolean loadIndex) DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
throws IOException, InterruptedException { throws IOException, InterruptedException {
RangedUri initializationUri = representation.getInitializationUri(); RangedUri initializationUri = representation.getInitializationUri();
...@@ -187,7 +191,8 @@ public final class DashUtil { ...@@ -187,7 +191,8 @@ public final class DashUtil {
return new ChunkExtractorWrapper(extractor, trackType, format); return new ChunkExtractorWrapper(extractor, trackType, format);
} }
private static @Nullable Representation getFirstRepresentation(Period period, int type) { @Nullable
private static Representation getFirstRepresentation(Period period, int type) {
int index = period.getAdaptationSetIndex(type); int index = period.getAdaptationSetIndex(type);
if (index == C.INDEX_UNSET) { if (index == C.INDEX_UNSET) {
return null; return null;
...@@ -197,5 +202,4 @@ public final class DashUtil { ...@@ -197,5 +202,4 @@ public final class DashUtil {
} }
private DashUtil() {} private DashUtil() {}
} }
...@@ -67,7 +67,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -67,7 +67,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
private final int maxSegmentsPerLoad; private final int maxSegmentsPerLoad;
public Factory(DataSource.Factory dataSourceFactory) { public Factory(DataSource.Factory dataSourceFactory) {
this(dataSourceFactory, 1); this(dataSourceFactory, /* maxSegmentsPerLoad= */ 1);
} }
public Factory(DataSource.Factory dataSourceFactory, int maxSegmentsPerLoad) { public Factory(DataSource.Factory dataSourceFactory, int maxSegmentsPerLoad) {
...@@ -633,7 +633,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -633,7 +633,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
Representation representation, Representation representation,
boolean enableEventMessageTrack, boolean enableEventMessageTrack,
List<Format> closedCaptionFormats, List<Format> closedCaptionFormats,
TrackOutput playerEmsgTrackOutput) { @Nullable TrackOutput playerEmsgTrackOutput) {
this( this(
periodDurationUs, periodDurationUs,
representation, representation,
...@@ -787,7 +787,7 @@ public class DefaultDashChunkSource implements DashChunkSource { ...@@ -787,7 +787,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
Representation representation, Representation representation,
boolean enableEventMessageTrack, boolean enableEventMessageTrack,
List<Format> closedCaptionFormats, List<Format> closedCaptionFormats,
TrackOutput playerEmsgTrackOutput) { @Nullable TrackOutput playerEmsgTrackOutput) {
String containerMimeType = representation.format.containerMimeType; String containerMimeType = representation.format.containerMimeType;
if (mimeTypeIsRawText(containerMimeType)) { if (mimeTypeIsRawText(containerMimeType)) {
return null; return null;
......
...@@ -80,12 +80,10 @@ public class DashManifest implements FilterableManifest<DashManifest> { ...@@ -80,12 +80,10 @@ public class DashManifest implements FilterableManifest<DashManifest> {
* The {@link UtcTimingElement}, or null if not present. Defined in DVB A168:7/2016, Section * The {@link UtcTimingElement}, or null if not present. Defined in DVB A168:7/2016, Section
* 4.7.2. * 4.7.2.
*/ */
public final UtcTimingElement utcTiming; @Nullable public final UtcTimingElement utcTiming;
/** /** The location of this manifest, or null if not present. */
* The location of this manifest. @Nullable public final Uri location;
*/
public final Uri location;
/** The {@link ProgramInformation}, or null if not present. */ /** The {@link ProgramInformation}, or null if not present. */
@Nullable public final ProgramInformation programInformation; @Nullable public final ProgramInformation programInformation;
...@@ -106,8 +104,8 @@ public class DashManifest implements FilterableManifest<DashManifest> { ...@@ -106,8 +104,8 @@ public class DashManifest implements FilterableManifest<DashManifest> {
long timeShiftBufferDepthMs, long timeShiftBufferDepthMs,
long suggestedPresentationDelayMs, long suggestedPresentationDelayMs,
long publishTimeMs, long publishTimeMs,
UtcTimingElement utcTiming, @Nullable UtcTimingElement utcTiming,
Uri location, @Nullable Uri location,
List<Period> periods) { List<Period> periods) {
this( this(
availabilityStartTimeMs, availabilityStartTimeMs,
...@@ -134,8 +132,8 @@ public class DashManifest implements FilterableManifest<DashManifest> { ...@@ -134,8 +132,8 @@ public class DashManifest implements FilterableManifest<DashManifest> {
long suggestedPresentationDelayMs, long suggestedPresentationDelayMs,
long publishTimeMs, long publishTimeMs,
@Nullable ProgramInformation programInformation, @Nullable ProgramInformation programInformation,
UtcTimingElement utcTiming, @Nullable UtcTimingElement utcTiming,
Uri location, @Nullable Uri location,
List<Period> periods) { List<Period> periods) {
this.availabilityStartTimeMs = availabilityStartTimeMs; this.availabilityStartTimeMs = availabilityStartTimeMs;
this.durationMs = durationMs; this.durationMs = durationMs;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.source.dash.manifest; package com.google.android.exoplayer2.source.dash.manifest;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -24,10 +23,8 @@ import com.google.android.exoplayer2.util.Util; ...@@ -24,10 +23,8 @@ import com.google.android.exoplayer2.util.Util;
*/ */
public final class Descriptor { public final class Descriptor {
/** /** The scheme URI. */
* The scheme URI. public final String schemeIdUri;
*/
@NonNull public final String schemeIdUri;
/** /**
* The value, or null. * The value, or null.
*/ */
...@@ -42,7 +39,7 @@ public final class Descriptor { ...@@ -42,7 +39,7 @@ public final class Descriptor {
* @param value The value, or null. * @param value The value, or null.
* @param id The identifier, or null. * @param id The identifier, or null.
*/ */
public Descriptor(@NonNull String schemeIdUri, @Nullable String value, @Nullable String id) { public Descriptor(String schemeIdUri, @Nullable String value, @Nullable String id) {
this.schemeIdUri = schemeIdUri; this.schemeIdUri = schemeIdUri;
this.value = value; this.value = value;
this.id = id; this.id = id;
...@@ -63,10 +60,9 @@ public final class Descriptor { ...@@ -63,10 +60,9 @@ public final class Descriptor {
@Override @Override
public int hashCode() { public int hashCode() {
int result = (schemeIdUri != null ? schemeIdUri.hashCode() : 0); int result = schemeIdUri.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (value != null ? value.hashCode() : 0);
result = 31 * result + (id != null ? id.hashCode() : 0); result = 31 * result + (id != null ? id.hashCode() : 0);
return result; return result;
} }
} }
...@@ -21,22 +21,26 @@ import com.google.android.exoplayer2.util.Util; ...@@ -21,22 +21,26 @@ import com.google.android.exoplayer2.util.Util;
/** A parsed program information element. */ /** A parsed program information element. */
public class ProgramInformation { public class ProgramInformation {
/** The title for the media presentation. */ /** The title for the media presentation. */
public final String title; @Nullable public final String title;
/** Information about the original source of the media presentation. */ /** Information about the original source of the media presentation. */
public final String source; @Nullable public final String source;
/** A copyright statement for the media presentation. */ /** A copyright statement for the media presentation. */
public final String copyright; @Nullable public final String copyright;
/** A URL that provides more information about the media presentation. */ /** A URL that provides more information about the media presentation. */
public final String moreInformationURL; @Nullable public final String moreInformationURL;
/** Declares the language code(s) for this ProgramInformation. */ /** Declares the language code(s) for this ProgramInformation. */
public final String lang; @Nullable public final String lang;
public ProgramInformation( public ProgramInformation(
String title, String source, String copyright, String moreInformationURL, String lang) { @Nullable String title,
@Nullable String source,
@Nullable String copyright,
@Nullable String moreInformationURL,
@Nullable String lang) {
this.title = title; this.title = title;
this.source = source; this.source = source;
this.copyright = copyright; this.copyright = copyright;
......
...@@ -83,7 +83,7 @@ public final class RangedUri { ...@@ -83,7 +83,7 @@ public final class RangedUri {
* <p>If {@code other} is null then the merge is considered unsuccessful, and null is returned. * <p>If {@code other} is null then the merge is considered unsuccessful, and null is returned.
* *
* @param other The {@link RangedUri} to merge. * @param other The {@link RangedUri} to merge.
* @param baseUri The optional base Uri. * @param baseUri The base Uri.
* @return The merged {@link RangedUri} if the merge was successful. Null otherwise. * @return The merged {@link RangedUri} if the merge was successful. Null otherwise.
*/ */
@Nullable @Nullable
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.dash.manifest; package com.google.android.exoplayer2.source.dash.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.source.dash.DashSegmentIndex; import com.google.android.exoplayer2.source.dash.DashSegmentIndex;
...@@ -53,9 +54,7 @@ public abstract class Representation { ...@@ -53,9 +54,7 @@ public abstract class Representation {
* The offset of the presentation timestamps in the media stream relative to media time. * The offset of the presentation timestamps in the media stream relative to media time.
*/ */
public final long presentationTimeOffsetUs; public final long presentationTimeOffsetUs;
/** /** The in-band event streams in the representation. May be empty. */
* The in-band event streams in the representation. Never null, but may be empty.
*/
public final List<Descriptor> inbandEventStreams; public final List<Descriptor> inbandEventStreams;
private final RangedUri initializationUri; private final RangedUri initializationUri;
...@@ -71,7 +70,7 @@ public abstract class Representation { ...@@ -71,7 +70,7 @@ public abstract class Representation {
*/ */
public static Representation newInstance( public static Representation newInstance(
long revisionId, Format format, String baseUrl, SegmentBase segmentBase) { long revisionId, Format format, String baseUrl, SegmentBase segmentBase) {
return newInstance(revisionId, format, baseUrl, segmentBase, null); return newInstance(revisionId, format, baseUrl, segmentBase, /* inbandEventStreams= */ null);
} }
/** /**
...@@ -89,8 +88,9 @@ public abstract class Representation { ...@@ -89,8 +88,9 @@ public abstract class Representation {
Format format, Format format,
String baseUrl, String baseUrl,
SegmentBase segmentBase, SegmentBase segmentBase,
List<Descriptor> inbandEventStreams) { @Nullable List<Descriptor> inbandEventStreams) {
return newInstance(revisionId, format, baseUrl, segmentBase, inbandEventStreams, null); return newInstance(
revisionId, format, baseUrl, segmentBase, inbandEventStreams, /* cacheKey= */ null);
} }
/** /**
...@@ -110,8 +110,8 @@ public abstract class Representation { ...@@ -110,8 +110,8 @@ public abstract class Representation {
Format format, Format format,
String baseUrl, String baseUrl,
SegmentBase segmentBase, SegmentBase segmentBase,
List<Descriptor> inbandEventStreams, @Nullable List<Descriptor> inbandEventStreams,
String cacheKey) { @Nullable String cacheKey) {
if (segmentBase instanceof SingleSegmentBase) { if (segmentBase instanceof SingleSegmentBase) {
return new SingleSegmentRepresentation( return new SingleSegmentRepresentation(
revisionId, revisionId,
...@@ -135,7 +135,7 @@ public abstract class Representation { ...@@ -135,7 +135,7 @@ public abstract class Representation {
Format format, Format format,
String baseUrl, String baseUrl,
SegmentBase segmentBase, SegmentBase segmentBase,
List<Descriptor> inbandEventStreams) { @Nullable List<Descriptor> inbandEventStreams) {
this.revisionId = revisionId; this.revisionId = revisionId;
this.format = format; this.format = format;
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
...@@ -151,6 +151,7 @@ public abstract class Representation { ...@@ -151,6 +151,7 @@ public abstract class Representation {
* Returns a {@link RangedUri} defining the location of the representation's initialization data, * Returns a {@link RangedUri} defining the location of the representation's initialization data,
* or null if no initialization data exists. * or null if no initialization data exists.
*/ */
@Nullable
public RangedUri getInitializationUri() { public RangedUri getInitializationUri() {
return initializationUri; return initializationUri;
} }
...@@ -159,14 +160,15 @@ public abstract class Representation { ...@@ -159,14 +160,15 @@ public abstract class Representation {
* Returns a {@link RangedUri} defining the location of the representation's segment index, or * Returns a {@link RangedUri} defining the location of the representation's segment index, or
* null if the representation provides an index directly. * null if the representation provides an index directly.
*/ */
@Nullable
public abstract RangedUri getIndexUri(); public abstract RangedUri getIndexUri();
/** /** Returns an index if the representation provides one directly, or null otherwise. */
* Returns an index if the representation provides one directly, or null otherwise. @Nullable
*/
public abstract DashSegmentIndex getIndex(); public abstract DashSegmentIndex getIndex();
/** Returns a cache key for the representation if set, or null. */ /** Returns a cache key for the representation if set, or null. */
@Nullable
public abstract String getCacheKey(); public abstract String getCacheKey();
/** /**
...@@ -184,9 +186,9 @@ public abstract class Representation { ...@@ -184,9 +186,9 @@ public abstract class Representation {
*/ */
public final long contentLength; public final long contentLength;
private final String cacheKey; @Nullable private final String cacheKey;
private final RangedUri indexUri; @Nullable private final RangedUri indexUri;
private final SingleSegmentIndex segmentIndex; @Nullable private final SingleSegmentIndex segmentIndex;
/** /**
* @param revisionId Identifies the revision of the content. * @param revisionId Identifies the revision of the content.
...@@ -209,7 +211,7 @@ public abstract class Representation { ...@@ -209,7 +211,7 @@ public abstract class Representation {
long indexStart, long indexStart,
long indexEnd, long indexEnd,
List<Descriptor> inbandEventStreams, List<Descriptor> inbandEventStreams,
String cacheKey, @Nullable String cacheKey,
long contentLength) { long contentLength) {
RangedUri rangedUri = new RangedUri(null, initializationStart, RangedUri rangedUri = new RangedUri(null, initializationStart,
initializationEnd - initializationStart + 1); initializationEnd - initializationStart + 1);
...@@ -233,8 +235,8 @@ public abstract class Representation { ...@@ -233,8 +235,8 @@ public abstract class Representation {
Format format, Format format,
String baseUrl, String baseUrl,
SingleSegmentBase segmentBase, SingleSegmentBase segmentBase,
List<Descriptor> inbandEventStreams, @Nullable List<Descriptor> inbandEventStreams,
String cacheKey, @Nullable String cacheKey,
long contentLength) { long contentLength) {
super(revisionId, format, baseUrl, segmentBase, inbandEventStreams); super(revisionId, format, baseUrl, segmentBase, inbandEventStreams);
this.uri = Uri.parse(baseUrl); this.uri = Uri.parse(baseUrl);
...@@ -248,16 +250,19 @@ public abstract class Representation { ...@@ -248,16 +250,19 @@ public abstract class Representation {
} }
@Override @Override
@Nullable
public RangedUri getIndexUri() { public RangedUri getIndexUri() {
return indexUri; return indexUri;
} }
@Override @Override
@Nullable
public DashSegmentIndex getIndex() { public DashSegmentIndex getIndex() {
return segmentIndex; return segmentIndex;
} }
@Override @Override
@Nullable
public String getCacheKey() { public String getCacheKey() {
return cacheKey; return cacheKey;
} }
...@@ -284,12 +289,13 @@ public abstract class Representation { ...@@ -284,12 +289,13 @@ public abstract class Representation {
Format format, Format format,
String baseUrl, String baseUrl,
MultiSegmentBase segmentBase, MultiSegmentBase segmentBase,
List<Descriptor> inbandEventStreams) { @Nullable List<Descriptor> inbandEventStreams) {
super(revisionId, format, baseUrl, segmentBase, inbandEventStreams); super(revisionId, format, baseUrl, segmentBase, inbandEventStreams);
this.segmentBase = segmentBase; this.segmentBase = segmentBase;
} }
@Override @Override
@Nullable
public RangedUri getIndexUri() { public RangedUri getIndexUri() {
return null; return null;
} }
...@@ -300,6 +306,7 @@ public abstract class Representation { ...@@ -300,6 +306,7 @@ public abstract class Representation {
} }
@Override @Override
@Nullable
public String getCacheKey() { public String getCacheKey() {
return null; return null;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package com.google.android.exoplayer2.source.dash.manifest; package com.google.android.exoplayer2.source.dash.manifest;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.dash.DashSegmentIndex; import com.google.android.exoplayer2.source.dash.DashSegmentIndex;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -25,7 +26,7 @@ import java.util.List; ...@@ -25,7 +26,7 @@ import java.util.List;
*/ */
public abstract class SegmentBase { public abstract class SegmentBase {
/* package */ final RangedUri initialization; /* package */ @Nullable final RangedUri initialization;
/* package */ final long timescale; /* package */ final long timescale;
/* package */ final long presentationTimeOffset; /* package */ final long presentationTimeOffset;
...@@ -36,7 +37,8 @@ public abstract class SegmentBase { ...@@ -36,7 +37,8 @@ public abstract class SegmentBase {
* @param presentationTimeOffset The presentation time offset. The value in seconds is the * @param presentationTimeOffset The presentation time offset. The value in seconds is the
* division of this value and {@code timescale}. * division of this value and {@code timescale}.
*/ */
public SegmentBase(RangedUri initialization, long timescale, long presentationTimeOffset) { public SegmentBase(
@Nullable RangedUri initialization, long timescale, long presentationTimeOffset) {
this.initialization = initialization; this.initialization = initialization;
this.timescale = timescale; this.timescale = timescale;
this.presentationTimeOffset = presentationTimeOffset; this.presentationTimeOffset = presentationTimeOffset;
...@@ -49,6 +51,7 @@ public abstract class SegmentBase { ...@@ -49,6 +51,7 @@ public abstract class SegmentBase {
* @param representation The {@link Representation} for which initialization data is required. * @param representation The {@link Representation} for which initialization data is required.
* @return A {@link RangedUri} defining the location of the initialization data, or null. * @return A {@link RangedUri} defining the location of the initialization data, or null.
*/ */
@Nullable
public RangedUri getInitialization(Representation representation) { public RangedUri getInitialization(Representation representation) {
return initialization; return initialization;
} }
...@@ -77,19 +80,31 @@ public abstract class SegmentBase { ...@@ -77,19 +80,31 @@ public abstract class SegmentBase {
* @param indexStart The byte offset of the index data in the segment. * @param indexStart The byte offset of the index data in the segment.
* @param indexLength The length of the index data in bytes. * @param indexLength The length of the index data in bytes.
*/ */
public SingleSegmentBase(RangedUri initialization, long timescale, long presentationTimeOffset, public SingleSegmentBase(
long indexStart, long indexLength) { @Nullable RangedUri initialization,
long timescale,
long presentationTimeOffset,
long indexStart,
long indexLength) {
super(initialization, timescale, presentationTimeOffset); super(initialization, timescale, presentationTimeOffset);
this.indexStart = indexStart; this.indexStart = indexStart;
this.indexLength = indexLength; this.indexLength = indexLength;
} }
public SingleSegmentBase() { public SingleSegmentBase() {
this(null, 1, 0, 0, 0); this(
/* initialization= */ null,
/* timescale= */ 1,
/* presentationTimeOffset= */ 0,
/* indexStart= */ 0,
/* indexLength= */ 0);
} }
@Nullable
public RangedUri getIndex() { public RangedUri getIndex() {
return indexLength <= 0 ? null : new RangedUri(null, indexStart, indexLength); return indexLength <= 0
? null
: new RangedUri(/* referenceUri= */ null, indexStart, indexLength);
} }
} }
...@@ -101,7 +116,7 @@ public abstract class SegmentBase { ...@@ -101,7 +116,7 @@ public abstract class SegmentBase {
/* package */ final long startNumber; /* package */ final long startNumber;
/* package */ final long duration; /* package */ final long duration;
/* package */ final List<SegmentTimelineElement> segmentTimeline; /* package */ @Nullable final List<SegmentTimelineElement> segmentTimeline;
/** /**
* @param initialization A {@link RangedUri} corresponding to initialization data, if such data * @param initialization A {@link RangedUri} corresponding to initialization data, if such data
...@@ -118,12 +133,12 @@ public abstract class SegmentBase { ...@@ -118,12 +133,12 @@ public abstract class SegmentBase {
* parameter. * parameter.
*/ */
public MultiSegmentBase( public MultiSegmentBase(
RangedUri initialization, @Nullable RangedUri initialization,
long timescale, long timescale,
long presentationTimeOffset, long presentationTimeOffset,
long startNumber, long startNumber,
long duration, long duration,
List<SegmentTimelineElement> segmentTimeline) { @Nullable List<SegmentTimelineElement> segmentTimeline) {
super(initialization, timescale, presentationTimeOffset); super(initialization, timescale, presentationTimeOffset);
this.startNumber = startNumber; this.startNumber = startNumber;
this.duration = duration; this.duration = duration;
...@@ -223,7 +238,7 @@ public abstract class SegmentBase { ...@@ -223,7 +238,7 @@ public abstract class SegmentBase {
*/ */
public static class SegmentList extends MultiSegmentBase { public static class SegmentList extends MultiSegmentBase {
/* package */ final List<RangedUri> mediaSegments; /* package */ @Nullable final List<RangedUri> mediaSegments;
/** /**
* @param initialization A {@link RangedUri} corresponding to initialization data, if such data * @param initialization A {@link RangedUri} corresponding to initialization data, if such data
...@@ -246,8 +261,8 @@ public abstract class SegmentBase { ...@@ -246,8 +261,8 @@ public abstract class SegmentBase {
long presentationTimeOffset, long presentationTimeOffset,
long startNumber, long startNumber,
long duration, long duration,
List<SegmentTimelineElement> segmentTimeline, @Nullable List<SegmentTimelineElement> segmentTimeline,
List<RangedUri> mediaSegments) { @Nullable List<RangedUri> mediaSegments) {
super(initialization, timescale, presentationTimeOffset, startNumber, duration, super(initialization, timescale, presentationTimeOffset, startNumber, duration,
segmentTimeline); segmentTimeline);
this.mediaSegments = mediaSegments; this.mediaSegments = mediaSegments;
...@@ -275,8 +290,8 @@ public abstract class SegmentBase { ...@@ -275,8 +290,8 @@ public abstract class SegmentBase {
*/ */
public static class SegmentTemplate extends MultiSegmentBase { public static class SegmentTemplate extends MultiSegmentBase {
/* package */ final UrlTemplate initializationTemplate; /* package */ @Nullable final UrlTemplate initializationTemplate;
/* package */ final UrlTemplate mediaTemplate; /* package */ @Nullable final UrlTemplate mediaTemplate;
/* package */ final long endNumber; /* package */ final long endNumber;
/** /**
...@@ -308,9 +323,9 @@ public abstract class SegmentBase { ...@@ -308,9 +323,9 @@ public abstract class SegmentBase {
long startNumber, long startNumber,
long endNumber, long endNumber,
long duration, long duration,
List<SegmentTimelineElement> segmentTimeline, @Nullable List<SegmentTimelineElement> segmentTimeline,
UrlTemplate initializationTemplate, @Nullable UrlTemplate initializationTemplate,
UrlTemplate mediaTemplate) { @Nullable UrlTemplate mediaTemplate) {
super( super(
initialization, initialization,
timescale, timescale,
...@@ -324,6 +339,7 @@ public abstract class SegmentBase { ...@@ -324,6 +339,7 @@ public abstract class SegmentBase {
} }
@Override @Override
@Nullable
public RangedUri getInitialization(Representation representation) { public RangedUri getInitialization(Representation representation) {
if (initializationTemplate != null) { if (initializationTemplate != null) {
String urlString = initializationTemplate.buildUri(representation.format.id, 0, String urlString = initializationTemplate.buildUri(representation.format.id, 0,
......
/*
* 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.dash.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.dash.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.dash;
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