public abstract class BinarySearchSeeker extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
BinarySearchSeeker.BinarySearchSeekMap
A
SeekMap implementation that returns the estimated byte location from BinarySearchSeeker.SeekOperationParams.calculateNextSearchBytePosition(long, long, long, long, long, long) for
each BinarySearchSeeker.BinarySearchSeekMap.getSeekPoints(long) query. |
static class |
BinarySearchSeeker.DefaultSeekTimestampConverter
A
BinarySearchSeeker.SeekTimestampConverter implementation that returns the seek time itself as the
timestamp for a seek time position. |
static class |
BinarySearchSeeker.OutputFrameHolder
Holds a frame extracted from a stream, together with the time stamp of the frame in
microseconds.
|
protected static class |
BinarySearchSeeker.SeekOperationParams
Contains parameters for a pending seek operation by
BinarySearchSeeker . |
protected static interface |
BinarySearchSeeker.SeekTimestampConverter
A converter that converts seek time in stream time into target timestamp for the
BinarySearchSeeker . |
static class |
BinarySearchSeeker.TimestampSearchResult
Represents possible search results for
TimestampSeeker#searchForTimestamp(ExtractorInput, long, OutputFrameHolder) . |
protected static interface |
BinarySearchSeeker.TimestampSeeker
A seeker that looks for a given timestamp from an input.
|
Modifier and Type | Field and Description |
---|---|
protected BinarySearchSeeker.BinarySearchSeekMap |
seekMap |
protected BinarySearchSeeker.SeekOperationParams |
seekOperationParams |
protected BinarySearchSeeker.TimestampSeeker |
timestampSeeker |
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected BinarySearchSeeker.SeekOperationParams |
createSeekParamsForTargetTimeUs(long timeUs) |
SeekMap |
getSeekMap()
Returns the seek map for the stream.
|
int |
handlePendingSeek(ExtractorInput input,
PositionHolder seekPositionHolder,
BinarySearchSeeker.OutputFrameHolder outputFrameHolder)
Continues to handle the pending seek operation.
|
boolean |
isSeeking()
Returns whether the last operation set by
setSeekTargetUs(long) is still pending. |
protected void |
markSeekOperationFinished(boolean foundTargetFrame,
long resultPosition) |
protected void |
onSeekOperationFinished(boolean foundTargetFrame,
long resultPosition) |
protected int |
seekToPosition(ExtractorInput input,
long position,
PositionHolder seekPositionHolder) |
void |
setSeekTargetUs(long timeUs)
Sets the target time in microseconds within the stream to seek to.
|
protected boolean |
skipInputUntilPosition(ExtractorInput input,
long position) |
protected final BinarySearchSeeker.BinarySearchSeekMap seekMap
protected final BinarySearchSeeker.TimestampSeeker timestampSeeker
@Nullable protected BinarySearchSeeker.SeekOperationParams seekOperationParams
protected BinarySearchSeeker(BinarySearchSeeker.SeekTimestampConverter seekTimestampConverter, BinarySearchSeeker.TimestampSeeker timestampSeeker, long durationUs, long floorTimePosition, long ceilingTimePosition, long floorBytePosition, long ceilingBytePosition, long approxBytesPerFrame, int minimumSearchRange)
seekTimestampConverter
- The BinarySearchSeeker.SeekTimestampConverter
that converts seek time in
stream time into target timestamp.timestampSeeker
- A BinarySearchSeeker.TimestampSeeker
that will be used to search for timestamps
within the stream.durationUs
- The duration of the stream in microseconds.floorTimePosition
- The minimum timestamp value (inclusive) in the stream.ceilingTimePosition
- The minimum timestamp value (exclusive) in the stream.floorBytePosition
- The starting position of the frame with minimum timestamp value
(inclusive) in the stream.ceilingBytePosition
- The position after the frame with maximum timestamp value in the
stream.approxBytesPerFrame
- Approximated bytes per frame.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 final SeekMap getSeekMap()
public final void setSeekTargetUs(long timeUs)
timeUs
- The target time in microseconds within the stream.public final boolean isSeeking()
setSeekTargetUs(long)
is still pending.public int handlePendingSeek(ExtractorInput input, PositionHolder seekPositionHolder, BinarySearchSeeker.OutputFrameHolder outputFrameHolder) throws InterruptedException, IOException
RESULT_
values from
Extractor
.input
- The ExtractorInput
from which data should be read.seekPositionHolder
- If Extractor.RESULT_SEEK
is returned, this holder is updated
to hold the position of the required seek.outputFrameHolder
- If Extractor.RESULT_CONTINUE
is returned, this holder may be
updated to hold the extracted frame that contains the target sample. The caller needs to
check the byte buffer limit to see if an extracted frame is available.RESULT_
values defined in Extractor
.IOException
- If an error occurred reading from the input.InterruptedException
- If the thread was interrupted.protected BinarySearchSeeker.SeekOperationParams createSeekParamsForTargetTimeUs(long timeUs)
protected final void markSeekOperationFinished(boolean foundTargetFrame, long resultPosition)
protected void onSeekOperationFinished(boolean foundTargetFrame, long resultPosition)
protected final boolean skipInputUntilPosition(ExtractorInput input, long position) throws IOException, InterruptedException
IOException
InterruptedException
protected final int seekToPosition(ExtractorInput input, long position, PositionHolder seekPositionHolder)