Add explicit object for the encoder finishing

On a resize, the encoder is deleted. At present this is done by asking
the encoder to exit, and then waiting a second.

- On slower systems, a second may not be enough, and so the encoder
  data structures are freed while they are still being used by the
  encoder.
- On quicker systems, resizes are delayed by hundreds of milliseconds
  longer than they need to be.

This commit adds a wait object which the encoder can use to signal it
has actually finished.
This commit is contained in:
matt335672 2024-06-03 15:56:05 +01:00
parent 809df89c08
commit 985b0de35e
2 changed files with 14 additions and 6 deletions

View File

@ -220,7 +220,8 @@ xrdp_encoder_create(struct xrdp_mm *mm)
g_snprintf(buf, 1024, "xrdp_%8.8x_encoder_event_processed", pid);
self->xrdp_encoder_event_processed = g_create_wait_obj(buf);
g_snprintf(buf, 1024, "xrdp_%8.8x_encoder_term", pid);
self->xrdp_encoder_term = g_create_wait_obj(buf);
self->xrdp_encoder_term_request = g_create_wait_obj(buf);
self->xrdp_encoder_term_done = g_create_wait_obj(buf);
if (client_info->gfx)
{
const char *env_var = g_getenv("XRDP_GFX_FRAMES_IN_FLIGHT");
@ -296,8 +297,12 @@ xrdp_encoder_delete(struct xrdp_encoder *self)
return;
}
/* tell worker thread to shut down */
g_set_wait_obj(self->xrdp_encoder_term);
g_sleep(1000);
g_set_wait_obj(self->xrdp_encoder_term_request);
g_obj_wait(&self->xrdp_encoder_term_done, 1, NULL, 0, 5000);
if (!g_is_wait_obj_set(self->xrdp_encoder_term_done))
{
LOG(LOG_LEVEL_WARNING, "Encoder failed to shut down cleanly");
}
#ifdef XRDP_RFXCODEC
for (index = 0; index < 16; index++)
@ -330,7 +335,8 @@ xrdp_encoder_delete(struct xrdp_encoder *self)
/* destroy wait objects used for signalling */
g_delete_wait_obj(self->xrdp_encoder_event_to_proc);
g_delete_wait_obj(self->xrdp_encoder_event_processed);
g_delete_wait_obj(self->xrdp_encoder_term);
g_delete_wait_obj(self->xrdp_encoder_term_request);
g_delete_wait_obj(self->xrdp_encoder_term_done);
/* cleanup fifos */
fifo_delete(self->fifo_to_proc, NULL);
@ -1413,7 +1419,7 @@ proc_enc_msg(void *arg)
event_to_proc = self->xrdp_encoder_event_to_proc;
term_obj = g_get_term();
lterm_obj = self->xrdp_encoder_term;
lterm_obj = self->xrdp_encoder_term_request;
cont = 1;
while (cont)
@ -1464,6 +1470,7 @@ proc_enc_msg(void *arg)
}
} /* end while (cont) */
g_set_wait_obj(self->xrdp_encoder_term_done);
LOG_DEVEL(LOG_LEVEL_DEBUG, "proc_enc_msg: thread exit");
return 0;
}

View File

@ -24,7 +24,8 @@ struct xrdp_encoder
int max_compressed_bytes;
tbus xrdp_encoder_event_to_proc;
tbus xrdp_encoder_event_processed;
tbus xrdp_encoder_term;
tbus xrdp_encoder_term_request;
tbus xrdp_encoder_term_done;
struct fifo *fifo_to_proc;
struct fifo *fifo_processed;
tbus mutex;