Make sure that frames being written to are not in use by the encoder

pull/31/head
Andri Yngvason 2020-04-04 13:14:07 +00:00
parent 06ea9db40e
commit ee4917f200
1 changed files with 23 additions and 2 deletions

View File

@ -489,14 +489,18 @@ static void on_damage_check_done(struct pixman_region16* damage, void* userdata)
uint32_t y = ext->y1; uint32_t y = ext->y1;
uint32_t damage_height = ext->y2 - ext->y1; uint32_t damage_height = ext->y2 - ext->y1;
uint32_t* addr = nvnc_fb_get_addr(get_current_fb(self)); struct nvnc_fb* fb = get_current_fb(self);
uint32_t* addr = nvnc_fb_get_addr(fb);
uint32_t fb_width = nvnc_fb_get_width(get_current_fb(self)); uint32_t fb_width = nvnc_fb_get_width(get_current_fb(self));
renderer_read_frame(&self->renderer, addr + y * fb_width, y, renderer_read_frame(&self->renderer, addr + y * fb_width, y,
damage_height); damage_height);
nvnc_fb_unlock(fb);
nvnc_feed_frame(self->nvnc, get_current_fb(self), damage); nvnc_feed_frame(self->nvnc, fb, damage);
swap_fds(self); swap_fds(self);
} else {
nvnc_fb_unlock(get_current_fb(self));
} }
if (wayvnc_start_capture(self) < 0) { if (wayvnc_start_capture(self) < 0) {
@ -524,6 +528,21 @@ void wayvnc_process_frame(struct wayvnc* self)
assert(height == nvnc_fb_get_height(fb)); assert(height == nvnc_fb_get_height(fb));
} }
/* Check if frame is still in use. This can happen when encoding is too
* slow to keep up with frames being fed to it. When this happens the
* user can choose to do one of three things:
* - Grow the swap chain
* - Remove the frame from the swap chain and add a new one
* - Drop the frame. This is what we'll be doing here.
*
* TODO: Damage hints are not being used now, but if they will be used
* then this breaks things.
*/
if (!nvnc_fb_lock(fb)) {
log_debug("nvnc_fb(%p) still in use. Dropping frame.\n", fb);
goto done;
}
frame_capture_render(self->capture_backend, &self->renderer, fb); frame_capture_render(self->capture_backend, &self->renderer, fb);
if (!self->please_send_full_frame_next && !is_first_frame) { if (!self->please_send_full_frame_next && !is_first_frame) {
@ -558,6 +577,7 @@ void wayvnc_process_frame(struct wayvnc* self)
void* addr = nvnc_fb_get_addr(fb); void* addr = nvnc_fb_get_addr(fb);
renderer_read_frame(&self->renderer, addr, 0, height); renderer_read_frame(&self->renderer, addr, 0, height);
nvnc_fb_unlock(fb);
struct pixman_region16 damage; struct pixman_region16 damage;
pixman_region_init_rect(&damage, 0, 0, width, height); pixman_region_init_rect(&damage, 0, 0, width, height);
@ -565,6 +585,7 @@ void wayvnc_process_frame(struct wayvnc* self)
swap_fds(self); swap_fds(self);
pixman_region_fini(&damage); pixman_region_fini(&damage);
done:
if (wayvnc_start_capture(self) < 0) { if (wayvnc_start_capture(self) < 0) {
log_error("Failed to start capture. Exiting...\n"); log_error("Failed to start capture. Exiting...\n");
wayvnc_exit(self); wayvnc_exit(self);