BinarySearchSeeker


@UnstableApi
public abstract class BinarySearchSeeker


A seeker that supports seeking within a stream by searching for the target frame using binary search.

This seeker operates on a stream that contains multiple frames (or samples). Each frame is associated with some kind of timestamps, such as stream time, or frame indices. Given a target seek time, the seeker will find the corresponding target timestamp, and perform a search operation within the stream to identify the target frame and return the byte position in the stream of the target frame.

Summary

Nested types

A SeekMap implementation that returns the estimated byte location from calculateNextSearchBytePosition for each getSeekPoints query.

A SeekTimestampConverter implementation that returns the seek time itself as the timestamp for a seek time position.

Contains parameters for a pending seek operation by BinarySearchSeeker.

A converter that converts seek time in stream time into target timestamp for the .

Represents possible search results for searchForTimestamp.

A seeker that looks for a given timestamp from an input.

Protected constructors

BinarySearchSeeker(
    BinarySearchSeeker.SeekTimestampConverter seekTimestampConverter,
    BinarySearchSeeker.TimestampSeeker timestampSeeker,
    long durationUs,
    long floorTimePosition,
    long ceilingTimePosition,
    long floorBytePosition,
    long ceilingBytePosition,
    long approxBytesPerFrame,
    int minimumSearchRange
)

Constructs an instance.

Public methods

final SeekMap

Returns the seek map for the stream.

int
handlePendingSeek(
    ExtractorInput input,
    PositionHolder seekPositionHolder
)

Continues to handle the pending seek operation.

final boolean

Returns whether the last operation set by setSeekTargetUs is still pending.

final void
setSeekTargetUs(long timeUs)

Sets the target time in microseconds within the stream to seek to.

Protected methods

BinarySearchSeeker.SeekOperationParams
final void
markSeekOperationFinished(
    boolean foundTargetFrame,
    long resultPosition
)
void
onSeekOperationFinished(boolean foundTargetFrame, long resultPosition)
final int
seekToPosition(
    ExtractorInput input,
    long position,
    PositionHolder seekPositionHolder
)
final boolean
skipInputUntilPosition(ExtractorInput input, long position)

Protected fields

seekMap

protected final BinarySearchSeeker.BinarySearchSeekMap seekMap

timestampSeeker

protected final BinarySearchSeeker.TimestampSeeker timestampSeeker

Protected constructors

BinarySearchSeeker

protected BinarySearchSeeker(
    BinarySearchSeeker.SeekTimestampConverter seekTimestampConverter,
    BinarySearchSeeker.TimestampSeeker timestampSeeker,
    long durationUs,
    long floorTimePosition,
    long ceilingTimePosition,
    long floorBytePosition,
    long ceilingBytePosition,
    long approxBytesPerFrame,
    int minimumSearchRange
)

Constructs an instance.

Parameters
BinarySearchSeeker.SeekTimestampConverter seekTimestampConverter

The SeekTimestampConverter that converts seek time in stream time into target timestamp.

BinarySearchSeeker.TimestampSeeker timestampSeeker

A TimestampSeeker that will be used to search for timestamps within the stream.

long durationUs

The duration of the stream in microseconds.

long floorTimePosition

The minimum timestamp value (inclusive) in the stream.

long ceilingTimePosition

The minimum timestamp value (exclusive) in the stream.

long floorBytePosition

The starting position of the frame with minimum timestamp value (inclusive) in the stream.

long ceilingBytePosition

The position after the frame with maximum timestamp value in the stream.

long approxBytesPerFrame

Approximated bytes per frame.

int minimumSearchRange

The minimum byte range that this binary seeker will operate on. If the remaining search range is smaller than this value, the search will stop, and the seeker will return the position at the floor of the range as the result.

Public methods

getSeekMap

public final SeekMap getSeekMap()

Returns the seek map for the stream.

handlePendingSeek

public int handlePendingSeek(
    ExtractorInput input,
    PositionHolder seekPositionHolder
)

Continues to handle the pending seek operation. Returns one of the RESULT_ values from Extractor.

Parameters
ExtractorInput input

The ExtractorInput from which data should be read.

PositionHolder seekPositionHolder

If RESULT_SEEK is returned, this holder is updated to hold the position of the required seek.

Returns
int

One of the RESULT_ values defined in Extractor.

Throws
java.io.IOException

If an error occurred reading from the input.

isSeeking

public final boolean isSeeking()

Returns whether the last operation set by setSeekTargetUs is still pending.

setSeekTargetUs

public final void setSeekTargetUs(long timeUs)

Sets the target time in microseconds within the stream to seek to.

Parameters
long timeUs

The target time in microseconds within the stream.

Protected methods

createSeekParamsForTargetTimeUs

protected BinarySearchSeeker.SeekOperationParams createSeekParamsForTargetTimeUs(long timeUs)

markSeekOperationFinished

protected final void markSeekOperationFinished(
    boolean foundTargetFrame,
    long resultPosition
)

onSeekOperationFinished

protected void onSeekOperationFinished(boolean foundTargetFrame, long resultPosition)

seekToPosition

protected final int seekToPosition(
    ExtractorInput input,
    long position,
    PositionHolder seekPositionHolder
)

skipInputUntilPosition

protected final boolean skipInputUntilPosition(ExtractorInput input, long position)