Search in sources :

Example 1 with SeekPoint

use of com.google.android.exoplayer2.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 2 with SeekPoint

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

Example 3 with SeekPoint

use of com.google.android.exoplayer2.extractor.SeekPoint 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 4 with SeekPoint

use of com.google.android.exoplayer2.extractor.SeekPoint 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)

Example 5 with SeekPoint

use of com.google.android.exoplayer2.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)

Aggregations

SeekPoint (com.google.android.exoplayer2.extractor.SeekPoint)10 SeekPoints (com.google.android.exoplayer2.extractor.SeekMap.SeekPoints)3 Test (org.junit.Test)3 Nullable (androidx.annotation.Nullable)1