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
This commit is contained in:
tonihei 2023-07-06 09:22:13 +01:00 committed by Rohit Singh
parent 5050171ff6
commit c66adfeaaf

View file

@ -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.
*