Search in sources :

Example 6 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 7 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 8 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)

Example 9 with SeekPoint

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

Example 10 with SeekPoint

use of androidx.media3.extractor.SeekPoint in project Telegram-FOSS by Telegram-FOSS-Team.

the class MlltSeeker method getSeekPoints.

@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));
}
Also used : 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