Added setMinLiveStartPositionMs to DashMediaSource.Factory
This commit is contained in:
parent
997f2be5e5
commit
b417838209
@ -110,6 +110,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private long fallbackTargetLiveOffsetMs;
|
private long fallbackTargetLiveOffsetMs;
|
||||||
|
private long minLiveStartPositionUs;
|
||||||
@Nullable private ParsingLoadable.Parser<? extends DashManifest> manifestParser;
|
@Nullable private ParsingLoadable.Parser<? extends DashManifest> manifestParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,7 +146,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
* @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
|
* @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
|
||||||
* @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
|
* @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
|
||||||
* to load (and refresh) the manifest. May be {@code null} if the factory will only ever be
|
* to load (and refresh) the manifest. May be {@code null} if the factory will only ever be
|
||||||
* used to create create media sources with sideloaded manifests via {@link
|
* used to create media sources with sideloaded manifests via {@link
|
||||||
* #createMediaSource(DashManifest, MediaItem)}.
|
* #createMediaSource(DashManifest, MediaItem)}.
|
||||||
*/
|
*/
|
||||||
public Factory(
|
public Factory(
|
||||||
@ -156,6 +157,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
|
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
|
||||||
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||||
fallbackTargetLiveOffsetMs = DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS;
|
fallbackTargetLiveOffsetMs = DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS;
|
||||||
|
minLiveStartPositionUs = MIN_LIVE_DEFAULT_START_POSITION_US;
|
||||||
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +201,21 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the minimum position to start playback from, in a live stream.
|
||||||
|
* This value will override any suggested value from the manifest.
|
||||||
|
*
|
||||||
|
* <p>The default value is {@link #MIN_LIVE_DEFAULT_START_POSITION_US}.
|
||||||
|
*
|
||||||
|
* @param minLiveStartPositionUs The minimum live start position in microseconds.
|
||||||
|
* @return This factory, for convenience.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public Factory setMinLiveStartPositionUs(long minLiveStartPositionUs) {
|
||||||
|
this.minLiveStartPositionUs = minLiveStartPositionUs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the manifest parser to parse loaded manifest data when loading a manifest URI.
|
* Sets the manifest parser to parse loaded manifest data when loading a manifest URI.
|
||||||
*
|
*
|
||||||
@ -278,7 +295,8 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
drmSessionManagerProvider.get(mediaItem),
|
drmSessionManagerProvider.get(mediaItem),
|
||||||
loadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
fallbackTargetLiveOffsetMs);
|
fallbackTargetLiveOffsetMs,
|
||||||
|
minLiveStartPositionUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,7 +327,8 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
drmSessionManagerProvider.get(mediaItem),
|
drmSessionManagerProvider.get(mediaItem),
|
||||||
loadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
fallbackTargetLiveOffsetMs);
|
fallbackTargetLiveOffsetMs,
|
||||||
|
minLiveStartPositionUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -330,16 +349,18 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
/** The media id used by media items of dash media sources without a manifest URI. */
|
/** The media id used by media items of dash media sources without a manifest URI. */
|
||||||
public static final String DEFAULT_MEDIA_ID = "DashMediaSource";
|
public static final String DEFAULT_MEDIA_ID = "DashMediaSource";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum default start position for live streams in micro seconds, relative to
|
||||||
|
* the start of the live window.
|
||||||
|
*/
|
||||||
|
public static final long MIN_LIVE_DEFAULT_START_POSITION_US = 5_000_000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interval in milliseconds between invocations of {@link
|
* The interval in milliseconds between invocations of {@link
|
||||||
* MediaSourceCaller#onSourceInfoRefreshed(MediaSource, Timeline)} when the source's {@link
|
* MediaSourceCaller#onSourceInfoRefreshed(MediaSource, Timeline)} when the source's {@link
|
||||||
* Timeline} is changing dynamically (for example, for incomplete live streams).
|
* Timeline} is changing dynamically (for example, for incomplete live streams).
|
||||||
*/
|
*/
|
||||||
private static final long DEFAULT_NOTIFY_MANIFEST_INTERVAL_MS = 5000;
|
private static final long DEFAULT_NOTIFY_MANIFEST_INTERVAL_MS = 5000;
|
||||||
/**
|
|
||||||
* The minimum default start position for live streams, relative to the start of the live window.
|
|
||||||
*/
|
|
||||||
private static final long MIN_LIVE_DEFAULT_START_POSITION_US = 5_000_000;
|
|
||||||
|
|
||||||
private static final String TAG = "DashMediaSource";
|
private static final String TAG = "DashMediaSource";
|
||||||
|
|
||||||
@ -352,6 +373,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private final BaseUrlExclusionList baseUrlExclusionList;
|
private final BaseUrlExclusionList baseUrlExclusionList;
|
||||||
private final long fallbackTargetLiveOffsetMs;
|
private final long fallbackTargetLiveOffsetMs;
|
||||||
|
private final long minLiveStartPositionUs;
|
||||||
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;
|
||||||
@ -392,7 +414,8 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||||
DrmSessionManager drmSessionManager,
|
DrmSessionManager drmSessionManager,
|
||||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
long fallbackTargetLiveOffsetMs) {
|
long fallbackTargetLiveOffsetMs,
|
||||||
|
long minLiveStartPositionUs) {
|
||||||
this.mediaItem = mediaItem;
|
this.mediaItem = mediaItem;
|
||||||
this.liveConfiguration = mediaItem.liveConfiguration;
|
this.liveConfiguration = mediaItem.liveConfiguration;
|
||||||
this.manifestUri = checkNotNull(mediaItem.localConfiguration).uri;
|
this.manifestUri = checkNotNull(mediaItem.localConfiguration).uri;
|
||||||
@ -404,6 +427,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
this.drmSessionManager = drmSessionManager;
|
this.drmSessionManager = drmSessionManager;
|
||||||
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
this.fallbackTargetLiveOffsetMs = fallbackTargetLiveOffsetMs;
|
this.fallbackTargetLiveOffsetMs = fallbackTargetLiveOffsetMs;
|
||||||
|
this.minLiveStartPositionUs = minLiveStartPositionUs;
|
||||||
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
|
||||||
baseUrlExclusionList = new BaseUrlExclusionList();
|
baseUrlExclusionList = new BaseUrlExclusionList();
|
||||||
sideloadedManifest = manifest != null;
|
sideloadedManifest = manifest != null;
|
||||||
@ -830,7 +854,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
manifest.availabilityStartTimeMs + Util.usToMs(windowStartTimeInManifestUs);
|
manifest.availabilityStartTimeMs + Util.usToMs(windowStartTimeInManifestUs);
|
||||||
windowDefaultPositionUs = nowInWindowUs - Util.msToUs(liveConfiguration.targetOffsetMs);
|
windowDefaultPositionUs = nowInWindowUs - Util.msToUs(liveConfiguration.targetOffsetMs);
|
||||||
long minimumWindowDefaultPositionUs =
|
long minimumWindowDefaultPositionUs =
|
||||||
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
|
min(minLiveStartPositionUs, windowDurationUs / 2);
|
||||||
if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) {
|
if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) {
|
||||||
// The default position is too close to the start of the live window. Set it to the minimum
|
// The default position is too close to the start of the live window. Set it to the minimum
|
||||||
// default position provided the window is at least twice as big. Else set it to the middle
|
// default position provided the window is at least twice as big. Else set it to the middle
|
||||||
@ -940,7 +964,7 @@ public final class DashMediaSource extends BaseMediaSource {
|
|||||||
}
|
}
|
||||||
if (targetOffsetMs > maxLiveOffsetMs) {
|
if (targetOffsetMs > maxLiveOffsetMs) {
|
||||||
long safeDistanceFromWindowStartUs =
|
long safeDistanceFromWindowStartUs =
|
||||||
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
|
min(minLiveStartPositionUs, windowDurationUs / 2);
|
||||||
long maxTargetOffsetForSafeDistanceToWindowStartMs =
|
long maxTargetOffsetForSafeDistanceToWindowStartMs =
|
||||||
usToMs(nowInWindowUs - safeDistanceFromWindowStartUs);
|
usToMs(nowInWindowUs - safeDistanceFromWindowStartUs);
|
||||||
targetOffsetMs =
|
targetOffsetMs =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user