Skip to content

Commit

Permalink
Expose scale factor value
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Mar 2, 2024
1 parent 3568b7a commit 92e5967
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions pkg/api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type (
AppVideoInfo struct {
W int `json:"w"`
H int `json:"h"`
S int `json:"s"`
A float32 `json:"a"`
}
)
1 change: 1 addition & 0 deletions pkg/worker/caged/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type App interface {
AspectEnabled() bool
Init() error
ViewportSize() (int, int)
Scale() float64
Start()
Close()

Expand Down
3 changes: 2 additions & 1 deletion pkg/worker/coordinatorhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h1>Options</h1>
<script src="js/env.js?v=5"></script>
<script src="js/input/input.js?v=3"></script>
<script src="js/gameList.js?v=3"></script>
<script src="js/stream/stream.js?v=5"></script>
<script src="js/stream/stream.js?v=6"></script>
<script src="js/room.js?v=3"></script>
<script src="js/network/ajax.js?v=3"></script>
<script src="js/network/socket.js?v=4"></script>
Expand Down
19 changes: 11 additions & 8 deletions web/js/stream/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 92e5967

Please sign in to comment.