Add option to stream at device native FPS

Useful for phones with overclocked refresh rate
This commit is contained in:
semjon00
2023-04-19 15:29:53 +03:00
committed by Cameron Gutman
parent 388343c3ee
commit 90afecd766
2 changed files with 49 additions and 16 deletions

View File

@@ -123,6 +123,7 @@ public class StreamSettings extends Activity {
public static class SettingsFragment extends PreferenceFragment {
private int nativeResolutionStartIndex = Integer.MAX_VALUE;
private boolean nativeFramerateShown = false;
private void setValue(String preferenceKey, String value) {
ListPreference pref = (ListPreference) findPreference(preferenceKey);
@@ -130,6 +131,18 @@ public class StreamSettings extends Activity {
pref.setValue(value);
}
private void appendPreferenceEntry(ListPreference pref, String newEntryName, String newEntryValue) {
CharSequence[] newEntries = Arrays.copyOf(pref.getEntries(), pref.getEntries().length + 1);
CharSequence[] newValues = Arrays.copyOf(pref.getEntryValues(), pref.getEntryValues().length + 1);
// Add the new option
newEntries[newEntries.length - 1] = newEntryName;
newValues[newValues.length - 1] = newEntryValue;
pref.setEntries(newEntries);
pref.setEntryValues(newValues);
}
private void addNativeResolutionEntry(int nativeWidth, int nativeHeight, boolean insetsRemoved, boolean portrait) {
ListPreference pref = (ListPreference) findPreference(PreferenceConfiguration.RESOLUTION_PREF_STRING);
@@ -155,29 +168,18 @@ public class StreamSettings extends Activity {
String newValue = nativeWidth+"x"+nativeHeight;
CharSequence[] values = pref.getEntryValues();
// Check if the native resolution is already present
for (CharSequence value : values) {
for (CharSequence value : pref.getEntryValues()) {
if (newValue.equals(value.toString())) {
// It is present in the default list, so don't add it again
return;
}
}
CharSequence[] newEntries = Arrays.copyOf(pref.getEntries(), pref.getEntries().length + 1);
CharSequence[] newValues = Arrays.copyOf(values, values.length + 1);
// Add the new native option
newEntries[newEntries.length - 1] = newName;
newValues[newValues.length - 1] = newValue;
pref.setEntries(newEntries);
pref.setEntryValues(newValues);
if (newValues.length - 1 < nativeResolutionStartIndex) {
nativeResolutionStartIndex = newValues.length - 1;
if (pref.getEntryValues().length < nativeResolutionStartIndex) {
nativeResolutionStartIndex = pref.getEntryValues().length;
}
appendPreferenceEntry(pref, newName, newValue);
}
private void addNativeResolutionEntries(int nativeWidth, int nativeHeight, boolean insetsRemoved) {
@@ -187,6 +189,25 @@ public class StreamSettings extends Activity {
addNativeResolutionEntry(nativeWidth, nativeHeight, insetsRemoved, false);
}
private void addNativeFrameRateEntry(float framerate) {
ListPreference pref = (ListPreference) findPreference(PreferenceConfiguration.FPS_PREF_STRING);
String fpsValue = Integer.toString(Math.round(framerate));
String fpsName = getResources().getString(R.string.resolution_prefix_native) +
" (" + fpsValue + " " + getResources().getString(R.string.fps_suffix_fps) + ")";
// Check if the native frame rate is already present
for (CharSequence value : pref.getEntryValues()) {
if (fpsValue.equals(value.toString())) {
// It is present in the default list, so don't add it again
nativeFramerateShown = false;
return;
}
}
appendPreferenceEntry(pref, fpsName, fpsValue);
nativeFramerateShown = true;
}
private void removeValue(String preferenceKey, String value, Runnable onMatched) {
int matchingCount = 0;
@@ -508,6 +529,7 @@ public class StreamSettings extends Activity {
}
// Never remove 30 FPS or 60 FPS
}
addNativeFrameRateEntry(maxSupportedFps);
// Android L introduces proper 7.1 surround sound support. Remove the 7.1 option
// for earlier versions of Android to prevent AudioTrack initialization issues.
@@ -632,6 +654,15 @@ public class StreamSettings extends Activity {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
String valueStr = (String) newValue;
// If this is native frame rate, show the warning dialog
CharSequence[] values = ((ListPreference)preference).getEntryValues();
if (nativeFramerateShown && values[values.length - 1].toString().equals(newValue.toString())) {
Dialog.displayDialog(getActivity(),
getResources().getString(R.string.title_native_fps_dialog),
getResources().getString(R.string.text_native_res_dialog),
false);
}
// Write the new bitrate value
resetBitrateToDefault(prefs, null, valueStr);