From 6ba0896a6ee074203691c9e6502c7a5eb60e0ea8 Mon Sep 17 00:00:00 2001 From: V Date: Mon, 3 Jul 2023 22:12:26 +0200 Subject: [PATCH] Implement Screenshare Quality & fps settings --- src/renderer/components/ScreenSharePicker.tsx | 67 ++++++++++++++++--- src/renderer/components/screenSharePicker.css | 2 - 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/renderer/components/ScreenSharePicker.tsx b/src/renderer/components/ScreenSharePicker.tsx index d9d1e5f..e9dcb42 100644 --- a/src/renderer/components/ScreenSharePicker.tsx +++ b/src/renderer/components/ScreenSharePicker.tsx @@ -6,16 +6,17 @@ import "./screenSharePicker.css"; -import { classes, closeModal, Margins, Modals, openModal, useAwaiter } from "@vencord/types/utils"; -import { findByPropsLazy } from "@vencord/types/webpack"; +import { closeModal, Modals, openModal, useAwaiter } from "@vencord/types/utils"; +import { findStoreLazy } from "@vencord/types/webpack"; import { Button, Card, Forms, Switch, Text, useState } from "@vencord/types/webpack/common"; import type { Dispatch, SetStateAction } from "react"; +import { addPatch } from "renderer/patches/shared"; import { isWindows } from "renderer/utils"; -const StreamResolutions = ["720", "1080", "1440", "Source"] as const; +const StreamResolutions = ["480", "720", "1080", "1440"] as const; const StreamFps = ["15", "30", "60"] as const; -const WarningIconClasses = findByPropsLazy("warning", "error", "container"); +const MediaEngineStore = findStoreLazy("MediaEngineStore"); export type StreamResolution = (typeof StreamResolutions)[number]; export type StreamFps = (typeof StreamFps)[number]; @@ -36,6 +37,37 @@ interface Source { url: string; } +let currentSettings: StreamSettings | null = null; + +addPatch({ + patches: [ + { + find: "this.localWant=", + replacement: { + match: /this.localWant=/, + replace: "$self.patchStreamQuality(this);$&" + } + } + ], + patchStreamQuality(opts: any) { + if (!currentSettings) return; + + const framerate = Number(currentSettings.fps); + const height = Number(currentSettings.resolution); + const width = Math.round(height * (16 / 9)); + + Object.assign(opts.capture, { + framerate, + width, + height, + pixelCount: height * width, + bitrateMin: 500000, + bitrateMax: 8000000, + bitrateTarget: 600000 + }); + } +}); + export function openScreenSharePicker(screens: Source[]) { return new Promise((resolve, reject) => { const key = openModal( @@ -100,12 +132,6 @@ function StreamSettings({ Stream Settings - - - Resolution and Frame Rate aren't implemented for now. Locked to 720p 30fps - - -
Resolution @@ -200,10 +226,31 @@ function ModalComponent({