Dynamic resolutions seems to be working

This commit is contained in:
Benjamin Bädorf 2020-11-19 21:19:35 +01:00
parent a947442044
commit e5cea6701f
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C

View file

@ -5,6 +5,7 @@ use std::collections::HashMap;
use std::env; use std::env;
use std::io::{BufRead, BufReader, Error}; use std::io::{BufRead, BufReader, Error};
use std::process::{Child, Command, Stdio}; use std::process::{Child, Command, Stdio};
use std::{thread, time};
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
struct SwayScreenRect { struct SwayScreenRect {
@ -62,7 +63,7 @@ struct Resolution {
struct Config { struct Config {
current_output: String, current_output: String,
devices_from: usize, devices_from: usize,
current_device_index: usize, last_device_index: usize,
screen_blacklist: Vec<String>, screen_blacklist: Vec<String>,
workspace_blacklist: Vec<usize>, workspace_blacklist: Vec<usize>,
verbose: bool, verbose: bool,
@ -154,11 +155,9 @@ fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Box<Chil
let device_number = match config.outputs.get(&resolution) { let device_number = match config.outputs.get(&resolution) {
Some(device_number) => *device_number, Some(device_number) => *device_number,
None => { None => {
config config.last_device_index += 1;
.outputs config.outputs.insert(resolution, config.last_device_index);
.insert(resolution, config.current_device_index); config.last_device_index
config.current_device_index += 1;
config.current_device_index
} }
}; };
@ -198,6 +197,11 @@ fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Box<Chil
println!("Does not have the maximum combined resolution, filtering through ffmpeg"); println!("Does not have the maximum combined resolution, filtering through ffmpeg");
} }
// TODO: This is slow, ugly, and prone to failure. ffmpeg will fail if wf-recorder isn't
// writing yet, however I'm not sure how to get an exact timing of when it's okay to start
// reading from the device.
thread::sleep(time::Duration::from_millis(40));
let upscaler = Command::new("ffmpeg") let upscaler = Command::new("ffmpeg")
.args(&[ .args(&[
"-i", "-i",
@ -216,20 +220,19 @@ fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Box<Chil
]) ])
.stdin(Stdio::piped()) .stdin(Stdio::piped())
.stdout(if config.verbose { .stdout(if config.verbose {
Stdio::piped()
} else {
Stdio::inherit() Stdio::inherit()
} else {
Stdio::piped()
}) })
.stderr(if config.verbose { .stderr(if config.verbose {
Stdio::piped()
} else {
Stdio::inherit() Stdio::inherit()
} else {
Stdio::piped()
}) })
.spawn()?; .spawn()?;
processes.push(Box::new(upscaler)); processes.push(Box::new(upscaler));
} }
format!("/dev/video{}", device_number).as_str();
return Ok(processes); return Ok(processes);
} }
@ -364,7 +367,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = Config { let mut config = Config {
current_output: "".to_string(), current_output: "".to_string(),
devices_from: 0, devices_from: 0,
current_device_index: 0, last_device_index: 0,
screen_blacklist: Vec::new(), screen_blacklist: Vec::new(),
workspace_blacklist: Vec::new(), workspace_blacklist: Vec::new(),
verbose: false, verbose: false,
@ -391,7 +394,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} else if arg == "-d" || arg == "--devices-from" { } else if arg == "-d" || arg == "--devices-from" {
i += 1; i += 1;
config.devices_from = args[i].clone().parse::<usize>().unwrap(); config.devices_from = args[i].clone().parse::<usize>().unwrap();
config.current_device_index = config.devices_from;
} else if arg == "--verbose" { } else if arg == "--verbose" {
config.verbose = true; config.verbose = true;
} else if arg == "-v" || arg == "--version" { } else if arg == "-v" || arg == "--version" {
@ -410,7 +412,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
config config
.outputs .outputs
.insert(config.resolutions[0], config.devices_from); .insert(config.resolutions[0], config.devices_from);
config.current_device_index += 1; config.last_device_index = config.devices_from;
let valid_screens = get_valid_screens_for_recording(&config); let valid_screens = get_valid_screens_for_recording(&config);
let mut recorders: Vec<Box<Child>> = if valid_screens.len() == 0 { let mut recorders: Vec<Box<Child>> = if valid_screens.len() == 0 {
stream_black(&mut config)? stream_black(&mut config)?