Using Box for child
This commit is contained in:
parent
da4dcf9968
commit
a947442044
65
src/main.rs
65
src/main.rs
|
@ -110,8 +110,8 @@ fn help() {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stream_black(config: &mut Config) -> Result<Vec<Child>, Error> {
|
fn stream_black(config: &mut Config) -> Result<Vec<Box<Child>>, Error> {
|
||||||
let mut cmd = Command::new("ffmpeg")
|
let cmd = Command::new("ffmpeg")
|
||||||
.args(&[
|
.args(&[
|
||||||
"-i",
|
"-i",
|
||||||
format!(
|
format!(
|
||||||
|
@ -142,10 +142,10 @@ fn stream_black(config: &mut Config) -> Result<Vec<Child>, Error> {
|
||||||
|
|
||||||
config.current_output = "".to_string();
|
config.current_output = "".to_string();
|
||||||
|
|
||||||
return Ok(vec![cmd]);
|
return Ok(vec![Box::new(cmd)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Child>, Error> {
|
fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Box<Child>>, Error> {
|
||||||
let resolution = Resolution {
|
let resolution = Resolution {
|
||||||
height: output.current_mode.height,
|
height: output.current_mode.height,
|
||||||
width: output.current_mode.width,
|
width: output.current_mode.width,
|
||||||
|
@ -191,7 +191,7 @@ fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Child>,
|
||||||
|
|
||||||
config.current_output = output.name.as_str().to_string();
|
config.current_output = output.name.as_str().to_string();
|
||||||
|
|
||||||
let mut processes = vec![recorder];
|
let mut processes = vec![Box::new(recorder)];
|
||||||
|
|
||||||
if device_number != config.devices_from {
|
if device_number != config.devices_from {
|
||||||
if config.verbose {
|
if config.verbose {
|
||||||
|
@ -227,7 +227,7 @@ fn record_screen(config: &mut Config, output: SwayOutput) -> Result<Vec<Child>,
|
||||||
})
|
})
|
||||||
.spawn()?;
|
.spawn()?;
|
||||||
|
|
||||||
processes.push(upscaler);
|
processes.push(Box::new(upscaler));
|
||||||
}
|
}
|
||||||
format!("/dev/video{}", device_number).as_str();
|
format!("/dev/video{}", device_number).as_str();
|
||||||
|
|
||||||
|
@ -411,6 +411,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.outputs
|
.outputs
|
||||||
.insert(config.resolutions[0], config.devices_from);
|
.insert(config.resolutions[0], config.devices_from);
|
||||||
config.current_device_index += 1;
|
config.current_device_index += 1;
|
||||||
|
let valid_screens = get_valid_screens_for_recording(&config);
|
||||||
|
let mut recorders: Vec<Box<Child>> = if valid_screens.len() == 0 {
|
||||||
|
stream_black(&mut config)?
|
||||||
|
} else {
|
||||||
|
let output = get_output(&mut config, valid_screens[0].output.as_str());
|
||||||
|
record_screen(&mut config, output)?
|
||||||
|
};
|
||||||
|
|
||||||
let stdout = match Command::new("sh")
|
let stdout = match Command::new("sh")
|
||||||
.args(&["-c", "swaymsg -t subscribe -m \"['window']\""])
|
.args(&["-c", "swaymsg -t subscribe -m \"['window']\""])
|
||||||
|
@ -425,33 +432,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let reader = BufReader::new(stdout);
|
let reader = BufReader::new(stdout);
|
||||||
reader
|
reader.lines().filter_map(|line| line.ok()).for_each(|_| {
|
||||||
.lines()
|
println!("Switched focus");
|
||||||
.filter_map(|line| line.ok())
|
let valid_screens = get_valid_screens_for_recording(&config);
|
||||||
.for_each(|_| -> Result<(), Error> {
|
if valid_screens.len() > 0 && valid_screens[0].output == config.current_output {
|
||||||
println!("Switched focus");
|
return;
|
||||||
let valid_screens = get_valid_screens_for_recording(&config);
|
}
|
||||||
if valid_screens.len() > 0 && valid_screens[0].output == config.current_output {
|
for recorder in recorders.iter_mut() {
|
||||||
return Ok(());
|
if config.verbose {
|
||||||
|
println!("Killing child");
|
||||||
}
|
}
|
||||||
let output = get_output(&mut config, valid_screens[0].output.as_str());
|
match recorder.kill() {
|
||||||
for recorder in recorders.iter() {
|
Ok(_) => {}
|
||||||
match recorder.kill() {
|
Err(err) => panic!("{:?}", err),
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => panic!("{:?}", err),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut recorders: Vec<Child> = if valid_screens.len() != 0 {
|
|
||||||
stream_black(&mut config)?
|
|
||||||
} else {
|
|
||||||
let output = get_output(&mut config, valid_screens[0].output.as_str());
|
|
||||||
record_screen(&mut config, output)?
|
|
||||||
};
|
};
|
||||||
println!("Recording {}", config.current_output);
|
}
|
||||||
|
|
||||||
Ok(())
|
recorders = if valid_screens.len() == 0 {
|
||||||
});
|
stream_black(&mut config).unwrap()
|
||||||
|
} else {
|
||||||
|
let output = get_output(&mut config, valid_screens[0].output.as_str());
|
||||||
|
record_screen(&mut config, output).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Recording {}", config.current_output);
|
||||||
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue