mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:23:28 +00:00
separed video stream oss in scopes
This commit is contained in:
@@ -25,65 +25,56 @@ pub fn start_stream(
|
|||||||
) -> &'static str {
|
) -> &'static str {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
return ctx.callback_null(
|
ctx.callback_null(
|
||||||
"armatak_video_error",
|
"armatak_video_error",
|
||||||
"Screen capture is only supported on Windows",
|
"Screen capture is only supported on Windows",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (tx, rx): (Sender<()>, Receiver<()>) = mpsc::channel();
|
#[cfg(target_os = "windows")]
|
||||||
let rtsp_url = format!(
|
{
|
||||||
"rtsp://{}:{}@{}:{}/{}",
|
let (tx, rx): (Sender<()>, Receiver<()>) = mpsc::channel();
|
||||||
username, password, address, port, stream_path
|
let rtsp_url = format!(
|
||||||
);
|
"rtsp://{}:{}@{}:{}/{}",
|
||||||
let rtsp_url_clone = rtsp_url.clone();
|
username, password, address, port, stream_path
|
||||||
|
);
|
||||||
|
let rtsp_url_clone = rtsp_url.clone();
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut cmd = Command::new("ffmpeg");
|
let mut cmd = Command::new("ffmpeg");
|
||||||
|
|
||||||
cmd.args(&[
|
cmd.args(&[
|
||||||
"-f",
|
"-f",
|
||||||
"gdigrab",
|
"gdigrab",
|
||||||
"-i",
|
"-i",
|
||||||
"desktop",
|
"desktop",
|
||||||
"-f",
|
"-f",
|
||||||
"rtsp",
|
"rtsp",
|
||||||
"-rtsp_transport",
|
"-rtsp_transport",
|
||||||
"tcp",
|
"tcp",
|
||||||
&rtsp_url_clone,
|
&rtsp_url_clone,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
let mut child = cmd.creation_flags(CREATE_NO_WINDOW).spawn().unwrap();
|
||||||
let mut child = match cmd.creation_flags(CREATE_NO_WINDOW).spawn() {
|
|
||||||
Ok(child) => child,
|
if rx.recv().is_err() {
|
||||||
Err(e) => {
|
let _ = ctx.callback_null("armatak_video_error", "Error receiving stop signal");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = child.kill() {
|
||||||
let _ = ctx.callback_data(
|
let _ = ctx.callback_data(
|
||||||
"armatak_video_error",
|
"armatak_video_error",
|
||||||
"Failed to Start FFmpeg",
|
"Failed to Stop FFmpeg",
|
||||||
e.to_string(),
|
e.to_string(),
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
if rx.recv().is_err() {
|
match STREAM_CTRL.lock() {
|
||||||
let _ = ctx.callback_null("armatak_video_error", "Error receiving stop signal");
|
Ok(mut lock) => *lock = Some(tx),
|
||||||
}
|
Err(e) => {
|
||||||
|
eprintln!("Failed to acquire lock: {}", e);
|
||||||
#[cfg(target_os = "windows")]
|
}
|
||||||
if let Err(e) = child.kill() {
|
|
||||||
let _ = ctx.callback_data(
|
|
||||||
"armatak_video_error",
|
|
||||||
"Failed to Stop FFmpeg",
|
|
||||||
e.to_string(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
match STREAM_CTRL.lock() {
|
|
||||||
Ok(mut lock) => *lock = Some(tx),
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Failed to acquire lock: {}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user