mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Simplify bufferTimestampAdjustment handling
PiperOrigin-RevId: 696060496
This commit is contained in:
parent
8393c2e445
commit
9db66d6c6b
@ -468,9 +468,12 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
defaultVideoSink.setPlaybackSpeed(speed);
|
defaultVideoSink.setPlaybackSpeed(speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onStreamTimestampInfoChange(
|
private void setBufferTimestampAdjustment(long bufferTimestampAdjustmentUs) {
|
||||||
long bufferTimestampAdjustmentUs, long bufferPresentationTimeUs, long streamStartPositionUs) {
|
|
||||||
this.bufferTimestampAdjustmentUs = bufferTimestampAdjustmentUs;
|
this.bufferTimestampAdjustmentUs = bufferTimestampAdjustmentUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onStreamStartPositionChange(
|
||||||
|
long bufferPresentationTimeUs, long streamStartPositionUs) {
|
||||||
videoFrameRenderControl.onStreamStartPositionChanged(
|
videoFrameRenderControl.onStreamStartPositionChanged(
|
||||||
bufferPresentationTimeUs, streamStartPositionUs);
|
bufferPresentationTimeUs, streamStartPositionUs);
|
||||||
}
|
}
|
||||||
@ -496,7 +499,7 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
private long inputStreamStartPositionUs;
|
private long inputStreamStartPositionUs;
|
||||||
private long inputBufferTimestampAdjustmentUs;
|
private long inputBufferTimestampAdjustmentUs;
|
||||||
private long lastResetPositionUs;
|
private long lastResetPositionUs;
|
||||||
private boolean pendingInputStreamTimestampInfoChange;
|
private boolean pendingInputStartPositionChange;
|
||||||
|
|
||||||
/** The buffer presentation time, in microseconds, of the final frame in the stream. */
|
/** The buffer presentation time, in microseconds, of the final frame in the stream. */
|
||||||
private long finalBufferPresentationTimeUs;
|
private long finalBufferPresentationTimeUs;
|
||||||
@ -660,11 +663,14 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
public void setStreamTimestampInfo(
|
public void setStreamTimestampInfo(
|
||||||
long streamStartPositionUs, long bufferTimestampAdjustmentUs, long lastResetPositionUs) {
|
long streamStartPositionUs, long bufferTimestampAdjustmentUs, long lastResetPositionUs) {
|
||||||
// Ors because this method could be called multiple times on a timestamp info change.
|
// Ors because this method could be called multiple times on a timestamp info change.
|
||||||
pendingInputStreamTimestampInfoChange |=
|
pendingInputStartPositionChange |= inputStreamStartPositionUs != streamStartPositionUs;
|
||||||
inputStreamStartPositionUs != streamStartPositionUs
|
|
||||||
|| inputBufferTimestampAdjustmentUs != bufferTimestampAdjustmentUs;
|
|
||||||
inputStreamStartPositionUs = streamStartPositionUs;
|
inputStreamStartPositionUs = streamStartPositionUs;
|
||||||
inputBufferTimestampAdjustmentUs = bufferTimestampAdjustmentUs;
|
inputBufferTimestampAdjustmentUs = bufferTimestampAdjustmentUs;
|
||||||
|
// The buffer timestamp adjustment is only allowed to change after a flush to make sure that
|
||||||
|
// the buffer timestamps are increasing. We can update the buffer timestamp adjustment
|
||||||
|
// directly at the output of the VideoGraph because no frame has been input yet following the
|
||||||
|
// flush.
|
||||||
|
PlaybackVideoGraphWrapper.this.setBufferTimestampAdjustment(inputBufferTimestampAdjustmentUs);
|
||||||
this.lastResetPositionUs = lastResetPositionUs;
|
this.lastResetPositionUs = lastResetPositionUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,7 +767,7 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeSetStreamTimestampInfo(bufferPresentationTimeUs);
|
maybeSetStreamStartPosition(bufferPresentationTimeUs);
|
||||||
lastBufferPresentationTimeUs = bufferPresentationTimeUs;
|
lastBufferPresentationTimeUs = bufferPresentationTimeUs;
|
||||||
if (isLastFrame) {
|
if (isLastFrame) {
|
||||||
finalBufferPresentationTimeUs = bufferPresentationTimeUs;
|
finalBufferPresentationTimeUs = bufferPresentationTimeUs;
|
||||||
@ -794,7 +800,7 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
long lastBufferPresentationTimeUs =
|
long lastBufferPresentationTimeUs =
|
||||||
copyTimestampIterator.getLastTimestampUs() - inputBufferTimestampAdjustmentUs;
|
copyTimestampIterator.getLastTimestampUs() - inputBufferTimestampAdjustmentUs;
|
||||||
checkState(lastBufferPresentationTimeUs != C.TIME_UNSET);
|
checkState(lastBufferPresentationTimeUs != C.TIME_UNSET);
|
||||||
maybeSetStreamTimestampInfo(bufferPresentationTimeUs);
|
maybeSetStreamStartPosition(bufferPresentationTimeUs);
|
||||||
this.lastBufferPresentationTimeUs = lastBufferPresentationTimeUs;
|
this.lastBufferPresentationTimeUs = lastBufferPresentationTimeUs;
|
||||||
finalBufferPresentationTimeUs = lastBufferPresentationTimeUs;
|
finalBufferPresentationTimeUs = lastBufferPresentationTimeUs;
|
||||||
return true;
|
return true;
|
||||||
@ -817,11 +823,11 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
|
|||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
|
|
||||||
private void maybeSetStreamTimestampInfo(long bufferPresentationTimeUs) {
|
private void maybeSetStreamStartPosition(long bufferPresentationTimeUs) {
|
||||||
if (pendingInputStreamTimestampInfoChange) {
|
if (pendingInputStartPositionChange) {
|
||||||
PlaybackVideoGraphWrapper.this.onStreamTimestampInfoChange(
|
PlaybackVideoGraphWrapper.this.onStreamStartPositionChange(
|
||||||
inputBufferTimestampAdjustmentUs, bufferPresentationTimeUs, inputStreamStartPositionUs);
|
bufferPresentationTimeUs, inputStreamStartPositionUs);
|
||||||
pendingInputStreamTimestampInfoChange = false;
|
pendingInputStartPositionChange = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user