From c66adfeaaf2f06559e70871d29d1a83496096fab Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 6 Jul 2023 09:22:13 +0100 Subject: [PATCH] Add customization option to disable same-release-time skipping We have the optimization to skip buffers if the release time is exactly the same as the one for the previous buffer. This makes sense under the assumption that these buffers get released to a visible Surface and will be ignored anyway. However, it's also helpful to provide a customization option to not do this for cases where the outputting MediaCodecAdapter is not directly talking to a visible Surface or for tests where we can't fully control the vsync timing of the Surface and want to ensure we output all samples that are meant to be shown. PiperOrigin-RevId: 545906113 --- .../exoplayer/video/MediaCodecVideoRenderer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java index 5900dc5067..d65e4da7cf 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/video/MediaCodecVideoRenderer.java @@ -1287,7 +1287,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { if (Util.SDK_INT >= 21) { // Let the underlying framework time the release. if (earlyUs < 50000) { - if (adjustedReleaseTimeNs == lastFrameReleaseTimeNs) { + if (shouldSkipBuffersWithIdenticalReleaseTime() + && adjustedReleaseTimeNs == lastFrameReleaseTimeNs) { // This frame should be displayed on the same vsync with the previous released frame. We // are likely rendering frames at a rate higher than the screen refresh rate. Skip // this buffer so that it's returned to MediaCodec sooner otherwise MediaCodec may not @@ -1443,6 +1444,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { return isBufferVeryLate(earlyUs) && !isLastBuffer; } + /** + * Returns whether to skip buffers that have an identical release time as the previous released + * buffer. + */ + protected boolean shouldSkipBuffersWithIdenticalReleaseTime() { + return true; + } + /** * Returns whether to force rendering an output buffer. *