mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-11 13:46:17 +00:00
feat(YouTube): Add Disable video codecs patch (#5981)
This commit is contained in:
committed by
GitHub
parent
ee4755646b
commit
bfbffbd1f5
@@ -1727,6 +1727,10 @@ public final class app/revanced/patches/youtube/video/audio/ForceOriginalAudioPa
|
||||
public static final fun getForceOriginalAudioPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||
}
|
||||
|
||||
public final class app/revanced/patches/youtube/video/codecs/DisableVideoCodecsPatchKt {
|
||||
public static final fun getDisableVideoCodecsPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||
}
|
||||
|
||||
public final class app/revanced/patches/youtube/video/hdr/DisableHdrPatchKt {
|
||||
public static final fun getDisableHdrPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package app.revanced.patches.youtube.video.codecs
|
||||
|
||||
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 com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
private const val EXTENSION_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/extension/youtube/patches/DisableVideoCodecsPatch;"
|
||||
|
||||
@Suppress("unused")
|
||||
val disableVideoCodecsPatch = bytecodePatch(
|
||||
name = "disable video codecs",
|
||||
description = "Adds options to disable HDR and VP9 codecs.",
|
||||
) {
|
||||
dependsOn(
|
||||
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(
|
||||
"com.google.android.youtube"(
|
||||
"19.34.42",
|
||||
"20.07.39",
|
||||
"20.13.41",
|
||||
"20.14.43",
|
||||
)
|
||||
)
|
||||
|
||||
execute {
|
||||
addResources("youtube", "video.codecs.disableVideoCodecsPatch")
|
||||
|
||||
PreferenceScreen.VIDEO.addPreferences(
|
||||
SwitchPreference("revanced_disable_hdr_video"),
|
||||
SwitchPreference("revanced_force_avc_codec")
|
||||
)
|
||||
|
||||
vp9CapabilityFingerprint.method.addInstructionsWithLabels(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->allowVP9()Z
|
||||
move-result v0
|
||||
if-nez v0, :default
|
||||
return v0
|
||||
:default
|
||||
nop
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.revanced.patches.youtube.video.codecs
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal val vp9CapabilityFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
|
||||
returns("Z")
|
||||
strings(
|
||||
"vp9_supported",
|
||||
"video/x-vnd.on2.vp9"
|
||||
)
|
||||
}
|
||||
@@ -1,71 +1,10 @@
|
||||
package app.revanced.patches.youtube.video.hdr
|
||||
|
||||
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 com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
|
||||
private const val EXTENSION_CLASS_DESCRIPTOR =
|
||||
"Lapp/revanced/extension/youtube/patches/DisableHdrPatch;"
|
||||
import app.revanced.patches.youtube.video.codecs.disableVideoCodecsPatch
|
||||
|
||||
@Deprecated("Patch was renamed", ReplaceWith("disableVideoCodecsPatch"))
|
||||
@Suppress("unused")
|
||||
val disableHdrPatch = bytecodePatch(
|
||||
name = "Disable HDR video",
|
||||
description = "Adds an option to disable video HDR.",
|
||||
) {
|
||||
dependsOn(
|
||||
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(
|
||||
"com.google.android.youtube"(
|
||||
"19.34.42",
|
||||
"20.07.39",
|
||||
"20.13.41",
|
||||
"20.14.43",
|
||||
)
|
||||
)
|
||||
|
||||
execute {
|
||||
addResources("youtube", "video.hdr.disableHdrPatch")
|
||||
|
||||
PreferenceScreen.VIDEO.addPreferences(
|
||||
SwitchPreference("revanced_disable_hdr_video")
|
||||
)
|
||||
}
|
||||
}
|
||||
val disableHdrPatch = bytecodePatch{
|
||||
dependsOn(disableVideoCodecsPatch)
|
||||
}
|
||||
@@ -26,7 +26,6 @@ internal val videoQualityItemOnClickFingerprint = fingerprint {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal val videoQualityMenuOptionsFingerprint = fingerprint {
|
||||
accessFlags(AccessFlags.STATIC)
|
||||
returns("[L")
|
||||
|
||||
@@ -14,12 +14,13 @@ internal val settingsMenuVideoQualityGroup = mutableSetOf<BasePreference>()
|
||||
@Suppress("unused")
|
||||
val videoQualityPatch = bytecodePatch(
|
||||
name = "Video quality",
|
||||
description = "Adds options to use the advanced video quality menu and set default video qualities."
|
||||
description = "Adds options to use the advanced video quality menu, set default video qualities, " +
|
||||
"and disable video codecs such as VP9/HDR."
|
||||
) {
|
||||
dependsOn(
|
||||
rememberVideoQualityPatch,
|
||||
advancedVideoQualityMenuPatch,
|
||||
videoQualityDialogButtonPatch,
|
||||
videoQualityDialogButtonPatch
|
||||
)
|
||||
|
||||
compatibleWith(
|
||||
|
||||
@@ -1641,10 +1641,22 @@ Enabling this can unlock higher video qualities"</string>
|
||||
<string name="revanced_playback_speed_default_title">Default playback speed</string>
|
||||
<string name="revanced_remember_playback_speed_toast">Changed default speed to: %s</string>
|
||||
</patch>
|
||||
<patch id="video.hdr.disableHdrPatch">
|
||||
<patch id="video.codecs.disableVideoCodecsPatch">
|
||||
<string name="revanced_disable_hdr_video_title">Disable HDR video</string>
|
||||
<string name="revanced_disable_hdr_video_summary_on">HDR video is disabled</string>
|
||||
<string name="revanced_disable_hdr_video_summary_off">HDR video is enabled</string>
|
||||
<string name="revanced_force_avc_codec_title">Force AVC (H.264)</string>
|
||||
<string name="revanced_force_avc_codec_summary_on">Video codec is forced to AVC (H.264)</string>
|
||||
<string name="revanced_force_avc_codec_summary_off">Video codec is determined automatically</string>
|
||||
<string name="revanced_force_avc_codec_user_dialog_message">"Benefits:
|
||||
• Can improve battery life.
|
||||
• Can restore missing video resolutions on older device.
|
||||
|
||||
Limitations:
|
||||
• Maximum resolution is 1080p.
|
||||
• Video playback will use more internet data than VP9 or AV1.
|
||||
• HDR videos may not use AVC.
|
||||
• Some devices cannot force AVC."</string>
|
||||
</patch>
|
||||
<patch id="video.quality.advancedVideoQualityMenuPatch">
|
||||
<string name="revanced_advanced_video_quality_menu_title">Show advanced video quality menu</string>
|
||||
|
||||
Reference in New Issue
Block a user