Commit c5e11696 by bachinger Committed by Oliver Woodman

make media source factories reusable

First cl towards DefaultMediaSourceFactory (<unknown commit>) does not change the MediaSourceFactory interface except adding @Nullable anotations to setters.

PiperOrigin-RevId: 290269640
parent 118d6906
...@@ -64,12 +64,11 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -64,12 +64,11 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
private final DataSource.Factory dataSourceFactory; private final DataSource.Factory dataSourceFactory;
@Nullable private ExtractorsFactory extractorsFactory; private ExtractorsFactory extractorsFactory;
@Nullable private String customCacheKey;
@Nullable private Object tag;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private int continueLoadingCheckIntervalBytes; private int continueLoadingCheckIntervalBytes;
private boolean isCreateCalled; @Nullable private String customCacheKey;
@Nullable private Object tag;
/** /**
* Creates a new factory for {@link ExtractorMediaSource}s. * Creates a new factory for {@link ExtractorMediaSource}s.
...@@ -78,6 +77,7 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -78,6 +77,7 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
*/ */
public Factory(DataSource.Factory dataSourceFactory) { public Factory(DataSource.Factory dataSourceFactory) {
this.dataSourceFactory = dataSourceFactory; this.dataSourceFactory = dataSourceFactory;
extractorsFactory = new DefaultExtractorsFactory();
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy(); loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES; continueLoadingCheckIntervalBytes = DEFAULT_LOADING_CHECK_INTERVAL_BYTES;
} }
...@@ -90,11 +90,10 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -90,11 +90,10 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
* possible formats are known, pass a factory that instantiates extractors for those * possible formats are known, pass a factory that instantiates extractors for those
* formats. * formats.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setExtractorsFactory(ExtractorsFactory extractorsFactory) { public Factory setExtractorsFactory(@Nullable ExtractorsFactory extractorsFactory) {
Assertions.checkState(!isCreateCalled); this.extractorsFactory =
this.extractorsFactory = extractorsFactory; extractorsFactory != null ? extractorsFactory : new DefaultExtractorsFactory();
return this; return this;
} }
...@@ -105,10 +104,8 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -105,10 +104,8 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
* @param customCacheKey A custom key that uniquely identifies the original stream. Used for * @param customCacheKey A custom key that uniquely identifies the original stream. Used for
* cache indexing. * cache indexing.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setCustomCacheKey(String customCacheKey) { public Factory setCustomCacheKey(@Nullable String customCacheKey) {
Assertions.checkState(!isCreateCalled);
this.customCacheKey = customCacheKey; this.customCacheKey = customCacheKey;
return this; return this;
} }
...@@ -120,27 +117,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -120,27 +117,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
* *
* @param tag A tag for the media source. * @param tag A tag for the media source.
* @return This factory, for convenience. * @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; this.tag = tag;
return this; return this;
} }
/** /** @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead. */
* Sets the minimum number of times to retry if a loading error occurs. See {@link
* #setLoadErrorHandlingPolicy} for the default value.
*
* <p>Calling this method is equivalent to calling {@link #setLoadErrorHandlingPolicy} with
* {@link DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy(int)
* DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)}
*
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead.
*/
@Deprecated @Deprecated
public Factory setMinLoadableRetryCount(int minLoadableRetryCount) { public Factory setMinLoadableRetryCount(int minLoadableRetryCount) {
return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)); return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount));
...@@ -154,11 +137,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -154,11 +137,13 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
* *
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}. * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) { public Factory setLoadErrorHandlingPolicy(
Assertions.checkState(!isCreateCalled); @Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy; this.loadErrorHandlingPolicy =
loadErrorHandlingPolicy != null
? loadErrorHandlingPolicy
: new DefaultLoadErrorHandlingPolicy();
return this; return this;
} }
...@@ -171,18 +156,16 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -171,18 +156,16 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
* each invocation of {@link * each invocation of {@link
* MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}. * MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckIntervalBytes) { public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckIntervalBytes) {
Assertions.checkState(!isCreateCalled);
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes; this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
return this; return this;
} }
/** @deprecated Use {@link ProgressiveMediaSource.Factory#setDrmSessionManager} instead. */ /** @deprecated Use {@link ProgressiveMediaSource.Factory#setDrmSessionManager} instead. */
@Override
@Deprecated @Deprecated
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) { @Override
public Factory setDrmSessionManager(@Nullable DrmSessionManager<?> drmSessionManager) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
...@@ -194,10 +177,6 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> { ...@@ -194,10 +177,6 @@ public final class ExtractorMediaSource extends CompositeMediaSource<Void> {
*/ */
@Override @Override
public ExtractorMediaSource createMediaSource(Uri uri) { public ExtractorMediaSource createMediaSource(Uri uri) {
isCreateCalled = true;
if (extractorsFactory == null) {
extractorsFactory = new DefaultExtractorsFactory();
}
return new ExtractorMediaSource( return new ExtractorMediaSource(
uri, uri,
dataSourceFactory, dataSourceFactory,
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source; package com.google.android.exoplayer2.source;
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.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
...@@ -30,9 +31,8 @@ public interface MediaSourceFactory { ...@@ -30,9 +31,8 @@ public interface MediaSourceFactory {
* *
* @param streamKeys A list of {@link StreamKey StreamKeys}. * @param streamKeys A list of {@link StreamKey StreamKeys}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/ */
default MediaSourceFactory setStreamKeys(List<StreamKey> streamKeys) { default MediaSourceFactory setStreamKeys(@Nullable List<StreamKey> streamKeys) {
return this; return this;
} }
...@@ -41,9 +41,8 @@ public interface MediaSourceFactory { ...@@ -41,9 +41,8 @@ public interface MediaSourceFactory {
* *
* @param drmSessionManager The {@link DrmSessionManager}. * @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
MediaSourceFactory setDrmSessionManager(DrmSessionManager<?> drmSessionManager); MediaSourceFactory setDrmSessionManager(@Nullable DrmSessionManager<?> drmSessionManager);
/** /**
* Creates a new {@link MediaSource} with the specified {@code uri}. * Creates a new {@link MediaSource} with the specified {@code uri}.
......
...@@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.DataSource; ...@@ -28,7 +28,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException; import java.io.IOException;
/** /**
...@@ -51,12 +50,11 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -51,12 +50,11 @@ public final class ProgressiveMediaSource extends BaseMediaSource
private final DataSource.Factory dataSourceFactory; private final DataSource.Factory dataSourceFactory;
private ExtractorsFactory extractorsFactory; private ExtractorsFactory extractorsFactory;
@Nullable private String customCacheKey;
@Nullable private Object tag;
private DrmSessionManager<?> drmSessionManager; private DrmSessionManager<?> drmSessionManager;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private int continueLoadingCheckIntervalBytes; private int continueLoadingCheckIntervalBytes;
private boolean isCreateCalled; @Nullable private String customCacheKey;
@Nullable private Object tag;
/** /**
* Creates a new factory for {@link ProgressiveMediaSource}s, using the extractors provided by * Creates a new factory for {@link ProgressiveMediaSource}s, using the extractors provided by
...@@ -83,22 +81,14 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -83,22 +81,14 @@ public final class ProgressiveMediaSource extends BaseMediaSource
} }
/** /**
* Sets the factory for {@link Extractor}s to process the media stream. The default value is an
* instance of {@link DefaultExtractorsFactory}.
*
* @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
* possible formats are known, pass a factory that instantiates extractors for those
* formats.
* @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
* @deprecated Pass the {@link ExtractorsFactory} via {@link #Factory(DataSource.Factory, * @deprecated Pass the {@link ExtractorsFactory} via {@link #Factory(DataSource.Factory,
* ExtractorsFactory)}. This is necessary so that proguard can treat the default extractors * ExtractorsFactory)}. This is necessary so that proguard can treat the default extractors
* factory as unused. * factory as unused.
*/ */
@Deprecated @Deprecated
public Factory setExtractorsFactory(ExtractorsFactory extractorsFactory) { public Factory setExtractorsFactory(@Nullable ExtractorsFactory extractorsFactory) {
Assertions.checkState(!isCreateCalled); this.extractorsFactory =
this.extractorsFactory = extractorsFactory; extractorsFactory != null ? extractorsFactory : new DefaultExtractorsFactory();
return this; return this;
} }
...@@ -109,10 +99,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -109,10 +99,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* @param customCacheKey A custom key that uniquely identifies the original stream. Used for * @param customCacheKey A custom key that uniquely identifies the original stream. Used for
* cache indexing. * cache indexing.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/ */
public Factory setCustomCacheKey(@Nullable String customCacheKey) { public Factory setCustomCacheKey(@Nullable String customCacheKey) {
Assertions.checkState(!isCreateCalled);
this.customCacheKey = customCacheKey; this.customCacheKey = customCacheKey;
return this; return this;
} }
...@@ -124,10 +112,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -124,10 +112,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* *
* @param tag A tag for the media source. * @param tag A tag for the media source.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/ */
public Factory setTag(Object tag) { public Factory setTag(@Nullable Object tag) {
Assertions.checkState(!isCreateCalled);
this.tag = tag; this.tag = tag;
return this; return this;
} }
...@@ -138,11 +124,13 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -138,11 +124,13 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* *
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}. * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/ */
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) { public Factory setLoadErrorHandlingPolicy(
Assertions.checkState(!isCreateCalled); @Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy; this.loadErrorHandlingPolicy =
loadErrorHandlingPolicy != null
? loadErrorHandlingPolicy
: new DefaultLoadErrorHandlingPolicy();
return this; return this;
} }
...@@ -155,10 +143,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -155,10 +143,8 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* each invocation of {@link * each invocation of {@link
* MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}. * MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If {@link #createMediaSource(Uri)} has already been called.
*/ */
public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckIntervalBytes) { public Factory setContinueLoadingCheckIntervalBytes(int continueLoadingCheckIntervalBytes) {
Assertions.checkState(!isCreateCalled);
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes; this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
return this; return this;
} }
...@@ -169,12 +155,13 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -169,12 +155,13 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* *
* @param drmSessionManager The {@link DrmSessionManager}. * @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
@Override @Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) { public Factory setDrmSessionManager(@Nullable DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled); this.drmSessionManager =
this.drmSessionManager = drmSessionManager; drmSessionManager != null
? drmSessionManager
: DrmSessionManager.getDummyDrmSessionManager();
return this; return this;
} }
...@@ -186,7 +173,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -186,7 +173,6 @@ public final class ProgressiveMediaSource extends BaseMediaSource
*/ */
@Override @Override
public ProgressiveMediaSource createMediaSource(Uri uri) { public ProgressiveMediaSource createMediaSource(Uri uri) {
isCreateCalled = true;
return new ProgressiveMediaSource( return new ProgressiveMediaSource(
uri, uri,
dataSourceFactory, dataSourceFactory,
......
...@@ -83,13 +83,12 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -83,13 +83,12 @@ public final class DashMediaSource extends BaseMediaSource {
@Nullable private final DataSource.Factory manifestDataSourceFactory; @Nullable private final DataSource.Factory manifestDataSourceFactory;
private DrmSessionManager<?> drmSessionManager; private DrmSessionManager<?> drmSessionManager;
@Nullable private ParsingLoadable.Parser<? extends DashManifest> manifestParser;
@Nullable private List<StreamKey> streamKeys;
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory; private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private long livePresentationDelayMs; private long livePresentationDelayMs;
private boolean livePresentationDelayOverridesManifest; private boolean livePresentationDelayOverridesManifest;
private boolean isCreateCalled; @Nullable private ParsingLoadable.Parser<? extends DashManifest> manifestParser;
@Nullable private List<StreamKey> streamKeys;
@Nullable private Object tag; @Nullable private Object tag;
/** /**
...@@ -129,27 +128,35 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -129,27 +128,35 @@ public final class DashMediaSource extends BaseMediaSource {
* *
* @param tag A tag for the media source. * @param tag A tag for the media source.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setTag(@Nullable Object tag) { public Factory setTag(@Nullable Object tag) {
Assertions.checkState(!isCreateCalled);
this.tag = tag; this.tag = tag;
return this; return this;
} }
@Override
public Factory setStreamKeys(@Nullable List<StreamKey> streamKeys) {
this.streamKeys = streamKeys != null && !streamKeys.isEmpty() ? streamKeys : null;
return this;
}
/** /**
* Sets the minimum number of times to retry if a loading error occurs. See {@link * Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* #setLoadErrorHandlingPolicy} for the default value. * default value is {@link DrmSessionManager#DUMMY}.
*
* <p>Calling this method is equivalent to calling {@link #setLoadErrorHandlingPolicy} with
* {@link DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy(int)
* DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)}
* *
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead.
*/ */
@Override
public Factory setDrmSessionManager(@Nullable DrmSessionManager<?> drmSessionManager) {
this.drmSessionManager =
drmSessionManager != null
? drmSessionManager
: DrmSessionManager.getDummyDrmSessionManager();
return this;
}
/** @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead. */
@Deprecated @Deprecated
public Factory setMinLoadableRetryCount(int minLoadableRetryCount) { public Factory setMinLoadableRetryCount(int minLoadableRetryCount) {
return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)); return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount));
...@@ -163,15 +170,16 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -163,15 +170,16 @@ public final class DashMediaSource extends BaseMediaSource {
* *
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}. * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) { public Factory setLoadErrorHandlingPolicy(
Assertions.checkState(!isCreateCalled); @Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy; this.loadErrorHandlingPolicy =
loadErrorHandlingPolicy != null
? loadErrorHandlingPolicy
: new DefaultLoadErrorHandlingPolicy();
return this; return this;
} }
/** @deprecated Use {@link #setLivePresentationDelayMs(long, boolean)}. */
@Deprecated @Deprecated
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Factory setLivePresentationDelayMs(long livePresentationDelayMs) { public Factory setLivePresentationDelayMs(long livePresentationDelayMs) {
...@@ -194,11 +202,9 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -194,11 +202,9 @@ public final class DashMediaSource extends BaseMediaSource {
* @param overridesManifest Whether the value is used in preference to one in the manifest, if * @param overridesManifest Whether the value is used in preference to one in the manifest, if
* present. * present.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setLivePresentationDelayMs( public Factory setLivePresentationDelayMs(
long livePresentationDelayMs, boolean overridesManifest) { long livePresentationDelayMs, boolean overridesManifest) {
Assertions.checkState(!isCreateCalled);
this.livePresentationDelayMs = livePresentationDelayMs; this.livePresentationDelayMs = livePresentationDelayMs;
this.livePresentationDelayOverridesManifest = overridesManifest; this.livePresentationDelayOverridesManifest = overridesManifest;
return this; return this;
...@@ -209,12 +215,10 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -209,12 +215,10 @@ public final class DashMediaSource extends BaseMediaSource {
* *
* @param manifestParser A parser for loaded manifest data. * @param manifestParser A parser for loaded manifest data.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setManifestParser( public Factory setManifestParser(
ParsingLoadable.Parser<? extends DashManifest> manifestParser) { @Nullable ParsingLoadable.Parser<? extends DashManifest> manifestParser) {
Assertions.checkState(!isCreateCalled); this.manifestParser = manifestParser;
this.manifestParser = Assertions.checkNotNull(manifestParser);
return this; return this;
} }
...@@ -227,13 +231,13 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -227,13 +231,13 @@ public final class DashMediaSource extends BaseMediaSource {
* SequenceableLoader}s for when this media source loads data from multiple streams (video, * SequenceableLoader}s for when this media source loads data from multiple streams (video,
* audio etc...). * audio etc...).
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setCompositeSequenceableLoaderFactory( public Factory setCompositeSequenceableLoaderFactory(
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { @Nullable CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) {
Assertions.checkState(!isCreateCalled);
this.compositeSequenceableLoaderFactory = this.compositeSequenceableLoaderFactory =
Assertions.checkNotNull(compositeSequenceableLoaderFactory); compositeSequenceableLoaderFactory != null
? compositeSequenceableLoaderFactory
: new DefaultCompositeSequenceableLoaderFactory();
return this; return this;
} }
...@@ -247,8 +251,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -247,8 +251,7 @@ public final class DashMediaSource extends BaseMediaSource {
*/ */
public DashMediaSource createMediaSource(DashManifest manifest) { public DashMediaSource createMediaSource(DashManifest manifest) {
Assertions.checkArgument(!manifest.dynamic); Assertions.checkArgument(!manifest.dynamic);
isCreateCalled = true; if (streamKeys != null) {
if (streamKeys != null && !streamKeys.isEmpty()) {
manifest = manifest.copy(streamKeys); manifest = manifest.copy(streamKeys);
} }
return new DashMediaSource( return new DashMediaSource(
...@@ -298,21 +301,6 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -298,21 +301,6 @@ public final class DashMediaSource extends BaseMediaSource {
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link DashMediaSource} using the current parameters. * Returns a new {@link DashMediaSource} using the current parameters.
* *
* @param manifestUri The manifest {@link Uri}. * @param manifestUri The manifest {@link Uri}.
...@@ -320,7 +308,7 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -320,7 +308,7 @@ public final class DashMediaSource extends BaseMediaSource {
*/ */
@Override @Override
public DashMediaSource createMediaSource(Uri manifestUri) { public DashMediaSource createMediaSource(Uri manifestUri) {
isCreateCalled = true; @Nullable ParsingLoadable.Parser<? extends DashManifest> manifestParser = this.manifestParser;
if (manifestParser == null) { if (manifestParser == null) {
manifestParser = new DashManifestParser(); manifestParser = new DashManifestParser();
} }
...@@ -342,13 +330,6 @@ public final class DashMediaSource extends BaseMediaSource { ...@@ -342,13 +330,6 @@ public final class DashMediaSource extends BaseMediaSource {
} }
@Override @Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
@Override
public int[] getSupportedTypes() { public int[] getSupportedTypes() {
return new int[] {C.TYPE_DASH}; return new int[] {C.TYPE_DASH};
} }
......
...@@ -69,13 +69,12 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -69,13 +69,12 @@ public final class SsMediaSource extends BaseMediaSource
private final SsChunkSource.Factory chunkSourceFactory; private final SsChunkSource.Factory chunkSourceFactory;
@Nullable private final DataSource.Factory manifestDataSourceFactory; @Nullable private final DataSource.Factory manifestDataSourceFactory;
@Nullable private ParsingLoadable.Parser<? extends SsManifest> manifestParser;
@Nullable private List<StreamKey> streamKeys;
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory; private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
private DrmSessionManager<?> drmSessionManager; private DrmSessionManager<?> drmSessionManager;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private long livePresentationDelayMs; private long livePresentationDelayMs;
private boolean isCreateCalled; @Nullable private ParsingLoadable.Parser<? extends SsManifest> manifestParser;
@Nullable private List<StreamKey> streamKeys;
@Nullable private Object tag; @Nullable private Object tag;
/** /**
...@@ -114,27 +113,13 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -114,27 +113,13 @@ public final class SsMediaSource extends BaseMediaSource
* *
* @param tag A tag for the media source. * @param tag A tag for the media source.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setTag(@Nullable Object tag) { public Factory setTag(@Nullable Object tag) {
Assertions.checkState(!isCreateCalled);
this.tag = tag; this.tag = tag;
return this; return this;
} }
/** /** @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead. */
* Sets the minimum number of times to retry if a loading error occurs. See {@link
* #setLoadErrorHandlingPolicy} for the default value.
*
* <p>Calling this method is equivalent to calling {@link #setLoadErrorHandlingPolicy} with
* {@link DefaultLoadErrorHandlingPolicy#DefaultLoadErrorHandlingPolicy(int)
* DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)}
*
* @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
* @deprecated Use {@link #setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy)} instead.
*/
@Deprecated @Deprecated
public Factory setMinLoadableRetryCount(int minLoadableRetryCount) { public Factory setMinLoadableRetryCount(int minLoadableRetryCount) {
return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount)); return setLoadErrorHandlingPolicy(new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount));
...@@ -148,11 +133,13 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -148,11 +133,13 @@ public final class SsMediaSource extends BaseMediaSource
* *
* @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}. * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) { public Factory setLoadErrorHandlingPolicy(
Assertions.checkState(!isCreateCalled); @Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy; this.loadErrorHandlingPolicy =
loadErrorHandlingPolicy != null
? loadErrorHandlingPolicy
: new DefaultLoadErrorHandlingPolicy();
return this; return this;
} }
...@@ -164,10 +151,8 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -164,10 +151,8 @@ public final class SsMediaSource extends BaseMediaSource
* @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
* default start position should precede the end of the live window. * default start position should precede the end of the live window.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setLivePresentationDelayMs(long livePresentationDelayMs) { public Factory setLivePresentationDelayMs(long livePresentationDelayMs) {
Assertions.checkState(!isCreateCalled);
this.livePresentationDelayMs = livePresentationDelayMs; this.livePresentationDelayMs = livePresentationDelayMs;
return this; return this;
} }
...@@ -177,11 +162,10 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -177,11 +162,10 @@ public final class SsMediaSource extends BaseMediaSource
* *
* @param manifestParser A parser for loaded manifest data. * @param manifestParser A parser for loaded manifest data.
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setManifestParser(ParsingLoadable.Parser<? extends SsManifest> manifestParser) { public Factory setManifestParser(
Assertions.checkState(!isCreateCalled); @Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser) {
this.manifestParser = Assertions.checkNotNull(manifestParser); this.manifestParser = manifestParser;
return this; return this;
} }
...@@ -194,13 +178,35 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -194,13 +178,35 @@ public final class SsMediaSource extends BaseMediaSource
* SequenceableLoader}s for when this media source loads data from multiple streams (video, * SequenceableLoader}s for when this media source loads data from multiple streams (video,
* audio etc.). * audio etc.).
* @return This factory, for convenience. * @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/ */
public Factory setCompositeSequenceableLoaderFactory( public Factory setCompositeSequenceableLoaderFactory(
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) { @Nullable CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory) {
Assertions.checkState(!isCreateCalled);
this.compositeSequenceableLoaderFactory = this.compositeSequenceableLoaderFactory =
Assertions.checkNotNull(compositeSequenceableLoaderFactory); compositeSequenceableLoaderFactory != null
? compositeSequenceableLoaderFactory
: new DefaultCompositeSequenceableLoaderFactory();
return this;
}
/**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
*/
@Override
public Factory setDrmSessionManager(@Nullable DrmSessionManager<?> drmSessionManager) {
this.drmSessionManager =
drmSessionManager != null
? drmSessionManager
: DrmSessionManager.getDummyDrmSessionManager();
return this;
}
@Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
this.streamKeys = streamKeys != null && !streamKeys.isEmpty() ? streamKeys : null;
return this; return this;
} }
...@@ -214,8 +220,7 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -214,8 +220,7 @@ public final class SsMediaSource extends BaseMediaSource
*/ */
public SsMediaSource createMediaSource(SsManifest manifest) { public SsMediaSource createMediaSource(SsManifest manifest) {
Assertions.checkArgument(!manifest.isLive); Assertions.checkArgument(!manifest.isLive);
isCreateCalled = true; if (streamKeys != null) {
if (streamKeys != null && !streamKeys.isEmpty()) {
manifest = manifest.copy(streamKeys); manifest = manifest.copy(streamKeys);
} }
return new SsMediaSource( return new SsMediaSource(
...@@ -264,21 +269,6 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -264,21 +269,6 @@ public final class SsMediaSource extends BaseMediaSource
} }
/** /**
* Sets the {@link DrmSessionManager} to use for acquiring {@link DrmSession DrmSessions}. The
* default value is {@link DrmSessionManager#DUMMY}.
*
* @param drmSessionManager The {@link DrmSessionManager}.
* @return This factory, for convenience.
* @throws IllegalStateException If one of the {@code create} methods has already been called.
*/
@Override
public Factory setDrmSessionManager(DrmSessionManager<?> drmSessionManager) {
Assertions.checkState(!isCreateCalled);
this.drmSessionManager = drmSessionManager;
return this;
}
/**
* Returns a new {@link SsMediaSource} using the current parameters. * Returns a new {@link SsMediaSource} using the current parameters.
* *
* @param manifestUri The manifest {@link Uri}. * @param manifestUri The manifest {@link Uri}.
...@@ -286,7 +276,7 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -286,7 +276,7 @@ public final class SsMediaSource extends BaseMediaSource
*/ */
@Override @Override
public SsMediaSource createMediaSource(Uri manifestUri) { public SsMediaSource createMediaSource(Uri manifestUri) {
isCreateCalled = true; @Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser = this.manifestParser;
if (manifestParser == null) { if (manifestParser == null) {
manifestParser = new SsManifestParser(); manifestParser = new SsManifestParser();
} }
...@@ -307,17 +297,9 @@ public final class SsMediaSource extends BaseMediaSource ...@@ -307,17 +297,9 @@ public final class SsMediaSource extends BaseMediaSource
} }
@Override @Override
public Factory setStreamKeys(List<StreamKey> streamKeys) {
Assertions.checkState(!isCreateCalled);
this.streamKeys = streamKeys;
return this;
}
@Override
public int[] getSupportedTypes() { public int[] getSupportedTypes() {
return new int[] {C.TYPE_SS}; return new int[] {C.TYPE_SS};
} }
} }
/** /**
......
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