Search in sources :

Example 11 with SeekPoint

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);
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SeekPoints(com.google.android.exoplayer2.extractor.SeekMap.SeekPoints) Test(org.junit.Test)

Example 12 with SeekPoint

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);
    }
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SeekPoints(com.google.android.exoplayer2.extractor.SeekMap.SeekPoints) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) Test(org.junit.Test)

Example 13 with SeekPoint

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);
    }
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint)

Example 14 with SeekPoint

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));
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint)

Example 15 with SeekPoint

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);
    }
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint)

Aggregations

SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)17 SeekPoint (androidx.media3.extractor.SeekPoint)10 Test (org.junit.Test)6 Nullable (androidx.annotation.Nullable)4 SeekPoints (androidx.media3.extractor.SeekMap.SeekPoints)3 SeekPoints (com.google.android.exoplayer2.extractor.SeekMap.SeekPoints)3