From b2221b114ef605aedc3cc858f2ae65d727d8c979 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 24 May 2022 00:05:22 +1000 Subject: [PATCH] [client] spice: more fixes to video source transition --- client/include/app.h | 5 +++++ client/src/app.c | 39 +++++++++++++++++++++++++++++++++++---- client/src/keybind.c | 17 +---------------- client/src/main.c | 23 +++++++++++------------ client/src/main.h | 2 ++ client/src/render_queue.c | 3 +++ repos/PureSpice | 2 +- 7 files changed, 58 insertions(+), 33 deletions(-) diff --git a/client/include/app.h b/client/include/app.h index 6276aba2..b3fe3cbb 100644 --- a/client/include/app.h +++ b/client/include/app.h @@ -179,6 +179,11 @@ bool app_guestIsOSX(void); bool app_guestIsBSD(void); bool app_guestIsOther(void); +/** + * Enable/disable the LG display + */ +void app_stopVideo(bool stop); + /** * Enable/disable the spice display */ diff --git a/client/src/app.c b/client/src/app.c index e0eadb11..4c2fb890 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -1009,17 +1009,48 @@ bool app_guestIsOther(void) return g_state.guestOS == KVMFR_OS_OTHER; } +void app_stopVideo(bool stop) +{ + if (g_state.stopVideo == stop) + return; + + // do not change the state if the host app is not connected + if (!g_state.lgHostConnected) + return; + + g_state.stopVideo = stop; + + app_alert( + LG_ALERT_INFO, + stop ? "Video Stream Disabled" : "Video Stream Enabled" + ); + + if (stop) + { + core_stopCursorThread(); + core_stopFrameThread(); + } + else + { + core_startCursorThread(); + core_startFrameThread(); + } +} + void app_useSpiceDisplay(bool enable) { - static bool enabled = false; - - if (!g_params.useSpice || enabled == enable) + static bool lastState = false; + if (!g_params.useSpice || lastState == enable) return; if (!purespice_hasChannel(PS_CHANNEL_DISPLAY)) return; - enabled = enable; + // do not allow stopping of the host app is not connected + if (!enable && !g_state.lgHostConnected) + return; + + lastState = enable; if (enable) { purespice_connectChannel(PS_CHANNEL_DISPLAY); diff --git a/client/src/keybind.c b/client/src/keybind.c index 37569bc9..008f1d56 100644 --- a/client/src/keybind.c +++ b/client/src/keybind.c @@ -35,22 +35,7 @@ static void bind_fullscreen(int sc, void * opaque) static void bind_video(int sc, void * opaque) { - g_state.stopVideo = !g_state.stopVideo; - app_alert( - LG_ALERT_INFO, - g_state.stopVideo ? "Video Stream Disabled" : "Video Stream Enabled" - ); - - if (g_state.stopVideo) - { - core_stopCursorThread(); - core_stopFrameThread(); - } - else - { - core_startCursorThread(); - core_startFrameThread(); - } + app_stopVideo(!g_state.stopVideo); } static void bind_rotate(int sc, void * opaque) diff --git a/client/src/main.c b/client/src/main.c index 1e9c3398..2d0b62e0 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -600,9 +600,6 @@ int main_frameThread(void * unused) break; } - // disable the spice display as we have a frame from the LG host - app_useSpiceDisplay(false); - KVMFRFrame * frame = (KVMFRFrame *)msg.mem; // ignore any repeated frames, this happens when a new client connects to @@ -805,6 +802,9 @@ int main_frameThread(void * unused) lgSignalEvent(g_state.frameEvent); lgmpClientMessageDone(queue); + + // switch over to the LG stream + app_useSpiceDisplay(false); } lgmpClientUnsubscribe(&queue); @@ -890,8 +890,7 @@ static void spice_surfaceCreate(unsigned int surfaceId, PSSurfaceFormat format, static void spice_surfaceDestroy(unsigned int surfaceId) { DEBUG_INFO("Destroy spice surface %d", surfaceId); - if (g_state.lgr) - RENDERER(spiceShow, false); + app_useSpiceDisplay(false); } static void spice_drawFill(unsigned int surfaceId, int x, int y, int width, @@ -933,6 +932,7 @@ int spiceThread(void * arg) .display = { .enable = true, + .autoConnect = false, .surfaceCreate = spice_surfaceCreate, .surfaceDestroy = spice_surfaceDestroy, .drawFill = spice_drawFill, @@ -1316,9 +1316,8 @@ static int lg_run(void) if (g_state.cbAvailable) g_state.cbRequestList = ll_new(); - // fallback to the spice display - if (g_params.useSpice && purespice_hasChannel(PS_CHANNEL_DISPLAY)) - purespice_connectChannel(PS_CHANNEL_DISPLAY); + // use the spice display until we get frames from the LG host application + app_useSpiceDisplay(true); LGMP_STATUS status; @@ -1574,7 +1573,10 @@ restart: checkUUID(); if (g_state.state == APP_STATE_RUNNING) + { DEBUG_INFO("Starting session"); + g_state.lgHostConnected = true; + } g_state.kvmfrFeatures = udata->features; @@ -1589,6 +1591,7 @@ restart: { if (!lgmpClientSessionValid(g_state.lgmp)) { + g_state.lgHostConnected = false; DEBUG_INFO("Waiting for the host to restart..."); g_state.state = APP_STATE_RESTART; break; @@ -1604,11 +1607,8 @@ restart: core_stopFrameThread(); core_stopCursorThread(); - g_state.state = APP_STATE_RUNNING; lgInit(); - - RENDERER(onRestart); goto restart; } @@ -1721,7 +1721,6 @@ int main(int argc, char * argv[]) app_registerOverlay(&LGOverlayMsg , NULL); app_registerOverlay(&LGOverlayRecord, NULL); - // early renderer setup for option registration for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i) LG_Renderers[i]->setup(); diff --git a/client/src/main.h b/client/src/main.h index 1bfcd40e..47184ef7 100644 --- a/client/src/main.h +++ b/client/src/main.h @@ -75,6 +75,8 @@ struct AppState bool guestUUIDValid; KVMFROS guestOS; + bool lgHostConnected; + bool stopVideo; bool ignoreInput; bool escapeActive; diff --git a/client/src/render_queue.c b/client/src/render_queue.c index 102f3b76..162e7dde 100644 --- a/client/src/render_queue.c +++ b/client/src/render_queue.c @@ -54,6 +54,9 @@ void renderQueue_clear(void) void renderQueue_spiceConfigure(int width, int height) { + // reconfigurations invalidate the entire queue + renderQueue_clear(); + RenderCommand * cmd = malloc(sizeof(*cmd)); cmd->op = SPICE_OP_CONFIGURE; cmd->configure.width = width; diff --git a/repos/PureSpice b/repos/PureSpice index 44aafd25..1a91bbb7 160000 --- a/repos/PureSpice +++ b/repos/PureSpice @@ -1 +1 @@ -Subproject commit 44aafd252723ecc5117d6c4bb699f035adcc4f1a +Subproject commit 1a91bbb760d5e70d7e7fffad2eb2b1cb1a22f6a1