mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 15:11:31 +00:00
[client] transport: make video waits cancellable
This commit is contained in:
@@ -1187,14 +1187,14 @@ bool app_guestIsOther(void)
|
||||
|
||||
void app_stopVideo(bool stop)
|
||||
{
|
||||
if (g_state.stopVideo == stop)
|
||||
if (atomic_load_explicit(&g_state.stopVideo, memory_order_acquire) == stop)
|
||||
return;
|
||||
|
||||
// do not change the state if the host app is not connected
|
||||
if (!atomic_load_explicit(&g_state.lgHostConnected, memory_order_acquire))
|
||||
return;
|
||||
|
||||
g_state.stopVideo = stop;
|
||||
atomic_store_explicit(&g_state.stopVideo, stop, memory_order_release);
|
||||
|
||||
app_alert(
|
||||
LG_ALERT_INFO,
|
||||
@@ -1204,10 +1204,7 @@ void app_stopVideo(bool stop)
|
||||
if (stop)
|
||||
{
|
||||
if (g_state.videoOps->type == LG_VIDEO_TYPE_FRAME)
|
||||
{
|
||||
core_stopCursorThread();
|
||||
core_stopFrameThread();
|
||||
}
|
||||
core_stopVideoThreads();
|
||||
else
|
||||
g_state.videoOps->swSurface->setActive(
|
||||
g_state.transport.handle, false);
|
||||
@@ -1216,8 +1213,12 @@ void app_stopVideo(bool stop)
|
||||
{
|
||||
if (g_state.videoOps->type == LG_VIDEO_TYPE_FRAME)
|
||||
{
|
||||
core_startCursorThread();
|
||||
core_startFrameThread();
|
||||
if (!core_startVideoThreads())
|
||||
{
|
||||
atomic_store_explicit(
|
||||
&g_state.stopVideo, true, memory_order_release);
|
||||
app_alert(LG_ALERT_ERROR, "Failed to enable the video stream");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -621,54 +621,59 @@ bool core_isValidPointerPos(int x, int y)
|
||||
return g_state.ds->isValidPointerPos(x, y);
|
||||
}
|
||||
|
||||
bool core_startCursorThread(void)
|
||||
static void cancelVideoWaits(void)
|
||||
{
|
||||
if (g_state.cursorThread)
|
||||
return true;
|
||||
if (!g_state.videoOps || g_state.videoOps->type != LG_VIDEO_TYPE_FRAME)
|
||||
return;
|
||||
|
||||
g_state.stopVideo = false;
|
||||
const LG_FrameOps * ops = g_state.videoOps->frame;
|
||||
if (g_state.frameThread && ops->cancelFrameWait)
|
||||
ops->cancelFrameWait(g_state.transport.handle);
|
||||
if (g_state.cursorThread && ops->cancelPointerWait)
|
||||
ops->cancelPointerWait(g_state.transport.handle);
|
||||
}
|
||||
|
||||
void core_stopVideoThreads(void)
|
||||
{
|
||||
atomic_store_explicit(
|
||||
&g_state.stopVideoThreads, true, memory_order_release);
|
||||
cancelVideoWaits();
|
||||
|
||||
if (g_state.frameThread)
|
||||
lgJoinThread(g_state.frameThread, NULL);
|
||||
if (g_state.cursorThread)
|
||||
lgJoinThread(g_state.cursorThread, NULL);
|
||||
|
||||
g_state.frameThread = NULL;
|
||||
g_state.cursorThread = NULL;
|
||||
}
|
||||
|
||||
bool core_startVideoThreads(void)
|
||||
{
|
||||
if (g_state.frameThread && g_state.cursorThread)
|
||||
return true;
|
||||
if (g_state.frameThread || g_state.cursorThread)
|
||||
core_stopVideoThreads();
|
||||
|
||||
atomic_store_explicit(
|
||||
&g_state.stopVideoThreads, false, memory_order_release);
|
||||
if (!lgCreateThread("cursorThread", main_cursorThread, NULL,
|
||||
&g_state.cursorThread))
|
||||
{
|
||||
DEBUG_ERROR("cursor create thread failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void core_stopCursorThread(void)
|
||||
{
|
||||
g_state.stopVideo = true;
|
||||
if (g_state.cursorThread)
|
||||
lgJoinThread(g_state.cursorThread, NULL);
|
||||
|
||||
g_state.cursorThread = NULL;
|
||||
}
|
||||
|
||||
bool core_startFrameThread(void)
|
||||
{
|
||||
if (g_state.frameThread)
|
||||
return true;
|
||||
|
||||
g_state.stopVideo = false;
|
||||
if (!lgCreateThread("frameThread", main_frameThread, NULL,
|
||||
&g_state.frameThread))
|
||||
{
|
||||
DEBUG_ERROR("frame create thread failed");
|
||||
core_stopVideoThreads();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void core_stopFrameThread(void)
|
||||
{
|
||||
g_state.stopVideo = true;
|
||||
if (g_state.frameThread)
|
||||
lgJoinThread(g_state.frameThread, NULL);
|
||||
|
||||
g_state.frameThread = NULL;
|
||||
}
|
||||
|
||||
void core_handleGuestMouseUpdate(void)
|
||||
{
|
||||
/* The local cursor is authoritative with absolute input. Sending delayed
|
||||
@@ -932,7 +937,7 @@ void core_handleMouseNormal(double ex, double ey)
|
||||
struct DoublePoint guest;
|
||||
util_localCurToGuest(&guest);
|
||||
|
||||
if (!g_state.stopVideo &&
|
||||
if (!atomic_load_explicit(&g_state.stopVideo, memory_order_acquire) &&
|
||||
g_state.transportFeatures & LG_TRANSPORT_FEATURE_SET_CURSOR_POS)
|
||||
{
|
||||
const LG_TransportControl control = {
|
||||
|
||||
@@ -34,10 +34,8 @@ void core_onWindowSizeChanged(unsigned width, unsigned height);
|
||||
void core_updatePositionInfo(void);
|
||||
void core_alignToGuest(void);
|
||||
bool core_isValidPointerPos(int x, int y);
|
||||
bool core_startCursorThread(void);
|
||||
void core_stopCursorThread(void);
|
||||
bool core_startFrameThread(void);
|
||||
void core_stopFrameThread(void);
|
||||
bool core_startVideoThreads(void);
|
||||
void core_stopVideoThreads(void);
|
||||
void core_handleGuestMouseUpdate(void);
|
||||
void core_handleMouseAbsolute(void);
|
||||
void core_handleMousePosition(double x, double y);
|
||||
|
||||
@@ -37,7 +37,8 @@ static void bind_fullscreen(int sc, void * opaque)
|
||||
|
||||
static void bind_video(int sc, void * opaque)
|
||||
{
|
||||
app_stopVideo(!g_state.stopVideo);
|
||||
app_stopVideo(!atomic_load_explicit(
|
||||
&g_state.stopVideo, memory_order_acquire));
|
||||
}
|
||||
|
||||
static void bind_rotate(int sc, void * opaque)
|
||||
|
||||
@@ -1101,8 +1101,7 @@ static int renderThread(void * unused)
|
||||
lgClipboard_dropTransport();
|
||||
}
|
||||
|
||||
core_stopCursorThread();
|
||||
core_stopFrameThread();
|
||||
core_stopVideoThreads();
|
||||
|
||||
if (g_state.videoOps && g_state.videoOps->type == LG_VIDEO_TYPE_FRAME &&
|
||||
g_state.videoOps->frame->detachRenderer)
|
||||
@@ -1135,7 +1134,9 @@ int main_cursorThread(void * unused)
|
||||
lgWaitEvent(e_startup, TIMEOUT_INFINITE);
|
||||
|
||||
// subscribe to the pointer queue
|
||||
while(app_getState() == APP_STATE_RUNNING && !g_state.stopVideo)
|
||||
while(app_getState() == APP_STATE_RUNNING &&
|
||||
!atomic_load_explicit(
|
||||
&g_state.stopVideoThreads, memory_order_acquire))
|
||||
{
|
||||
LG_TransportPointer pointer;
|
||||
const LG_TransportStatus status = g_state.videoOps->frame->nextPointer(
|
||||
@@ -1144,7 +1145,9 @@ int main_cursorThread(void * unused)
|
||||
{
|
||||
if (status == LG_TRANSPORT_TIMEOUT || status == LG_TRANSPORT_UNAVAILABLE)
|
||||
{
|
||||
if (!g_state.stopVideo && queueCursorRedraw())
|
||||
if (!atomic_load_explicit(
|
||||
&g_state.stopVideoThreads, memory_order_acquire) &&
|
||||
queueCursorRedraw())
|
||||
cursorRepaintRequest();
|
||||
continue;
|
||||
}
|
||||
@@ -1288,7 +1291,8 @@ int main_cursorThread(void * unused)
|
||||
const bool contentChanged =
|
||||
(pointer.flags & (LG_TRANSPORT_POINTER_SHAPE |
|
||||
LG_TRANSPORT_POINTER_COLOR_TRANSFORM)) || whiteLevelChanged;
|
||||
if (sourceApplied && !g_state.stopVideo &&
|
||||
if (sourceApplied &&
|
||||
!atomic_load_explicit(&g_state.stopVideo, memory_order_acquire) &&
|
||||
(wasRendered != isRendered ||
|
||||
((wasRendered || isRendered) &&
|
||||
(g_params.mouseRedraw || contentChanged))))
|
||||
@@ -1324,7 +1328,9 @@ int main_frameThread(void * unused)
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(app_getState() == APP_STATE_RUNNING && !g_state.stopVideo)
|
||||
while(app_getState() == APP_STATE_RUNNING &&
|
||||
!atomic_load_explicit(
|
||||
&g_state.stopVideoThreads, memory_order_acquire))
|
||||
{
|
||||
LG_TransportFrame frame;
|
||||
const LG_TransportStatus status = g_state.videoOps->frame->nextFrame(
|
||||
@@ -3485,7 +3491,8 @@ restart:
|
||||
if (g_state.videoOps->type == LG_VIDEO_TYPE_FRAME)
|
||||
{
|
||||
videoSourceBegin(LG_VIDEO_SOURCE_PRIMARY);
|
||||
if (!core_startCursorThread() || !core_startFrameThread())
|
||||
if (!atomic_load_explicit(&g_state.stopVideo, memory_order_acquire) &&
|
||||
!core_startVideoThreads())
|
||||
return recoveryExit(&recoveryPrompt, -1);
|
||||
}
|
||||
else
|
||||
@@ -3529,10 +3536,7 @@ restart:
|
||||
lgSignalEvent(g_state.frameEvent);
|
||||
|
||||
if (g_state.videoOps->type == LG_VIDEO_TYPE_FRAME)
|
||||
{
|
||||
core_stopFrameThread();
|
||||
core_stopCursorThread();
|
||||
}
|
||||
core_stopVideoThreads();
|
||||
else
|
||||
g_state.videoOps->swSurface->setActive(
|
||||
g_state.transport.handle, false);
|
||||
|
||||
@@ -114,7 +114,8 @@ struct AppState
|
||||
|
||||
atomic_bool lgHostConnected;
|
||||
|
||||
bool stopVideo;
|
||||
atomic_bool stopVideo;
|
||||
atomic_bool stopVideoThreads;
|
||||
bool ignoreInput;
|
||||
bool escapeActive;
|
||||
uint64_t escapeTime;
|
||||
|
||||
Reference in New Issue
Block a user