mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:43:29 +00:00
Added handling for letting only windows calls work and throw a callback when called form a linux on video streams
This commit is contained in:
@@ -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<Option<Sender<()>>> = 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,8 +39,9 @@ pub fn start_stream(
|
||||
let rtsp_url_clone = rtsp_url.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
let mut child = match Command::new("ffmpeg")
|
||||
.args(&[
|
||||
let mut cmd = Command::new("ffmpeg");
|
||||
|
||||
cmd.args(&[
|
||||
"-f",
|
||||
"gdigrab",
|
||||
"-i",
|
||||
@@ -39,13 +51,17 @@ pub fn start_stream(
|
||||
"-rtsp_transport",
|
||||
"tcp",
|
||||
&rtsp_url_clone,
|
||||
])
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.spawn()
|
||||
{
|
||||
]);
|
||||
|
||||
#[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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user