mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:13: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 arma_rs::Context;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::os::windows::process::CommandExt;
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref STREAM_CTRL: Mutex<Option<Sender<()>>> = Mutex::new(None);
|
static ref STREAM_CTRL: Mutex<Option<Sender<()>>> = Mutex::new(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
||||||
|
|
||||||
pub fn start_stream(
|
pub fn start_stream(
|
||||||
@@ -20,6 +23,14 @@ pub fn start_stream(
|
|||||||
username: String,
|
username: String,
|
||||||
password: String,
|
password: String,
|
||||||
) -> &'static str {
|
) -> &'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 (tx, rx): (Sender<()>, Receiver<()>) = mpsc::channel();
|
||||||
let rtsp_url = format!(
|
let rtsp_url = format!(
|
||||||
"rtsp://{}:{}@{}:{}/{}",
|
"rtsp://{}:{}@{}:{}/{}",
|
||||||
@@ -28,24 +39,29 @@ pub fn start_stream(
|
|||||||
let rtsp_url_clone = rtsp_url.clone();
|
let rtsp_url_clone = rtsp_url.clone();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut child = match Command::new("ffmpeg")
|
let mut cmd = Command::new("ffmpeg");
|
||||||
.args(&[
|
|
||||||
"-f",
|
cmd.args(&[
|
||||||
"gdigrab",
|
"-f",
|
||||||
"-i",
|
"gdigrab",
|
||||||
"desktop",
|
"-i",
|
||||||
"-f",
|
"desktop",
|
||||||
"rtsp",
|
"-f",
|
||||||
"-rtsp_transport",
|
"rtsp",
|
||||||
"tcp",
|
"-rtsp_transport",
|
||||||
&rtsp_url_clone,
|
"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,
|
Ok(child) => child,
|
||||||
Err(e) => {
|
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() {
|
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) => {
|
Ok(mut lock) => {
|
||||||
if let Some(tx) = lock.take() {
|
if let Some(tx) = lock.take() {
|
||||||
if let Err(e) = tx.send(()) {
|
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 {
|
} 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) => {
|
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