mirror of https://github.com/jetkvm/kvm.git
feat: stop video stream only if it's active
This commit is contained in:
parent
24ec74a441
commit
dc611870c7
|
|
@ -367,6 +367,10 @@ void jetkvm_video_stop() {
|
|||
video_stop_streaming();
|
||||
}
|
||||
|
||||
uint8_t jetkvm_is_video_streaming() {
|
||||
return video_is_streaming();
|
||||
}
|
||||
|
||||
int jetkvm_video_set_quality_factor(float quality_factor) {
|
||||
if (quality_factor <= 0 || quality_factor > 1) {
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ int jetkvm_video_init(float quality_factor);
|
|||
void jetkvm_video_shutdown();
|
||||
void jetkvm_video_start();
|
||||
void jetkvm_video_stop();
|
||||
uint8_t jetkvm_is_video_streaming();
|
||||
int jetkvm_video_set_quality_factor(float quality_factor);
|
||||
float jetkvm_video_get_quality_factor();
|
||||
int jetkvm_video_set_edid(const char *edid_hex);
|
||||
|
|
|
|||
|
|
@ -727,6 +727,13 @@ void video_stop_streaming()
|
|||
log_info("video streaming stopped");
|
||||
}
|
||||
|
||||
uint8_t video_is_streaming() {
|
||||
// streaming flag can be false when stopping streaming
|
||||
if (get_streaming_flag() == true) return 1;
|
||||
if (streaming_stopped == false) return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void video_restart_streaming()
|
||||
{
|
||||
if (get_streaming_flag() == true)
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@ void video_start_streaming();
|
|||
*/
|
||||
void video_stop_streaming();
|
||||
|
||||
/**
|
||||
* @brief Check if the video streaming is active
|
||||
*
|
||||
* @return uint8_t 1 if the video streaming is active, 2 if the video streaming is stopping, 0 otherwise
|
||||
*/
|
||||
uint8_t video_is_streaming();
|
||||
|
||||
/**
|
||||
* @brief Set the quality factor of the video
|
||||
*
|
||||
|
|
|
|||
|
|
@ -168,6 +168,15 @@ func videoStop() {
|
|||
C.jetkvm_video_stop()
|
||||
}
|
||||
|
||||
func videoIsStreaming() (bool, error) {
|
||||
cgoLock.Lock()
|
||||
defer cgoLock.Unlock()
|
||||
|
||||
isStreaming := C.jetkvm_is_video_streaming()
|
||||
|
||||
return isStreaming == 1, nil
|
||||
}
|
||||
|
||||
func videoLogStatus() string {
|
||||
cgoLock.Lock()
|
||||
defer cgoLock.Unlock()
|
||||
|
|
|
|||
|
|
@ -123,6 +123,11 @@ func videoSetEDID(edid string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func videoIsStreaming() (bool, error) {
|
||||
panicPlatformNotSupported()
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func crash() {
|
||||
panicPlatformNotSupported()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,21 @@ func (n *Native) setSleepMode(enabled bool) error {
|
|||
}
|
||||
|
||||
bEnabled := "0"
|
||||
shouldStopVideo := false
|
||||
if enabled {
|
||||
bEnabled = "1"
|
||||
|
||||
isStreaming, err := n.VideoIsStreaming()
|
||||
if isStreaming || err != nil {
|
||||
shouldStopVideo = true
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
@ -165,3 +175,11 @@ func (n *Native) VideoStart() error {
|
|||
videoStart()
|
||||
return nil
|
||||
}
|
||||
|
||||
// VideoIsStreaming checks if the video stream is active.
|
||||
func (n *Native) VideoIsStreaming() (bool, error) {
|
||||
n.videoLock.Lock()
|
||||
defer n.videoLock.Unlock()
|
||||
|
||||
return videoIsStreaming()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue