@@ -9,7 +9,7 @@ use gstreamer_rtsp_server::{
99} ;
1010use structopt:: StructOpt ;
1111
12- use pipe_builder:: { Encoder , Input , VideoSize } ;
12+ use pipe_builder:: { Encoder , Input , Pipe , VideoSize } ;
1313
1414#[ derive( Debug , StructOpt ) ]
1515#[ structopt(
@@ -34,9 +34,10 @@ struct Opt {
3434 long,
3535 help = "Input mode to use" ,
3636 required_unless = "list" ,
37+ required_unless = "pipes-as-json" ,
3738 possible_values( & [ "v4l2" , "shmem" , "rpi" ] )
3839 ) ]
39- input : Input ,
40+ input : Option < Input > , // this looks stupid, but some library freaks out without it. we get the desired effect at run anyway
4041 #[ structopt(
4142 short,
4243 long,
@@ -54,6 +55,8 @@ struct Opt {
5455 default_value_if( "input" , Some ( "rpi" ) , "camera" )
5556 ) ]
5657 encoder : Encoder ,
58+ #[ structopt( long, help = "Pipelines to run as JSON." ) ]
59+ pipes_as_json : Option < String > ,
5760 #[ structopt( long, help = "List all input modes and exit." , group = "list" ) ]
5861 list_in : bool ,
5962 #[ structopt( long, help = "List all encoders and exit." , group = "list" ) ]
@@ -79,30 +82,46 @@ fn main() {
7982 }
8083 return ;
8184 }
82- // try to set up video size
83- let size = VideoSize :: new ( opt. width , opt. height , opt. framerate ) ;
84- let device = opt. device . unwrap_or ( "" . to_string ( ) ) ;
85- let mut input = opt. input ;
86- input = match input {
87- Input :: Video4Linux ( _) => Input :: Video4Linux ( device) ,
88- Input :: SharedMemory ( _) => Input :: SharedMemory ( device) ,
89- _ => input,
90- } ;
91- let encoder = opt. encoder ;
92- let pipe = pipe_builder:: create_pipe ( input, encoder, size) ;
93- println ! ( "Pipeline constructed: {}" , pipe) ;
85+ // set up basic Gst stuff
9486 gstreamer:: init ( ) . expect ( "GStreamer could not init!" ) ;
9587 let loop_ = MainLoop :: new ( Option :: None , false ) ;
9688 let server = RTSPServer :: new ( ) ;
9789 server. set_service ( & opt. net_opt . get_port ( ) . to_string ( ) ) ;
98- let factory = RTSPMediaFactory :: new ( ) ;
99- factory. set_launch ( & pipe) ;
100- factory. set_shared ( true ) ;
10190 let mounts = server
10291 . get_mount_points ( )
10392 . expect ( "Failed to get mount points" ) ;
104- // set up mounts
105- mounts. add_factory ( opt. net_opt . get_url ( ) , & factory) ;
93+ if opt. pipes_as_json . is_some ( ) {
94+ let config = opt. pipes_as_json . unwrap ( ) ;
95+ let pipes: Vec < Pipe > = serde_json:: from_str ( & config) . expect ( "JSON could not parse!" ) ;
96+ println ! ( "{:#?}" , pipes) ;
97+ for pipe in pipes. iter ( ) {
98+ let factory = RTSPMediaFactory :: new ( ) ;
99+ let pipe_str = pipe_builder:: create_pipe ( pipe) ;
100+ println ! ( "Pipeline constructed: {}" , pipe_str) ;
101+ factory. set_launch ( & pipe_str) ;
102+ factory. set_shared ( true ) ;
103+ mounts. add_factory ( pipe. url ( ) , & factory) ;
104+ }
105+ } else {
106+ // try to set up video size
107+ let size = VideoSize :: new ( opt. width , opt. height , opt. framerate ) ;
108+ let device = opt. device . unwrap_or ( "" . to_string ( ) ) ;
109+ let mut input = opt. input . unwrap ( ) ;
110+ input = match input {
111+ Input :: Video4Linux ( _) => Input :: Video4Linux ( device) ,
112+ Input :: SharedMemory ( _) => Input :: SharedMemory ( device) ,
113+ _ => input,
114+ } ;
115+ let encoder = opt. encoder ;
116+ let pipe = Pipe :: new ( input, encoder, size, String :: from ( opt. net_opt . get_url ( ) ) ) ;
117+ let pipe_str = pipe_builder:: create_pipe ( & pipe) ;
118+ println ! ( "Pipeline constructed: {}" , pipe_str) ;
119+ let factory = RTSPMediaFactory :: new ( ) ;
120+ factory. set_launch ( & pipe_str) ;
121+ factory. set_shared ( true ) ;
122+ // set up mounts
123+ mounts. add_factory ( pipe. url ( ) , & factory) ;
124+ }
106125 server. attach ( Option :: None ) ;
107126 println ! ( "Starting loop..." ) ;
108127 loop_. run ( ) ;
0 commit comments