[Android] AdvSettings: add dav1d thread number prompt
Duncan McNamara
git at videolan.org
Tue Jun 18 13:09:35 UTC 2024
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Mon Jun 17 18:55:20 2024 +0200| [747ac96ec408dc9e71035b843b15bb11b78ba96f] | committer: Nicolas Pomepuy
AdvSettings: add dav1d thread number prompt
This is to be able to change dav1d's thread number on the fly
> https://code.videolan.org/videolan/vlc-android/commit/747ac96ec408dc9e71035b843b15bb11b78ba96f
---
.../resources/src/main/res/values/strings.xml | 2 ++
.../television/ui/preferences/PreferencesAdvanced.kt | 20 ++++++++++++++++++++
.../src/main/java/org/videolan/tools/Settings.kt | 1 +
application/vlc-android/res/xml/preferences_adv.xml | 6 ++++++
.../vlc/gui/preferences/PreferencesAdvanced.kt | 18 ++++++++++++++++++
.../src/org/videolan/vlc/media/PlaylistManager.kt | 5 +++++
6 files changed, 52 insertions(+)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 2de2c7230a..243a5b811d 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -563,6 +563,8 @@
<string name="http_user_agent">HTTP user agent</string>
<string name="custom_libvlc_options">Custom libVLC options</string>
<string name="custom_libvlc_options_invalid">Invalid libVLC options!</string>
+ <string name="dav1d_thread_number">Dav1d thread number</string>
+ <string name="dav1d_thread_number_invalid">Invalid thread number! (>=1)</string>
<string name="serious_crash">Unfortunately, a serious error has occurred and VLC had to close.</string>
<string name="help_us_send_log">Help us improving VLC by sending the following crash log:</string>
diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
index 644c56f7bc..b890ef19f2 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
@@ -36,6 +36,7 @@ import android.text.InputType
import android.util.Log
import android.widget.Toast
import androidx.core.content.edit
+import androidx.core.text.isDigitsOnly
import androidx.fragment.app.FragmentActivity
import androidx.preference.EditTextPreference
import androidx.preference.Preference
@@ -43,6 +44,7 @@ import kotlinx.coroutines.*
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.*
import org.videolan.tools.BitmapCache
+import org.videolan.tools.DAV1D_THREAD_NUMBER
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.MediaParsingService
@@ -50,6 +52,7 @@ import org.videolan.vlc.R
import org.videolan.vlc.gui.DebugLogActivity
import org.videolan.vlc.gui.dialogs.ConfirmDeleteDialog
import org.videolan.vlc.gui.dialogs.RenameDialog
+import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getWritePermission
import org.videolan.vlc.gui.helpers.restartMediaPlayer
import org.videolan.vlc.util.FeatureFlag
@@ -269,6 +272,23 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
}
}
+ DAV1D_THREAD_NUMBER -> {
+ val threadNumber = sharedPreferences.getString(key, "") ?: ""
+ if (threadNumber != "" ) {
+ if ((threadNumber.isDigitsOnly() && threadNumber.toInt() < 1) || !threadNumber.isDigitsOnly()) {
+ UiTools.snacker(activity, R.string.dav1d_thread_number_invalid)
+ sharedPreferences.putSingle(DAV1D_THREAD_NUMBER, "")
+ }
+ } else {
+ // In case of failure, after resetting the value to "" the SimpleSummaryProvider
+ // doesn't re-update it's summary to the default, has to be forced
+ val pref = findPreference<EditTextPreference>(key)
+ if (pref?.callChangeListener("") == true) {
+ pref.setText("");
+ }
+ }
+ }
+
"opengl", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode", "prefer_smbv1" -> {
launch { restartLibVLC() }
}
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index b12f2f5809..e93e5fae05 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -225,6 +225,7 @@ const val SLEEP_TIMER_RESET_INTERACTION = "sleep_timer_reset_interaction"
const val NOTIFICATION_PERMISSION_ASKED = "notification_permission_asked"
const val PLAYLIST_REPLACE = "playlist_replace"
const val HTTP_USER_AGENT = "http_user_agent"
+const val DAV1D_THREAD_NUMBER = "dav1d_thread_number"
//files
const val BROWSER_SHOW_HIDDEN_FILES = "browser_show_hidden_files"
diff --git a/application/vlc-android/res/xml/preferences_adv.xml b/application/vlc-android/res/xml/preferences_adv.xml
index e241087cd8..75a51ae593 100644
--- a/application/vlc-android/res/xml/preferences_adv.xml
+++ b/application/vlc-android/res/xml/preferences_adv.xml
@@ -93,6 +93,12 @@
android:key="enable_frame_skip"
android:summary="@string/enable_frame_skip_summary"
android:title="@string/enable_frame_skip"/>
+ <EditTextPreference
+ android:defaultValue=""
+ android:inputType="textMultiLine"
+ android:key="dav1d_thread_number"
+ app:useSimpleSummaryProvider="true"
+ android:title="@string/dav1d_thread_number"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/developer_prefs_category">
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index aaea5c7aed..d1cbb2b22d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -36,6 +36,7 @@ import android.text.InputType
import android.util.Log
import android.widget.Toast
import androidx.core.content.edit
+import androidx.core.text.isDigitsOnly
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference
@@ -58,6 +59,7 @@ import org.videolan.resources.ROOM_DATABASE
import org.videolan.resources.SCHEME_PACKAGE
import org.videolan.resources.VLCInstance
import org.videolan.tools.BitmapCache
+import org.videolan.tools.DAV1D_THREAD_NUMBER
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.vlc.R
@@ -279,6 +281,22 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
restartLibVLC()
}
}
+ DAV1D_THREAD_NUMBER -> {
+ val threadNumber = sharedPreferences.getString(key, "") ?: ""
+ if (threadNumber != "" ) {
+ if ((threadNumber.isDigitsOnly() && threadNumber.toInt() < 1) || !threadNumber.isDigitsOnly()) {
+ UiTools.snacker(requireActivity(), R.string.dav1d_thread_number_invalid)
+ sharedPreferences.putSingle(DAV1D_THREAD_NUMBER, "")
+ }
+ } else {
+ // In case of failure, after resetting the value to "" the SimpleSummaryProvider
+ // doesn't re-update it's summary to the default, has to be forced
+ val pref = findPreference<EditTextPreference>(key)
+ if (pref?.callChangeListener("") == true) {
+ pref.setText("");
+ }
+ }
+ }
"opengl", "deblocking", "enable_frame_skip", "enable_time_stretching_audio", "enable_verbose_mode" -> {
lifecycleScope.launch { restartLibVLC() }
}
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 8dfaad78e5..52f199d32e 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -54,6 +54,7 @@ import org.videolan.tools.AUDIO_RESUME_PLAYBACK
import org.videolan.tools.AUDIO_SHUFFLING
import org.videolan.tools.AUDIO_STOP_AFTER
import org.videolan.tools.AppScope
+import org.videolan.tools.DAV1D_THREAD_NUMBER
import org.videolan.tools.HTTP_USER_AGENT
import org.videolan.tools.KEY_AUDIO_FORCE_SHUFFLE
import org.videolan.tools.KEY_INCOGNITO
@@ -530,6 +531,10 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
settings.getString(HTTP_USER_AGENT, null)?.let {
media.addOption(":http-user-agent=$it")
}
+ val dav1dThreadNumber = settings.getString(DAV1D_THREAD_NUMBER, "") ?: ""
+ if (dav1dThreadNumber.toInt() >= 1) {
+ media.addOption(":dav1d-thread-frames=$dav1dThreadNumber")
+ }
//todo in VLC 4.0, this should be done by using libvlc_media_player_set_time instead of start-time
media.addOption(":start-time=${start/1000L}")
VLCOptions.setMediaOptions(media, ctx, flags or mw.flags, PlaybackService.hasRenderer())
More information about the Android
mailing list