WiP: Implement frame capturing

shader-damage
Andri Yngvason 2019-10-06 22:50:11 +00:00
parent eaae3ba2db
commit 119ee0efef
3 changed files with 67 additions and 2 deletions

View File

@ -5,6 +5,7 @@ EXEC := wayvnc
SOURCES := \ SOURCES := \
src/main.c \ src/main.c \
src/render.c \ src/render.c \
src/dmabuf.c \
src/strlcpy.c \ src/strlcpy.c \
include common.mk include common.mk

View File

@ -37,6 +37,7 @@ struct dmabuf_capture {
enum dmabuf_capture_status status; enum dmabuf_capture_status status;
void (*on_done)(struct dmabuf_capture*); void (*on_done)(struct dmabuf_capture*);
void* userdata;
}; };
struct dmabuf_capture* struct dmabuf_capture*

View File

@ -37,6 +37,7 @@ struct wayvnc {
struct renderer renderer; struct renderer renderer;
struct zwlr_export_dmabuf_manager_v1* export_manager; struct zwlr_export_dmabuf_manager_v1* export_manager;
const struct output* selected_output; const struct output* selected_output;
struct dmabuf_capture* capture;
uv_poll_t wayland_poller; uv_poll_t wayland_poller;
uv_prepare_t flusher; uv_prepare_t flusher;
@ -45,6 +46,8 @@ struct wayvnc {
struct nvnc* nvnc; struct nvnc* nvnc;
}; };
void on_capture_done(struct dmabuf_capture* capture);
static void output_handle_geometry(void* data, struct wl_output* wl_output, static void output_handle_geometry(void* data, struct wl_output* wl_output,
int32_t x, int32_t y, int32_t phys_width, int32_t x, int32_t y, int32_t phys_width,
int32_t phys_height, int32_t subpixel, int32_t phys_height, int32_t subpixel,
@ -235,10 +238,14 @@ void on_uv_walk(uv_handle_t* handle, void* arg)
uv_close(handle, NULL); uv_close(handle, NULL);
} }
void wayvnc_exit(void)
{
uv_walk(uv_default_loop(), on_uv_walk, NULL);
}
void on_signal(uv_signal_t* handle, int signo) void on_signal(uv_signal_t* handle, int signo)
{ {
struct wayvnc* self = wl_container_of(handle, self, signal_handler); wayvnc_exit();
uv_walk(handle->loop, on_uv_walk, NULL);
} }
int init_main_loop(struct wayvnc* self) int init_main_loop(struct wayvnc* self)
@ -289,6 +296,52 @@ int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port)
return 0; return 0;
} }
int wayvnc_start_capture(struct wayvnc* self)
{
self->capture = dmabuf_capture_start(self->export_manager, false,
self->selected_output->wl_output,
on_capture_done);
if (!self->capture)
return -1;
self->capture->userdata = self;
return 0;
}
void wayvnc_process_frame(struct wayvnc* self, struct dmabuf_frame* frame)
{
/* TODO */
if (wayvnc_start_capture(self) < 0) {
log_error("Failed to start capture. Exiting...\n");
wayvnc_exit();
}
}
void on_capture_done(struct dmabuf_capture* capture)
{
struct wayvnc* self = capture->userdata;
switch (capture->status) {
case DMABUF_CAPTURE_FATAL:
log_error("Fatal error while capturing. Exiting...\n");
wayvnc_exit();
break;
case DMABUF_CAPTURE_CANCELLED:
if (wayvnc_start_capture(self) < 0) {
log_error("Failed to start capture. Exiting...\n");
wayvnc_exit();
}
break;
case DMABUF_CAPTURE_DONE:
wayvnc_process_frame(self, &capture->frame);
break;
case DMABUF_CAPTURE_UNSPEC:
abort();
}
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
struct wayvnc self; struct wayvnc self;
@ -323,13 +376,23 @@ int main(int argc, char* argv[])
if (init_nvnc(&self, "0.0.0.0", 5900) < 0) if (init_nvnc(&self, "0.0.0.0", 5900) < 0)
goto nvnc_failure; goto nvnc_failure;
if (wayvnc_start_capture(&self) < 0)
goto capture_failure;
self.capture->userdata = &self;
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
if (self.capture)
dmabuf_capture_stop(self.capture);
nvnc_close(self.nvnc); nvnc_close(self.nvnc);
renderer_destroy(&self.renderer); renderer_destroy(&self.renderer);
wayvnc_destroy(&self); wayvnc_destroy(&self);
return 0; return 0;
capture_failure:
nvnc_close(self.nvnc);
nvnc_failure: nvnc_failure:
main_loop_failure: main_loop_failure:
renderer_destroy(&self.renderer); renderer_destroy(&self.renderer);