Add option parsing and the ability to select a frame capturing backend

shader-damage
Andri Yngvason 2019-10-12 12:17:22 +00:00
parent b07de643ab
commit 9cd6811efa
1 changed files with 83 additions and 2 deletions

View File

@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h>
#include <getopt.h>
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <neatvnc.h> #include <neatvnc.h>
@ -37,6 +39,12 @@
#include "strlcpy.h" #include "strlcpy.h"
#include "logging.h" #include "logging.h"
enum frame_capture_backend_type {
FRAME_CAPTURE_BACKEND_NONE = 0,
FRAME_CAPTURE_BACKEND_SCREENCOPY,
FRAME_CAPTURE_BACKEND_DMABUF,
};
struct output { struct output {
struct wl_output* wl_output; struct wl_output* wl_output;
struct wl_list link; struct wl_list link;
@ -75,6 +83,18 @@ struct wayvnc {
void on_capture_done(struct frame_capture* capture); void on_capture_done(struct frame_capture* capture);
static enum frame_capture_backend_type
frame_capture_backend_from_string(const char* str)
{
if (strcmp(str, "screencopy") == 0)
return FRAME_CAPTURE_BACKEND_SCREENCOPY;
if (strcmp(str, "dmabuf") == 0)
return FRAME_CAPTURE_BACKEND_DMABUF;
return FRAME_CAPTURE_BACKEND_NONE;
}
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,
@ -474,10 +494,57 @@ void on_capture_done(struct frame_capture* capture)
} }
} }
int wayvnc_usage(FILE* stream, int rc)
{
static const char* usage =
"Usage: wayvnc [options]\n"
"\n"
" -c,--frame-capturing=screencopy|dmabuf Select frame capturing backend.\n"
" -h,--help Get help (this text).\n"
"\n";
fprintf(stream, "%s", usage);
return rc;
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
struct wayvnc self = { 0 }; struct wayvnc self = { 0 };
enum frame_capture_backend_type fcbackend =
FRAME_CAPTURE_BACKEND_DMABUF;
static const char* shortopts = "c:h";
static const struct option longopts[] = {
{ "frame-capturing", required_argument, NULL, 'c' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
while (1) {
int c = getopt_long(argc, argv, shortopts, longopts, NULL);
if (c < 0)
break;
switch (c) {
case 'c':
fcbackend = frame_capture_backend_from_string(optarg);
if (fcbackend == FRAME_CAPTURE_BACKEND_NONE) {
fprintf(stderr, "Invalid backend: %s\n\n",
optarg);
return wayvnc_usage(stderr, 1);
}
break;
case 'h':
return wayvnc_usage(stdout, 0);
default:
return wayvnc_usage(stderr, 1);
}
}
if (init_wayland(&self) < 0) { if (init_wayland(&self) < 0) {
log_error("Failed to initialise wayland\n"); log_error("Failed to initialise wayland\n");
return 1; return 1;
@ -510,14 +577,27 @@ int main(int argc, char* argv[])
screencopy_init(&self.screencopy_backend); screencopy_init(&self.screencopy_backend);
dmabuf_capture_init(&self.dmabuf_backend); dmabuf_capture_init(&self.dmabuf_backend);
switch (fcbackend) {
case FRAME_CAPTURE_BACKEND_SCREENCOPY:
self.capture_backend = &self.screencopy_backend.frame_capture;
break;
case FRAME_CAPTURE_BACKEND_DMABUF:
self.capture_backend = &self.dmabuf_backend.fc; self.capture_backend = &self.dmabuf_backend.fc;
break;
case FRAME_CAPTURE_BACKEND_NONE:
abort();
break;
}
if (wayvnc_start_capture(&self) < 0) if (wayvnc_start_capture(&self) < 0)
goto capture_failure; goto capture_failure;
uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_run(uv_default_loop(), UV_RUN_DEFAULT);
// dmabuf_capture_stop(&self.dmabuf_backend); uv_loop_close(uv_default_loop());
frame_capture_stop(self.capture_backend);
if (self.current_fb) nvnc_fb_unref(self.current_fb); if (self.current_fb) nvnc_fb_unref(self.current_fb);
if (self.last_fb) nvnc_fb_unref(self.last_fb); if (self.last_fb) nvnc_fb_unref(self.last_fb);
@ -525,6 +605,7 @@ int main(int argc, char* argv[])
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: capture_failure: