From 92e59672f9f117a58e38b357510b2fa903be71d4 Mon Sep 17 00:00:00 2001 From: Sergey Stepanov Date: Sat, 2 Mar 2024 16:38:53 +0300 Subject: [PATCH] Expose scale factor value --- pkg/api/worker.go | 1 + pkg/worker/caged/app/app.go | 1 + pkg/worker/coordinatorhandlers.go | 3 ++- web/index.html | 2 +- web/js/stream/stream.js | 19 +++++++++++-------- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/api/worker.go b/pkg/api/worker.go index 045fa429..2b2fc4dd 100644 --- a/pkg/api/worker.go +++ b/pkg/api/worker.go @@ -64,6 +64,7 @@ type ( AppVideoInfo struct { W int `json:"w"` H int `json:"h"` + S int `json:"s"` A float32 `json:"a"` } ) diff --git a/pkg/worker/caged/app/app.go b/pkg/worker/caged/app/app.go index fcf34fd9..2fd0704b 100644 --- a/pkg/worker/caged/app/app.go +++ b/pkg/worker/caged/app/app.go @@ -6,6 +6,7 @@ type App interface { AspectEnabled() bool Init() error ViewportSize() (int, int) + Scale() float64 Start() Close() diff --git a/pkg/worker/coordinatorhandlers.go b/pkg/worker/coordinatorhandlers.go index d5d9dd8e..336af811 100644 --- a/pkg/worker/coordinatorhandlers.go +++ b/pkg/worker/coordinatorhandlers.go @@ -130,6 +130,7 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke W: m.VideoW, H: m.VideoH, A: app.AspectRatio(), + S: int(app.Scale()), }}) if err != nil { c.log.Error().Err(err).Msgf("wrap") @@ -176,7 +177,7 @@ func (c *coordinator) HandleGameStart(rq api.StartGameRequest[com.Uid], w *Worke response := api.StartGameResponse{Room: api.Room{Rid: r.Id()}, Record: w.conf.Recording.Enabled} if r.App().AspectEnabled() { ww, hh := r.App().ViewportSize() - response.AV = &api.AppVideoInfo{W: ww, H: hh, A: r.App().AspectRatio()} + response.AV = &api.AppVideoInfo{W: ww, H: hh, A: r.App().AspectRatio(), S: int(r.App().Scale())} } return api.Out{Payload: response} diff --git a/web/index.html b/web/index.html index a760c3fc..87cdfe68 100644 --- a/web/index.html +++ b/web/index.html @@ -127,7 +127,7 @@ - + diff --git a/web/js/stream/stream.js b/web/js/stream/stream.js index e1a0ef4b..1ec88d8e 100644 --- a/web/js/stream/stream.js +++ b/web/js/stream/stream.js @@ -175,19 +175,22 @@ const stream = (() => { const fit = 'contain' event.sub(APP_VIDEO_CHANGED, (payload) => { - const {w, h, a} = payload + const {w, h, a, s} = payload + + const scale = !s ? 1 : s; + const ww = w * scale; + const hh = h * scale; state.aspect = a - const a2 = w / h + const a2 = ww / hh state.screen.style['object-fit'] = a.toFixed(6) !== a2.toFixed(6) ? 'fill' : fit - state.h = payload.h - state.w = Math.floor(payload.h * payload.a) - // payload.a > 0 && (state.aspect = payload.a) - state.screen.setAttribute('width', payload.w) - state.screen.setAttribute('height', payload.h) - state.screen.style.aspectRatio = state.aspect + state.h = hh + state.w = Math.floor(hh * a) + state.screen.setAttribute('width', '' + ww) + state.screen.setAttribute('height', '' + hh) + state.screen.style.aspectRatio = '' + state.aspect }) return {