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 |
|---|
public class BinarySearchSeeker.BinarySearchSeekMap implements SeekMapA |
public final class BinarySearchSeeker.DefaultSeekTimestampConverter implements BinarySearchSeeker.SeekTimestampConverterA |
protected class BinarySearchSeeker.SeekOperationParamsContains parameters for a pending seek operation by |
protected interface BinarySearchSeeker.SeekTimestampConverterA converter that converts seek time in stream time into target timestamp for the |
public final class BinarySearchSeeker.TimestampSearchResultRepresents possible search results for |
protected interface BinarySearchSeeker.TimestampSeekerA seeker that looks for a given timestamp from an input. |
Protected fields |
|
|---|---|
final BinarySearchSeeker.BinarySearchSeekMap |
|
@Nullable BinarySearchSeeker.SeekOperationParams |
|
final BinarySearchSeeker.TimestampSeeker |
Protected constructors |
|---|
BinarySearchSeeker(Constructs an instance. |
Public methods |
|
|---|---|
final SeekMap |
Returns the seek map for the stream. |
int |
handlePendingSeek(Continues to handle the pending seek operation. |
final boolean |
Returns whether the last operation set by |
final void |
setSeekTargetUs(long timeUs)Sets the target time in microseconds within the stream to seek to. |
Protected methods |
|
|---|---|
BinarySearchSeeker.SeekOperationParams |
createSeekParamsForTargetTimeUs(long timeUs) |
final void |
markSeekOperationFinished( |
void |
onSeekOperationFinished(boolean foundTargetFrame, long resultPosition) |
final int |
seekToPosition( |
final boolean |
skipInputUntilPosition(ExtractorInput input, long position) |
Protected fields
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 |
BinarySearchSeeker.TimestampSeeker timestampSeeker |
A |
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
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 |
PositionHolder seekPositionHolder |
If |
| Returns | |
|---|---|
int |
One of the |
| 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)
| Throws | |
|---|---|
java.io.IOException |