@@ -25,65 +25,56 @@ pub fn start_stream(
2525) -> & ' static str {
2626 #[ cfg( target_os = "linux" ) ]
2727 {
28- return ctx. callback_null (
28+ ctx. callback_null (
2929 "armatak_video_error" ,
3030 "Screen capture is only supported on Windows" ,
3131 ) ;
3232 }
3333
34- let ( tx, rx) : ( Sender < ( ) > , Receiver < ( ) > ) = mpsc:: channel ( ) ;
35- let rtsp_url = format ! (
36- "rtsp://{}:{}@{}:{}/{}" ,
37- username, password, address, port, stream_path
38- ) ;
39- let rtsp_url_clone = rtsp_url. clone ( ) ;
34+ #[ cfg( target_os = "windows" ) ]
35+ {
36+ let ( tx, rx) : ( Sender < ( ) > , Receiver < ( ) > ) = mpsc:: channel ( ) ;
37+ let rtsp_url = format ! (
38+ "rtsp://{}:{}@{}:{}/{}" ,
39+ username, password, address, port, stream_path
40+ ) ;
41+ let rtsp_url_clone = rtsp_url. clone ( ) ;
4042
41- thread:: spawn ( move || {
42- let mut cmd = Command :: new ( "ffmpeg" ) ;
43+ thread:: spawn ( move || {
44+ let mut cmd = Command :: new ( "ffmpeg" ) ;
4345
44- cmd. args ( & [
45- "-f" ,
46- "gdigrab" ,
47- "-i" ,
48- "desktop" ,
49- "-f" ,
50- "rtsp" ,
51- "-rtsp_transport" ,
52- "tcp" ,
53- & rtsp_url_clone,
54- ] ) ;
46+ cmd. args ( & [
47+ "-f" ,
48+ "gdigrab" ,
49+ "-i" ,
50+ "desktop" ,
51+ "-f" ,
52+ "rtsp" ,
53+ "-rtsp_transport" ,
54+ "tcp" ,
55+ & rtsp_url_clone,
56+ ] ) ;
5557
56- #[ cfg( target_os = "windows" ) ]
57- let mut child = match cmd. creation_flags ( CREATE_NO_WINDOW ) . spawn ( ) {
58- Ok ( child) => child,
59- Err ( e) => {
58+ let mut child = cmd. creation_flags ( CREATE_NO_WINDOW ) . spawn ( ) . unwrap ( ) ;
59+
60+ if rx. recv ( ) . is_err ( ) {
61+ let _ = ctx. callback_null ( "armatak_video_error" , "Error receiving stop signal" ) ;
62+ }
63+
64+ if let Err ( e) = child. kill ( ) {
6065 let _ = ctx. callback_data (
6166 "armatak_video_error" ,
62- "Failed to Start FFmpeg" ,
67+ "Failed to Stop FFmpeg" ,
6368 e. to_string ( ) ,
6469 ) ;
65- return ;
6670 }
67- } ;
68-
69- if rx. recv ( ) . is_err ( ) {
70- let _ = ctx. callback_null ( "armatak_video_error" , "Error receiving stop signal" ) ;
71- }
72-
73- #[ cfg( target_os = "windows" ) ]
74- if let Err ( e) = child. kill ( ) {
75- let _ = ctx. callback_data (
76- "armatak_video_error" ,
77- "Failed to Stop FFmpeg" ,
78- e. to_string ( ) ,
79- ) ;
80- }
81- } ) ;
71+ } ) ;
8272
83- match STREAM_CTRL . lock ( ) {
84- Ok ( mut lock) => * lock = Some ( tx) ,
85- Err ( e) => {
86- eprintln ! ( "Failed to acquire lock: {}" , e) ;
73+ match STREAM_CTRL . lock ( ) {
74+ Ok ( mut lock) => * lock = Some ( tx) ,
75+ Err ( e) => {
76+ eprintln ! ( "Failed to acquire lock: {}" , e) ;
77+ }
8778 }
8879 }
8980
0 commit comments