Support multiple native resolution options

This commit is contained in:
Cameron Gutman 2020-12-30 16:29:07 -06:00
parent d7a9a37a0e
commit 175e842feb
3 changed files with 33 additions and 45 deletions

View File

@ -68,7 +68,7 @@ public class StreamSettings extends Activity {
} }
public static class SettingsFragment extends PreferenceFragment { public static class SettingsFragment extends PreferenceFragment {
private boolean nativeResolutionOptionPresent = false; private int nativeResolutionStartIndex = Integer.MAX_VALUE;
private void setValue(String preferenceKey, String value) { private void setValue(String preferenceKey, String value) {
ListPreference pref = (ListPreference) findPreference(preferenceKey); ListPreference pref = (ListPreference) findPreference(preferenceKey);
@ -76,36 +76,35 @@ public class StreamSettings extends Activity {
pref.setValue(value); pref.setValue(value);
} }
private void updateNativeResolutionEntry(int nativeWidth, int nativeHeight) { private void addNativeResolutionEntry(int nativeWidth, int nativeHeight) {
ListPreference pref = (ListPreference) findPreference(PreferenceConfiguration.RESOLUTION_PREF_STRING); ListPreference pref = (ListPreference) findPreference(PreferenceConfiguration.RESOLUTION_PREF_STRING);
String nameSuffix = " ("+nativeWidth+"x"+nativeHeight+")"; String newName = getResources().getString(R.string.resolution_prefix_native) + " ("+nativeWidth+"x"+nativeHeight+")";
String newValue = nativeWidth+"x"+nativeHeight; String newValue = nativeWidth+"x"+nativeHeight;
CharSequence[] entries = pref.getEntries();
CharSequence[] values = pref.getEntryValues(); CharSequence[] values = pref.getEntryValues();
// Check if the native resolution is already present // Check if the native resolution is already present
for (CharSequence value : values) { for (CharSequence value : values) {
if (newValue.equals(value.toString())) { if (newValue.equals(value.toString())) {
// It is present in the default list, so remove the native option // It is present in the default list, so don't add it again
nativeResolutionOptionPresent = false;
pref.setEntries(Arrays.copyOf(entries, entries.length - 1));
pref.setEntryValues(Arrays.copyOf(values, values.length - 1));
return; return;
} }
} }
// Add the name suffix to the native option CharSequence[] newEntries = Arrays.copyOf(pref.getEntries(), pref.getEntries().length + 1);
entries[entries.length - 1] = entries[entries.length - 1].toString() + nameSuffix; CharSequence[] newValues = Arrays.copyOf(values, values.length + 1);
values[values.length - 1] = newValue;
pref.setEntries(entries); // Add the new native option
pref.setEntryValues(values); newEntries[newEntries.length - 1] = newName;
newValues[newValues.length - 1] = newValue;
nativeResolutionOptionPresent = true; pref.setEntries(newEntries);
pref.setEntryValues(newValues);
if (newValues.length - 1 < nativeResolutionStartIndex) {
nativeResolutionStartIndex = newValues.length - 1;
}
} }
private void removeValue(String preferenceKey, String value, Runnable onMatched) { private void removeValue(String preferenceKey, String value, Runnable onMatched) {
@ -226,7 +225,6 @@ public class StreamSettings extends Activity {
// HEVC Decoder: OMX.amlogic.hevc.decoder.awesome // HEVC Decoder: OMX.amlogic.hevc.decoder.awesome
// AVC supported width range: 64 - 384 // AVC supported width range: 64 - 384
// HEVC supported width range: 64 - 544 // HEVC supported width range: 64 - 544
int nativeWidth = 0, nativeHeight = 0;
for (Display.Mode candidate : display.getSupportedModes()) { for (Display.Mode candidate : display.getSupportedModes()) {
// Some devices report their dimensions in the portrait orientation // Some devices report their dimensions in the portrait orientation
// where height > width. Normalize these to the conventional width > height // where height > width. Normalize these to the conventional width > height
@ -235,12 +233,7 @@ public class StreamSettings extends Activity {
int width = Math.max(candidate.getPhysicalWidth(), candidate.getPhysicalHeight()); int width = Math.max(candidate.getPhysicalWidth(), candidate.getPhysicalHeight());
int height = Math.min(candidate.getPhysicalWidth(), candidate.getPhysicalHeight()); int height = Math.min(candidate.getPhysicalWidth(), candidate.getPhysicalHeight());
if (width > nativeWidth) { addNativeResolutionEntry(width, height);
nativeWidth = width;
}
if (height > nativeHeight) {
nativeHeight = height;
}
if ((width >= 3840 || height >= 2160) && maxSupportedResW < 3840) { if ((width >= 3840 || height >= 2160) && maxSupportedResW < 3840) {
maxSupportedResW = 3840; maxSupportedResW = 3840;
@ -257,8 +250,6 @@ public class StreamSettings extends Activity {
} }
} }
updateNativeResolutionEntry(nativeWidth, nativeHeight);
// This must be called to do runtime initialization before calling functions that evaluate // This must be called to do runtime initialization before calling functions that evaluate
// decoder lists. // decoder lists.
MediaCodecHelper.initialize(getContext(), GlPreferences.readPreferences(getContext()).glRenderer); MediaCodecHelper.initialize(getContext(), GlPreferences.readPreferences(getContext()).glRenderer);
@ -347,7 +338,7 @@ public class StreamSettings extends Activity {
Display display = getActivity().getWindowManager().getDefaultDisplay(); Display display = getActivity().getWindowManager().getDefaultDisplay();
int width = Math.max(display.getWidth(), display.getHeight()); int width = Math.max(display.getWidth(), display.getHeight());
int height = Math.min(display.getWidth(), display.getHeight()); int height = Math.min(display.getWidth(), display.getHeight());
updateNativeResolutionEntry(width, height); addNativeResolutionEntry(width, height);
} }
if (!PreferenceConfiguration.readPreferences(this.getActivity()).unlockFps) { if (!PreferenceConfiguration.readPreferences(this.getActivity()).unlockFps) {
@ -458,25 +449,23 @@ public class StreamSettings extends Activity {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
String valueStr = (String) newValue; String valueStr = (String) newValue;
if (nativeResolutionOptionPresent) { // Detect if this value is the native resolution option
// Detect if this value is the native resolution option CharSequence[] values = ((ListPreference)preference).getEntryValues();
CharSequence[] values = ((ListPreference)preference).getEntryValues(); boolean isNativeRes = true;
boolean isNativeRes = true; for (int i = 0; i < values.length; i++) {
for (int i = 0; i < values.length; i++) { // Look for a match prior to the start of the native resolution entries
// If get a match prior to the end, it's not native res if (valueStr.equals(values[i].toString()) && i < nativeResolutionStartIndex) {
if (valueStr.equals(values[i].toString()) && i < values.length - 1) { isNativeRes = false;
isNativeRes = false; break;
break;
}
} }
}
// If this is native resolution, show the warning dialog // If this is native resolution, show the warning dialog
if (isNativeRes) { if (isNativeRes) {
Dialog.displayDialog(getActivity(), Dialog.displayDialog(getActivity(),
getResources().getString(R.string.title_native_res_dialog), getResources().getString(R.string.title_native_res_dialog),
getResources().getString(R.string.text_native_res_dialog), getResources().getString(R.string.text_native_res_dialog),
false); false);
}
} }
// Write the new bitrate value // Write the new bitrate value

View File

@ -7,7 +7,6 @@
<item>1080p</item> <item>1080p</item>
<item>1440p</item> <item>1440p</item>
<item>4K</item> <item>4K</item>
<item>Native</item>
</string-array> </string-array>
<string-array name="resolution_values" translatable="false"> <string-array name="resolution_values" translatable="false">
<item>640x360</item> <item>640x360</item>
@ -16,7 +15,6 @@
<item>1920x1080</item> <item>1920x1080</item>
<item>2560x1440</item> <item>2560x1440</item>
<item>3840x2160</item> <item>3840x2160</item>
<item>Native</item>
</string-array> </string-array>
<string-array name="fps_names"> <string-array name="fps_names">

View File

@ -147,6 +147,7 @@
<string name="summary_seekbar_bitrate">Increase for better image quality. Decrease to improve performance on slower connections.</string> <string name="summary_seekbar_bitrate">Increase for better image quality. Decrease to improve performance on slower connections.</string>
<string name="suffix_seekbar_bitrate_mbps">Mbps</string> <string name="suffix_seekbar_bitrate_mbps">Mbps</string>
<string name="title_checkbox_stretch_video">Stretch video to full-screen</string> <string name="title_checkbox_stretch_video">Stretch video to full-screen</string>
<string name="resolution_prefix_native">Native</string>
<string name="category_audio_settings">Audio Settings</string> <string name="category_audio_settings">Audio Settings</string>
<string name="title_audio_config_list">Surround sound configuration</string> <string name="title_audio_config_list">Surround sound configuration</string>