Skip to content

Commit

Permalink
fix(YouTube): Fix issues related to playback by replace streaming data (
Browse files Browse the repository at this point in the history
ReVanced#680)

Co-authored-by: kitadai31 <[email protected]>
Co-authored-by: LisoUseInAIKyrios <[email protected]>
Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
4 people authored Sep 17, 2024
1 parent ca50665 commit 0468235
Show file tree
Hide file tree
Showing 13 changed files with 615 additions and 777 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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 androidx.annotation.Nullable;

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)",
null,
// 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",
"32", // Android 12.1
"1.56.21"
);

/**
* 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;

/**
* Android SDK version, equivalent to {@link Build.VERSION#SDK} (System property: ro.build.version.sdk)
* Field is null if not applicable.
*/
@Nullable
public final String androidSdkVersion;

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

ClientType(int id, String model, String osVersion, String userAgent, @Nullable String androidSdkVersion, String appVersion) {
this.id = id;
this.model = model;
this.osVersion = osVersion;
this.userAgent = userAgent;
this.androidSdkVersion = androidSdkVersion;
this.appVersion = appVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 {
public static final boolean DEVICE_HAS_HARDWARE_DECODING_VP9;
public static final boolean DEVICE_HAS_HARDWARE_DECODING_AV1;

static {
boolean vp9found = false;
boolean av1found = false;
MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
final boolean deviceIsAndroidTenOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;

for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) {
final boolean isHardwareAccelerated = deviceIsAndroidTenOrLater
? 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")) {
vp9found = true;
} else if (type.equalsIgnoreCase("video/av01")) {
av1found = true;
}
}
}
}

DEVICE_HAS_HARDWARE_DECODING_VP9 = vp9found;
DEVICE_HAS_HARDWARE_DECODING_AV1 = av1found;

Logger.printDebug(() -> DEVICE_HAS_HARDWARE_DECODING_AV1
? "Device supports AV1 hardware decoding\n"
: "Device does not support AV1 hardware decoding\n"
+ (DEVICE_HAS_HARDWARE_DECODING_VP9
? "Device supports VP9 hardware decoding"
: "Device does not support VP9 hardware decoding"));
}

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

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

0 comments on commit 0468235

Please sign in to comment.