Skip to content

Commit

Permalink
Force hardware plus decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
syphyr committed Jan 30, 2024
1 parent 03908f0 commit dcad459
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/is/xyz/mpv/MPVActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,21 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
Pair("HW (mediacodec-copy)", "mediacodec-copy"),
Pair("SW", "no")
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || player.forceHardwarePlus())
items.add(0, Pair("HW+ (mediacodec)", "mediacodec"))
val hwdecActive = player.hwdecActive
val selectedIndex = items.indexOfFirst { it.second == hwdecActive }
with (AlertDialog.Builder(this)) {
setSingleChoiceItems(items.map { it.first }.toTypedArray(), selectedIndex ) { dialog, idx ->
MPVLib.setPropertyString("hwdec", items[idx].second)
if (player.forceHardwarePlus()) {
if (items[idx].second == "mediacodec")
MPVLib.setPropertyString("vo", "mediacodec_embed")
else if (player.enableGpuNext())
MPVLib.setPropertyString("vo", "gpu-next")
else
MPVLib.setPropertyString("vo", "gpu")
}
dialog.dismiss()
}
setOnDismissListener { restore() }
Expand Down
31 changes: 26 additions & 5 deletions app/src/main/java/is/xyz/mpv/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,25 @@ internal class MPVView(context: Context, attrs: AttributeSet) : SurfaceView(cont
}

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

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))
val vo = if (forceHardwarePlus())
"mediacodec_embed"
else if (enableGpuNext())
"gpu-next"
else
"gpu"
voInUse = vo

// hwdec
val hwdec = if (sharedPreferences.getBoolean("hardware_decoding", true))
val hwdec = if (forceHardwarePlus())
"mediacodec"
else if (sharedPreferences.getBoolean("hardware_decoding", true))
"auto"
else
"no"
Expand Down Expand Up @@ -364,7 +367,17 @@ internal class MPVView(context: Context, attrs: AttributeSet) : SurfaceView(cont
fun cyclePause() = MPVLib.command(arrayOf("cycle", "pause"))
fun cycleAudio() = MPVLib.command(arrayOf("cycle", "audio"))
fun cycleSub() = MPVLib.command(arrayOf("cycle", "sub"))
fun cycleHwdec() = MPVLib.command(arrayOf("cycle-values", "hwdec", "auto", "no"))
fun cycleHwdec() {
if (!forceHardwarePlus())
MPVLib.command(arrayOf("cycle-values", "hwdec", "auto", "no"))
else {
MPVLib.command(arrayOf("cycle-values", "hwdec", "mediacodec", "mediacodec-copy"))
if (enableGpuNext())
MPVLib.command(arrayOf("cycle-values", "vo", "mediacodec_embed", "gpu-next"))
else
MPVLib.command(arrayOf("cycle-values", "vo", "mediacodec_embed", "gpu"))
}
}

fun cycleSpeed() {
val speeds = arrayOf(0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0)
Expand Down Expand Up @@ -397,6 +410,14 @@ internal class MPVView(context: Context, attrs: AttributeSet) : SurfaceView(cont
return MPVLib.getPropertyBoolean("shuffle")
}

fun forceHardwarePlus(): Boolean {
return sharedPreferences.getBoolean("hardware_plus_decoding", false)
}

fun enableGpuNext(): Boolean {
return sharedPreferences.getBoolean("gpu_next", false)
}

fun changeShuffle(cycle: Boolean, value: Boolean = true) {
// Use the 'shuffle' property to store the shuffled state, since changing
// it at runtime doesn't do anything.
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<string name="pref_hardware_decoding_title">Hardware decoding</string>
<string name="pref_hardware_decoding_summary">Attempt hardware decoding before falling back to software</string>

<string name="pref_hardware_plus_decoding_title">Force hardware plus decoding</string>
<string name="pref_hardware_plus_decoding_summary">This option is not compatible with subtitle rendering, OSD/OSC, and video filters.</string>

<string name="pref_background_play_title">Background playback</string>
<string name="pref_background_play_summary">Select when playback should be automatically resumed background</string>
<string name="pref_background_play_default" translatable="false">never</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/pref_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
android:summary="@string/pref_hardware_decoding_summary"
android:title="@string/pref_hardware_decoding_title" />

<CheckBoxPreference
android:defaultValue="false"
android:key="hardware_plus_decoding"
android:summary="@string/pref_hardware_plus_decoding_summary"
android:title="@string/pref_hardware_plus_decoding_title" />

<ListPreference
android:defaultValue="@string/pref_background_play_default"
android:key="background_play"
Expand Down

0 comments on commit dcad459

Please sign in to comment.