Java Code Examples for com.google.android.exoplayer2.util.Util#binarySearchCeil()

The following examples show how to use com.google.android.exoplayer2.util.Util#binarySearchCeil() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventSampleStream.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
void updateEventStream(EventStream eventStream, boolean eventStreamUpdatable) {
  long lastReadPositionUs = currentIndex == 0 ? C.TIME_UNSET : eventTimesUs[currentIndex - 1];

  this.eventStreamUpdatable = eventStreamUpdatable;
  this.eventStream = eventStream;
  this.eventTimesUs = eventStream.presentationTimesUs;
  if (pendingSeekPositionUs != C.TIME_UNSET) {
    seekToUs(pendingSeekPositionUs);
  } else if (lastReadPositionUs != C.TIME_UNSET) {
    currentIndex = Util.binarySearchCeil(eventTimesUs, lastReadPositionUs, false, false);
  }
}
 
Example 2
Source File: EventSampleStream.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void updateEventStream(EventStream eventStream, boolean eventStreamAppendable) {
  long lastReadPositionUs = currentIndex == 0 ? C.TIME_UNSET : eventTimesUs[currentIndex - 1];

  this.eventStreamAppendable = eventStreamAppendable;
  this.eventStream = eventStream;
  this.eventTimesUs = eventStream.presentationTimesUs;
  if (pendingSeekPositionUs != C.TIME_UNSET) {
    seekToUs(pendingSeekPositionUs);
  } else if (lastReadPositionUs != C.TIME_UNSET) {
    currentIndex =
        Util.binarySearchCeil(
            eventTimesUs, lastReadPositionUs, /* inclusive= */ false, /* stayInBounds= */ false);
  }
}
 
Example 3
Source File: TrackSampleTable.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Returns the sample index of the closest synchronization sample at or after the given timestamp,
 * if one is available.
 *
 * @param timeUs Timestamp adjacent to which to find a synchronization sample.
 * @return index Index of the synchronization sample, or {@link C#INDEX_UNSET} if none.
 */
public int getIndexOfLaterOrEqualSynchronizationSample(long timeUs) {
  int startIndex = Util.binarySearchCeil(timestampsUs, timeUs, true, false);
  for (int i = startIndex; i < timestampsUs.length; i++) {
    if ((flags[i] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
 
Example 4
Source File: EventSampleStream.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Seeks to the specified position in microseconds.
 *
 * @param positionUs The seek position in microseconds.
 */
public void seekToUs(long positionUs) {
  currentIndex =
      Util.binarySearchCeil(
          eventTimesUs, positionUs, /* inclusive= */ true, /* stayInBounds= */ false);
  boolean isPendingSeek = eventStreamAppendable && currentIndex == eventTimesUs.length;
  pendingSeekPositionUs = isPendingSeek ? positionUs : C.TIME_UNSET;
}
 
Example 5
Source File: EventSampleStream.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Seeks to the specified position in microseconds.
 *
 * @param positionUs The seek position in microseconds.
 */
public void seekToUs(long positionUs) {
  currentIndex =
      Util.binarySearchCeil(
          eventTimesUs, positionUs, /* inclusive= */ true, /* stayInBounds= */ false);
  boolean isPendingSeek = eventStreamAppendable && currentIndex == eventTimesUs.length;
  pendingSeekPositionUs = isPendingSeek ? positionUs : C.TIME_UNSET;
}
 
Example 6
Source File: TrackSampleTable.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the sample index of the closest synchronization sample at or after the given timestamp,
 * if one is available.
 *
 * @param timeUs Timestamp adjacent to which to find a synchronization sample.
 * @return index Index of the synchronization sample, or {@link C#INDEX_UNSET} if none.
 */
public int getIndexOfLaterOrEqualSynchronizationSample(long timeUs) {
  int startIndex = Util.binarySearchCeil(timestampsUs, timeUs, true, false);
  for (int i = startIndex; i < timestampsUs.length; i++) {
    if ((flags[i] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
 
Example 7
Source File: TrackSampleTable.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the sample index of the closest synchronization sample at or after the given timestamp,
 * if one is available.
 *
 * @param timeUs Timestamp adjacent to which to find a synchronization sample.
 * @return index Index of the synchronization sample, or {@link C#INDEX_UNSET} if none.
 */
public int getIndexOfLaterOrEqualSynchronizationSample(long timeUs) {
  int startIndex = Util.binarySearchCeil(timestampsUs, timeUs, true, false);
  for (int i = startIndex; i < timestampsUs.length; i++) {
    if ((flags[i] & C.BUFFER_FLAG_KEY_FRAME) != 0) {
      return i;
    }
  }
  return C.INDEX_UNSET;
}
 
Example 8
Source File: EventSampleStream.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
void updateEventStream(EventStream eventStream, boolean eventStreamUpdatable) {
  long lastReadPositionUs = currentIndex == 0 ? C.TIME_UNSET : eventTimesUs[currentIndex - 1];

  this.eventStreamUpdatable = eventStreamUpdatable;
  this.eventStream = eventStream;
  this.eventTimesUs = eventStream.presentationTimesUs;
  if (pendingSeekPositionUs != C.TIME_UNSET) {
    seekToUs(pendingSeekPositionUs);
  } else if (lastReadPositionUs != C.TIME_UNSET) {
    currentIndex = Util.binarySearchCeil(eventTimesUs, lastReadPositionUs, false, false);
  }
}
 
Example 9
Source File: WebvttSubtitle.java    From no-player with Apache License 2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(sortedCueTimesUs, timeUs, false, false);
  return index < sortedCueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 10
Source File: SubripSubtitle.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(cueTimesUs, timeUs, false, false);
  return index < cueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 11
Source File: TtmlSubtitle.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(eventTimesUs, timeUs, false, false);
  return index < eventTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 12
Source File: SsaSubtitle.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(cueTimesUs, timeUs, false, false);
  return index < cueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 13
Source File: WebvttSubtitle.java    From K-Sonic with MIT License 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(sortedCueTimesUs, timeUs, false, false);
  return index < sortedCueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 14
Source File: TtmlSubtitle.java    From K-Sonic with MIT License 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(eventTimesUs, timeUs, false, false);
  return index < eventTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 15
Source File: SsaSubtitle.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(cueTimesUs, timeUs, false, false);
  return index < cueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 16
Source File: WebvttSubtitle.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(sortedCueTimesUs, timeUs, false, false);
  return index < sortedCueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 17
Source File: WebvttSubtitle.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(sortedCueTimesUs, timeUs, false, false);
  return index < sortedCueTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 18
Source File: TtmlSubtitle.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(eventTimesUs, timeUs, false, false);
  return index < eventTimesUs.length ? index : C.INDEX_UNSET;
}
 
Example 19
Source File: EventSampleStream.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Seeks to the specified position in microseconds.
 *
 * @param positionUs The seek position in microseconds.
 */
public void seekToUs(long positionUs) {
  currentIndex = Util.binarySearchCeil(eventTimesUs, positionUs, true, false);
  boolean isPendingSeek = eventStreamUpdatable && currentIndex == eventTimesUs.length;
  pendingSeekPositionUs = isPendingSeek ? positionUs : C.TIME_UNSET;
}
 
Example 20
Source File: SsaSubtitle.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getNextEventTimeIndex(long timeUs) {
  int index = Util.binarySearchCeil(cueTimesUs, timeUs, false, false);
  return index < cueTimesUs.length ? index : C.INDEX_UNSET;
}