@UnstableApi
public final class IndexSeekMap implements SeekMap


A SeekMap implementation based on a mapping between times and positions in the input stream.

Summary

Public fields

long

Public constructors

IndexSeekMap(long[] positions, long[] timesUs, long durationUs)

Creates an instance.

Public methods

void
addSeekPoint(long timeUs, long position)

Adds a seek point to the index.

long

Returns the duration of the stream in microseconds.

SeekMap.SeekPoints
getSeekPoints(long timeUs)

Obtains seek points for the specified seek time in microseconds.

long
getTimeUs(long position)

Maps a position (byte offset) to a corresponding sample timestamp.

boolean

Returns whether seeking is supported.

boolean
isTimeUsInIndex(long timeUs, long minTimeBetweenPointsUs)

Returns whether timeUs (in microseconds) should be considered as part of the index based on its proximity to the last recorded seek point in the index.

void
setDurationUs(long durationUs)

Sets the duration of the input stream, or TIME_UNSET if it is unknown.

Public fields

durationUs

public long durationUs

Public constructors

IndexSeekMap

public IndexSeekMap(long[] positions, long[] timesUs, long durationUs)

Creates an instance.

Parameters
long[] positions

The positions in the stream corresponding to timesUs, in bytes.

long[] timesUs

The times corresponding to positions, in microseconds.

long durationUs

The duration of the input stream, or TIME_UNSET if it is unknown.

Public methods

addSeekPoint

public void addSeekPoint(long timeUs, long position)

Adds a seek point to the index.

Seek points must be added in order.

Parameters
long timeUs

The time of the seek point in microseconds.

long position

The position in the stream corresponding to the seek point, in bytes.

getDurationUs

public long getDurationUs()

Returns the duration of the stream in microseconds.

Returns
long

The duration of the stream in microseconds, or TIME_UNSET if the duration is unknown.

getSeekPoints

public SeekMap.SeekPoints getSeekPoints(long timeUs)

Obtains seek points for the specified seek time in microseconds. The returned will contain one or two distinct seek points.

Two seek points [A, B] are returned in the case that seeking can only be performed to discrete points in time, there does not exist a seek point at exactly the requested time, and there exist seek points on both sides of it. In this case A and B are the closest seek points before and after the requested time. A single seek point is returned in all other cases.

Parameters
long timeUs

A seek time in microseconds.

Returns
SeekMap.SeekPoints

The corresponding seek points.

getTimeUs

public long getTimeUs(long position)

Maps a position (byte offset) to a corresponding sample timestamp.

Parameters
long position

A seek position (byte offset) relative to the start of the stream.

Returns
long

The corresponding timestamp of the seek point at or before the given position, in microseconds, or TIME_UNSET if no seek points exist.

isSeekable

public boolean isSeekable()

Returns whether seeking is supported.

Returns
boolean

Whether seeking is supported.

isTimeUsInIndex

public boolean isTimeUsInIndex(long timeUs, long minTimeBetweenPointsUs)

Returns whether timeUs (in microseconds) should be considered as part of the index based on its proximity to the last recorded seek point in the index.

This method assumes that timeUs is provided in increasing order, consistent with how points are added to the index in addSeekPoint.

Parameters
long timeUs

The time in microseconds to check if it is included in the index.

long minTimeBetweenPointsUs

The minimum time in microseconds that should exist between points for the current time to be considered as part of the index.

setDurationUs

public void setDurationUs(long durationUs)

Sets the duration of the input stream, or TIME_UNSET if it is unknown.