mirror of https://github.com/jetkvm/kvm.git
apply changes based on Copilot suggestions
This commit is contained in:
parent
dc611870c7
commit
ae742e3c8f
|
|
@ -367,8 +367,8 @@ void jetkvm_video_stop() {
|
||||||
video_stop_streaming();
|
video_stop_streaming();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t jetkvm_is_video_streaming() {
|
uint8_t jetkvm_video_get_streaming_status() {
|
||||||
return video_is_streaming();
|
return video_get_streaming_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
int jetkvm_video_set_quality_factor(float quality_factor) {
|
int jetkvm_video_set_quality_factor(float quality_factor) {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ int jetkvm_video_init(float quality_factor);
|
||||||
void jetkvm_video_shutdown();
|
void jetkvm_video_shutdown();
|
||||||
void jetkvm_video_start();
|
void jetkvm_video_start();
|
||||||
void jetkvm_video_stop();
|
void jetkvm_video_stop();
|
||||||
uint8_t jetkvm_is_video_streaming();
|
uint8_t jetkvm_video_get_streaming_status();
|
||||||
int jetkvm_video_set_quality_factor(float quality_factor);
|
int jetkvm_video_set_quality_factor(float quality_factor);
|
||||||
float jetkvm_video_get_quality_factor();
|
float jetkvm_video_get_quality_factor();
|
||||||
int jetkvm_video_set_edid(const char *edid_hex);
|
int jetkvm_video_set_edid(const char *edid_hex);
|
||||||
|
|
|
||||||
|
|
@ -727,9 +727,10 @@ void video_stop_streaming()
|
||||||
log_info("video streaming stopped");
|
log_info("video streaming stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t video_is_streaming() {
|
uint8_t video_get_streaming_status() {
|
||||||
// streaming flag can be false when stopping streaming
|
// streaming flag can be false when stopping streaming
|
||||||
if (get_streaming_flag() == true) return 1;
|
if (get_streaming_flag() == true) return 1;
|
||||||
|
// streaming_stopped isn't protected by a mutex, but we won't care about race conditions here
|
||||||
if (streaming_stopped == false) return 2;
|
if (streaming_stopped == false) return 2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,11 @@ void video_start_streaming();
|
||||||
void video_stop_streaming();
|
void video_stop_streaming();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the video streaming is active
|
* @brief Get the streaming status of the video
|
||||||
*
|
*
|
||||||
* @return uint8_t 1 if the video streaming is active, 2 if the video streaming is stopping, 0 otherwise
|
* @return VideoStreamingStatus 1 if the video streaming is active, 2 if the video streaming is stopping, 0 otherwise
|
||||||
*/
|
*/
|
||||||
uint8_t video_is_streaming();
|
uint8_t video_get_streaming_status();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the quality factor of the video
|
* @brief Set the quality factor of the video
|
||||||
|
|
|
||||||
|
|
@ -168,13 +168,13 @@ func videoStop() {
|
||||||
C.jetkvm_video_stop()
|
C.jetkvm_video_stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func videoIsStreaming() (bool, error) {
|
func videoGetStreamingStatus() VideoStreamingStatus {
|
||||||
cgoLock.Lock()
|
cgoLock.Lock()
|
||||||
defer cgoLock.Unlock()
|
defer cgoLock.Unlock()
|
||||||
|
|
||||||
isStreaming := C.jetkvm_is_video_streaming()
|
isStreaming := C.jetkvm_video_get_streaming_status()
|
||||||
|
|
||||||
return isStreaming == 1, nil
|
return VideoStreamingStatus(isStreaming)
|
||||||
}
|
}
|
||||||
|
|
||||||
func videoLogStatus() string {
|
func videoLogStatus() string {
|
||||||
|
|
|
||||||
|
|
@ -123,9 +123,9 @@ func videoSetEDID(edid string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func videoIsStreaming() (bool, error) {
|
func videoGetStreamingStatus() VideoStreamingStatus {
|
||||||
panicPlatformNotSupported()
|
panicPlatformNotSupported()
|
||||||
return false, nil
|
return VideoStreamingStatusInactive
|
||||||
}
|
}
|
||||||
|
|
||||||
func crash() {
|
func crash() {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,14 @@ type NativeOptions struct {
|
||||||
OnNativeRestart func()
|
OnNativeRestart func()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type VideoStreamingStatus uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
VideoStreamingStatusActive VideoStreamingStatus = 1
|
||||||
|
VideoStreamingStatusStopping VideoStreamingStatus = 2 // video is stopping, but not yet stopped
|
||||||
|
VideoStreamingStatusInactive VideoStreamingStatus = 0
|
||||||
|
)
|
||||||
|
|
||||||
func NewNative(opts NativeOptions) *Native {
|
func NewNative(opts NativeOptions) *Native {
|
||||||
pid := os.Getpid()
|
pid := os.Getpid()
|
||||||
nativeSubLogger := nativeLogger.With().Int("pid", pid).Str("scope", "native").Logger()
|
nativeSubLogger := nativeLogger.With().Int("pid", pid).Str("scope", "native").Logger()
|
||||||
|
|
|
||||||
|
|
@ -27,31 +27,32 @@ func isSleepModeSupported() bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sleepModeWaitTimeout = 3 * time.Second
|
||||||
|
|
||||||
func (n *Native) setSleepMode(enabled bool) error {
|
func (n *Native) setSleepMode(enabled bool) error {
|
||||||
if !n.sleepModeSupported {
|
if !n.sleepModeSupported {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bEnabled := "0"
|
bEnabled := "0"
|
||||||
shouldStopVideo := false
|
|
||||||
if enabled {
|
if enabled {
|
||||||
bEnabled = "1"
|
bEnabled = "1"
|
||||||
|
|
||||||
isStreaming, err := n.VideoIsStreaming()
|
switch n.VideoGetStreamingStatus() {
|
||||||
if isStreaming || err != nil {
|
case VideoStreamingStatusActive:
|
||||||
shouldStopVideo = true
|
n.l.Info().Msg("stopping video stream to enable sleep mode")
|
||||||
|
if err := n.VideoStop(); err != nil {
|
||||||
|
return fmt.Errorf("video stop failed, won't enable sleep mode: %w", err)
|
||||||
|
}
|
||||||
|
// wait a few seconds to ensure the video stream is stopped
|
||||||
|
time.Sleep(sleepModeWaitTimeout)
|
||||||
|
case VideoStreamingStatusStopping:
|
||||||
|
n.l.Info().Msg("video stream is stopping, will enable sleep mode in a few seconds")
|
||||||
|
// wait a few seconds to ensure the video stream is stopped
|
||||||
|
time.Sleep(sleepModeWaitTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if shouldStopVideo {
|
|
||||||
if err := n.VideoStop(); err != nil {
|
|
||||||
return fmt.Errorf("video stop failed, won't enable sleep mode: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait few seconds to ensure the video stream is stopped
|
|
||||||
time.Sleep(3 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(sleepModeFile, []byte(bEnabled), 0644)
|
return os.WriteFile(sleepModeFile, []byte(bEnabled), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,10 +177,10 @@ func (n *Native) VideoStart() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// VideoIsStreaming checks if the video stream is active.
|
// VideoGetStreamingStatus gets the streaming status of the video.
|
||||||
func (n *Native) VideoIsStreaming() (bool, error) {
|
func (n *Native) VideoGetStreamingStatus() VideoStreamingStatus {
|
||||||
n.videoLock.Lock()
|
n.videoLock.Lock()
|
||||||
defer n.videoLock.Unlock()
|
defer n.videoLock.Unlock()
|
||||||
|
|
||||||
return videoIsStreaming()
|
return videoGetStreamingStatus()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue