Files
discord-decomp/_bundle/MediaSinkWantsLadder.js
T
2026-11-01 12:12:55 +02:00

162 lines
4.6 KiB
JavaScript

// Metro module 4299 (f4300).
import { VIDEO_QUALITY_FRAMERATE, VIDEO_QUALITY_FRAMERATE_MUTED, VIDEO_QUALITY_FRAMERATE_MUTED_2, defaultVideoQualityOptions } from "./Module4250";
class MediaSinkWantsLadder {
constructor(r4 = defaultVideoQualityOptions) {
const prototype = new.target.prototype;
const videoBudget = r4.videoBudget;
const { width, height } = videoBudget;
if (!(width <= 0) && !(height <= 0)) {
const r11 = {
__proto__: prototype
};
r11.pixelBudget = width * height;
r11.ladder = MediaSinkWantsLadder.calculateLadder(r11.pixelBudget);
r11.orderedLadder = MediaSinkWantsLadder.calculateOrderedLadder(r11.ladder);
return r11;
}
throw new Error("Invalid argument");
}
getMaxSinkValue(a0, r9 = 0) {
if (a0 < 0) {
throw new Error("getMaxSinkValue: Requested " + a0);
}
let wantValue = this.orderedLadder[0].wantValue;
for (const item of this.orderedLadder) {
const { pixelCount, wantValue: wantValue2 } = item;
if (!(r9 > 0 && r9 < pixelCount)) {
if (pixelCount * a0 > this.pixelBudget) {
break;
}
wantValue = wantValue2;
continue;
}
wantValue = wantValue2;
break;
}
return wantValue;
}
getResolution(a0) {
let r2 = null;
for (const item of this.orderedLadder) {
if (a0 >= item.wantValue) {
r2 = item;
continue;
}
break;
}
let r19 = r2;
if (r19 == null) {
r19 = this.orderedLadder[0];
}
return {
width: r19.width,
height: r19.height,
budgetPortion: r19.budgetPortion,
mutedFramerate: r19.mutedFramerate,
framerate: r19.framerate
};
}
static calculateLadder(a0) {
let r34;
const set = new Set([0, 4, 8, 10]);
const r8 = [];
let r38 = 1;
while (true) {
const width = 16 * r38 / 9;
const r40 = set.has(width % 16);
const height = r38;
if (r40 && set.has(height % 16)) {
const pixelCount = width * height;
r8.push({
pixelCount,
width,
height,
budgetPortion: pixelCount / a0,
wantValue: 0
});
}
r38 = height + 1;
if (!(r38 < 4096)) {
const r48 = {};
let r49 = 100;
let r52 = 1;
let r53 = 0;
loop6: while (true) {
let r54 = 0;
let height2 = 0;
let budgetPortion = 0;
let r19 = r8[Symbol.iterator]();
const next = r19.next;
const r59 = r52;
const r20 = r49;
let r60 = r53;
while (true) {
const r61 = r19 === void 0 ? void 0 : (r34 = next.call(r19)).done ? r19 = void 0 : r34.value;
if (r19 !== void 0) {
try {
if (!(r61.pixelCount * r59 > a0)) {
r54 = r61.width;
height2 = r61.height;
budgetPortion = r61.budgetPortion;
continue;
}
} catch (r67) {
if (r19 !== void 0 && typeof r19.return === "function") {
try {
r19.return();
} catch {}
}
throw r67;
}
const r66 = r19;
if (r66 !== void 0 && typeof r66.return === "function") {
r66.return();
}
}
const r68 = r54;
let r69 = r20;
if (r60 !== r68) {
const mutedFramerate = MediaSinkWantsLadder.getMutedFramerate(r20);
const width2 = r54;
r48[r20] = {
width: width2,
height: height2,
budgetPortion,
mutedFramerate,
framerate: VIDEO_QUALITY_FRAMERATE
};
r69 = r20 - 10;
r60 = width2;
}
r52 = r59 + 1;
r49 = r69;
r53 = r60;
if (r52 <= 25) {
continue loop6;
}
return r48;
}
}
}
}
}
static getMutedFramerate(a0) {
return a0 <= 20 ? VIDEO_QUALITY_FRAMERATE_MUTED_2 : VIDEO_QUALITY_FRAMERATE_MUTED;
}
static calculateOrderedLadder(a0) {
const r0 = [];
for (const item of Object.keys(a0).map((item) => Number(item)).sort((a, b) => a - b)) {
if (item !== 0) {
const r9 = a0[item];
r0.push({
pixelCount: r9.width * r9.height,
wantValue: item,
...r9
});
}
}
return r0;
}
}
export { MediaSinkWantsLadder };