Added setMinLiveStartPositionMs to DashMediaSource.Factory

This commit is contained in:
Vishnu Chilakala 2023-05-29 20:09:35 +05:30 committed by tonihei
parent 997f2be5e5
commit b417838209

View File

@ -110,6 +110,7 @@ public final class DashMediaSource extends BaseMediaSource {
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private long fallbackTargetLiveOffsetMs;
private long minLiveStartPositionUs;
@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 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
* used to create create media sources with sideloaded manifests via {@link
* used to create media sources with sideloaded manifests via {@link
* #createMediaSource(DashManifest, MediaItem)}.
*/
public Factory(
@ -156,6 +157,7 @@ public final class DashMediaSource extends BaseMediaSource {
drmSessionManagerProvider = new DefaultDrmSessionManagerProvider();
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
fallbackTargetLiveOffsetMs = DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS;
minLiveStartPositionUs = MIN_LIVE_DEFAULT_START_POSITION_US;
compositeSequenceableLoaderFactory = new DefaultCompositeSequenceableLoaderFactory();
}
@ -199,6 +201,21 @@ public final class DashMediaSource extends BaseMediaSource {
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.
*
@ -278,7 +295,8 @@ public final class DashMediaSource extends BaseMediaSource {
compositeSequenceableLoaderFactory,
drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
fallbackTargetLiveOffsetMs,
minLiveStartPositionUs);
}
/**
@ -309,7 +327,8 @@ public final class DashMediaSource extends BaseMediaSource {
compositeSequenceableLoaderFactory,
drmSessionManagerProvider.get(mediaItem),
loadErrorHandlingPolicy,
fallbackTargetLiveOffsetMs);
fallbackTargetLiveOffsetMs,
minLiveStartPositionUs);
}
@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. */
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
* MediaSourceCaller#onSourceInfoRefreshed(MediaSource, Timeline)} when the source's {@link
* Timeline} is changing dynamically (for example, for incomplete live streams).
*/
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";
@ -352,6 +373,7 @@ public final class DashMediaSource extends BaseMediaSource {
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
private final BaseUrlExclusionList baseUrlExclusionList;
private final long fallbackTargetLiveOffsetMs;
private final long minLiveStartPositionUs;
private final EventDispatcher manifestEventDispatcher;
private final ParsingLoadable.Parser<? extends DashManifest> manifestParser;
private final ManifestCallback manifestCallback;
@ -392,7 +414,8 @@ public final class DashMediaSource extends BaseMediaSource {
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
DrmSessionManager drmSessionManager,
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
long fallbackTargetLiveOffsetMs) {
long fallbackTargetLiveOffsetMs,
long minLiveStartPositionUs) {
this.mediaItem = mediaItem;
this.liveConfiguration = mediaItem.liveConfiguration;
this.manifestUri = checkNotNull(mediaItem.localConfiguration).uri;
@ -404,6 +427,7 @@ public final class DashMediaSource extends BaseMediaSource {
this.drmSessionManager = drmSessionManager;
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
this.fallbackTargetLiveOffsetMs = fallbackTargetLiveOffsetMs;
this.minLiveStartPositionUs = minLiveStartPositionUs;
this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
baseUrlExclusionList = new BaseUrlExclusionList();
sideloadedManifest = manifest != null;
@ -830,7 +854,7 @@ public final class DashMediaSource extends BaseMediaSource {
manifest.availabilityStartTimeMs + Util.usToMs(windowStartTimeInManifestUs);
windowDefaultPositionUs = nowInWindowUs - Util.msToUs(liveConfiguration.targetOffsetMs);
long minimumWindowDefaultPositionUs =
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
min(minLiveStartPositionUs, windowDurationUs / 2);
if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) {
// 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
@ -940,7 +964,7 @@ public final class DashMediaSource extends BaseMediaSource {
}
if (targetOffsetMs > maxLiveOffsetMs) {
long safeDistanceFromWindowStartUs =
min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
min(minLiveStartPositionUs, windowDurationUs / 2);
long maxTargetOffsetForSafeDistanceToWindowStartMs =
usToMs(nowInWindowUs - safeDistanceFromWindowStartUs);
targetOffsetMs =