fix(YouTube - Video playback): Disable HDR video does not disable Dolby Vision HDR (#5661)

This commit is contained in:
LisoUseInAIKyrios
2025-08-16 15:10:31 -04:00
committed by GitHub
parent d3f63461e7
commit 4aaa7ca895
3 changed files with 34 additions and 40 deletions

View File

@@ -1,5 +1,7 @@
package app.revanced.extension.youtube.patches;
import android.view.Display;
import app.revanced.extension.youtube.settings.Settings;
@SuppressWarnings("unused")
@@ -8,8 +10,10 @@ public class DisableHdrPatch {
/**
* Injection point.
*/
public static boolean disableHDRVideo() {
return !Settings.DISABLE_HDR_VIDEO.get();
public static int[] disableHdrVideo(Display.HdrCapabilities capabilities) {
return Settings.DISABLE_HDR_VIDEO.get()
? new int[0]
: capabilities.getSupportedHdrTypes();
}
}

View File

@@ -1,15 +1,16 @@
package app.revanced.patches.youtube.video.hdr
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.all.misc.resources.addResources
import app.revanced.patches.all.misc.resources.addResourcesPatch
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
@@ -24,6 +25,31 @@ val disableHdrPatch = bytecodePatch(
sharedExtensionPatch,
settingsPatch,
addResourcesPatch,
// Override all calls of `getSupportedHdrTypes`.
transformInstructionsPatch(
filterMap = filterMap@{ classDef, _, instruction, instructionIndex ->
if (classDef.type.startsWith("Lapp/revanced/")) {
return@filterMap null
}
val reference = instruction.getReference<MethodReference>()
if (reference?.definingClass =="Landroid/view/Display\$HdrCapabilities;"
&& reference.name == "getSupportedHdrTypes") {
return@filterMap instruction to instructionIndex
}
return@filterMap null
},
transform = { method, entry ->
val (instruction, index) = entry
val register = (instruction as FiveRegisterInstruction).registerC
method.replaceInstruction(
index,
"invoke-static/range { v$register .. v$register }, $EXTENSION_CLASS_DESCRIPTOR->" +
"disableHdrVideo(Landroid/view/Display\$HdrCapabilities;)[I",
)
}
)
)
compatibleWith(
@@ -43,29 +69,5 @@ val disableHdrPatch = bytecodePatch(
PreferenceScreen.VIDEO.addPreferences(
SwitchPreference("revanced_disable_hdr_video")
)
hdrCapabilityFingerprint.let {
it.originalMethod.apply {
val stringIndex = it.stringMatches!!.first().index
val navigateIndex = indexOfFirstInstructionOrThrow(stringIndex) {
val reference = getReference<MethodReference>()
reference?.parameterTypes == listOf("I", "Landroid/view/Display;") &&
reference.returnType == "Z"
}
// Modify the HDR lookup method (Method is in the same class as the fingerprint).
navigate(this).to(navigateIndex).stop().addInstructionsWithLabels(
0,
"""
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->disableHDRVideo()Z
move-result v0
if-nez v0, :useHdr
return v0
:useHdr
nop
"""
)
}
}
}
}

View File

@@ -1,12 +0,0 @@
package app.revanced.patches.youtube.video.hdr
import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal val hdrCapabilityFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
strings(
"av1_profile_main_10_hdr_10_plus_supported",
"video/av01"
)
}