mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[c-host] app: reinit on failure to capture a frame
A failed to capture a frame should not be considered fatal as it may be due to a driver issue or bug, instead try to reinitialize first
This commit is contained in:
parent
f79a1b2533
commit
6e35033f2e
57
c-host/app.c
57
c-host/app.c
@ -48,6 +48,7 @@ struct app
|
|||||||
unsigned int frameOffset[MAX_FRAMES];
|
unsigned int frameOffset[MAX_FRAMES];
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
|
bool reinit;
|
||||||
osEventHandle * updateEvent;
|
osEventHandle * updateEvent;
|
||||||
osThreadHandle * pointerThread;
|
osThreadHandle * pointerThread;
|
||||||
osEventHandle * pointerEvent;
|
osEventHandle * pointerEvent;
|
||||||
@ -94,12 +95,19 @@ static int frameThread(void * opaque)
|
|||||||
CaptureFrame frame;
|
CaptureFrame frame;
|
||||||
frame.data = app.frame[frameIndex];
|
frame.data = app.frame[frameIndex];
|
||||||
if (!app.iface->getFrame(&frame))
|
if (!app.iface->getFrame(&frame))
|
||||||
|
{
|
||||||
DEBUG_ERROR("Failed to get the frame");
|
DEBUG_ERROR("Failed to get the frame");
|
||||||
|
app.reinit = true;
|
||||||
|
os_signalEvent(app.updateEvent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
os_signalEvent(app.updateEvent);
|
os_signalEvent(app.updateEvent);
|
||||||
|
|
||||||
// wait for the client to finish with the previous frame
|
// wait for the client to finish with the previous frame
|
||||||
while(fi->flags & KVMFR_FRAME_FLAG_UPDATE)
|
while(fi->flags & KVMFR_FRAME_FLAG_UPDATE)
|
||||||
{
|
{
|
||||||
|
DEBUG_WARN("Waiting for the client");
|
||||||
// this generally never happens
|
// this generally never happens
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
@ -185,10 +193,31 @@ static bool captureStart()
|
|||||||
}
|
}
|
||||||
DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize);
|
DEBUG_INFO("Capture Size : %u MiB (%u)", maxFrameSize / 1048576, maxFrameSize);
|
||||||
|
|
||||||
|
// start signalled
|
||||||
|
os_signalEvent(app.updateEvent);
|
||||||
|
|
||||||
DEBUG_INFO("==== [ Capture Start ] ====");
|
DEBUG_INFO("==== [ Capture Start ] ====");
|
||||||
return startThreads();
|
return startThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool captureRestart()
|
||||||
|
{
|
||||||
|
DEBUG_INFO("==== [ Capture Restart ] ====");
|
||||||
|
if (!stopThreads())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!app.iface->deinit() || !app.iface->init())
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to reinitialize the capture device");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!captureStart())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int app_main()
|
int app_main()
|
||||||
{
|
{
|
||||||
unsigned int shmemSize = os_shmemSize();
|
unsigned int shmemSize = os_shmemSize();
|
||||||
@ -300,6 +329,13 @@ int app_main()
|
|||||||
if (!os_waitEvent(app.updateEvent) || !app.running)
|
if (!os_waitEvent(app.updateEvent) || !app.running)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (app.reinit && !captureRestart())
|
||||||
|
{
|
||||||
|
exitcode = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
app.reinit = false;
|
||||||
|
|
||||||
bool frameUpdate = false;
|
bool frameUpdate = false;
|
||||||
bool pointerUpdate = false;
|
bool pointerUpdate = false;
|
||||||
|
|
||||||
@ -313,28 +349,11 @@ retry_capture:
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CAPTURE_RESULT_REINIT:
|
case CAPTURE_RESULT_REINIT:
|
||||||
DEBUG_INFO("==== [ Capture Reinit ] ====");
|
if (!captureRestart())
|
||||||
if (!stopThreads())
|
|
||||||
{
|
{
|
||||||
exitcode = -1;
|
exitcode = -1;
|
||||||
goto finish;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iface->deinit() || !iface->init())
|
|
||||||
{
|
|
||||||
DEBUG_ERROR("Failed to reinitialize the capture device");
|
|
||||||
exitcode = -1;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!captureStart())
|
|
||||||
{
|
|
||||||
exitcode = -1;
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start signalled
|
|
||||||
os_signalEvent(app.updateEvent);
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CAPTURE_RESULT_ERROR:
|
case CAPTURE_RESULT_ERROR:
|
||||||
|
Loading…
Reference in New Issue
Block a user