From 073d3a1248a82223264447c4270d93a2f503c479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Thu, 6 Jan 2022 18:27:02 +0100 Subject: [PATCH] Little better docs --- .envrc | 2 ++ .gitignore | 2 ++ README.md | 31 ++++++++++++++++++++++++++++++- shell.nix | 7 +++++++ src/main.rs | 13 +++++++++---- 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 .envrc create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a53d257 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +watch_file shell/* shell.nix +use nix diff --git a/.gitignore b/.gitignore index ea8c4bf..d4af4d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +tags +.direnv diff --git a/README.md b/README.md index 26c3da5..ba35af9 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,33 @@ There's an AUR package called `wlstreamer-git`, alternatively you can build and ## Usage -See `--help`. If there are no screens available for streaming, a black screen will be shown instead. +See `wlstreamer --help`. If there are no screens available for streaming, a black screen will be shown instead. + +``` +Usage: wlstreamer [options] +Wrapper around wf-recorder and ffmpeg that automatically switches the screen being recorded based on current window focus + +Options: + --not-ws Do not show this workspace. Can be used multiple times. Example: 3 + --not-screen Do not show this screen. Can be used multiple times. Example: HDMI-A-1 + -d|--devices-from Use video devices starting at $id. Defaults to 0. /dev/video$id will be used as output. See DIFFERENT RESOLUTIONS below. + -v|--version Display version and exit + --verbose Verbose logging + +If there are no screens available for streaming, a black screen will be shown instead. + +DIFFERENT RESOLUTIONS + +When running outputs with different resolutions, the resulting stream will be the smallest possible resolution that can fit all output resolutions. +For example, two outputs, one 1600x1200, another 1920x1080, will result in an output stream of 1920x1200. Any remaining space will be padded black. +Another example, two outputs, one 640x480, another 1920x1080, will result in an output stream of 1920x1080. Space will only be padded black on the smaller screen. + +To support this behaviour, wlstreamer needs access to a v4l2loopback device for each resolution, included the combined upscaled one if applicable. For the first example above, this would mean you would need 3 devices. For the second, you'd need two. If all your outputs have the same resolution, you only need an output device. + +The --devices-from or -d option specifies at which device index it is okay to start using loopback devices. For example, if you specify -d 3, and you need 2 capture devices, /dev/video3 and /dev/video4 will be used by wlstreamer, with /dev/video3 being the output you want to use in other applications. + +DYNAMICALLY CHANGING RESOLUTIONS + +As long as you have enough v4l2loopback devices available for new resolutions, it should be fine to change resolutions on an output. +However, if your resolution is either wider or taller than the output resolution, this will result in failures, since dynamically changing the v4l2loopback device resolution is not possible. +``` diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..80ed4ef --- /dev/null +++ b/shell.nix @@ -0,0 +1,7 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo gcc wf-recorder ]; + buildInputs = with pkgs; [ rustfmt clippy ]; + + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; +} diff --git a/src/main.rs b/src/main.rs index c4bd58e..a2e3c43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -268,6 +268,7 @@ fn get_resolutions(config: &mut Config) -> Vec { .collect_vec(); if config.verbose { + println!("Found resolutions:"); println!("{:?}", resolutions); } @@ -291,7 +292,10 @@ fn get_resolutions(config: &mut Config) -> Vec { ); if config.verbose { - println!("Combined maximum resolution {:?}", combined_resolution); + println!( + "Found combined maximum resolution {:?}", + combined_resolution + ); } resolutions.insert(0, combined_resolution); @@ -313,7 +317,7 @@ fn get_valid_screens_for_recording(config: &Config) -> Vec { serde_json::from_str(stdout_string.as_str()).expect("Invalid json from get_workspaces"); if config.verbose { - println!("Found workspaces"); + println!("Found workspaces:"); for elem in workspaces.iter() { println!("{:?}", elem); } @@ -332,7 +336,7 @@ fn get_valid_screens_for_recording(config: &Config) -> Vec { .collect(); if config.verbose { - println!("Filtered workspaces"); + println!("Blacklisted workspaces filtered out:"); for elem in workspaces.iter() { println!("{:?}", elem); } @@ -423,9 +427,10 @@ fn main() -> Result<(), Box> { let reader = BufReader::new(stdout); reader.lines().filter_map(|line| line.ok()).for_each(|_| { - println!("Switched focus"); + println!("Focus switched event"); let valid_screens = get_valid_screens_for_recording(&config); if valid_screens.len() > 0 && valid_screens[0].output == config.current_output { + println!("Screen is the same, no need to switch"); return; } for recorder in recorders.iter_mut() {