DashWrappingSegmentIndex


@UnstableApi
public final class DashWrappingSegmentIndex implements DashSegmentIndex


An implementation of DashSegmentIndex that wraps a ChunkIndex parsed from a media stream.

Summary

Public constructors

DashWrappingSegmentIndex(ChunkIndex chunkIndex, long timeOffsetUs)

Public methods

long
getAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs)

Returns the number of available segments in the index.

long
getDurationUs(long segmentNum, long periodDurationUs)

Returns the duration of a segment.

long
getFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs)

Returns the segment number of the first available segment in the index.

long

Returns the segment number of the first defined segment in the index.

long
getNextSegmentAvailableTimeUs(
    long periodDurationUs,
    long nowUnixTimeUs
)

Returns the time, in microseconds, at which a new segment becomes available, or TIME_UNSET if not applicable.

long
getSegmentCount(long periodDurationUs)

Returns the number of segments defined in the index, or INDEX_UNBOUNDED.

long
getSegmentNum(long timeUs, long periodDurationUs)

Returns getFirstSegmentNum() if the index has no segments or if the given media time is earlier than the start of the first segment.

RangedUri
getSegmentUrl(long segmentNum)

Returns a RangedUri defining the location of a segment.

long
getTimeUs(long segmentNum)

Returns the start time of a segment.

boolean

Returns true if segments are defined explicitly by the index.

Inherited Constants

From androidx.media3.exoplayer.dash.DashSegmentIndex
static final int

Public constructors

DashWrappingSegmentIndex

public DashWrappingSegmentIndex(ChunkIndex chunkIndex, long timeOffsetUs)
Parameters
ChunkIndex chunkIndex

The ChunkIndex to wrap.

long timeOffsetUs

An offset to subtract from the times in the wrapped index, in microseconds.

Public methods

getAvailableSegmentCount

public long getAvailableSegmentCount(long periodDurationUs, long nowUnixTimeUs)

Returns the number of available segments in the index.

Parameters
long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

long nowUnixTimeUs

The current time in milliseconds since the Unix epoch.

Returns
long

The number of available segments in the index.

getDurationUs

public long getDurationUs(long segmentNum, long periodDurationUs)

Returns the duration of a segment.

Parameters
long segmentNum

The segment number.

long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

Returns
long

The duration of the segment, in microseconds.

getFirstAvailableSegmentNum

public long getFirstAvailableSegmentNum(long periodDurationUs, long nowUnixTimeUs)

Returns the segment number of the first available segment in the index.

Parameters
long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

long nowUnixTimeUs

The current time in milliseconds since the Unix epoch.

Returns
long

The number of the first available segment.

getFirstSegmentNum

public long getFirstSegmentNum()

Returns the segment number of the first defined segment in the index.

getNextSegmentAvailableTimeUs

public long getNextSegmentAvailableTimeUs(
    long periodDurationUs,
    long nowUnixTimeUs
)

Returns the time, in microseconds, at which a new segment becomes available, or TIME_UNSET if not applicable.

Parameters
long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

long nowUnixTimeUs

The current time in milliseconds since the Unix epoch.

Returns
long

The time, in microseconds, at which a new segment becomes available, or TIME_UNSET if not applicable.

getSegmentCount

public long getSegmentCount(long periodDurationUs)

Returns the number of segments defined in the index, or INDEX_UNBOUNDED.

An unbounded index occurs if a dynamic manifest uses SegmentTemplate elements without a SegmentTimeline element, and if the period duration is not yet known. In this case the caller can query the available segment using getFirstAvailableSegmentNum and getAvailableSegmentCount.

Parameters
long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

Returns
long

The number of segments in the index, or INDEX_UNBOUNDED.

getSegmentNum

public long getSegmentNum(long timeUs, long periodDurationUs)

Returns getFirstSegmentNum() if the index has no segments or if the given media time is earlier than the start of the first segment. Returns getFirstSegmentNum() + getSegmentCount() - 1 if the given media time is later than the end of the last segment. Otherwise, returns the segment number of the segment containing the given media time.

Parameters
long timeUs

The time in microseconds.

long periodDurationUs

The duration of the enclosing period in microseconds, or TIME_UNSET if the period's duration is not yet known.

Returns
long

The segment number of the corresponding segment.

getSegmentUrl

public RangedUri getSegmentUrl(long segmentNum)

Returns a RangedUri defining the location of a segment.

Parameters
long segmentNum

The segment number.

Returns
RangedUri

The RangedUri defining the location of the data.

getTimeUs

public long getTimeUs(long segmentNum)

Returns the start time of a segment.

Parameters
long segmentNum

The segment number.

Returns
long

The corresponding start time in microseconds.

isExplicit

public boolean isExplicit()

Returns true if segments are defined explicitly by the index.

If true is returned, each segment is defined explicitly by the index data, and all of the listed segments are guaranteed to be available at the time when the index was obtained.

If false is returned then segment information was derived from properties such as a fixed segment duration. If the presentation is dynamic, it's possible that only a subset of the segments are available.

Returns
boolean

Whether segments are defined explicitly by the index.