Skip to content

Commit 36cad15

Browse files
committed
framerate configuration (in progress)
1 parent 532de99 commit 36cad15

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

frontend/src/lib/webrtc/stream/host_stream_hook.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ resolutions.set(fixedResolutions.resolution720p,{width: 1280, height: 720})
3333
resolutions.set(fixedResolutions.resolution480p, {width:854, height: 480})
3434
resolutions.set(fixedResolutions.resolution360p, {width: 640, height:360})
3535

36+
const DEFAULT_MAX_FRAMERATE = 60
37+
const DEFAULT_IDEAL_FRAMERATE = 30
38+
3639
let stream: MediaStream | undefined
3740
let unlistenerStreamingSignal: (() => void) | undefined
3841

39-
async function getDisplayMediaStream(resolution: fixedResolutions = fixedResolutions.resolution720p) {
42+
async function getDisplayMediaStream(resolution: fixedResolutions = fixedResolutions.resolution720p, idealFrameRate = DEFAULT_IDEAL_FRAMERATE, maxFramerate = DEFAULT_MAX_FRAMERATE) {
4043
try {
4144
const mediastream = await navigator.mediaDevices.getDisplayMedia({
4245
video: {
43-
frameRate: { ideal:30, max: 60 },
46+
frameRate: { ideal: idealFrameRate, max: maxFramerate },
4447
...(resolutions.get(resolution) ?? {}),
4548
noiseSuppression: true,
4649
autoGainControl: true,
@@ -73,7 +76,7 @@ export function StopStreaming() {
7376
}
7477
}
7578

76-
export function CreateHostStream(resolution: fixedResolutions = fixedResolutions.resolution720p) {
79+
export function CreateHostStream(resolution: fixedResolutions = fixedResolutions.resolution720p, idealFrameRate = DEFAULT_IDEAL_FRAMERATE, maxFramerate = DEFAULT_MAX_FRAMERATE) {
7780
initStreamingPeerConnection();
7881

7982
if (!peerConnection) {
@@ -135,9 +138,8 @@ export function CreateHostStream(resolution: fixedResolutions = fixedResolutions
135138
if (!offer || offerArrived) return;
136139
await peerConnection.setRemoteDescription(offer);
137140
offerArrived = true
138-
console.log("displaymedia");
139141
// eslint-disable-next-line no-case-declarations
140-
stream = await getDisplayMediaStream(resolution);
142+
stream = await getDisplayMediaStream(resolution, idealFrameRate, maxFramerate);
141143

142144
stream?.getTracks().forEach((track) => {
143145
if (!stream) return
@@ -149,7 +151,7 @@ export function CreateHostStream(resolution: fixedResolutions = fixedResolutions
149151
}
150152
params.encodings.forEach((_, i) => {
151153
params.encodings[i].maxBitrate = 5_000_000
152-
params.encodings[i].maxFramerate = 60
154+
params.encodings[i].maxFramerate = maxFramerate
153155
// params.encodings[i].scaleResolutionDownBy = 1.25
154156
params.encodings[i].priority = "high"
155157
})

frontend/src/routes/mode/host/connection/+page.svelte

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import { ListenForConnectionChanges } from '$lib/webrtc/host_webrtc_hook';
44
import { _ } from 'svelte-i18n'
55
import { streaming } from "$lib/webrtc/stream/stream_signal_hook.svelte";
6+
import { slide } from 'svelte/transition';
67
78
import { onMount } from 'svelte';
9+
import { elasticOut } from 'svelte/easing';
810
911
let selected_resolution = $state(fixedResolutions.resolution720p)
1012
13+
let idealFramerate = $state(25)
14+
1115
function createStream() {
1216
CreateHostStream(selected_resolution);
1317
streaming.value = true;
@@ -18,13 +22,43 @@
1822
});
1923
</script>
2024

21-
<div class:hidden={streaming.value} class="w-full h-full">
22-
<h2>{$_("resolutions")}</h2>
23-
<select class="select select-primary w-full max-w-xs" bind:value={selected_resolution} id="resolution" aria-label="Default select example">
24-
{#each Object.values(fixedResolutions) as resolution}
25-
<option selected={resolution === selected_resolution} value={resolution}>{resolution}</option>
26-
{/each}
27-
</select>
25+
<div class:hidden={streaming.value} class="w-full h-full grid grid-rows-2 grid-cols-1 gap-10">
26+
<div class="w-full h-full">
27+
<h3>{$_("resolutions")}</h3>
28+
<select class="select select-primary w-full max-w-xs mt-6" bind:value={selected_resolution} id="resolution" aria-label="Default select example">
29+
{#each Object.values(fixedResolutions) as resolution}
30+
<option selected={resolution === selected_resolution} value={resolution}>{resolution}p</option>
31+
{/each}
32+
</select>
33+
</div>
34+
<div class="w-full h-full">
35+
<h3 class="">{$_("framerate")}</h3>
36+
<div class="flex flex-row gap-10 h-full w-full mt-6">
37+
<div class="w-full h-full flex flex-col">
38+
<h4>{$_("ideal-framerate")}</h4>
39+
<div class="w-10 h-10 bg-neutral">
40+
{#key idealFramerate}
41+
<p transition:slide={{easing: elasticOut }} class="text-white text-center">
42+
{idealFramerate}
43+
</p>
44+
{/key}
45+
</div>
46+
<input type="range" min="25" max="145" bind:value={idealFramerate} class="range range-lg" step="5" />
47+
48+
</div>
49+
<div class="w-full h-full flex flex-col">
50+
<h4>{$_("max-framerate")}</h4>
51+
<input type="range" min="30" max="150" value="30" class="range range-lg" step="30" />
52+
<div class="flex w-full justify-between px-2 text-xs">
53+
<span>30</span>
54+
<span>60</span>
55+
<span>90</span>
56+
<span>120</span>
57+
<span>150</span>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
2862
</div>
2963

3064
<button onclick={createStream} disabled={streaming.value} class="btn btn-primary">{$_('start-streaming')}</button>

0 commit comments

Comments
 (0)