Handle initial RTSP seek

PiperOrigin-RevId: 469143613
This commit is contained in:
claincly 2022-08-22 10:39:48 +00:00 committed by Marc Baechinger
parent ee04bb8825
commit a62cf312b7
2 changed files with 20 additions and 3 deletions

View File

@ -187,6 +187,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public void seek(long nextRtpTimestamp, long playbackStartTimeUs) {
synchronized (lock) {
if (!isSeekPending) {
// Sets the isSeekPending flag, in the case preSeek() is not called, when seeking does not
// require RTSP message exchange. For example, playing back with non-zero start position.
isSeekPending = true;
}
this.nextRtpTimestamp = nextRtpTimestamp;
this.playbackStartTimeUs = playbackStartTimeUs;
}

View File

@ -229,6 +229,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
}
trackSelected = true;
if (positionUs != 0) {
// Track selection is performed only once in RTSP streams.
requestedSeekPositionUs = positionUs;
pendingSeekPositionUs = positionUs;
pendingSeekPositionUsForTcpRetry = positionUs;
}
maybeSetupTracks();
return positionUs;
}
@ -273,7 +279,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
// 2b.2. If RTSP PLAY (for the first seek) has not been sent, the new seek position will be
// used in the following PLAY request.
// TODO(internal: b/198620566) Handle initial seek.
// TODO(internal: b/213153670) Handle dropped seek position.
if (getBufferedPositionUs() == 0 && !isUsingRtpTcp) {
// Stores the seek position for later, if no RTP packet is received when using UDP.
@ -571,7 +576,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public void onRtspSetupCompleted() {
rtspClient.startPlayback(/* offsetMs= */ 0);
long offsetMs = 0;
if (pendingSeekPositionUs != C.TIME_UNSET) {
offsetMs = Util.usToMs(pendingSeekPositionUs);
} else if (pendingSeekPositionUsForTcpRetry != C.TIME_UNSET) {
offsetMs = Util.usToMs(pendingSeekPositionUsForTcpRetry);
}
rtspClient.startPlayback(offsetMs);
}
@Override
@ -610,6 +621,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (isSeekPending() && pendingSeekPositionUs == requestedSeekPositionUs) {
// Seek loadable only when all pending seeks are processed, or SampleQueues will report
// inconsistent bufferedPosition.
// Seeks to the start position when the initial seek position is set.
dataLoadable.seekToUs(startPositionUs, trackTiming.rtpTimestamp);
}
}
@ -624,7 +636,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
pendingSeekPositionUs = C.TIME_UNSET;
seekToUs(requestedSeekPositionUs);
}
} else if (pendingSeekPositionUsForTcpRetry != C.TIME_UNSET) {
} else if (pendingSeekPositionUsForTcpRetry != C.TIME_UNSET && isUsingRtpTcp) {
seekToUs(pendingSeekPositionUsForTcpRetry);
pendingSeekPositionUsForTcpRetry = C.TIME_UNSET;
}