Reintroduce option of using old frame pacing algorithm using capped FPS

This commit is contained in:
Cameron Gutman 2022-05-08 15:20:08 -05:00
parent 23a7d8555f
commit dc85ddb3f9
5 changed files with 34 additions and 4 deletions

View File

@ -389,6 +389,28 @@ public class Game extends Activity implements SurfaceHolder.Callback,
float displayRefreshRate = prepareDisplayForRendering(); float displayRefreshRate = prepareDisplayForRendering();
LimeLog.info("Display refresh rate: "+displayRefreshRate); LimeLog.info("Display refresh rate: "+displayRefreshRate);
// If the user requested frame pacing using a capped FPS, we will need to change our
// desired FPS setting here in accordance with the active display refresh rate.
int roundedRefreshRate = Math.round(displayRefreshRate);
int chosenFrameRate = prefConfig.fps;
if (prefConfig.framePacing == PreferenceConfiguration.FRAME_PACING_CAP_FPS) {
if (prefConfig.fps >= roundedRefreshRate) {
if (prefConfig.unlockFps) {
// Use frame drops when rendering above the screen frame rate
prefConfig.framePacing = PreferenceConfiguration.FRAME_PACING_BALANCED;
LimeLog.info("Using drop mode for FPS > Hz");
} else if (roundedRefreshRate <= 49) {
// Let's avoid clearly bogus refresh rates and fall back to legacy rendering
prefConfig.framePacing = PreferenceConfiguration.FRAME_PACING_BALANCED;
LimeLog.info("Bogus refresh rate: " + roundedRefreshRate);
}
else {
chosenFrameRate = roundedRefreshRate - 1;
LimeLog.info("Adjusting FPS target for screen to " + chosenFrameRate);
}
}
}
boolean vpnActive = NetHelper.isActiveNetworkVpn(this); boolean vpnActive = NetHelper.isActiveNetworkVpn(this);
if (vpnActive) { if (vpnActive) {
LimeLog.info("Detected active network is a VPN"); LimeLog.info("Detected active network is a VPN");
@ -397,7 +419,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
StreamConfiguration config = new StreamConfiguration.Builder() StreamConfiguration config = new StreamConfiguration.Builder()
.setResolution(prefConfig.width, prefConfig.height) .setResolution(prefConfig.width, prefConfig.height)
.setLaunchRefreshRate(prefConfig.fps) .setLaunchRefreshRate(prefConfig.fps)
.setRefreshRate(prefConfig.fps) .setRefreshRate(chosenFrameRate)
.setApp(new NvApp(appName != null ? appName : "app", appId, appSupportsHdr)) .setApp(new NvApp(appName != null ? appName : "app", appId, appSupportsHdr))
.setBitrate(prefConfig.bitrate) .setBitrate(prefConfig.bitrate)
.setEnableSops(prefConfig.enableSops) .setEnableSops(prefConfig.enableSops)

View File

@ -468,8 +468,9 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
presentationTimeUs = info.presentationTimeUs; presentationTimeUs = info.presentationTimeUs;
} }
if (prefs.framePacing == PreferenceConfiguration.FRAME_PACING_MAX_SMOOTHNESS) { if (prefs.framePacing == PreferenceConfiguration.FRAME_PACING_MAX_SMOOTHNESS ||
// In max smoothness mode, we want to never drop frames prefs.framePacing == PreferenceConfiguration.FRAME_PACING_CAP_FPS) {
// In max smoothness or cap FPS mode, we want to never drop frames
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Use a PTS that will cause this frame to never be dropped // Use a PTS that will cause this frame to never be dropped
videoDecoder.releaseOutputBuffer(lastIndex, 0); videoDecoder.releaseOutputBuffer(lastIndex, 0);

View File

@ -80,7 +80,8 @@ public class PreferenceConfiguration {
public static final int FRAME_PACING_MIN_LATENCY = 0; public static final int FRAME_PACING_MIN_LATENCY = 0;
public static final int FRAME_PACING_BALANCED = 1; public static final int FRAME_PACING_BALANCED = 1;
public static final int FRAME_PACING_MAX_SMOOTHNESS = 2; public static final int FRAME_PACING_CAP_FPS = 2;
public static final int FRAME_PACING_MAX_SMOOTHNESS = 3;
public static final String RES_360P = "640x360"; public static final String RES_360P = "640x360";
public static final String RES_480P = "854x480"; public static final String RES_480P = "854x480";
@ -288,6 +289,9 @@ public class PreferenceConfiguration {
else if (str.equals("balanced")) { else if (str.equals("balanced")) {
return FRAME_PACING_BALANCED; return FRAME_PACING_BALANCED;
} }
else if (str.equals("cap-fps")) {
return FRAME_PACING_CAP_FPS;
}
else if (str.equals("smoothness")) { else if (str.equals("smoothness")) {
return FRAME_PACING_MAX_SMOOTHNESS; return FRAME_PACING_MAX_SMOOTHNESS;
} }

View File

@ -98,11 +98,13 @@
<string-array name="video_frame_pacing_names"> <string-array name="video_frame_pacing_names">
<item>@string/pacing_latency</item> <item>@string/pacing_latency</item>
<item>@string/pacing_balanced</item> <item>@string/pacing_balanced</item>
<item>@string/pacing_balanced_alt</item>
<item>@string/pacing_smoothness</item> <item>@string/pacing_smoothness</item>
</string-array> </string-array>
<string-array name="video_frame_pacing_values" translatable="false"> <string-array name="video_frame_pacing_values" translatable="false">
<item>latency</item> <item>latency</item>
<item>balanced</item> <item>balanced</item>
<item>cap-fps</item>
<item>smoothness</item> <item>smoothness</item>
</string-array> </string-array>
</resources> </resources>

View File

@ -252,5 +252,6 @@
<string name="summary_frame_pacing">Specify how to balance video latency and smoothness</string> <string name="summary_frame_pacing">Specify how to balance video latency and smoothness</string>
<string name="pacing_latency">Prefer lowest latency</string> <string name="pacing_latency">Prefer lowest latency</string>
<string name="pacing_balanced">Balanced</string> <string name="pacing_balanced">Balanced</string>
<string name="pacing_balanced_alt">Balanced with FPS cap (may perform better on certain devices)</string>
<string name="pacing_smoothness">Prefer smoothest video (may significantly increase latency)</string> <string name="pacing_smoothness">Prefer smoothest video (may significantly increase latency)</string>
</resources> </resources>