mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
feat(YouTube/Video playback): add Replace software AV1 codec
and Reject software AV1 codec response
settings
This commit is contained in:
@ -21,6 +21,9 @@ import app.revanced.patches.youtube.utils.recyclerview.BottomSheetRecyclerViewPa
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.patches.youtube.video.information.VideoInformationPatch
|
||||
import app.revanced.patches.youtube.video.information.VideoInformationPatch.speedSelectionInsertMethod
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.AV1CodecFingerprint
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.ByteBufferArrayFingerprint
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.ByteBufferArrayParentFingerprint
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.DeviceDimensionsModelToStringFingerprint
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.HDRCapabilityFingerprint
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.PlaybackSpeedChangedFromRecyclerViewFingerprint
|
||||
@ -29,6 +32,7 @@ import app.revanced.patches.youtube.video.playback.fingerprints.QualityChangedFr
|
||||
import app.revanced.patches.youtube.video.playback.fingerprints.QualitySetterFingerprint
|
||||
import app.revanced.patches.youtube.video.videoid.VideoIdPatch
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.getStringInstructionIndex
|
||||
import app.revanced.util.getTargetIndex
|
||||
import app.revanced.util.indexOfFirstInstruction
|
||||
import app.revanced.util.patch.BaseBytecodePatch
|
||||
@ -58,6 +62,8 @@ object VideoPlaybackPatch : BaseBytecodePatch(
|
||||
),
|
||||
compatiblePackages = COMPATIBLE_PACKAGE,
|
||||
fingerprints = setOf(
|
||||
AV1CodecFingerprint,
|
||||
ByteBufferArrayParentFingerprint,
|
||||
DeviceDimensionsModelToStringFingerprint,
|
||||
HDRCapabilityFingerprint,
|
||||
PlaybackSpeedChangedFromRecyclerViewFingerprint,
|
||||
@ -72,6 +78,8 @@ object VideoPlaybackPatch : BaseBytecodePatch(
|
||||
"$COMPONENTS_PATH/PlaybackSpeedMenuFilter;"
|
||||
private const val VIDEO_QUALITY_MENU_FILTER_CLASS_DESCRIPTOR =
|
||||
"$COMPONENTS_PATH/VideoQualityMenuFilter;"
|
||||
private const val INTEGRATIONS_AV1_CODEC_CLASS_DESCRIPTOR =
|
||||
"$VIDEO_PATH/AV1CodecPatch;"
|
||||
private const val INTEGRATIONS_CUSTOM_PLAYBACK_SPEED_CLASS_DESCRIPTOR =
|
||||
"$VIDEO_PATH/CustomPlaybackSpeedPatch;"
|
||||
private const val INTEGRATIONS_HDR_VIDEO_CLASS_DESCRIPTOR =
|
||||
@ -256,6 +264,50 @@ object VideoPlaybackPatch : BaseBytecodePatch(
|
||||
|
||||
// endregion
|
||||
|
||||
// region patch for disable AV1 codec
|
||||
|
||||
// replace av1 codec
|
||||
|
||||
AV1CodecFingerprint.result?.let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex = getStringInstructionIndex("video/av01")
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
insertIndex + 1, """
|
||||
invoke-static {v$insertRegister}, $INTEGRATIONS_AV1_CODEC_CLASS_DESCRIPTOR->replaceCodec(Ljava/lang/String;)Ljava/lang/String;
|
||||
move-result-object v$insertRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
SettingsPatch.addPreference(
|
||||
arrayOf(
|
||||
"SETTINGS: REPLACE_AV1_CODEC"
|
||||
)
|
||||
)
|
||||
} // for compatibility with old versions, no exceptions are raised.
|
||||
|
||||
// reject av1 codec response
|
||||
|
||||
ByteBufferArrayParentFingerprint.resultOrThrow().classDef.let { classDef ->
|
||||
ByteBufferArrayFingerprint.also { it.resolve(context, classDef) }.resultOrThrow().let {
|
||||
it.mutableMethod.apply {
|
||||
val insertIndex = it.scanResult.patternScanResult!!.endIndex
|
||||
val insertRegister = getInstruction<OneRegisterInstruction>(insertIndex).registerA
|
||||
|
||||
addInstructions(
|
||||
insertIndex, """
|
||||
invoke-static {v$insertRegister}, $INTEGRATIONS_AV1_CODEC_CLASS_DESCRIPTOR->rejectResponse(I)I
|
||||
move-result v$insertRegister
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
/**
|
||||
* Add settings
|
||||
*/
|
||||
|
@ -0,0 +1,18 @@
|
||||
package app.revanced.patches.youtube.video.playback.fingerprints
|
||||
|
||||
import app.revanced.patcher.extensions.or
|
||||
import app.revanced.patcher.fingerprint.MethodFingerprint
|
||||
import app.revanced.util.containsWideLiteralInstructionIndex
|
||||
import com.android.tools.smali.dexlib2.AccessFlags
|
||||
|
||||
internal object AV1CodecFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
|
||||
returnType = "L",
|
||||
strings = listOf("AtomParsers", "video/av01"),
|
||||
customFingerprint = handler@{ methodDef, _ ->
|
||||
if (methodDef.returnType == "Ljava/util/List;")
|
||||
return@handler false
|
||||
|
||||
methodDef.containsWideLiteralInstructionIndex(1987076931)
|
||||
}
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
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
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
|
||||
internal object ByteBufferArrayFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
|
||||
returnType = "I",
|
||||
parameters = emptyList(),
|
||||
opcodes = listOf(
|
||||
Opcode.SHL_INT_LIT8,
|
||||
Opcode.SHL_INT_LIT8,
|
||||
Opcode.OR_INT_2ADDR,
|
||||
Opcode.SHL_INT_LIT8,
|
||||
Opcode.OR_INT_2ADDR,
|
||||
Opcode.OR_INT_2ADDR,
|
||||
Opcode.RETURN
|
||||
)
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
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 ByteBufferArrayParentFingerprint : MethodFingerprint(
|
||||
accessFlags = AccessFlags.PRIVATE or AccessFlags.FINAL,
|
||||
returnType = "C",
|
||||
parameters = listOf("Ljava/nio/charset/Charset;", "[C")
|
||||
)
|
@ -985,8 +985,6 @@ Limitation: Official headers in search results will be hidden."</string>
|
||||
<string name="revanced_enable_default_playback_speed_shorts_title">Enable shorts default playback speed</string>
|
||||
<string name="revanced_enable_default_playback_speed_shorts_summary_on">Default playback speed applies to Shorts.</string>
|
||||
<string name="revanced_enable_default_playback_speed_shorts_summary_off">Default playback speed does not apply to Shorts.</string>
|
||||
<string name="revanced_spoof_device_dimensions_title">Spoof device dimensions</string>
|
||||
<string name="revanced_spoof_device_dimensions_summary">Spoofs the device dimensions in order to unlock higher video qualities that may not be available on your device.</string>
|
||||
<string name="revanced_skipped_preloaded_buffer">Skipped preloaded buffer.</string>
|
||||
<string name="revanced_skip_preloaded_buffer_title">Skip preloaded buffer</string>
|
||||
<string name="revanced_skip_preloaded_buffer_summary">"Skip preloaded buffer at video start to bypass default video quality enforcement delay.
|
||||
@ -996,6 +994,14 @@ Limitation: Official headers in search results will be hidden."</string>
|
||||
<string name="revanced_skip_preloaded_buffer_toast_title">Show a toast when skipped</string>
|
||||
<string name="revanced_skip_preloaded_buffer_toast_summary_on">Toast is shown.</string>
|
||||
<string name="revanced_skip_preloaded_buffer_toast_summary_off">Toast is not shown.</string>
|
||||
<string name="revanced_spoof_device_dimensions_title">Spoof device dimensions</string>
|
||||
<string name="revanced_spoof_device_dimensions_summary">Spoofs the device dimensions in order to unlock higher video qualities that may not be available on your device.</string>
|
||||
<string name="revanced_replace_av1_codec_title">Replace software AV1 codec</string>
|
||||
<string name="revanced_replace_av1_codec_summary">Replace software AV1 codec with VP9 codec.</string>
|
||||
<string name="revanced_reject_av1_codec_title">Reject software AV1 codec response</string>
|
||||
<string name="revanced_reject_av1_codec_summary">"Forcefully rejects the software AV1 codec response.
|
||||
After about 20 seconds of buffering, switches to different codec."</string>
|
||||
<string name="revanced_reject_av1_codec_toast">Fallback process causes about 20 seconds of buffering.</string>
|
||||
<string name="revanced_remember_playback_speed_toast">Changing default speed to %s.</string>
|
||||
<string name="revanced_remember_video_quality_mobile">Changing default mobile data quality to %s.</string>
|
||||
<string name="revanced_remember_video_quality_none">Failed to set video quality.</string>
|
||||
|
@ -467,9 +467,13 @@
|
||||
<SwitchPreference android:title="@string/revanced_restore_old_video_quality_menu_title" android:key="revanced_restore_old_video_quality_menu" android:defaultValue="true" android:summaryOn="@string/revanced_restore_old_video_quality_menu_summary_on" android:summaryOff="@string/revanced_restore_old_video_quality_menu_summary_off" />
|
||||
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>
|
||||
<SwitchPreference android:title="@string/revanced_enable_default_playback_speed_shorts_title" android:key="revanced_enable_default_playback_speed_shorts" android:defaultValue="false" android:summaryOn="@string/revanced_enable_default_playback_speed_shorts_summary_on" android:summaryOff="@string/revanced_enable_default_playback_speed_shorts_summary_off" />
|
||||
<SwitchPreference android:title="@string/revanced_spoof_device_dimensions_title" android:key="revanced_spoof_device_dimensions" android:defaultValue="false" android:summary="@string/revanced_spoof_device_dimensions_summary" />
|
||||
<SwitchPreference android:title="@string/revanced_skip_preloaded_buffer_title" android:key="revanced_skip_preloaded_buffer" android:defaultValue="false" android:summary="@string/revanced_skip_preloaded_buffer_summary" />
|
||||
<SwitchPreference android:title="@string/revanced_skip_preloaded_buffer_toast_title" android:key="revanced_skip_preloaded_buffer_toast" android:defaultValue="true" android:summaryOn="@string/revanced_skip_preloaded_buffer_toast_summary_on" android:summaryOff="@string/revanced_skip_preloaded_buffer_toast_summary_off" android:dependency="revanced_skip_preloaded_buffer" />
|
||||
<SwitchPreference android:title="@string/revanced_spoof_device_dimensions_title" android:key="revanced_spoof_device_dimensions" android:defaultValue="false" android:summary="@string/revanced_spoof_device_dimensions_summary" />PREFERENCE_SCREEN: VIDEO -->
|
||||
<!-- SETTINGS: REPLACE_AV1_CODEC
|
||||
<SwitchPreference android:title="@string/revanced_replace_av1_codec_title" android:key="revanced_replace_av1_codec" android:defaultValue="false" android:summary="@string/revanced_replace_av1_codec_summary" />SETTINGS: REPLACE_AV1_CODEC -->
|
||||
<!-- PREFERENCE_SCREEN: VIDEO
|
||||
<SwitchPreference android:title="@string/revanced_reject_av1_codec_title" android:key="revanced_reject_av1_codec" android:defaultValue="false" android:summary="@string/revanced_reject_av1_codec_summary" />
|
||||
</PreferenceScreen>PREFERENCE_SCREEN: VIDEO -->
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user