use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class XingSeeker method getSeekPoints.
@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.checkStateNotNull(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));
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class WavSeekMap method getSeekPoints.
@Override
public SeekPoints getSeekPoints(long timeUs) {
// Calculate the containing block index, constraining to valid indices.
long blockIndex = (timeUs * wavFormat.frameRateHz) / (C.MICROS_PER_SECOND * framesPerBlock);
blockIndex = Util.constrainValue(blockIndex, 0, blockCount - 1);
long seekPosition = firstBlockPosition + (blockIndex * wavFormat.blockSize);
long seekTimeUs = blockIndexToTimeUs(blockIndex);
SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
if (seekTimeUs >= timeUs || blockIndex == blockCount - 1) {
return new SeekPoints(seekPoint);
} else {
long secondBlockIndex = blockIndex + 1;
long secondSeekPosition = firstBlockPosition + (secondBlockIndex * wavFormat.blockSize);
long secondSeekTimeUs = blockIndexToTimeUs(secondBlockIndex);
SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
return new SeekPoints(seekPoint, secondSeekPoint);
}
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class IndexSeeker method getSeekPoints.
@Override
public SeekPoints getSeekPoints(long timeUs) {
int targetIndex = Util.binarySearchFloor(timesUs, timeUs, /* inclusive= */
true, /* stayInBounds= */
true);
SeekPoint seekPoint = new SeekPoint(timesUs.get(targetIndex), positions.get(targetIndex));
if (seekPoint.timeUs == timeUs || targetIndex == timesUs.size() - 1) {
return new SeekPoints(seekPoint);
} else {
SeekPoint nextSeekPoint = new SeekPoint(timesUs.get(targetIndex + 1), positions.get(targetIndex + 1));
return new SeekPoints(seekPoint, nextSeekPoint);
}
}
use of androidx.media3.extractor.SeekPoint in project Telegram-FOSS by Telegram-FOSS-Team.
the class XingSeeker method getSeekPoints.
@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));
}
use of androidx.media3.extractor.SeekPoint in project Telegram-FOSS by Telegram-FOSS-Team.
the class Mp4Extractor method getSeekPoints.
@Override
public SeekPoints getSeekPoints(long timeUs) {
if (tracks.length == 0) {
return new SeekPoints(SeekPoint.START);
}
long firstTimeUs;
long firstOffset;
long secondTimeUs = C.TIME_UNSET;
long secondOffset = C.POSITION_UNSET;
// If we have a video track, use it to establish one or two seek points.
if (firstVideoTrackIndex != C.INDEX_UNSET) {
TrackSampleTable sampleTable = tracks[firstVideoTrackIndex].sampleTable;
int sampleIndex = getSynchronizationSampleIndex(sampleTable, timeUs);
if (sampleIndex == C.INDEX_UNSET) {
return new SeekPoints(SeekPoint.START);
}
long sampleTimeUs = sampleTable.timestampsUs[sampleIndex];
firstTimeUs = sampleTimeUs;
firstOffset = sampleTable.offsets[sampleIndex];
if (sampleTimeUs < timeUs && sampleIndex < sampleTable.sampleCount - 1) {
int secondSampleIndex = sampleTable.getIndexOfLaterOrEqualSynchronizationSample(timeUs);
if (secondSampleIndex != C.INDEX_UNSET && secondSampleIndex != sampleIndex) {
secondTimeUs = sampleTable.timestampsUs[secondSampleIndex];
secondOffset = sampleTable.offsets[secondSampleIndex];
}
}
} else {
firstTimeUs = timeUs;
firstOffset = Long.MAX_VALUE;
}
// Take into account other tracks.
for (int i = 0; i < tracks.length; i++) {
if (i != firstVideoTrackIndex) {
TrackSampleTable sampleTable = tracks[i].sampleTable;
firstOffset = maybeAdjustSeekOffset(sampleTable, firstTimeUs, firstOffset);
if (secondTimeUs != C.TIME_UNSET) {
secondOffset = maybeAdjustSeekOffset(sampleTable, secondTimeUs, secondOffset);
}
}
}
SeekPoint firstSeekPoint = new SeekPoint(firstTimeUs, firstOffset);
if (secondTimeUs == C.TIME_UNSET) {
return new SeekPoints(firstSeekPoint);
} else {
SeekPoint secondSeekPoint = new SeekPoint(secondTimeUs, secondOffset);
return new SeekPoints(firstSeekPoint, secondSeekPoint);
}
}
Aggregations