Search in sources :

Example 1 with SeekPoints

use of com.google.android.exoplayer2.extractor.SeekMap.SeekPoints in project ExoPlayer by google.

the class FlacDecoderJni method getSeekPoints.

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

Example 2 with SeekPoints

use of com.google.android.exoplayer2.extractor.SeekMap.SeekPoints in project ExoPlayer by google.

the class ProgressiveMediaPeriod method getAdjustedSeekPositionUs.

@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
    assertPrepared();
    if (!seekMap.isSeekable()) {
        // Treat all seeks into non-seekable media as being to t=0.
        return 0;
    }
    SeekPoints seekPoints = seekMap.getSeekPoints(positionUs);
    return seekParameters.resolveSeekPositionUs(positionUs, seekPoints.first.timeUs, seekPoints.second.timeUs);
}
Also used : SeekPoints(com.google.android.exoplayer2.extractor.SeekMap.SeekPoints)

Example 3 with SeekPoints

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

Example 4 with SeekPoints

use of com.google.android.exoplayer2.extractor.SeekMap.SeekPoints in project ExoPlayer by google.

the class PsExtractorSeekTest method seekToTimeUs.

/**
 * Seeks to the given seek time and keeps reading from input until we can extract at least one
 * frame from the seek position, or until end-of-input is reached.
 *
 * @return The index of the first extracted frame written to the given {@code trackOutput} after
 *     the seek is completed, or -1 if the seek is completed without any extracted frame.
 */
private int seekToTimeUs(PsExtractor psExtractor, SeekMap seekMap, long seekTimeUs, FakeTrackOutput trackOutput) throws IOException {
    int numSampleBeforeSeek = trackOutput.getSampleCount();
    SeekMap.SeekPoints seekPoints = seekMap.getSeekPoints(seekTimeUs);
    long initialSeekLoadPosition = seekPoints.first.position;
    psExtractor.seek(initialSeekLoadPosition, seekTimeUs);
    positionHolder.position = C.POSITION_UNSET;
    ExtractorInput extractorInput = getExtractorInputFromPosition(initialSeekLoadPosition);
    int extractorReadResult = Extractor.RESULT_CONTINUE;
    while (true) {
        try {
            // Keep reading until we can read at least one frame after seek
            while (extractorReadResult == Extractor.RESULT_CONTINUE && trackOutput.getSampleCount() == numSampleBeforeSeek) {
                extractorReadResult = psExtractor.read(extractorInput, positionHolder);
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (extractorReadResult == Extractor.RESULT_SEEK) {
            extractorInput = getExtractorInputFromPosition(positionHolder.position);
            extractorReadResult = Extractor.RESULT_CONTINUE;
        } else if (extractorReadResult == Extractor.RESULT_END_OF_INPUT) {
            return -1;
        } else if (trackOutput.getSampleCount() > numSampleBeforeSeek) {
            // First index after seek = num sample before seek.
            return numSampleBeforeSeek;
        }
    }
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

Example 5 with SeekPoints

use of com.google.android.exoplayer2.extractor.SeekMap.SeekPoints in project ExoPlayer by google.

the class XingSeekerTest method getSeekPointsAtStartOfStream.

@Test
public void getSeekPointsAtStartOfStream() {
    SeekPoints seekPoints = seeker.getSeekPoints(0);
    SeekPoint seekPoint = seekPoints.first;
    assertThat(seekPoint).isEqualTo(seekPoints.second);
    assertThat(seekPoint.timeUs).isEqualTo(0);
    assertThat(seekPoint.position).isEqualTo(XING_FRAME_POSITION + xingFrameSize);
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SeekPoints(com.google.android.exoplayer2.extractor.SeekMap.SeekPoints) Test(org.junit.Test)

Aggregations

SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)17 Test (org.junit.Test)6 SeekPoints (com.google.android.exoplayer2.extractor.SeekMap.SeekPoints)5 SeekPoints (androidx.media3.extractor.SeekMap.SeekPoints)4 Nullable (androidx.annotation.Nullable)3 SeekPoint (androidx.media3.extractor.SeekPoint)3 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)3 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)2 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)1 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)1