mirror of https://github.com/jetkvm/kvm.git
82 lines
2.0 KiB
Go
82 lines
2.0 KiB
Go
package native
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/Masterminds/semver/v3"
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type Native struct {
|
|
ready chan struct{}
|
|
l *zerolog.Logger
|
|
lD *zerolog.Logger
|
|
systemVersion *semver.Version
|
|
appVersion *semver.Version
|
|
displayRotation uint16
|
|
onVideoStateChange func(state VideoState)
|
|
onVideoFrameReceived func(frame []byte, duration time.Duration)
|
|
onIndevEvent func(event string)
|
|
}
|
|
|
|
type NativeOptions struct {
|
|
SystemVersion *semver.Version
|
|
AppVersion *semver.Version
|
|
DisplayRotation uint16
|
|
OnVideoStateChange func(state VideoState)
|
|
OnVideoFrameReceived func(frame []byte, duration time.Duration)
|
|
OnIndevEvent func(event string)
|
|
}
|
|
|
|
func NewNative(opts NativeOptions) *Native {
|
|
onVideoStateChange := opts.OnVideoStateChange
|
|
if onVideoStateChange == nil {
|
|
onVideoStateChange = func(state VideoState) {
|
|
nativeLogger.Info().Msg("video state changed")
|
|
}
|
|
}
|
|
|
|
onVideoFrameReceived := opts.OnVideoFrameReceived
|
|
if onVideoFrameReceived == nil {
|
|
onVideoFrameReceived = func(frame []byte, duration time.Duration) {
|
|
nativeLogger.Info().Msg("video frame received")
|
|
}
|
|
}
|
|
|
|
onIndevEvent := opts.OnIndevEvent
|
|
if onIndevEvent == nil {
|
|
onIndevEvent = func(event string) {
|
|
nativeLogger.Info().Str("event", event).Msg("indev event")
|
|
}
|
|
}
|
|
|
|
return &Native{
|
|
ready: make(chan struct{}),
|
|
l: nativeLogger,
|
|
lD: displayLogger,
|
|
systemVersion: opts.SystemVersion,
|
|
appVersion: opts.AppVersion,
|
|
displayRotation: opts.DisplayRotation,
|
|
onVideoStateChange: opts.OnVideoStateChange,
|
|
onVideoFrameReceived: opts.OnVideoFrameReceived,
|
|
onIndevEvent: opts.OnIndevEvent,
|
|
}
|
|
}
|
|
|
|
func (n *Native) Start() {
|
|
// set up singleton
|
|
setInstance(n)
|
|
setUpNativeHandlers()
|
|
|
|
// start the native video
|
|
go n.handleLogChan()
|
|
go n.handleVideoStateChan()
|
|
go n.handleVideoFrameChan()
|
|
go n.handleIndevEventChan()
|
|
|
|
n.initUI()
|
|
go n.tickUI()
|
|
|
|
close(n.ready)
|
|
}
|