This commit is contained in:
parent
0ddfc32f0c
commit
34ce402203
@ -46,11 +46,11 @@ pub fn new() -> GenericService {
|
||||
fn run(sp: GenericService) -> ResultType<()> {
|
||||
let fps = 30;
|
||||
let spf = time::Duration::from_secs_f32(1. / (fps as f32));
|
||||
let (n, current, display) = get_current_display()?;
|
||||
let (ndisplay, current, display) = get_current_display()?;
|
||||
let (origin, width, height) = (display.origin(), display.width(), display.height());
|
||||
log::debug!(
|
||||
"#displays={}, current={}, origin: {:?}, width={}, height={}",
|
||||
n,
|
||||
ndisplay,
|
||||
current,
|
||||
&origin,
|
||||
width,
|
||||
@ -74,7 +74,11 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
speed,
|
||||
};
|
||||
let mut vpx;
|
||||
match Encoder::new(&cfg, 1) {
|
||||
let mut n = ((width * height) as f64 / (1920 * 1080) as f64).round() as u32;
|
||||
if n < 1 {
|
||||
n = 1;
|
||||
}
|
||||
match Encoder::new(&cfg, n) {
|
||||
Ok(x) => vpx = x,
|
||||
Err(err) => bail!("Failed to create encoder: {}", err),
|
||||
}
|
||||
@ -113,6 +117,7 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
let start = time::Instant::now();
|
||||
let mut crc = (0, 0);
|
||||
let mut last_sent = time::Instant::now();
|
||||
let mut last_check_displays = time::Instant::now();
|
||||
while sp.ok() {
|
||||
if *SWITCH.lock().unwrap() {
|
||||
bail!("SWITCH");
|
||||
@ -131,6 +136,14 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
}
|
||||
}
|
||||
let now = time::Instant::now();
|
||||
if last_check_displays.elapsed().as_millis() > 1000 {
|
||||
last_check_displays = now;
|
||||
if ndisplay != get_display_num() {
|
||||
log::info!("Displays changed");
|
||||
*SWITCH.lock().unwrap() = true;
|
||||
bail!("SWITCH");
|
||||
}
|
||||
}
|
||||
*LAST_ACTIVE.lock().unwrap() = now;
|
||||
if get_latency() < 1000 || last_sent.elapsed().as_millis() > 1000 {
|
||||
match c.frame(wait as _) {
|
||||
@ -228,6 +241,14 @@ fn handle_one_frame(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_display_num() -> usize {
|
||||
if let Ok(d) = Display::all() {
|
||||
d.len()
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_displays() -> ResultType<(usize, Vec<DisplayInfo>)> {
|
||||
// switch to primary display if long time (30 seconds) no users
|
||||
if LAST_ACTIVE.lock().unwrap().elapsed().as_secs() >= 30 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user