Add a brief timeout between a capture failure and the retry

Ensures we don't spin eating CPU if capture is continually failing due
to DPMS (for example) by only trying to restart screen capture every
100ms.

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/196/head
Jim Ramsay 2022-11-26 14:48:29 -05:00 committed by Andri Yngvason
parent e958b06e44
commit 89bd6da3bb
1 changed files with 28 additions and 1 deletions

View File

@ -104,6 +104,8 @@ struct wayvnc {
int nr_clients;
struct aml_ticker* performance_ticker;
struct aml_timer* capture_retry_timer;
struct ctl* ctl;
};
@ -335,6 +337,9 @@ void wayvnc_destroy(struct wayvnc* self)
if (self->performance_ticker)
aml_unref(self->performance_ticker);
if (self->capture_retry_timer)
aml_unref(self->capture_retry_timer);
wl_registry_destroy(self->registry);
wl_display_disconnect(self->display);
}
@ -720,6 +725,9 @@ int wayvnc_start_capture(struct wayvnc* self)
int wayvnc_start_capture_immediate(struct wayvnc* self)
{
if (self->capture_retry_timer)
return 0;
int rc = screencopy_start_immediate(&self->screencopy);
if (rc < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to start capture. Exiting...");
@ -728,6 +736,25 @@ int wayvnc_start_capture_immediate(struct wayvnc* self)
return rc;
}
static void on_capture_restart_timer(void* obj)
{
struct wayvnc* self = aml_get_userdata(obj);
aml_unref(self->capture_retry_timer);
self->capture_retry_timer = NULL;
wayvnc_start_capture_immediate(self);
}
static void wayvnc_restart_capture(struct wayvnc* self)
{
if (self->capture_retry_timer)
return;
int timeout = 100000;
self->capture_retry_timer = aml_timer_new(timeout,
on_capture_restart_timer, self, NULL);
aml_start(aml_get_default(), self->capture_retry_timer);
}
// TODO: Handle transform change too
void on_output_dimension_change(struct output* output)
{
@ -812,7 +839,7 @@ void on_capture_done(struct screencopy* sc)
wayvnc_exit(self);
break;
case SCREENCOPY_FAILED:
wayvnc_start_capture_immediate(self);
wayvnc_restart_capture(self);
break;
case SCREENCOPY_DONE:
wayvnc_process_frame(self);