-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial caged apps abstraction
In the current version of the application, we have strictly hardcoded the captured runtime application (FFI Libretro frontend) as well as the streaming transport (WebRTC). This commit makes it possible to choose these components at runtime. In this commit, we no longer manage initially connected users separately from the rooms, and instead, we treat all users as abstract app sessions, rather than hardcoded WebRTC connections. These sessions may contain all the transport specifics, such as WebRTC and so on. Rooms, instead of having the hardcoded emulator app and WebRTC media encoders, now have these components decoupled. In theory, it is possible to add new transports (e.g., WebTransport) and streaming apps (e.g., wrapped into an ffmpeg desktop app).
- Loading branch information
1 parent
878d7fe
commit 1969302
Showing
70 changed files
with
2,537 additions
and
2,412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package app | ||
|
||
import "image" | ||
|
||
type App interface { | ||
AudioSampleRate() int | ||
Init() error | ||
ViewportSize() (int, int) | ||
Start() | ||
Close() | ||
|
||
SetAudioCb(func(Audio)) | ||
SetVideoCb(func(Video)) | ||
SendControl(port int, data []byte) | ||
} | ||
|
||
type Audio struct { | ||
Data []int16 | ||
Duration int32 // up to 6y nanosecond-wise | ||
} | ||
|
||
type Video struct { | ||
Frame image.RGBA | ||
Duration int32 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package caged | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
|
||
"github.com/giongto35/cloud-game/v3/pkg/config" | ||
"github.com/giongto35/cloud-game/v3/pkg/logger" | ||
"github.com/giongto35/cloud-game/v3/pkg/worker/caged/app" | ||
"github.com/giongto35/cloud-game/v3/pkg/worker/caged/libretro" | ||
) | ||
|
||
type Manager struct { | ||
list map[ModName]app.App | ||
log *logger.Logger | ||
} | ||
|
||
type ModName string | ||
|
||
const Libretro ModName = "libretro" | ||
|
||
func NewManager(log *logger.Logger) *Manager { | ||
return &Manager{log: log, list: make(map[ModName]app.App)} | ||
} | ||
|
||
func (m *Manager) Get(name ModName) app.App { return m.list[name] } | ||
|
||
func (m *Manager) Load(name ModName, conf any) error { | ||
if name == Libretro { | ||
caged, err := m.loadLibretro(conf) | ||
if err != nil { | ||
return err | ||
} | ||
m.list[name] = caged | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Manager) loadLibretro(conf any) (*libretro.Caged, error) { | ||
s := reflect.ValueOf(conf) | ||
|
||
e := s.FieldByName("Emulator") | ||
if !e.IsValid() { | ||
return nil, errors.New("no emulator conf") | ||
} | ||
r := s.FieldByName("Recording") | ||
if !r.IsValid() { | ||
return nil, errors.New("no recording conf") | ||
} | ||
|
||
c := libretro.CagedConf{ | ||
Emulator: e.Interface().(config.Emulator), | ||
Recording: r.Interface().(config.Recording), | ||
} | ||
|
||
caged := libretro.Cage(c, m.log) | ||
if err := caged.Init(); err != nil { | ||
return nil, err | ||
} | ||
return &caged, nil | ||
} |
Oops, something went wrong.