Class BinarySearchSeeker

  • public abstract class BinarySearchSeeker
    extends Object
    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.

    • Constructor Detail

      • 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.
        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.
    • Method Detail

      • getSeekMap

        public final SeekMap getSeekMap()
        Returns the seek map for the stream.
      • setSeekTargetUs

        public final void setSeekTargetUs​(long timeUs)
        Sets the target time in microseconds within the stream to seek to.
        timeUs - The target time in microseconds within the stream.
      • isSeeking

        public final boolean isSeeking()
        Returns whether the last operation set by setSeekTargetUs(long) is still pending.
      • handlePendingSeek

        public int handlePendingSeek​(ExtractorInput input,
                                     PositionHolder seekPositionHolder)
                              throws IOException
        Continues to handle the pending seek operation. Returns one of the 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.
        One of the RESULT_ values defined in Extractor.
        IOException - If an error occurred reading from the input.
      • markSeekOperationFinished

        protected final void markSeekOperationFinished​(boolean foundTargetFrame,
                                                       long resultPosition)
      • onSeekOperationFinished

        protected void onSeekOperationFinished​(boolean foundTargetFrame,
                                               long resultPosition)