From 7fe53f10b926f7513f5525d161b0d8804cac38cd Mon Sep 17 00:00:00 2001 From: matanui159 Date: Sat, 10 Jul 2021 17:29:52 +1000 Subject: [PATCH] Update documentation --- CMakeLists.txt | 13 +++++---- README.md | 48 +++++++++++++++++++++++++++---- src/socket.c | 6 ++-- sys/replay-sorcery-kms.service.in | 11 +++++++ sys/replay-sorcery.conf | 11 +++---- 5 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 sys/replay-sorcery-kms.service.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2291792..3ac6b60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,7 @@ add_custom_target(clang-format ) # Install binary -option(RS_SETUID "Enable the SETUID permission" ON) +option(RS_SETUID "Enable the SETUID permission" OFF) set(permissions OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE @@ -226,8 +226,9 @@ install(TARGETS ${binary} DESTINATION bin PERMISSIONS ${permissions}) # Install config install(FILES sys/replay-sorcery.conf DESTINATION etc) -# Install service -set(RS_SYSTEMD_DIR /usr/lib/systemd/user CACHE STRING "Where to install the systemd service") -set(service replay-sorcery.service) -configure_file(sys/${service}.in ${service}) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${service}" DESTINATION "${RS_SYSTEMD_DIR}") +# Install services +set(RS_SYSTEMD_DIR /usr/lib/systemd CACHE STRING "Where to install the systemd services") +configure_file(sys/replay-sorcery.service.in replay-sorcery.service) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/replay-sorcery.service" DESTINATION "${RS_SYSTEMD_DIR}/user") +configure_file(sys/replay-sorcery-kms.service.in replay-sorcery-kms.service) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/replay-sorcery-kms.service" DESTINATION "${RS_SYSTEMD_DIR}/system") diff --git a/README.md b/README.md index 638c188..d8260ac 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,19 @@ I wanted something like this for Linux... I got tired waiting for someone else to do it. # Documentation +- [Installing](#installing) + - [Arch](#arch) +- [Building from Source](#building-from-source) + - [Required Dependencies](#required-dependencies) + - [Optional Dependencies](#optional-dependencies) +- [Running](#running) +- [Configuration](#configuration) +- [Hardware Acceleration](#hardware-acceleration) + - [Using `replay-sorcery-kms`](#using-replay-sorcery-kms) + - [Using `RS_SETUID`](#using-rs_setuid) + - [nVidia Support](#nvidia-support) +- [Wayland Support](#wayland-support) + ## Installing ### Arch There is an official AUR package that gets updated from the CI (thanks to [Bennett Hardwick](https://github.com/bennetthardwick)): [replay-sorcery](https://aur.archlinux.org/packages/replay-sorcery). @@ -24,9 +37,9 @@ $ sudo make -C bin install ### Required dependencies - CMake - FFmpeg -- X11 ### Optional dependencies +- Xlib (for the keyboard shortcut on X11) - PulseAudio (for audio recording) - `libdrm` (for listing `kms` devices) @@ -47,11 +60,6 @@ You can also use systemd to look at the output: $ journalctl --user -fu replay-sorcery ``` -The service runs as root using the `SETUID` permission since this is needed if you enable hardware acceleration. If this causes issues, you can disable it with `-DRS_SETUID=OFF` in CMake: -``` -$ cmake -B bin -DRS_SETUID=OFF -``` - ## Configuration The config file location and options has completely changed since version 0.3.x @@ -61,6 +69,34 @@ There are two config files: See [`sys/replay-sorcery.conf`](sys/replay-sorcery.conf) for the default values along with documentation. This file is installed into the global config file location. +## Hardware Acceleration +### Using `replay-sorcery-kms` +Due to hardware acceleration requiring root permissions, the recommended way of enabling hardware acceleration is by using the KMS service. Start the service by running: +``` +$ sudo systemctl enable --now replay-sorcery-kms +``` + +Then set `videoInput` in the configuration file to either `hwaccel` or `kms_service` and start or restart the user service as documented above. + +### Using `RS_SETUID` +**NOTE: from a security perspective this is a BAD IDEA. This will be removed in a future release.** + +You can able `setuid` on the user service so it can access KMS without requiring a second service. You can enable it by using the CMake option: +``` +$ cmake -B bin -DRS_SETUID=ON +``` + +### nVidia Support +The Nouveau open source drivers are supported but sadly the proprietary nVidia drivers do not support VA-API which is currently required for hardware acceleration. In the future NVENC might be supported. Software encoding is always supported and tries to use as little CPU as possible. + +## Wayland Support +Wayland screen grabbing is not currently supported, however hardware accelerated screen grabbing works fine. See above for steps for enabling that. + +Wayland also does not allow listening to keyboard events unless you are the active window. To get around this you can set `controller` in the configuration file to `command` and setup a shortcut in your window manager to run: +``` +$ replay-sorcery save +``` + # TODO - Support NVENC API - Document code better diff --git a/src/socket.c b/src/socket.c index bf2cab5..8b30b01 100644 --- a/src/socket.c +++ b/src/socket.c @@ -164,9 +164,10 @@ int rsSocketSend(RSSocket *sock, size_t size, const void *buffer, size_t fileCou } struct msghdr msg = {0}; + struct iovec *iov = &(struct iovec){.iov_base = (void *)buffer, .iov_len = size}; if (size > 0) { msg.msg_iovlen = 1; - msg.msg_iov = &(struct iovec){.iov_base = (void *)buffer, .iov_len = size}; + msg.msg_iov = iov; } if (fileCount > 0) { size_t filesSize = sizeof(int) * fileCount; @@ -203,11 +204,12 @@ int rsSocketReceive(RSSocket *sock, size_t size, void *buffer, size_t fileCount, } struct msghdr msg = {0}; + struct iovec *iov = &(struct iovec){.iov_base = buffer, .iov_len = size}; size_t filesSize = sizeof(int) * fileCount; struct cmsghdr *cmsg = NULL; if (size > 0) { msg.msg_iovlen = 1; - msg.msg_iov = &(struct iovec){.iov_base = buffer, .iov_len = size}; + msg.msg_iov = iov; } if (fileCount > 0) { msg.msg_control = sock->buffer; diff --git a/sys/replay-sorcery-kms.service.in b/sys/replay-sorcery-kms.service.in new file mode 100644 index 0000000..a8156ce --- /dev/null +++ b/sys/replay-sorcery-kms.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=ReplaySorcery KMS service + +[Service] +Type=simple +ExecStart=@CMAKE_INSTALL_PREFIX@/bin/replay-sorcery kms-service +TimeoutStopSec=60 +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/sys/replay-sorcery.conf b/sys/replay-sorcery.conf index 5cd0aa6..ab042e0 100644 --- a/sys/replay-sorcery.conf +++ b/sys/replay-sorcery.conf @@ -12,16 +12,13 @@ traceLevel = error # Default value: 30 recordSeconds = 30 -# SET THIS VALUE TO hwaccel TO ENABLE HARDWARE ACCELERATION -# IT IS NOT ENABLED BY DEFAULT DUE TO ISSUES WITH CERTAIN COMPUTERS -# HERE BE DRAGONS AND YOUR MILEAGE MAY VARY # The video input backend to use for video recording -# Possible values: auto, hwaccel, x11, kms +# Possible values: auto, hwaccel, x11, kms, kms_service # Default value: auto videoInput = auto # The name of the input video device -# For kms, see `replay-sorcery kms-devices` +# For kms and kms_service, see `replay-sorcery kms-devices` # Possible values: auto, or a device string # Default value: auto videoDevice = auto @@ -40,7 +37,7 @@ videoHeight = auto videoFramerate = 30 # The video encoder backend to use for video recording -# Possible values: auto, x264, openh264, vaapi +# Possible values: auto, hevc, x264, openh264, x265, vaapi_h264, vaapi_hevc # Default value: auto videoEncoder = auto @@ -119,7 +116,7 @@ keyMods = ctrl+super # Where to save the output file # Possible values: a strftime formatted file path # Default value: ~/Videos/ReplaySorcery_%F_%H-%M-%S.mp4 -outputFile = ~/Videos/ReplaySorcery_%F_%H-%M-%S.mp4 +outputFile = ~/Videos/ReplaySorcery/%F_%H-%M-%S.mp4 # A command to run when a video is successfully saved # Possible values: a printf formatted command