mirror of
https://github.com/samsonjs/media.git
synced 2026-03-30 10:15:48 +00:00
Make video playback smoother at the beginning
Video renderers assume that the player position is advancing linearly while in the started state. MediaCodecVideoRenderer schedules frames for rendering in the future in the expectation that the player position is advancing. This assumption is not currently true when using a position from the AudioTrack: the player position can be fixed for (in the worst case) up to about 100 ms before it starts increasing. This leads to an effect where the first frame is rendered then a few other frames are rendered, then there's a pause before frames start being rendered smoothly. Work around this issue by checking whether the position has started advancing before scheduling frames to be rendered in the future. It might be preferable to make the audio renderer only become ready when its timestamp can start advancing, but this is likely to be complicated. Issue: #3841 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190937429
This commit is contained in:
parent
7820497006
commit
8d47209a46
2 changed files with 14 additions and 2 deletions
|
|
@ -127,6 +127,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
|
|||
|
||||
private Bitmap bitmap;
|
||||
private boolean renderedFirstFrame;
|
||||
private long initialPositionUs;
|
||||
private long joiningDeadlineMs;
|
||||
private Surface surface;
|
||||
private VpxOutputBufferRenderer outputBufferRenderer;
|
||||
|
|
@ -303,6 +304,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
|
|||
inputStreamEnded = false;
|
||||
outputStreamEnded = false;
|
||||
clearRenderedFirstFrame();
|
||||
initialPositionUs = C.TIME_UNSET;
|
||||
consecutiveDroppedFrameCount = 0;
|
||||
if (decoder != null) {
|
||||
flushDecoder();
|
||||
|
|
@ -809,6 +811,10 @@ public class LibvpxVideoRenderer extends BaseRenderer {
|
|||
*/
|
||||
private boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs)
|
||||
throws ExoPlaybackException {
|
||||
if (initialPositionUs == C.TIME_UNSET) {
|
||||
initialPositionUs = positionUs;
|
||||
}
|
||||
|
||||
long earlyUs = outputBuffer.timeUs - positionUs;
|
||||
if (outputMode == VpxDecoder.OUTPUT_MODE_NONE) {
|
||||
// Skip frames in sync with playback, so we'll be at the right frame if the mode changes.
|
||||
|
|
@ -828,7 +834,7 @@ public class LibvpxVideoRenderer extends BaseRenderer {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!isStarted) {
|
||||
if (!isStarted || positionUs == initialPositionUs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||
@C.VideoScalingMode
|
||||
private int scalingMode;
|
||||
private boolean renderedFirstFrame;
|
||||
private long initialPositionUs;
|
||||
private long joiningDeadlineMs;
|
||||
private long droppedFrameAccumulationStartTimeMs;
|
||||
private int droppedFrames;
|
||||
|
|
@ -276,6 +277,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException {
|
||||
super.onPositionReset(positionUs, joining);
|
||||
clearRenderedFirstFrame();
|
||||
initialPositionUs = C.TIME_UNSET;
|
||||
consecutiveDroppedFrameCount = 0;
|
||||
if (pendingOutputStreamOffsetCount != 0) {
|
||||
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[pendingOutputStreamOffsetCount - 1];
|
||||
|
|
@ -532,6 +534,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||
protected boolean processOutputBuffer(long positionUs, long elapsedRealtimeUs, MediaCodec codec,
|
||||
ByteBuffer buffer, int bufferIndex, int bufferFlags, long bufferPresentationTimeUs,
|
||||
boolean shouldSkip) throws ExoPlaybackException {
|
||||
if (initialPositionUs == C.TIME_UNSET) {
|
||||
initialPositionUs = positionUs;
|
||||
}
|
||||
|
||||
while (pendingOutputStreamOffsetCount != 0
|
||||
&& bufferPresentationTimeUs >= pendingOutputStreamOffsetsUs[0]) {
|
||||
outputStreamOffsetUs = pendingOutputStreamOffsetsUs[0];
|
||||
|
|
@ -569,7 +575,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!isStarted) {
|
||||
if (!isStarted || positionUs == initialPositionUs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue