From 60070e60765dc2d6913dba20d3f72556ec822690 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 24 Jul 2018 01:09:53 +1000 Subject: [PATCH] [client] implement stream paused alert --- client/lg-renderer.h | 2 +- client/main.c | 29 ++++++++++++++++++++++++++-- client/renderers/opengl.c | 40 +++++++++++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/client/lg-renderer.h b/client/lg-renderer.h index 827336a1..1cda88ba 100644 --- a/client/lg-renderer.h +++ b/client/lg-renderer.h @@ -118,7 +118,7 @@ typedef void (* LG_RendererOnResize )(void * opaque, const int width, typedef bool (* LG_RendererOnMouseShape)(void * opaque, const LG_RendererCursor cursor, const int width, const int height, const int pitch, const uint8_t * data); typedef bool (* LG_RendererOnMouseEvent)(void * opaque, const bool visible , const int x, const int y); typedef bool (* LG_RendererOnFrameEvent)(void * opaque, const LG_RendererFormat format, const uint8_t * data); -typedef void (* LG_RendererOnAlert )(void * opaque, const LG_RendererAlert alert, const char * message); +typedef void (* LG_RendererOnAlert )(void * opaque, const LG_RendererAlert alert, const char * message, bool ** closeFlag); typedef bool (* LG_RendererRender )(void * opaque, SDL_Window *window); typedef struct LG_Renderer diff --git a/client/main.c b/client/main.c index 368ec6c7..84ea3c2b 100644 --- a/client/main.c +++ b/client/main.c @@ -540,7 +540,8 @@ int eventFilter(void * userdata, SDL_Event * event) state.lgr->on_alert( state.lgrData, serverMode ? LG_ALERT_SUCCESS : LG_ALERT_WARNING, - serverMode ? "Capture Enabled" : "Capture Disabled" + serverMode ? "Capture Enabled" : "Capture Disabled", + NULL ); if (!serverMode) @@ -970,6 +971,7 @@ int run() break; } + bool *closeAlert = NULL; while(state.running) { SDL_Event event; @@ -982,6 +984,29 @@ int run() break; } } + + if (closeAlert == NULL) + { + if (state.shm->flags & KVMFR_HEADER_FLAG_PAUSED) + { + if (state.lgr && !params.disableAlerts) + state.lgr->on_alert( + state.lgrData, + LG_ALERT_WARNING, + "Stream Paused", + &closeAlert + ); + } + } + else + { + if (!(state.shm->flags & KVMFR_HEADER_FLAG_PAUSED)) + { + *closeAlert = true; + closeAlert = NULL; + } + } + usleep(1000); } @@ -1595,4 +1620,4 @@ int main(int argc, char * argv[]) } return ret; -} +} \ No newline at end of file diff --git a/client/renderers/opengl.c b/client/renderers/opengl.c index a9fdee08..ab55d14f 100644 --- a/client/renderers/opengl.c +++ b/client/renderers/opengl.c @@ -43,6 +43,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #define ALERT_TEXTURE 2 #define TEXTURE_COUNT 3 +#define ALERT_TIMEOUT_FLAG ((uint64_t)-1) + #define FADE_TIME 1000000 struct Options @@ -63,9 +65,13 @@ static struct Options defaultOptions = struct Alert { + bool ready; + bool useCloseFlag; + SDL_Surface *text; float r, g, b, a; uint64_t timeout; + bool closeFlag; }; struct Inst @@ -343,7 +349,7 @@ bool opengl_on_frame_event(void * opaque, const LG_RendererFormat format, const return true; } -void opengl_on_alert(void * opaque, const LG_RendererAlert alert, const char * message) +void opengl_on_alert(void * opaque, const LG_RendererAlert alert, const char * message, bool ** closeFlag) { struct Inst * this = (struct Inst *)opaque; struct Alert * a = malloc(sizeof(struct Alert)); @@ -388,6 +394,12 @@ void opengl_on_alert(void * opaque, const LG_RendererAlert alert, const char * m return; } + if (closeFlag) + { + a->useCloseFlag = true; + *closeFlag = &a->closeFlag; + } + ll_push(this->alerts, a); } @@ -534,7 +546,7 @@ bool opengl_render(void * opaque, SDL_Window * window) struct Alert * alert; while(ll_peek_head(this->alerts, (void **)&alert)) { - if (alert->timeout == 0) + if (!alert->ready) { surface_to_texture(alert->text, this->textures[ALERT_TEXTURE]); @@ -566,16 +578,28 @@ bool opengl_render(void * opaque, SDL_Window * window) glDisable(GL_BLEND); glEndList(); - alert->timeout = microtime() + 2*1000000; + if (!alert->useCloseFlag) + alert->timeout = microtime() + 2*1000000; + alert->ready = true; SDL_FreeSurface(alert->text); - alert->text = NULL; + alert->text = NULL; + alert->ready = true; } - else if (alert->timeout < microtime()) + else { - free(alert); - ll_shift(this->alerts, NULL); - continue; + bool close = false; + if (alert->useCloseFlag) + close = alert->closeFlag; + else if (alert->timeout < microtime()) + close = true; + + if (close) + { + free(alert); + ll_shift(this->alerts, NULL); + continue; + } } glPushMatrix();