From 753a44f67c96899b33ef828098192bc6d991cc5c Mon Sep 17 00:00:00 2001
From: inotia00 <108592928+inotia00@users.noreply.github.com>
Date: Sun, 15 Sep 2024 19:08:28 +0900
Subject: [PATCH] feat(YouTube/Video playback): add `Disable VP9 codec` setting
https://github.com/inotia00/ReVanced_Extended/issues/2384
---
.../video/playback/VideoPlaybackPatch.kt | 21 ++++++++++++++++++-
.../fingerprints/VP9CapabilityFingerprint.kt | 14 +++++++++++++
.../youtube/settings/host/values/strings.xml | 7 +++++++
.../youtube/settings/xml/revanced_prefs.xml | 3 ++-
4 files changed, 43 insertions(+), 2 deletions(-)
create mode 100644 src/main/kotlin/app/revanced/patches/youtube/video/playback/fingerprints/VP9CapabilityFingerprint.kt
diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt
index 90188b9b19..23edbf0257 100644
--- a/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt
+++ b/src/main/kotlin/app/revanced/patches/youtube/video/playback/VideoPlaybackPatch.kt
@@ -30,6 +30,7 @@ import app.revanced.patches.youtube.video.playback.fingerprints.PlaybackSpeedCha
import app.revanced.patches.youtube.video.playback.fingerprints.PlaybackSpeedInitializeFingerprint
import app.revanced.patches.youtube.video.playback.fingerprints.QualityChangedFromRecyclerViewFingerprint
import app.revanced.patches.youtube.video.playback.fingerprints.QualitySetterFingerprint
+import app.revanced.patches.youtube.video.playback.fingerprints.VP9CapabilityFingerprint
import app.revanced.patches.youtube.video.videoid.VideoIdPatch
import app.revanced.util.getReference
import app.revanced.util.getStringInstructionIndex
@@ -72,7 +73,8 @@ object VideoPlaybackPatch : BaseBytecodePatch(
QualityChangedFromRecyclerViewFingerprint,
QualityMenuViewInflateFingerprint,
QualitySetterFingerprint,
- VideoEndFingerprint
+ VideoEndFingerprint,
+ VP9CapabilityFingerprint
)
) {
private const val PLAYBACK_SPEED_MENU_FILTER_CLASS_DESCRIPTOR =
@@ -81,6 +83,8 @@ object VideoPlaybackPatch : BaseBytecodePatch(
"$COMPONENTS_PATH/VideoQualityMenuFilter;"
private const val INTEGRATIONS_AV1_CODEC_CLASS_DESCRIPTOR =
"$VIDEO_PATH/AV1CodecPatch;"
+ private const val INTEGRATIONS_VP9_CODEC_CLASS_DESCRIPTOR =
+ "$VIDEO_PATH/VP9CodecPatch;"
private const val INTEGRATIONS_CUSTOM_PLAYBACK_SPEED_CLASS_DESCRIPTOR =
"$VIDEO_PATH/CustomPlaybackSpeedPatch;"
private const val INTEGRATIONS_HDR_VIDEO_CLASS_DESCRIPTOR =
@@ -326,6 +330,21 @@ object VideoPlaybackPatch : BaseBytecodePatch(
// endregion
+ // region patch for disable VP9 codec
+
+ VP9CapabilityFingerprint.resultOrThrow().mutableMethod.apply {
+ addInstructionsWithLabels(
+ 0, """
+ invoke-static {}, $INTEGRATIONS_VP9_CODEC_CLASS_DESCRIPTOR->disableVP9Codec()Z
+ move-result v0
+ if-nez v0, :default
+ return v0
+ """, ExternalLabel("default", getInstruction(0))
+ )
+ }
+
+ // endregion
+
/**
* Add settings
*/
diff --git a/src/main/kotlin/app/revanced/patches/youtube/video/playback/fingerprints/VP9CapabilityFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/video/playback/fingerprints/VP9CapabilityFingerprint.kt
new file mode 100644
index 0000000000..e904b93125
--- /dev/null
+++ b/src/main/kotlin/app/revanced/patches/youtube/video/playback/fingerprints/VP9CapabilityFingerprint.kt
@@ -0,0 +1,14 @@
+package app.revanced.patches.youtube.video.playback.fingerprints
+
+import app.revanced.patcher.extensions.or
+import app.revanced.patcher.fingerprint.MethodFingerprint
+import com.android.tools.smali.dexlib2.AccessFlags
+
+internal object VP9CapabilityFingerprint : MethodFingerprint(
+ accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
+ returnType = "Z",
+ strings = listOf(
+ "vp9_supported",
+ "video/x-vnd.on2.vp9"
+ )
+)
diff --git a/src/main/resources/youtube/settings/host/values/strings.xml b/src/main/resources/youtube/settings/host/values/strings.xml
index 3fd2dda6b6..8910eb9ec7 100644
--- a/src/main/resources/youtube/settings/host/values/strings.xml
+++ b/src/main/resources/youtube/settings/host/values/strings.xml
@@ -1295,6 +1295,13 @@ Info:
Spoof device dimensions
"Spoofs the device dimensions to the maximum value.
High quality may be unlocked on some videos that require high device dimensions, but not all videos."
+ Disable VP9 codec
+ "VP9 codec is disabled.
+
+• Maximum resolution is 1080p.
+• Video playback will use more internet data than VP9.
+• To get HDR playback, HDR video still uses the VP9 codec."
+ VP9 codec is enabled.
Replace software AV1 codec
Replaces the software AV1 codec with the VP9 codec.
Reject software AV1 codec response
diff --git a/src/main/resources/youtube/settings/xml/revanced_prefs.xml b/src/main/resources/youtube/settings/xml/revanced_prefs.xml
index 21123c7823..8f4ee65daf 100644
--- a/src/main/resources/youtube/settings/xml/revanced_prefs.xml
+++ b/src/main/resources/youtube/settings/xml/revanced_prefs.xml
@@ -590,7 +590,8 @@
- PREFERENCE_SCREEN: VIDEO -->
+
+ PREFERENCE_SCREEN: VIDEO -->