Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
refactor: Present stream replacement in the settings as an option sim…
Browse files Browse the repository at this point in the history
…ilar to `iOS` and `Android VR`
  • Loading branch information
LisoUseInAIKyrios committed Aug 26, 2024
1 parent 3c07c12 commit 094d608
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package app.revanced.integrations.youtube.patches.spoof;

import static app.revanced.integrations.youtube.patches.spoof.DeviceHardwareSupport.allowAV1;
import static app.revanced.integrations.youtube.patches.spoof.DeviceHardwareSupport.allowVP9;

import android.os.Build;

import app.revanced.integrations.shared.Utils;

public enum ClientType {
// https://dumps.tadiphone.dev/dumps/oculus/eureka
IOS(5,
// iPhone 15 supports AV1 hardware decoding.
// Only use if this Android device also has hardware decoding.
allowAV1()
? "iPhone16,2" // 15 Pro Max
: "iPhone11,4", // XS Max
// iOS 14+ forces VP9.
allowVP9()
? "17.5.1.21F90"
: "13.7.17H35",
allowVP9()
? "com.google.ios.youtube/19.10.7 (iPhone; U; CPU iOS 17_5_1 like Mac OS X)"
: "com.google.ios.youtube/19.10.7 (iPhone; U; CPU iOS 13_7 like Mac OS X)",
// Version number should be a valid iOS release.
// https://www.ipa4fun.com/history/185230
"19.10.7"
),
ANDROID_VR(28,
"Quest 3",
"12",
"com.google.android.apps.youtube.vr.oculus/1.56.21 (Linux; U; Android 12; GB) gzip",
"1.56.21"
),
@Deprecated() // Android spoofing in this context no longer works.
ANDROID(3,
Build.MODEL,
Build.VERSION.RELEASE,
String.format("com.google.android.youtube/%s (Linux; U; Android %s; GB) gzip",
Utils.getAppVersionName(), Build.VERSION.RELEASE),
Utils.getAppVersionName()
);

/**
* YouTube
* <a href="https://github.com/zerodytrash/YouTube-Internal-Clients?tab=readme-ov-file#clients">client type</a>
*/
public final int id;

/**
* Device model, equivalent to {@link Build#MODEL} (System property: ro.product.model)
*/
public final String model;

/**
* Device OS version.
*/
public final String osVersion;

/**
* Player user-agent.
*/
public final String userAgent;

/**
* App version.
*/
public final String appVersion;

ClientType(int id, String model, String osVersion, String userAgent, String appVersion) {
this.id = id;
this.model = model;
this.osVersion = osVersion;
this.userAgent = userAgent;
this.appVersion = appVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package app.revanced.integrations.youtube.patches.spoof;

import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.os.Build;

import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.youtube.settings.Settings;

public class DeviceHardwareSupport {
private static final boolean DEVICE_HAS_HARDWARE_DECODING_VP9 = deviceHasVP9HardwareDecoding();
private static final boolean DEVICE_HAS_HARDWARE_DECODING_AV1 = deviceHasAV1HardwareDecoding();

private static boolean deviceHasVP9HardwareDecoding() {
MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);

for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) {
final boolean isHardwareAccelerated = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
? codecInfo.isHardwareAccelerated()
: !codecInfo.getName().startsWith("OMX.google"); // Software decoder.
if (isHardwareAccelerated && !codecInfo.isEncoder()) {
for (String type : codecInfo.getSupportedTypes()) {
if (type.equalsIgnoreCase("video/x-vnd.on2.vp9")) {
Logger.printDebug(() -> "Device supports VP9 hardware decoding.");
return true;
}
}
}
}

Logger.printDebug(() -> "Device does not support VP9 hardware decoding.");
return false;
}

private static boolean deviceHasAV1HardwareDecoding() {
// It appears all devices with hardware AV1 are also Android 10 or newer.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);

for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) {
if (codecInfo.isHardwareAccelerated() && !codecInfo.isEncoder()) {
for (String type : codecInfo.getSupportedTypes()) {
if (type.equalsIgnoreCase("video/av01")) {
Logger.printDebug(() -> "Device supports AV1 hardware decoding.");
return true;
}
}
}
}
}

Logger.printDebug(() -> "Device does not support AV1 hardware decoding.");
return false;
}

public static boolean allowVP9() {
return DEVICE_HAS_HARDWARE_DECODING_VP9 && !Settings.SPOOF_CLIENT_FORCE_AVC.get();
}

public static boolean allowAV1() {
return allowVP9() && DEVICE_HAS_HARDWARE_DECODING_AV1;
}
}
Loading

0 comments on commit 094d608

Please sign in to comment.