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

Handle duplicate frames #448

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/knadh/koanf/maps v0.1.1
github.com/knadh/koanf/v2 v2.1.0
github.com/minio/minio-go/v7 v7.0.68
github.com/minio/minio-go/v7 v7.0.69
github.com/pion/ice/v3 v3.0.3
github.com/pion/interceptor v0.1.25
github.com/pion/logging v0.2.2
Expand Down Expand Up @@ -45,8 +45,8 @@ require (
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.14 // indirect
github.com/pion/rtp v1.8.3 // indirect
github.com/pion/sctp v1.8.12 // indirect
github.com/pion/rtp v1.8.4 // indirect
github.com/pion/sctp v1.8.13 // indirect
github.com/pion/sdp/v3 v3.0.8 // indirect
github.com/pion/srtp/v3 v3.0.1 // indirect
github.com/pion/stun/v2 v2.0.0 // indirect
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.68 h1:hTqSIfLlpXaKuNy4baAp4Jjy2sqZEN9hRxD0M4aOfrQ=
github.com/minio/minio-go/v7 v7.0.68/go.mod h1:XAvOPJQ5Xlzk5o3o/ArO2NMbhSGkimC+bpW/ngRKDmQ=
github.com/minio/minio-go/v7 v7.0.69 h1:l8AnsQFyY1xiwa/DaQskY4NXSLA2yrGsW5iD9nRPVS0=
github.com/minio/minio-go/v7 v7.0.69/go.mod h1:XAvOPJQ5Xlzk5o3o/ArO2NMbhSGkimC+bpW/ngRKDmQ=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand Down Expand Up @@ -106,11 +106,13 @@ github.com/pion/rtcp v1.2.13/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9
github.com/pion/rtcp v1.2.14 h1:KCkGV3vJ+4DAJmvP0vaQShsb0xkRfWkO540Gy102KyE=
github.com/pion/rtcp v1.2.14/go.mod h1:sn6qjxvnwyAkkPzPULIbVqSKI5Dv54Rv7VG0kNxh9L4=
github.com/pion/rtp v1.8.2/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.3 h1:VEHxqzSVQxCkKDSHro5/4IUUG1ea+MFdqR2R3xSpNU8=
github.com/pion/rtp v1.8.3/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/rtp v1.8.4 h1:VqNGMNjMDMy9y0d+h+0dfjiWVKUEDQvA963jhJwu200=
github.com/pion/rtp v1.8.4/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
github.com/pion/sctp v1.8.5/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0=
github.com/pion/sctp v1.8.12 h1:2VX50pedElH+is6FI+OKyRTeN5oy4mrk2HjnGa3UCmY=
github.com/pion/sctp v1.8.12/go.mod h1:cMLT45jqw3+jiJCrtHVwfQLnfR0MGZ4rgOJwUOIqLkI=
github.com/pion/sctp v1.8.13 h1:YUJR44pWM2FPUhkl8l+vDyF2EDE3aTWtr3c+LDhCRcQ=
github.com/pion/sctp v1.8.13/go.mod h1:YKSgO/bO/6aOMP9LCie1DuD7m+GamiK2yIiPM6vH+GA=
github.com/pion/sdp/v3 v3.0.8 h1:yd/wkrS0nzXEAb+uwv1TL3SG/gzsTiXHVOtXtD7EKl0=
github.com/pion/sdp/v3 v3.0.8/go.mod h1:B5xmvENq5IXJimIO4zfp6LAe1fD9N+kFv+V/1lOdz8M=
github.com/pion/srtp/v3 v3.0.1 h1:AkIQRIZ+3tAOJMQ7G301xtrD1vekQbNeRO7eY1K8ZHk=
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ emulator:
# Sets a limiter function for some spammy core callbacks.
# 0 - disabled, otherwise -- time in milliseconds for ignoring repeated calls except the last.
debounceMs: 0
# Allow duplicate frames
dup: true
# Libretro cores logging level: DEBUG = 0, INFO, WARN, ERROR, DUMMY = INT_MAX
logLevel: 1
cores:
Expand Down
1 change: 1 addition & 0 deletions pkg/config/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LibretroConfig struct {
List map[string]LibretroCoreConfig
}
DebounceMs int
Dup bool
SaveCompression bool
LogLevel int
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/worker/caged/libretro/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ var (
noData = func([]byte) {}
noVideo = func(app.Video) {}
videoPool sync.Pool
lastFrame *app.Video
)

// NewFrontend implements Emulator interface for a Libretro frontend.
Expand Down Expand Up @@ -156,6 +157,7 @@ func (f *Frontend) LoadCore(emu string) {
conf := f.conf.GetLibretroCoreConfig(emu)
meta := nanoarch.Metadata{
AutoGlContext: conf.AutoGlContext,
FrameDup: f.conf.Libretro.Dup,
Hacks: conf.Hacks,
HasVFR: conf.VFR,
Hid: conf.Hid,
Expand Down Expand Up @@ -190,7 +192,6 @@ func (f *Frontend) handleAudio(audio unsafe.Pointer, samples int) {
}

func (f *Frontend) handleVideo(data []byte, delta int32, fi nanoarch.FrameInfo) {
// !to merge both pools
fr, _ := videoPool.Get().(*app.Video)
if fr == nil {
fr = new(app.Video)
Expand All @@ -200,10 +201,17 @@ func (f *Frontend) handleVideo(data []byte, delta int32, fi nanoarch.FrameInfo)
fr.Frame.H = int(fi.H)
fr.Frame.Stride = int(fi.Stride)
fr.Duration = delta

lastFrame = fr
f.onVideo(*fr)

videoPool.Put(fr)
}

func (f *Frontend) handleDup() {
f.onVideo(*lastFrame)
}

func (f *Frontend) Shutdown() {
f.mu.Lock()
f.nano.Shutdown()
Expand All @@ -224,6 +232,7 @@ func (f *Frontend) linkNano(nano *nanoarch.Nanoarch) {
f.nano.OnDpad = f.input.isDpadTouched
f.nano.OnVideo = f.handleVideo
f.nano.OnAudio = f.handleAudio
f.nano.OnDup = f.handleDup
}

func (f *Frontend) SetVideoChangeCb(fn func()) {
Expand Down
13 changes: 8 additions & 5 deletions pkg/worker/caged/libretro/nanoarch/nanoarch.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Handlers struct {
OnKeyPress func(port uint, key int) int
OnAudio func(ptr unsafe.Pointer, frames int)
OnVideo func(data []byte, delta int32, fi FrameInfo)
OnDup func()
OnSystemAvInfo func()
}

Expand All @@ -88,6 +89,7 @@ type FrameInfo struct {
}

type Metadata struct {
FrameDup bool
LibPath string // the full path to some emulator lib
IsGlAllowed bool
UsesLibCo bool
Expand Down Expand Up @@ -127,6 +129,7 @@ var Nan0 = Nanoarch{
OnKeyPress: func(uint, int) int { return 0 },
OnAudio: func(unsafe.Pointer, int) {},
OnVideo: func([]byte, int32, FrameInfo) {},
OnDup: func() {},
},
}

Expand Down Expand Up @@ -559,9 +562,9 @@ func coreVideoRefresh(data unsafe.Pointer, width, height uint, packed uint) {
}
Nan0.LastFrameTime = t

// some cores can return nothing
// !to add duplicate if can dup
// when the core returns a duplicate frame
if data == nil {
Nan0.Handlers.OnDup()
return
}

Expand Down Expand Up @@ -694,9 +697,9 @@ func coreEnvironment(cmd C.unsigned, data unsafe.Pointer) C.bool {
setRotation((*(*uint)(data) % 4) * 90)
return true
case C.RETRO_ENVIRONMENT_GET_CAN_DUPE:
// !to implement frame dup (nil) some time later
*(*C.bool)(data) = C.bool(false)
return false
dup := C.bool(Nan0.meta.FrameDup)
*(*C.bool)(data) = dup
return dup
case C.RETRO_ENVIRONMENT_GET_USERNAME:
*(**C.char)(data) = Nan0.cUserName
return true
Expand Down