Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overhaul & improve Linux screenshare #489

Merged
merged 52 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
05df122
added hardware accel flags
Mar 31, 2024
1e57235
removed useless flags
Apr 5, 2024
83b7dd0
removed discord's arbitrary limit to bitrate
Apr 7, 2024
4152338
removed unnecessary flags
Apr 7, 2024
03a1806
fixed patch to not rely on minified variable names
Apr 7, 2024
dcf18ad
hopefully this works im bad at regex
Apr 7, 2024
27321eb
made better
Apr 7, 2024
040a82c
updated files to match vencord upstream
Apr 7, 2024
c571637
fix to allow compile
Apr 7, 2024
f81f3df
fix a stupid issue that i couldnt even see
Apr 7, 2024
2994065
fixed a few issues, removed a bunch of flags, and the side effect is …
Apr 7, 2024
06247ae
merged patches
Apr 7, 2024
060c522
removed another unneeded flag
Apr 7, 2024
2e153c1
NOW i removed the flag
Apr 7, 2024
4fad164
fixed my idiocy
Apr 7, 2024
07c7e22
fixed things who even knows what i did anymore
Apr 8, 2024
f18051e
fixed colors
Apr 8, 2024
ae9b4b5
fixed stream resolution and framerate selection
Apr 8, 2024
d259c57
only enable hardware acceleration if the user enables it in settings
Apr 9, 2024
5833627
Merge branch 'main' into hardware-accel
catgirlcataclysm Apr 9, 2024
80c9b5a
changed wording
Apr 9, 2024
c9229d7
Merge branch 'hardware-accel' of https://github.com/kaitlynkittyy/Ves…
Apr 9, 2024
419bfd0
begin reworking screenshare modal to properly fit all elements
Apr 9, 2024
c9b1c65
updated some stuff and fixed window resizing breaking streams
Apr 9, 2024
5d3cf70
updated patch to reference new discord API
Apr 9, 2024
c49dc03
yeah
Apr 10, 2024
ac3d2cb
Fixed stream starting and viewing
PolisanTheEasyNick Apr 10, 2024
83d4164
Fixed res and fps changing.. one more time
PolisanTheEasyNick Apr 10, 2024
006f4e9
Fixed setting stream settings while changing window
PolisanTheEasyNick Apr 10, 2024
45e4e1b
fixed formatting
Apr 11, 2024
b9b3361
started styling the screenshare picker and added a change window butt…
Apr 11, 2024
c345332
Fixed changing stream quality description
PolisanTheEasyNick Apr 11, 2024
6bb5f8a
major changes to the UI/UX of the screenshare modal
Apr 11, 2024
976c000
Revert "major changes to the UI/UX of the screenshare modal"
Apr 11, 2024
2be6b60
Properly rewrote modal UI/UX (not complete)
Apr 11, 2024
b68e4d1
fixed patch to properly update encoder resolution
Apr 12, 2024
31907d9
added missing fields to constraints
Apr 12, 2024
8f62a2e
add more params for testing
Apr 12, 2024
d0ff619
Revert "add more params for testing"
Apr 12, 2024
a2dcb90
rebase off of latest commit
Apr 14, 2024
4ee431b
Merge branch 'main' into hardware-accel
catgirlcataclysm Apr 14, 2024
60ab3c3
added contenthint picker to new ui
Apr 14, 2024
a582eec
fixed hw accel flags
Apr 14, 2024
f1f1c9a
removed unnecessary logs
Apr 14, 2024
cb8601b
applied resolution bounds to try and constrain it to discord's suppor…
Apr 14, 2024
3fdc55a
Update ScreenSharePicker.tsx
catgirlcataclysm Apr 14, 2024
11f9970
Major screen share refactor
PolisanTheEasyNick Apr 16, 2024
1d5000e
impoved stream quality changing stability
PolisanTheEasyNick Apr 17, 2024
6c52350
removed then() after submit
PolisanTheEasyNick Apr 17, 2024
520b5d0
clean up code
Vendicated Apr 17, 2024
1763bbd
make right column card fill empty space
Vendicated Apr 17, 2024
0cfb1f6
Update screenShareFixes.ts
Vendicated Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ function init() {
const { disableSmoothScroll, hardwareAcceleration } = Settings.store;

if (hardwareAcceleration === false) app.disableHardwareAcceleration();
if (hardwareAcceleration === true) {
app.commandLine.appendSwitch("enable-features", "VaapiVideoDecodeLinuxGL,VaapiVideoEncoder,VaapiVideoDecoder");
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
}
if (disableSmoothScroll) {
app.commandLine.appendSwitch("disable-smooth-scrolling");
}

// work around chrome 66 disabling autoplay by default
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");

// WinRetrieveSuggestionsOnlyOnDemand: Work around electron 13 bug w/ async spellchecking on Windows.
// HardwareMediaKeyHandling,MediaSessionService: Prevent Discord from registering as a media service.
//
Expand Down
160 changes: 133 additions & 27 deletions src/renderer/components/ScreenSharePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface StreamSettings {
fps: StreamFps;
audio: boolean;
audioSource?: string;
contentHint?: string;
workaround?: boolean;
}

Expand All @@ -49,7 +50,7 @@ interface Source {
url: string;
}

let currentSettings: StreamSettings | null = null;
export let currentSettings: StreamSettings | null = null;

addPatch({
patches: [
Expand All @@ -59,6 +60,20 @@ addPatch({
match: /this.localWant=/,
replace: "$self.patchStreamQuality(this);$&"
}
},
{
find: "x-google-max-bitrate",
replacement: [
{
// eslint-disable-next-line no-useless-escape
match: /"x-google-max-bitrate=".concat\(\i\)/,
replace: '"x-google-max-bitrate=".concat("80_000")'
},
{
match: /;level-asymmetry-allowed=1/,
replace: ";b=AS:800000;level-asymmetry-allowed=1"
}
]
}
],
patchStreamQuality(opts: any) {
Expand All @@ -73,6 +88,11 @@ addPatch({
bitrateMax: 8000000,
bitrateTarget: 600000
});
console.log("opts: ", opts);
// Object.assign(opts.encode, {
catgirlcataclysm marked this conversation as resolved.
Show resolved Hide resolved
// framerate,
// pixelCount: height * width
// });
Object.assign(opts.capture, {
framerate,
width,
Expand Down Expand Up @@ -165,17 +185,32 @@ function StreamSettings({
deps: [source.id]
}
);

const notVisible = false;
function setVisible() {
return !notVisible;
}
// the source's name is not properly being displayed
return (
<div>
<Forms.FormTitle>What you're streaming</Forms.FormTitle>
<Card className="vcd-screen-picker-card vcd-screen-picker-preview">
<img src={thumb} alt="" />
<Switch
onChange={setVisible}
value={notVisible ?? false}
className="vcd-screen-picker-audio vcd-screen-picker-preview-switch"
>
Show Preview
</Switch>
<Card
className={
notVisible
? "vcd-screen-picker-card vcd-screen-picker-preview not-visible"
: "vcd-screen-picker-card vcd-screen-picker-preview"
}
>
<img src={thumb} alt="stream preview" />
<Text variant="text-sm/normal">{source.name}</Text>
</Card>

<Forms.FormTitle>Stream Settings</Forms.FormTitle>

<Card className="vcd-screen-picker-card">
<div className="vcd-screen-picker-quality">
<section>
Expand Down Expand Up @@ -214,7 +249,39 @@ function StreamSettings({
</div>
</section>
</div>

<section>
<Forms.FormTitle>Content Type</Forms.FormTitle>
<div>
<div className="vcd-screen-picker-radios">
<label className="vcd-screen-picker-radio" data-checked={settings.contentHint === "motion"}>
<Text variant="text-sm/bold">Prefer Smoothness</Text>
<input
type="radio"
name="contenthint"
value="motion"
checked={settings.contentHint === "motion"}
onChange={() => setSettings(s => ({ ...s, contentHint: "motion" }))}
/>
</label>
<label className="vcd-screen-picker-radio" data-checked={settings.contentHint === "detail"}>
<Text variant="text-sm/bold">Prefer Clarity</Text>
<input
type="radio"
name="contenthint"
value="detail"
checked={settings.contentHint === "detail"}
onChange={() => setSettings(s => ({ ...s, contentHint: "detail" }))}
/>
</label>
</div>
<div className="vcd-screen-picker-hint-description">
<p>
Choosing "Prefer Clarity" will result in a significantly lower framerate in exchange for
a much sharper and clearer image.
</p>
</div>
</div>
</section>
{isWindows && (
<Switch
value={settings.audio}
Expand Down Expand Up @@ -319,6 +386,7 @@ function ModalComponent({
const [settings, setSettings] = useState<StreamSettings>({
resolution: "1080",
fps: "60",
contentHint: "motion",
audio: true
});

Expand Down Expand Up @@ -347,29 +415,67 @@ function ModalComponent({
disabled={!selected}
onClick={() => {
currentSettings = settings;

// If there are 2 connections, the second one is the existing stream.
// In that case, we patch its quality
const conn = [...MediaEngineStore.getMediaEngine().connections][1];
if (conn && conn.videoStreamParameters.length > 0) {
const height = Number(settings.resolution);
const width = Math.round(height * (16 / 9));
Object.assign(conn.videoStreamParameters[0], {
maxFrameRate: Number(settings.fps),
maxPixelCount: width * height,
maxBitrate: 8000000,
maxResolution: {
type: "fixed",
width,
height
}
});
try {
var conn = [...MediaEngineStore.getMediaEngine().connections].find(
connection => connection.streamUserId === UserStore.getCurrentUser().id
);
} catch {
console.log("No current stream.");
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
}
console.log([...MediaEngineStore.getMediaEngine().connections]);
try {
if (conn) {
catgirlcataclysm marked this conversation as resolved.
Show resolved Hide resolved
console.log(conn);
const track = conn.input.stream.getVideoTracks()[0];
console.log(track);
const frameRate = Number(settings.fps);
const height = Number(settings.resolution);
const width = Math.round(height * (16 / 9));
var constraints = track.getConstraints();
const newConstraints = {
...constraints,
frameRate,
advanced: [{ width: width, height: height }],
resizeMode: "none"
};
track.applyConstraints(newConstraints).then(() => {
console.log("Applied constraints from ScreenSharePicker successfully.");
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
console.log("New constraints:", track.getConstraints());
});
}
} catch {
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
console.log("No current stream.");
}
try {
if(!conn) {
submit({
id: selected!,
...settings
});
} else {
console.log(conn);
const track = conn.input.stream.getVideoTracks()[0];
console.log(track);
const frameRate = Number(settings.fps);
const height = Number(settings.resolution);
const width = Math.round(height * (16 / 9));
var constraints = track.getConstraints();
const newConstraints = {
...constraints,
frameRate,
advanced: [{ width: width, height: height }],
resizeMode: "none"
};
track.applyConstraints(newConstraints).then(() => {
console.log("Applied constraints from ScreenSharePicker successfully.");
console.log("New constraints:", track.getConstraints());
});
}
} catch {
console.log("Unable to start stream.");
}

submit({
id: selected!,
...settings
});

close();
}}
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/components/screenSharePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,18 @@
.vcd-screen-picker-audio {
margin-bottom: 0;
}

.vcd-screen-picker-hint-description {
font-size: 14px;
color: var(--text-normal);
width: 100%;
font-weight: 400;
}

.vcd-screen-picker-preview-switch {
margin-top: 1em;
}

.not-visible {
display: none;
}
2 changes: 1 addition & 1 deletion src/renderer/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
// TODO: Possibly auto generate glob if we have more patches in the future
import "./enableNotificationsByDefault";
import "./platformClass";
import "./screenShareAudio";
import "./screenShareFixes";
import "./spellCheck";
import "./windowsTitleBar";
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { currentSettings } from "renderer/components/ScreenSharePicker";
import { isLinux } from "renderer/utils";

if (isLinux) {
Expand All @@ -23,6 +24,25 @@ if (isLinux) {
const stream = await original.call(this, opts);
const id = await getVirtmic();

const frameRate = Number(currentSettings?.fps);
const height = Number(currentSettings?.resolution);
const width = Math.round(height * (16 / 9));
var track = stream.getVideoTracks()[0];

track.contentHint = String(currentSettings?.contentHint);
var constraints = track.getConstraints();
const newConstraints = {
...constraints,
frameRate,
advanced: [{ width: width, height: height }],
resizeMode: "none"
};

track.applyConstraints(newConstraints).then(() => {
console.log("Applied constraints from ScreenShareFixes successfully.");
console.log("New constraints:", track.getConstraints());
Vendicated marked this conversation as resolved.
Show resolved Hide resolved
});

if (id) {
const audio = await navigator.mediaDevices.getUserMedia({
audio: {
Expand Down