diff --git a/src/video_stream.rs b/src/video_stream.rs index 69fe5e0..0e1763f 100644 --- a/src/video_stream.rs +++ b/src/video_stream.rs @@ -1,15 +1,18 @@ use arma_rs::Context; use lazy_static::lazy_static; -use std::os::windows::process::CommandExt; use std::process::Command; use std::sync::mpsc::{self, Receiver, Sender}; use std::sync::Mutex; use std::thread; +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; + lazy_static! { static ref STREAM_CTRL: Mutex>> = Mutex::new(None); } +#[cfg(target_os = "windows")] const CREATE_NO_WINDOW: u32 = 0x08000000; pub fn start_stream( @@ -20,6 +23,14 @@ pub fn start_stream( username: String, password: String, ) -> &'static str { + #[cfg(target_os = "linux")] + { + return ctx.callback_null( + "armatak_video_error", + "Screen capture is only supported on Windows", + ); + } + let (tx, rx): (Sender<()>, Receiver<()>) = mpsc::channel(); let rtsp_url = format!( "rtsp://{}:{}@{}:{}/{}", @@ -28,24 +39,29 @@ pub fn start_stream( let rtsp_url_clone = rtsp_url.clone(); thread::spawn(move || { - let mut child = match Command::new("ffmpeg") - .args(&[ - "-f", - "gdigrab", - "-i", - "desktop", - "-f", - "rtsp", - "-rtsp_transport", - "tcp", - &rtsp_url_clone, - ]) - .creation_flags(CREATE_NO_WINDOW) - .spawn() - { + let mut cmd = Command::new("ffmpeg"); + + cmd.args(&[ + "-f", + "gdigrab", + "-i", + "desktop", + "-f", + "rtsp", + "-rtsp_transport", + "tcp", + &rtsp_url_clone, + ]); + + #[cfg(target_os = "windows")] + let mut child = match cmd.creation_flags(CREATE_NO_WINDOW).spawn() { Ok(child) => child, Err(e) => { - return ctx.callback_data("armatak_video_error", "Failed to Start FFmpeg", e.to_string()) + return ctx.callback_data( + "armatak_video_error", + "Failed to Start FFmpeg", + e.to_string(), + ); } }; @@ -54,7 +70,11 @@ pub fn start_stream( } Ok(if let Err(e) = child.kill() { - return ctx.callback_data("armatak_video_error", "Failed to Stop FFmpeg", e.to_string()) + return ctx.callback_data( + "armatak_video_error", + "Failed to Stop FFmpeg", + e.to_string(), + ); }) }); @@ -73,16 +93,25 @@ pub fn stop_stream(ctx: Context) -> &'static str { Ok(mut lock) => { if let Some(tx) = lock.take() { if let Err(e) = tx.send(()) { - let _ = ctx.callback_data("armatak_video_error", "Failed to send stop signal", e.to_string()); + let _ = ctx.callback_data( + "armatak_video_error", + "Failed to send stop signal", + e.to_string(), + ); } } else { - let _ = ctx.callback_null("armatak_video_error", "Tried to stop an unexistant stream"); + let _ = + ctx.callback_null("armatak_video_error", "Tried to stop a nonexistent stream"); } } Err(e) => { - let _ = ctx.callback_data("armatak_video_error", "Failed to acquire lock", e.to_string()); + let _ = ctx.callback_data( + "armatak_video_error", + "Failed to acquire lock", + e.to_string(), + ); } } - "starting video stream" + "stopping video stream" }