Skip to content

Commit

Permalink
Add mpv Settings: HW/SW+, Interpolation, Gpu-next, Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
yuroyami committed Jan 5, 2024
1 parent 81f55ba commit 42b0ced
Show file tree
Hide file tree
Showing 18 changed files with 549 additions and 440 deletions.
15 changes: 11 additions & 4 deletions androidApp/src/main/java/com/yuroyami/syncplay/WatchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import com.yuroyami.syncplay.player.PlayerUtils.pausePlayback
import com.yuroyami.syncplay.player.PlayerUtils.playPlayback
import com.yuroyami.syncplay.player.exo.ExoPlayer
import com.yuroyami.syncplay.player.mpv.MpvPlayer
import com.yuroyami.syncplay.player.mpv.mpvRoomSettings
import com.yuroyami.syncplay.settings.DataStoreKeys
import com.yuroyami.syncplay.settings.DataStoreKeys.PREF_INROOM_PIP
import com.yuroyami.syncplay.settings.MySettings.additionalPlayerRoomSettings
import com.yuroyami.syncplay.settings.settingBoolean
import com.yuroyami.syncplay.settings.settingString
import com.yuroyami.syncplay.settings.valueBlockingly
import com.yuroyami.syncplay.utils.UIUtils.cutoutMode
import com.yuroyami.syncplay.utils.UIUtils.hideSystemUI
Expand Down Expand Up @@ -81,8 +82,14 @@ class WatchActivity : ComponentActivity() {
)

when (engine) {
ENGINE.ANDROID_EXOPLAYER -> viewmodel?.player = ExoPlayer()
ENGINE.ANDROID_MPV -> viewmodel?.player = MpvPlayer()
ENGINE.ANDROID_EXOPLAYER -> {
additionalPlayerRoomSettings = listOf()
viewmodel?.player = ExoPlayer()
}
ENGINE.ANDROID_MPV -> {
additionalPlayerRoomSettings = mpvRoomSettings
viewmodel?.player = MpvPlayer()
}
else -> {}
}

Expand Down Expand Up @@ -269,7 +276,7 @@ class WatchActivity : ComponentActivity() {
/** Applying the locale language preference */
override fun attachBaseContext(newBase: Context?) {
/** Applying saved language */
val lang = DataStoreKeys.PREF_DISPLAY_LANG.settingString()
val lang = valueBlockingly(DataStoreKeys.PREF_DISPLAY_LANG, "en")
super.attachBaseContext(newBase!!.changeLanguage(lang))
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package com.yuroyami.syncplay.player.mpv
import android.content.Context
import android.os.Build
import android.os.Environment
import android.preference.PreferenceManager
import android.util.AttributeSet
import android.util.Log
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.WindowManager
import com.yuroyami.syncplay.R
import com.yuroyami.syncplay.player.PlayerOptions
import com.yuroyami.syncplay.settings.DataStoreKeys.PREF_MPV_DEBUG_MODE
import com.yuroyami.syncplay.settings.DataStoreKeys.PREF_MPV_GPU_NEXT
import com.yuroyami.syncplay.settings.DataStoreKeys.PREF_MPV_HARDWARE_ACCELERATION
import com.yuroyami.syncplay.settings.DataStoreKeys.PREF_MPV_INTERPOLATION
import com.yuroyami.syncplay.settings.settingBoolean
import `is`.xyz.mpv.MPVLib
import `is`.xyz.mpv.MPVLib.mpvFormat.MPV_FORMAT_DOUBLE
import `is`.xyz.mpv.MPVLib.mpvFormat.MPV_FORMAT_FLAG
Expand Down Expand Up @@ -47,32 +50,20 @@ internal class MPVView(context: Context, attrs: AttributeSet) : SurfaceView(cont
observeProperties()
}

private var voInUse: String = ""

var voInUse: String = ""
private fun initOptions() {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.context)

// apply phone-optimized defaults
MPVLib.setOptionString("profile", "fast")

// vo
val vo = if (sharedPreferences.getBoolean("gpu_next", false))
"gpu-next"
else
"gpu"
voInUse = vo

// hwdec
val hwdec = if (sharedPreferences.getBoolean("hardware_decoding", true))
"auto"
else
"no"
voInUse = if (PREF_MPV_GPU_NEXT.settingBoolean()) "gpu-next" else "gpu"

val hwdec = if (PREF_MPV_HARDWARE_ACCELERATION.settingBoolean()) "auto" else "no"

// vo: set display fps as reported by android
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val disp = wm.defaultDisplay
val refreshRate = disp.mode.refreshRate

Log.v(TAG, "Display ${disp.displayId} reports FPS of $refreshRate")
MPVLib.setOptionString("display-fps-override", refreshRate.toString())

Expand All @@ -95,36 +86,37 @@ internal class MPVView(context: Context, attrs: AttributeSet) : SurfaceView(cont
)

for ((preference_name, mpv_option) in opts) {
val preference = sharedPreferences.getString(preference_name, "")
if (!preference.isNullOrBlank())
MPVLib.setOptionString(mpv_option, preference)
//val preference = sharedPreferences.getString(preference_name, "")
//if (!preference.isNullOrBlank())
MPVLib.setOptionString(mpv_option, "")
}

// set more options

val debandMode = sharedPreferences.getString("video_debanding", "")
val debandMode = "" //TODO: Preferencize: sharedPreferences.getString("video_debanding", "")
if (debandMode == "gradfun") {
// lower the default radius (16) to improve performance
MPVLib.setOptionString("vf", "gradfun=radius=12")
} else if (debandMode == "gpu") {
MPVLib.setOptionString("deband", "yes")
}

val vidsync = sharedPreferences.getString("video_sync", resources.getString(R.string.pref_video_interpolation_sync_default))
MPVLib.setOptionString("video-sync", vidsync!!)
//TODO: Preferencize
MPVLib.setOptionString("video-sync", "audio")


if (sharedPreferences.getBoolean("video_interpolation", false))
if (PREF_MPV_INTERPOLATION.settingBoolean())
MPVLib.setOptionString("interpolation", "yes")

if (sharedPreferences.getBoolean("gpudebug", false))
if (PREF_MPV_DEBUG_MODE.settingBoolean())
MPVLib.setOptionString("gpu-debug", "yes")

if (sharedPreferences.getBoolean("video_fastdecode", false)) {
if (false /* TODO: sharedPreferences.getBoolean("video_fastdecode", false) */) {
MPVLib.setOptionString("vd-lavc-fast", "yes")
MPVLib.setOptionString("vd-lavc-skiploopfilter", "nonkey")
}

MPVLib.setOptionString("vo", vo)
MPVLib.setOptionString("vo", voInUse)
MPVLib.setOptionString("gpu-context", "android")
MPVLib.setOptionString("opengl-es", "yes")
MPVLib.setOptionString("hwdec", hwdec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,22 @@ class MpvPlayer : BasePlayer() {
mpvView.removeObserver(observer)
}
}



fun toggleHardwareAcceleration(b: Boolean) {
MPVLib.setOptionString("hwdec", if (b) "auto" else "no" )
}

fun toggleGpuNext(b: Boolean) {
MPVLib.setOptionString("vo", if (b) "gpu-next" else "gpu")
}

fun toggleInterpolation(b: Boolean) {
MPVLib.setOptionString("interpolation", if (b) "yes" else "no")
}

fun toggleDebugMode(b: Boolean) {
MPVLib.setOptionString("gpu-debug", if (b) "yes" else "no")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.yuroyami.syncplay.player.mpv

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Adb
import androidx.compose.material.icons.filled.Memory
import androidx.compose.material.icons.filled.SlowMotionVideo
import androidx.compose.material.icons.filled.Speed
import com.yuroyami.syncplay.settings.DataStoreKeys
import com.yuroyami.syncplay.settings.MySettings
import com.yuroyami.syncplay.settings.Setting
import com.yuroyami.syncplay.settings.SettingType
import com.yuroyami.syncplay.watchroom.lyricist
import com.yuroyami.syncplay.watchroom.viewmodel

val mpvRoomSettings = listOf(
Setting.BooleanSetting(
type = SettingType.ToggleSettingType,
key = DataStoreKeys.PREF_MPV_HARDWARE_ACCELERATION,
title = lyricist.strings.uisettingMpvHardwareAccelerationTitle,
summary = lyricist.strings.uisettingMpvHardwareAccelerationSummary,
defaultValue = true,
icon = Icons.Filled.Speed,
styling = MySettings.settingROOMstyle,
onBooleanChanged = { b ->
(viewmodel?.player as? MpvPlayer)?.toggleHardwareAcceleration(b)
}
) to DataStoreKeys.CATEG_INROOM_MPV,

Setting.BooleanSetting(
type = SettingType.ToggleSettingType,
key = DataStoreKeys.PREF_MPV_GPU_NEXT,
title = lyricist.strings.uisettingMpvGpunextTitle,
summary = lyricist.strings.uisettingMpvGpunextSummary,
defaultValue = false,
icon = Icons.Filled.Memory,
styling = MySettings.settingROOMstyle,
onBooleanChanged = { b ->
(viewmodel?.player as? MpvPlayer)?.toggleGpuNext(b)
}
) to DataStoreKeys.CATEG_INROOM_MPV,

Setting.BooleanSetting(
type = SettingType.CheckboxSettingType,
key = DataStoreKeys.PREF_MPV_INTERPOLATION,
title = lyricist.strings.uiSettingMpvInterpolationTitle,
summary = lyricist.strings.uiSettingMpvInterpolationSummary,
defaultValue = false,
icon = Icons.Filled.SlowMotionVideo,
styling = MySettings.settingROOMstyle,
onBooleanChanged = { b ->
(viewmodel?.player as? MpvPlayer)?.toggleInterpolation(b)
}
) to DataStoreKeys.CATEG_INROOM_MPV,

Setting.BooleanSetting(
type = SettingType.CheckboxSettingType,
key = DataStoreKeys.PREF_MPV_DEBUG_MODE,
title = lyricist.strings.uiSettingMpvDebugTitle,
summary = lyricist.strings.uiSettingMpvDebugSummary,
defaultValue = false,
icon = Icons.Filled.Adb,
styling = MySettings.settingROOMstyle,
onBooleanChanged = { b ->
(viewmodel?.player as? MpvPlayer)?.toggleDebugMode(b)
}
) to DataStoreKeys.CATEG_INROOM_MPV,
)
8 changes: 0 additions & 8 deletions androidApp/src/main/res/values/strings.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
Expand Down Expand Up @@ -96,6 +97,7 @@ import com.yuroyami.syncplay.models.JoinInfo
import com.yuroyami.syncplay.settings.DataStoreKeys.MISC_NIGHTMODE
import com.yuroyami.syncplay.settings.DataStoreKeys.MISC_PLAYER_ENGINE
import com.yuroyami.syncplay.settings.MySettings.sgGLOBAL
import com.yuroyami.syncplay.settings.MySettings.sgROOM
import com.yuroyami.syncplay.settings.SettingsUI
import com.yuroyami.syncplay.settings.valueFlow
import com.yuroyami.syncplay.settings.writeValue
Expand All @@ -118,6 +120,8 @@ import syncplaymobile.generated.resources.Res
fun HomeScreen(config: HomeConfig) {
lyricist = rememberStrings()

LaunchedEffect(null) { sgGLOBAL;sgROOM }

val nightMode = valueFlow(MISC_NIGHTMODE, true).collectAsState(initial = true)

val savedConfig = remember { config }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ interface Strings {
val uisettingCategChatColors: String
val uisettingCategPlayerSettings: String
val uisettingCategChatProperties: String
val uisettingCategMpv: String
val uisettingMpvHardwareAccelerationTitle: String
val uisettingMpvHardwareAccelerationSummary: String
val uisettingMpvGpunextTitle: String
val uisettingMpvGpunextSummary: String
val uiSettingMpvDebugTitle: String
val uiSettingMpvDebugSummary: String
val uiSettingMpvInterpolationTitle: String
val uiSettingMpvInterpolationSummary: String
val uisettingApply: String
val uisettingTimestampSummary: String
val uisettingTimestampTitle: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ val ArStrings = object : Strings {
override val uisettingCategPlayerSettings = "إعدادات المشغل"
override val uisettingCategChatProperties = "خصائص الدردشة"

override val uisettingCategMpv = "mpv"
override val uisettingMpvHardwareAccelerationTitle = "تسارع الأجهزة"
override val uisettingMpvHardwareAccelerationSummary = "قم بتعطيل هذا لاستخدام التسارع البرمجي بدلاً من ذلك."
override val uisettingMpvGpunextTitle = "استخدام gpu-next"
override val uisettingMpvGpunextSummary = "فرض استخدام mpv لواجهة جديدة لعرض الفيديو، تعتمد على libplacebo."
override val uiSettingMpvDebugTitle = "تمكين التصحيح"
override val uiSettingMpvDebugSummary = "عرض معلومات التصحيح."
override val uiSettingMpvInterpolationTitle = "تكامل الإطارات في الثانية"
override val uiSettingMpvInterpolationSummary = "تقليل الاهتزاز عن طريق تمكين تكامل الإطارات في الثانية. قد لا يعمل هذا بشكل جيد في بعض الحالات."

override val uisettingApply = "تطبيق"
override val uisettingTimestampSummary = "قم بتعطيل هذا لإخفاء الطوابع الزمنية في بداية رسائل الدردشة."
override val uisettingTimestampTitle = "طوابع الزمن في الدردشة"
Expand Down
Loading

0 comments on commit 42b0ced

Please sign in to comment.