com.google.android.exoplayer2.extractor.SeekPoint Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.SeekPoint. 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: FlacReader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long granule = convertTimeToGranule(timeUs);
  int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
  long seekTimeUs = convertGranuleToTime(seekPointGranules[index]);
  long seekPosition = firstFrameOffset + seekPointOffsets[index];
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || index == seekPointGranules.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekTimeUs = convertGranuleToTime(seekPointGranules[index + 1]);
    long secondSeekPosition = firstFrameOffset + seekPointOffsets[index + 1];
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #2
Source File: FlacReader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long granule = convertTimeToGranule(timeUs);
  int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
  long seekTimeUs = convertGranuleToTime(seekPointGranules[index]);
  long seekPosition = firstFrameOffset + seekPointOffsets[index];
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || index == seekPointGranules.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekTimeUs = convertGranuleToTime(seekPointGranules[index + 1]);
    long secondSeekPosition = firstFrameOffset + seekPointOffsets[index + 1];
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #3
Source File: WavHeader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long dataSize = dataEndPosition - dataStartPosition;
  long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / blockAlignment) * blockAlignment;
  positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
  long seekPosition = dataStartPosition + positionOffset;
  long seekTimeUs = getTimeUs(seekPosition);
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekPosition = seekPosition + blockAlignment;
    long secondSeekTimeUs = getTimeUs(secondSeekPosition);
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #4
Source File: XingSeeker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (!isSeekable()) {
    return new SeekPoints(new SeekPoint(0, dataStartPosition + xingFrameSize));
  }
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  double percent = (timeUs * 100d) / durationUs;
  double scaledPosition;
  if (percent <= 0) {
    scaledPosition = 0;
  } else if (percent >= 100) {
    scaledPosition = 256;
  } else {
    int prevTableIndex = (int) percent;
    double prevScaledPosition = tableOfContents[prevTableIndex];
    double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
    // Linearly interpolate between the two scaled positions.
    double interpolateFraction = percent - prevTableIndex;
    scaledPosition = prevScaledPosition
        + (interpolateFraction * (nextScaledPosition - prevScaledPosition));
  }
  long positionOffset = Math.round((scaledPosition / 256) * dataSize);
  // Ensure returned positions skip the frame containing the XING header.
  positionOffset = Util.constrainValue(positionOffset, xingFrameSize, dataSize - 1);
  return new SeekPoints(new SeekPoint(timeUs, dataStartPosition + positionOffset));
}
 
Example #5
Source File: FlacReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long granule = convertTimeToGranule(timeUs);
  int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
  long seekTimeUs = convertGranuleToTime(seekPointGranules[index]);
  long seekPosition = firstFrameOffset + seekPointOffsets[index];
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || index == seekPointGranules.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekTimeUs = convertGranuleToTime(seekPointGranules[index + 1]);
    long secondSeekPosition = firstFrameOffset + seekPointOffsets[index + 1];
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #6
Source File: WavHeader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / blockAlignment) * blockAlignment;
  positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
  long seekPosition = dataStartPosition + positionOffset;
  long seekTimeUs = getTimeUs(seekPosition);
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekPosition = seekPosition + blockAlignment;
    long secondSeekTimeUs = getTimeUs(secondSeekPosition);
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #7
Source File: WavHeader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long dataSize = dataEndPosition - dataStartPosition;
  long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / blockAlignment) * blockAlignment;
  positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
  long seekPosition = dataStartPosition + positionOffset;
  long seekTimeUs = getTimeUs(seekPosition);
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekPosition = seekPosition + blockAlignment;
    long secondSeekTimeUs = getTimeUs(secondSeekPosition);
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #8
Source File: XingSeeker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (!isSeekable()) {
    return new SeekPoints(new SeekPoint(0, dataStartPosition + xingFrameSize));
  }
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  double percent = (timeUs * 100d) / durationUs;
  double scaledPosition;
  if (percent <= 0) {
    scaledPosition = 0;
  } else if (percent >= 100) {
    scaledPosition = 256;
  } else {
    int prevTableIndex = (int) percent;
    double prevScaledPosition = tableOfContents[prevTableIndex];
    double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
    // Linearly interpolate between the two scaled positions.
    double interpolateFraction = percent - prevTableIndex;
    scaledPosition = prevScaledPosition
        + (interpolateFraction * (nextScaledPosition - prevScaledPosition));
  }
  long positionOffset = Math.round((scaledPosition / 256) * dataSize);
  // Ensure returned positions skip the frame containing the XING header.
  positionOffset = Util.constrainValue(positionOffset, xingFrameSize, dataSize - 1);
  return new SeekPoints(new SeekPoint(timeUs, dataStartPosition + positionOffset));
}
 
Example #9
Source File: FlacReader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long granule = convertTimeToGranule(timeUs);
  int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
  long seekTimeUs = convertGranuleToTime(seekPointGranules[index]);
  long seekPosition = firstFrameOffset + seekPointOffsets[index];
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || index == seekPointGranules.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekTimeUs = convertGranuleToTime(seekPointGranules[index + 1]);
    long secondSeekPosition = firstFrameOffset + seekPointOffsets[index + 1];
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #10
Source File: FlacReader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long granule = convertTimeToGranule(timeUs);
  int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
  long seekTimeUs = convertGranuleToTime(seekPointGranules[index]);
  long seekPosition = firstFrameOffset + seekPointOffsets[index];
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || index == seekPointGranules.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekTimeUs = convertGranuleToTime(seekPointGranules[index + 1]);
    long secondSeekPosition = firstFrameOffset + seekPointOffsets[index + 1];
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #11
Source File: WavHeader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / blockAlignment) * blockAlignment;
  positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
  long seekPosition = dataStartPosition + positionOffset;
  long seekTimeUs = getTimeUs(seekPosition);
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekPosition = seekPosition + blockAlignment;
    long secondSeekTimeUs = getTimeUs(secondSeekPosition);
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #12
Source File: WavHeader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long dataSize = dataEndPosition - dataStartPosition;
  long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / blockAlignment) * blockAlignment;
  positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
  long seekPosition = dataStartPosition + positionOffset;
  long seekTimeUs = getTimeUs(seekPosition);
  SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
  if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
    return new SeekPoints(seekPoint);
  } else {
    long secondSeekPosition = seekPosition + blockAlignment;
    long secondSeekTimeUs = getTimeUs(secondSeekPosition);
    SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
    return new SeekPoints(seekPoint, secondSeekPoint);
  }
}
 
Example #13
Source File: DefaultOggSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long targetGranule = streamReader.convertTimeToGranule(timeUs);
  long estimatedPosition =
      payloadStartPosition
          + (targetGranule * (payloadEndPosition - payloadStartPosition) / totalGranules)
          - DEFAULT_OFFSET;
  estimatedPosition =
      Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);
  return new SeekPoints(new SeekPoint(timeUs, estimatedPosition));
}
 
Example #14
Source File: MlltSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  Pair<Long, Long> timeMsAndPosition =
      linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions);
  timeUs = C.msToUs(timeMsAndPosition.first);
  long position = timeMsAndPosition.second;
  return new SeekPoints(new SeekPoint(timeUs, position));
}
 
Example #15
Source File: VbriSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  int tableIndex = Util.binarySearchFloor(timesUs, timeUs, true, true);
  SeekPoint seekPoint = new SeekPoint(timesUs[tableIndex], positions[tableIndex]);
  if (seekPoint.timeUs >= timeUs || tableIndex == timesUs.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    SeekPoint nextSeekPoint = new SeekPoint(timesUs[tableIndex + 1], positions[tableIndex + 1]);
    return new SeekPoints(seekPoint, nextSeekPoint);
  }
}
 
Example #16
Source File: FlacDecoderJni.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps a seek position in microseconds to the corresponding {@link SeekMap.SeekPoints} in the
 * stream.
 *
 * @param timeUs A seek position in microseconds.
 * @return The corresponding {@link SeekMap.SeekPoints} obtained from the seek table, or {@code
 *     null} if the stream doesn't have a seek table.
 */
@Nullable
public SeekMap.SeekPoints getSeekPoints(long timeUs) {
  long[] seekPoints = new long[4];
  if (!flacGetSeekPoints(nativeDecoderContext, timeUs, seekPoints)) {
    return null;
  }
  SeekPoint firstSeekPoint = new SeekPoint(seekPoints[0], seekPoints[1]);
  SeekPoint secondSeekPoint =
      seekPoints[2] == seekPoints[0]
          ? firstSeekPoint
          : new SeekPoint(seekPoints[2], seekPoints[3]);
  return new SeekMap.SeekPoints(firstSeekPoint, secondSeekPoint);
}
 
Example #17
Source File: XingSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (!isSeekable()) {
    return new SeekPoints(new SeekPoint(0, dataStartPosition + xingFrameSize));
  }
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  double percent = (timeUs * 100d) / durationUs;
  double scaledPosition;
  if (percent <= 0) {
    scaledPosition = 0;
  } else if (percent >= 100) {
    scaledPosition = 256;
  } else {
    int prevTableIndex = (int) percent;
    long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
    double prevScaledPosition = tableOfContents[prevTableIndex];
    double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
    // Linearly interpolate between the two scaled positions.
    double interpolateFraction = percent - prevTableIndex;
    scaledPosition = prevScaledPosition
        + (interpolateFraction * (nextScaledPosition - prevScaledPosition));
  }
  long positionOffset = Math.round((scaledPosition / 256) * dataSize);
  // Ensure returned positions skip the frame containing the XING header.
  positionOffset = Util.constrainValue(positionOffset, xingFrameSize, dataSize - 1);
  return new SeekPoints(new SeekPoint(timeUs, dataStartPosition + positionOffset));
}
 
Example #18
Source File: XingSeeker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (!isSeekable()) {
    return new SeekPoints(new SeekPoint(0, dataStartPosition + xingFrameSize));
  }
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  double percent = (timeUs * 100d) / durationUs;
  double scaledPosition;
  if (percent <= 0) {
    scaledPosition = 0;
  } else if (percent >= 100) {
    scaledPosition = 256;
  } else {
    int prevTableIndex = (int) percent;
    long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
    double prevScaledPosition = tableOfContents[prevTableIndex];
    double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
    // Linearly interpolate between the two scaled positions.
    double interpolateFraction = percent - prevTableIndex;
    scaledPosition = prevScaledPosition
        + (interpolateFraction * (nextScaledPosition - prevScaledPosition));
  }
  long positionOffset = Math.round((scaledPosition / 256) * dataSize);
  // Ensure returned positions skip the frame containing the XING header.
  positionOffset = Util.constrainValue(positionOffset, xingFrameSize, dataSize - 1);
  return new SeekPoints(new SeekPoint(timeUs, dataStartPosition + positionOffset));
}
 
Example #19
Source File: VbriSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  int tableIndex = Util.binarySearchFloor(timesUs, timeUs, true, true);
  SeekPoint seekPoint = new SeekPoint(timesUs[tableIndex], positions[tableIndex]);
  if (seekPoint.timeUs >= timeUs || tableIndex == timesUs.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    SeekPoint nextSeekPoint = new SeekPoint(timesUs[tableIndex + 1], positions[tableIndex + 1]);
    return new SeekPoints(seekPoint, nextSeekPoint);
  }
}
 
Example #20
Source File: FlacDecoderJni.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps a seek position in microseconds to the corresponding {@link SeekMap.SeekPoints} in the
 * stream.
 *
 * @param timeUs A seek position in microseconds.
 * @return The corresponding {@link SeekMap.SeekPoints} obtained from the seek table, or {@code
 *     null} if the stream doesn't have a seek table.
 */
@Nullable
public SeekMap.SeekPoints getSeekPoints(long timeUs) {
  long[] seekPoints = new long[4];
  if (!flacGetSeekPoints(nativeDecoderContext, timeUs, seekPoints)) {
    return null;
  }
  SeekPoint firstSeekPoint = new SeekPoint(seekPoints[0], seekPoints[1]);
  SeekPoint secondSeekPoint =
      seekPoints[2] == seekPoints[0]
          ? firstSeekPoint
          : new SeekPoint(seekPoints[2], seekPoints[3]);
  return new SeekMap.SeekPoints(firstSeekPoint, secondSeekPoint);
}
 
Example #21
Source File: MlltSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  Pair<Long, Long> timeMsAndPosition =
      linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions);
  timeUs = C.msToUs(timeMsAndPosition.first);
  long position = timeMsAndPosition.second;
  return new SeekPoints(new SeekPoint(timeUs, position));
}
 
Example #22
Source File: DefaultOggSeeker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long targetGranule = streamReader.convertTimeToGranule(timeUs);
  long estimatedPosition =
      payloadStartPosition
          + (targetGranule * (payloadEndPosition - payloadStartPosition) / totalGranules)
          - DEFAULT_OFFSET;
  estimatedPosition =
      Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);
  return new SeekPoints(new SeekPoint(timeUs, estimatedPosition));
}
 
Example #23
Source File: VbriSeeker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  int tableIndex = Util.binarySearchFloor(timesUs, timeUs, true, true);
  SeekPoint seekPoint = new SeekPoint(timesUs[tableIndex], positions[tableIndex]);
  if (seekPoint.timeUs >= timeUs || tableIndex == timesUs.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    SeekPoint nextSeekPoint = new SeekPoint(timesUs[tableIndex + 1], positions[tableIndex + 1]);
    return new SeekPoints(seekPoint, nextSeekPoint);
  }
}
 
Example #24
Source File: DefaultOggSeeker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (timeUs == 0) {
    return new SeekPoints(new SeekPoint(0, startPosition));
  }
  long granule = streamReader.convertTimeToGranule(timeUs);
  long estimatedPosition = getEstimatedPosition(startPosition, granule, DEFAULT_OFFSET);
  return new SeekPoints(new SeekPoint(timeUs, estimatedPosition));
}
 
Example #25
Source File: VbriSeeker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  int tableIndex = Util.binarySearchFloor(timesUs, timeUs, true, true);
  SeekPoint seekPoint = new SeekPoint(timesUs[tableIndex], positions[tableIndex]);
  if (seekPoint.timeUs >= timeUs || tableIndex == timesUs.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    SeekPoint nextSeekPoint = new SeekPoint(timesUs[tableIndex + 1], positions[tableIndex + 1]);
    return new SeekPoints(seekPoint, nextSeekPoint);
  }
}
 
Example #26
Source File: DefaultOggSeeker.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (timeUs == 0) {
    return new SeekPoints(new SeekPoint(0, startPosition));
  }
  long granule = streamReader.convertTimeToGranule(timeUs);
  long estimatedPosition = getEstimatedPosition(startPosition, granule, DEFAULT_OFFSET);
  return new SeekPoints(new SeekPoint(timeUs, estimatedPosition));
}
 
Example #27
Source File: XingSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  if (!isSeekable()) {
    return new SeekPoints(new SeekPoint(0, dataStartPosition + xingFrameSize));
  }
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  double percent = (timeUs * 100d) / durationUs;
  double scaledPosition;
  if (percent <= 0) {
    scaledPosition = 0;
  } else if (percent >= 100) {
    scaledPosition = 256;
  } else {
    int prevTableIndex = (int) percent;
    long[] tableOfContents = Assertions.checkNotNull(this.tableOfContents);
    double prevScaledPosition = tableOfContents[prevTableIndex];
    double nextScaledPosition = prevTableIndex == 99 ? 256 : tableOfContents[prevTableIndex + 1];
    // Linearly interpolate between the two scaled positions.
    double interpolateFraction = percent - prevTableIndex;
    scaledPosition = prevScaledPosition
        + (interpolateFraction * (nextScaledPosition - prevScaledPosition));
  }
  long positionOffset = Math.round((scaledPosition / 256) * dataSize);
  // Ensure returned positions skip the frame containing the XING header.
  positionOffset = Util.constrainValue(positionOffset, xingFrameSize, dataSize - 1);
  return new SeekPoints(new SeekPoint(timeUs, dataStartPosition + positionOffset));
}
 
Example #28
Source File: VbriSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  int tableIndex = Util.binarySearchFloor(timesUs, timeUs, true, true);
  SeekPoint seekPoint = new SeekPoint(timesUs[tableIndex], positions[tableIndex]);
  if (seekPoint.timeUs >= timeUs || tableIndex == timesUs.length - 1) {
    return new SeekPoints(seekPoint);
  } else {
    SeekPoint nextSeekPoint = new SeekPoint(timesUs[tableIndex + 1], positions[tableIndex + 1]);
    return new SeekPoints(seekPoint, nextSeekPoint);
  }
}
 
Example #29
Source File: MlltSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  timeUs = Util.constrainValue(timeUs, 0, durationUs);
  Pair<Long, Long> timeMsAndPosition =
      linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions);
  timeUs = C.msToUs(timeMsAndPosition.first);
  long position = timeMsAndPosition.second;
  return new SeekPoints(new SeekPoint(timeUs, position));
}
 
Example #30
Source File: DefaultOggSeeker.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public SeekPoints getSeekPoints(long timeUs) {
  long targetGranule = streamReader.convertTimeToGranule(timeUs);
  long estimatedPosition =
      payloadStartPosition
          + (targetGranule * (payloadEndPosition - payloadStartPosition) / totalGranules)
          - DEFAULT_OFFSET;
  estimatedPosition =
      Util.constrainValue(estimatedPosition, payloadStartPosition, payloadEndPosition - 1);
  return new SeekPoints(new SeekPoint(timeUs, estimatedPosition));
}