BinarySearchSeeker


@UnstableApi
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(
    seekTimestampConverter: BinarySearchSeeker.SeekTimestampConverter!,
    timestampSeeker: BinarySearchSeeker.TimestampSeeker!,
    durationUs: Long,
    floorTimePosition: Long,
    ceilingTimePosition: Long,
    floorBytePosition: Long,
    ceilingBytePosition: Long,
    approxBytesPerFrame: Long,
    minimumSearchRange: Int
)

Constructs an instance.

Public functions

SeekMap!

Returns the seek map for the stream.

Int
handlePendingSeek(
    input: ExtractorInput!,
    seekPositionHolder: PositionHolder!
)

Continues to handle the pending seek operation.

Boolean

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

Unit

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

Protected functions

BinarySearchSeeker.SeekOperationParams!
Unit
markSeekOperationFinished(
    foundTargetFrame: Boolean,
    resultPosition: Long
)
Unit
onSeekOperationFinished(foundTargetFrame: Boolean, resultPosition: Long)
Int
seekToPosition(
    input: ExtractorInput!,
    position: Long,
    seekPositionHolder: PositionHolder!
)
Boolean

Protected constructors

BinarySearchSeeker

protected BinarySearchSeeker(
    seekTimestampConverter: BinarySearchSeeker.SeekTimestampConverter!,
    timestampSeeker: BinarySearchSeeker.TimestampSeeker!,
    durationUs: Long,
    floorTimePosition: Long,
    ceilingTimePosition: Long,
    floorBytePosition: Long,
    ceilingBytePosition: Long,
    approxBytesPerFrame: Long,
    minimumSearchRange: Int
)

Constructs an instance.

Parameters
seekTimestampConverter: BinarySearchSeeker.SeekTimestampConverter!

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

timestampSeeker: BinarySearchSeeker.TimestampSeeker!

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

durationUs: Long

The duration of the stream in microseconds.

floorTimePosition: Long

The minimum timestamp value (inclusive) in the stream.

ceilingTimePosition: Long

The minimum timestamp value (exclusive) in the stream.

floorBytePosition: Long

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

ceilingBytePosition: Long

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

approxBytesPerFrame: Long

Approximated bytes per frame.

minimumSearchRange: Int

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 functions

getSeekMap

fun getSeekMap(): SeekMap!

Returns the seek map for the stream.

handlePendingSeek

fun handlePendingSeek(
    input: ExtractorInput!,
    seekPositionHolder: PositionHolder!
): Int

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

Parameters
input: ExtractorInput!

The ExtractorInput from which data should be read.

seekPositionHolder: PositionHolder!

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

fun isSeeking(): Boolean

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

setSeekTargetUs

fun setSeekTargetUs(timeUs: Long): Unit

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

Parameters
timeUs: Long

The target time in microseconds within the stream.

Protected functions

createSeekParamsForTargetTimeUs

protected fun createSeekParamsForTargetTimeUs(timeUs: Long): BinarySearchSeeker.SeekOperationParams!

markSeekOperationFinished

protected fun markSeekOperationFinished(
    foundTargetFrame: Boolean,
    resultPosition: Long
): Unit

onSeekOperationFinished

protected fun onSeekOperationFinished(foundTargetFrame: Boolean, resultPosition: Long): Unit

seekToPosition

protected fun seekToPosition(
    input: ExtractorInput!,
    position: Long,
    seekPositionHolder: PositionHolder!
): Int

skipInputUntilPosition

protected fun skipInputUntilPosition(input: ExtractorInput!, position: Long): Boolean

Protected properties

seekMap

protected val seekMapBinarySearchSeeker.BinarySearchSeekMap!

seekOperationParams

protected val seekOperationParamsBinarySearchSeeker.SeekOperationParams?

timestampSeeker

protected val timestampSeekerBinarySearchSeeker.TimestampSeeker!