Add YouTube codec check and their settings

This commit is contained in:
wuggy 2026-09-15 14:15:53 -07:00
commit 9230d4f436
6 changed files with 157 additions and 0 deletions

View file

@ -99,6 +99,54 @@ InternalUserscriptsService.prototype = {
}
} catch (e) {}
let contentWin = win.wrappedJSObject || win;
let documentURI = null;
try {
documentURI = win.document.documentURIObject;
} catch (e) {}
// The codec shim is deliberately limited to YouTube. Use the browser's
// decoder probe rather than guessing from the user's graphics settings.
if (documentURI &&
documentURI.host &&
/(^|\.)youtube(?:-nocookie)?\.com$/i.test(documentURI.host)) {
let settings = {
hideUnaccelerated: Services.prefs.getBoolPref(
"browser.video.youtube.hide-unaccelerated", true),
forceH264: Services.prefs.getBoolPref(
"browser.video.youtube.force-h264", false),
disable60fps: Services.prefs.getBoolPref(
"browser.video.youtube.disable-60fps", false),
vp9HardwareAccelerated: false,
};
let loadCodecShim = function (vp9HardwareAccelerated) {
settings.vp9HardwareAccelerated = vp9HardwareAccelerated;
contentWin.__dactyloidaeYouTubeVideoSettings = settings;
try {
Services.scriptloader.loadSubScript(
"chrome://internaluserscripts/content/bundled-scripts/youtube-codec-check.user.js",
contentWin);
} catch (e) {}
};
try {
let utils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
let hardwareSupport = utils.supportsHardwareVP9Decoding;
if (hardwareSupport && typeof hardwareSupport.then === "function") {
hardwareSupport.then(function (result) {
loadCodecShim(/^Yes;/.test(result));
}, function () {
loadCodecShim(false);
});
} else {
loadCodecShim(/^Yes;/.test(hardwareSupport));
}
} catch (e) {
loadCodecShim(false);
}
}
let logPolyfill = function (name, source) {
try {
if (