[obs] Allow the client to auto-recover

Previously, if the client's subscription to the frame buffer became
invalid for any reason, the video feed in OBS would freeze until the
user goes in and changes any of the settings.  This commit allows the
plugin to automatically attempt to recover.
This commit is contained in:
esi 2022-08-08 19:11:33 -04:00 committed by Geoffrey McRae
parent d376dc4b5a
commit 28cba2e2b3
2 changed files with 30 additions and 9 deletions

View File

@ -64,3 +64,4 @@ Matthew McMullin <matthew@mcmullin.one> (matthewjmc)
Leonard Fricke <leonard.fricke98@gmail.com> (Leo1998) Leonard Fricke <leonard.fricke98@gmail.com> (Leo1998)
David Meier <meier_david_91@hotmail.com> (Kenny.ch) David Meier <meier_david_91@hotmail.com> (Kenny.ch)
Daniel Cordero <looking-glass@0xdc.io> (0xdc) Daniel Cordero <looking-glass@0xdc.io> (0xdc)
esi <git@esibun.net> (esibun)

View File

@ -54,7 +54,8 @@ typedef enum
STATE_OPEN, STATE_OPEN,
STATE_STARTING, STATE_STARTING,
STATE_RUNNING, STATE_RUNNING,
STATE_STOPPING STATE_STOPPING,
STATE_RESTARTING
} }
LGState; LGState;
@ -107,6 +108,8 @@ typedef struct
} }
LGPlugin; LGPlugin;
static void * frameThread(void * data);
static void * pointerThread(void * data);
static void lgUpdate(void * data, obs_data_t * settings); static void lgUpdate(void * data, obs_data_t * settings);
static const char * lgGetName(void * unused) static const char * lgGetName(void * unused)
@ -125,6 +128,20 @@ static void * lgCreate(obs_data_t * settings, obs_source_t * context)
return this; return this;
} }
static void createThreads(LGPlugin * this)
{
pthread_create(&this->frameThread, NULL, frameThread, this);
pthread_setname_np(this->frameThread, "LGFrameThread");
pthread_create(&this->pointerThread, NULL, pointerThread, this);
pthread_setname_np(this->pointerThread, "LGPointerThread");
}
static void waitThreads(LGPlugin * this)
{
pthread_join(this->frameThread, NULL);
pthread_join(this->pointerThread, NULL);
}
static void deinit(LGPlugin * this) static void deinit(LGPlugin * this)
{ {
switch(this->state) switch(this->state)
@ -137,9 +154,9 @@ static void deinit(LGPlugin * this)
case STATE_RUNNING: case STATE_RUNNING:
case STATE_STOPPING: case STATE_STOPPING:
case STATE_RESTARTING:
this->state = STATE_STOPPING; this->state = STATE_STOPPING;
pthread_join(this->frameThread , NULL); createThreads(this);
pthread_join(this->pointerThread, NULL);
this->state = STATE_STOPPED; this->state = STATE_STOPPED;
/* fallthrough */ /* fallthrough */
@ -251,7 +268,7 @@ static void * frameThread(void * data)
} }
lgmpClientUnsubscribe(&this->frameQueue); lgmpClientUnsubscribe(&this->frameQueue);
this->state = STATE_STOPPING; this->state = STATE_RESTARTING;
return NULL; return NULL;
} }
@ -375,7 +392,7 @@ static void * pointerThread(void * data)
this->cursorData = NULL; this->cursorData = NULL;
this->cursorSize = 0; this->cursorSize = 0;
this->state = STATE_STOPPING; this->state = STATE_RESTARTING;
return NULL; return NULL;
} }
@ -419,10 +436,7 @@ static void lgUpdate(void * data, obs_data_t * settings)
} }
this->state = STATE_STARTING; this->state = STATE_STARTING;
pthread_create(&this->frameThread, NULL, frameThread, this); createThreads(this);
pthread_setname_np(this->frameThread, "LGFrameThread");
pthread_create(&this->pointerThread, NULL, pointerThread, this);
pthread_setname_np(this->pointerThread, "LGPointerThread");
} }
#if LIBOBS_API_MAJOR_VER >= 27 #if LIBOBS_API_MAJOR_VER >= 27
@ -480,6 +494,12 @@ static void lgVideoTick(void * data, float seconds)
{ {
LGPlugin * this = (LGPlugin *)data; LGPlugin * this = (LGPlugin *)data;
if (this->state == STATE_RESTARTING) {
waitThreads(this);
this->state = STATE_STARTING;
createThreads(this);
}
if (this->state != STATE_RUNNING) if (this->state != STATE_RUNNING)
return; return;