use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class XingSeekerTest method getSeekPointsAtEndOfStream.
@Test
public void getSeekPointsAtEndOfStream() {
SeekPoints seekPoints = seeker.getSeekPoints(STREAM_DURATION_US);
SeekPoint seekPoint = seekPoints.first;
assertThat(seekPoint).isEqualTo(seekPoints.second);
assertThat(seekPoint.timeUs).isEqualTo(STREAM_DURATION_US);
assertThat(seekPoint.position).isEqualTo(STREAM_LENGTH - 1);
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class XingSeekerTest method getTimeForAllPositions.
@Test
public void getTimeForAllPositions() {
for (int offset = xingFrameSize; offset < DATA_SIZE_BYTES; offset++) {
int position = XING_FRAME_POSITION + offset;
// Test seeker.
long timeUs = seeker.getTimeUs(position);
SeekPoints seekPoints = seeker.getSeekPoints(timeUs);
SeekPoint seekPoint = seekPoints.first;
assertThat(seekPoint).isEqualTo(seekPoints.second);
assertThat(seekPoint.position).isEqualTo(position);
// Test seekerWithInputLength.
timeUs = seekerWithInputLength.getTimeUs(position);
seekPoints = seekerWithInputLength.getSeekPoints(timeUs);
seekPoint = seekPoints.first;
assertThat(seekPoint).isEqualTo(seekPoints.second);
assertThat(seekPoint.position).isEqualTo(position);
}
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class Mp4Extractor method getSeekPoints.
@Override
public SeekPoints getSeekPoints(long timeUs) {
if (checkNotNull(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);
}
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class MlltSeeker method getSeekPoints.
@Override
public SeekPoints getSeekPoints(long timeUs) {
timeUs = Util.constrainValue(timeUs, 0, durationUs);
Pair<Long, Long> timeMsAndPosition = linearlyInterpolate(Util.usToMs(timeUs), referenceTimesMs, referencePositions);
timeUs = Util.msToUs(timeMsAndPosition.first);
long position = timeMsAndPosition.second;
return new SeekPoints(new SeekPoint(timeUs, position));
}
use of androidx.media3.extractor.SeekPoint in project ExoPlayer by google.
the class VbriSeeker method getSeekPoints.
@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);
}
}
Aggregations