Simplify DASH live presentation delay override
This commit is contained in:
parent
58fcf52b17
commit
41345dcb83
@ -79,7 +79,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private int minLoadableRetryCount;
|
private int minLoadableRetryCount;
|
||||||
private long livePresentationDelayMs;
|
private long livePresentationDelayMs;
|
||||||
private long defaultLivePresentationDelayMs;
|
private boolean livePresentationDelayOverridesManifest;
|
||||||
private boolean isCreateCalled;
|
private boolean isCreateCalled;
|
||||||
private @Nullable Object tag;
|
private @Nullable Object tag;
|
||||||
|
|
||||||
@ -98,8 +98,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
this.chunkSourceFactory = Assertions.checkNotNull(chunkSourceFactory);
|
this.chunkSourceFactory = Assertions.checkNotNull(chunkSourceFactory);
|
||||||
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
||||||
minLoadableRetryCount = DEFAULT_MIN_LOADABLE_RETRY_COUNT;
|
minLoadableRetryCount = DEFAULT_MIN_LOADABLE_RETRY_COUNT;
|
||||||
livePresentationDelayMs = DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS;
|
livePresentationDelayMs = DEFAULT_LIVE_PRESENTATION_DELAY_MS;
|
||||||
defaultLivePresentationDelayMs = DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS;
|
|
||||||
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,41 +131,36 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link #setLivePresentationDelayMs(long, boolean)}. */
|
||||||
* Sets the duration in milliseconds by which the default start position should precede the end
|
@Deprecated
|
||||||
* of the live window for live playbacks. The default value is {@link
|
@SuppressWarnings("deprecation")
|
||||||
* #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS}.
|
|
||||||
*
|
|
||||||
* @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
|
|
||||||
* default start position should precede the end of the live window. Use {@link
|
|
||||||
* #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS} to use the value specified by the
|
|
||||||
* manifest, if present.
|
|
||||||
* @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);
|
if (livePresentationDelayMs == DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS) {
|
||||||
this.livePresentationDelayMs = livePresentationDelayMs;
|
return setLivePresentationDelayMs(DEFAULT_LIVE_PRESENTATION_DELAY_MS, false);
|
||||||
return this;
|
} else {
|
||||||
|
return setLivePresentationDelayMs(livePresentationDelayMs, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the duration in milliseconds by which the default start position should precede the end
|
* Sets the duration in milliseconds by which the default start position should precede the end
|
||||||
* of the live window for live playbacks if the value is not present in the manifest.
|
* of the live window for live playbacks. The {@code overridesManifest} parameter specifies
|
||||||
* The default value is {@link #DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS}. This value is only
|
* whether the value is used in preference to one in the manifest, if present. The default value
|
||||||
* used when {@link setLivePresentationDelayMs} has not overwritten the presentation delay to a
|
* is {@link #DEFAULT_LIVE_PRESENTATION_DELAY_MS}, and by default {@code overridesManifest} is
|
||||||
* value other than #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS
|
* false.
|
||||||
*
|
*
|
||||||
* @param defaultLivePresentationDelayMs For live playbacks, the duration in milliseconds by
|
* @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
|
||||||
* which the default start position should precede the end of the live window if the
|
* default start position should precede the end of the live window.
|
||||||
* duration is not specifed in the manifest or overwritten using
|
* @param overridesManifest Whether the value is used in preference to one in the manifest, if
|
||||||
* {@link setLivePresentationDelayMs}.
|
* present.
|
||||||
* @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 setDefaultLivePresentationDelayMs(long defaultLivePresentationDelayMs) {
|
public Factory setLivePresentationDelayMs(
|
||||||
|
long livePresentationDelayMs, boolean overridesManifest) {
|
||||||
Assertions.checkState(!isCreateCalled);
|
Assertions.checkState(!isCreateCalled);
|
||||||
this.defaultLivePresentationDelayMs = defaultLivePresentationDelayMs;
|
this.livePresentationDelayMs = livePresentationDelayMs;
|
||||||
|
this.livePresentationDelayOverridesManifest = overridesManifest;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +217,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
minLoadableRetryCount,
|
minLoadableRetryCount,
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs,
|
||||||
defaultLivePresentationDelayMs,
|
livePresentationDelayOverridesManifest,
|
||||||
tag);
|
tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +258,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
minLoadableRetryCount,
|
minLoadableRetryCount,
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs,
|
||||||
defaultLivePresentationDelayMs,
|
livePresentationDelayOverridesManifest,
|
||||||
tag);
|
tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,18 +288,18 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* The default minimum number of times to retry loading data prior to failing.
|
* The default minimum number of times to retry loading data prior to failing.
|
||||||
*/
|
*/
|
||||||
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A constant indicating that the presentation delay for live streams should be set to
|
* The default presentation delay for live streams. The presentation delay is the duration by
|
||||||
* {@link DashManifest#suggestedPresentationDelayMs} if specified by the manifest, or
|
* which the default start position precedes the end of the live window.
|
||||||
* {@link #DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS} otherwise. The presentation delay is the
|
|
||||||
* duration by which the default start position precedes the end of the live window.
|
|
||||||
*/
|
*/
|
||||||
public static final long DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS = -1;
|
public static final long DEFAULT_LIVE_PRESENTATION_DELAY_MS = 30000;
|
||||||
/**
|
/** @deprecated Use {@link #DEFAULT_LIVE_PRESENTATION_DELAY_MS}. */
|
||||||
* A fixed default presentation delay for live streams. The presentation delay is the duration
|
@Deprecated
|
||||||
* by which the default start position precedes the end of the live window.
|
public static final long DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS =
|
||||||
*/
|
DEFAULT_LIVE_PRESENTATION_DELAY_MS;
|
||||||
public static final long DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS = 30000;
|
/** @deprecated Use of this parameter is no longer necessary. */
|
||||||
|
@Deprecated public static final long DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interval in milliseconds between invocations of {@link
|
* The interval in milliseconds between invocations of {@link
|
||||||
@ -326,7 +320,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private final int minLoadableRetryCount;
|
private final int minLoadableRetryCount;
|
||||||
private final long livePresentationDelayMs;
|
private final long livePresentationDelayMs;
|
||||||
private final long defaultLivePresentationDelayMs;
|
private final boolean livePresentationDelayOverridesManifest;
|
||||||
private final EventDispatcher manifestEventDispatcher;
|
private final EventDispatcher manifestEventDispatcher;
|
||||||
private final ParsingLoadable.Parser<? extends DashManifest> manifestParser;
|
private final ParsingLoadable.Parser<? extends DashManifest> manifestParser;
|
||||||
private final ManifestCallback manifestCallback;
|
private final ManifestCallback manifestCallback;
|
||||||
@ -369,6 +363,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* @deprecated Use {@link Factory} instead.
|
* @deprecated Use {@link Factory} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DashMediaSource(
|
public DashMediaSource(
|
||||||
DashManifest manifest,
|
DashManifest manifest,
|
||||||
DashChunkSource.Factory chunkSourceFactory,
|
DashChunkSource.Factory chunkSourceFactory,
|
||||||
@ -403,8 +398,8 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
new DefaultCompositeSequenceableLoaderFactory(),
|
new DefaultCompositeSequenceableLoaderFactory(),
|
||||||
minLoadableRetryCount,
|
minLoadableRetryCount,
|
||||||
DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS,
|
DEFAULT_LIVE_PRESENTATION_DELAY_MS,
|
||||||
DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS,
|
/* livePresentationDelayOverridesManifest= */ false,
|
||||||
/* tag= */ null);
|
/* tag= */ null);
|
||||||
if (eventHandler != null && eventListener != null) {
|
if (eventHandler != null && eventListener != null) {
|
||||||
addEventListener(eventHandler, eventListener);
|
addEventListener(eventHandler, eventListener);
|
||||||
@ -424,6 +419,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* @deprecated Use {@link Factory} instead.
|
* @deprecated Use {@link Factory} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DashMediaSource(
|
public DashMediaSource(
|
||||||
Uri manifestUri,
|
Uri manifestUri,
|
||||||
DataSource.Factory manifestDataSourceFactory,
|
DataSource.Factory manifestDataSourceFactory,
|
||||||
@ -453,6 +449,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* @deprecated Use {@link Factory} instead.
|
* @deprecated Use {@link Factory} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DashMediaSource(
|
public DashMediaSource(
|
||||||
Uri manifestUri,
|
Uri manifestUri,
|
||||||
DataSource.Factory manifestDataSourceFactory,
|
DataSource.Factory manifestDataSourceFactory,
|
||||||
@ -461,8 +458,15 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
long livePresentationDelayMs,
|
long livePresentationDelayMs,
|
||||||
Handler eventHandler,
|
Handler eventHandler,
|
||||||
MediaSourceEventListener eventListener) {
|
MediaSourceEventListener eventListener) {
|
||||||
this(manifestUri, manifestDataSourceFactory, new DashManifestParser(), chunkSourceFactory,
|
this(
|
||||||
minLoadableRetryCount, livePresentationDelayMs, eventHandler, eventListener);
|
manifestUri,
|
||||||
|
manifestDataSourceFactory,
|
||||||
|
new DashManifestParser(),
|
||||||
|
chunkSourceFactory,
|
||||||
|
minLoadableRetryCount,
|
||||||
|
livePresentationDelayMs,
|
||||||
|
eventHandler,
|
||||||
|
eventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,6 +488,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* @deprecated Use {@link Factory} instead.
|
* @deprecated Use {@link Factory} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DashMediaSource(
|
public DashMediaSource(
|
||||||
Uri manifestUri,
|
Uri manifestUri,
|
||||||
DataSource.Factory manifestDataSourceFactory,
|
DataSource.Factory manifestDataSourceFactory,
|
||||||
@ -501,8 +506,10 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
new DefaultCompositeSequenceableLoaderFactory(),
|
new DefaultCompositeSequenceableLoaderFactory(),
|
||||||
minLoadableRetryCount,
|
minLoadableRetryCount,
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs == DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS
|
||||||
DEFAULT_LIVE_PRESENTATION_DELAY_FIXED_MS,
|
? DEFAULT_LIVE_PRESENTATION_DELAY_MS
|
||||||
|
: livePresentationDelayMs,
|
||||||
|
livePresentationDelayMs != DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS,
|
||||||
/* tag= */ null);
|
/* tag= */ null);
|
||||||
if (eventHandler != null && eventListener != null) {
|
if (eventHandler != null && eventListener != null) {
|
||||||
addEventListener(eventHandler, eventListener);
|
addEventListener(eventHandler, eventListener);
|
||||||
@ -518,7 +525,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||||
int minLoadableRetryCount,
|
int minLoadableRetryCount,
|
||||||
long livePresentationDelayMs,
|
long livePresentationDelayMs,
|
||||||
long defaultLivePresentationDelayMs,
|
boolean livePresentationDelayOverridesManifest,
|
||||||
@Nullable Object tag) {
|
@Nullable Object tag) {
|
||||||
this.initialManifestUri = manifestUri;
|
this.initialManifestUri = manifestUri;
|
||||||
this.manifest = manifest;
|
this.manifest = manifest;
|
||||||
@ -528,7 +535,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
this.chunkSourceFactory = chunkSourceFactory;
|
this.chunkSourceFactory = chunkSourceFactory;
|
||||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||||
this.livePresentationDelayMs = livePresentationDelayMs;
|
this.livePresentationDelayMs = livePresentationDelayMs;
|
||||||
this.defaultLivePresentationDelayMs = defaultLivePresentationDelayMs;
|
this.livePresentationDelayOverridesManifest = livePresentationDelayOverridesManifest;
|
||||||
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
sideloadedManifest = manifest != null;
|
sideloadedManifest = manifest != null;
|
||||||
@ -912,9 +919,9 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
long windowDefaultStartPositionUs = 0;
|
long windowDefaultStartPositionUs = 0;
|
||||||
if (manifest.dynamic) {
|
if (manifest.dynamic) {
|
||||||
long presentationDelayForManifestMs = livePresentationDelayMs;
|
long presentationDelayForManifestMs = livePresentationDelayMs;
|
||||||
if (presentationDelayForManifestMs == DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS) {
|
if (!livePresentationDelayOverridesManifest
|
||||||
presentationDelayForManifestMs = manifest.suggestedPresentationDelayMs != C.TIME_UNSET
|
&& manifest.suggestedPresentationDelayMs != C.TIME_UNSET) {
|
||||||
? manifest.suggestedPresentationDelayMs : defaultLivePresentationDelayMs;
|
presentationDelayForManifestMs = manifest.suggestedPresentationDelayMs;
|
||||||
}
|
}
|
||||||
// Snap the default position to the start of the segment containing it.
|
// Snap the default position to the start of the segment containing it.
|
||||||
windowDefaultStartPositionUs = windowDurationUs - C.msToUs(presentationDelayForManifestMs);
|
windowDefaultStartPositionUs = windowDurationUs - C.msToUs(presentationDelayForManifestMs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user