Moved gst launch str to gst and using enums
This commit is contained in:
2 files changed
+21
-15
No files matched your search
+14
-2
@@ -18,6 +18,12 @@ pub struct RtspServer {
|
||||
server: GstRTSPServer,
|
||||
}
|
||||
|
||||
pub enum StreamFormat {
|
||||
H264,
|
||||
H265,
|
||||
Custom(String)
|
||||
}
|
||||
|
||||
impl RtspServer {
|
||||
pub fn new() -> RtspServer {
|
||||
gstreamer::init().expect("Gstreamer should not explode");
|
||||
@@ -26,18 +32,24 @@ impl RtspServer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_stream(&self, name: &str, launch: &str) -> Result<MaybeAppSrc> {
|
||||
pub fn add_stream(&self, name: &str, stream_format: &StreamFormat) -> Result<MaybeAppSrc> {
|
||||
let mounts = self
|
||||
.server
|
||||
.get_mount_points()
|
||||
.expect("The server should have mountpoints");
|
||||
|
||||
let launch_str = match stream_format {
|
||||
StreamFormat::H264 => "! h264parse ! rtph264pay name=pay0",
|
||||
StreamFormat::H265 => "! h265parse ! rtph265pay name=pay0",
|
||||
StreamFormat::Custom(custom_format) => custom_format,
|
||||
};
|
||||
|
||||
let factory = RTSPMediaFactory::new();
|
||||
//factory.set_protocols(RTSPLowerTrans::TCP);
|
||||
factory.set_launch(&format!("{}{}{}{}",
|
||||
"( ",
|
||||
"appsrc name=writesrc is-live=true block=true emit-signals=false max-bytes=0 do-timestamp=true ",
|
||||
launch,
|
||||
launch_str,
|
||||
" )"
|
||||
));
|
||||
factory.set_shared(true);
|
||||
|
||||
+7
-13
@@ -56,19 +56,13 @@ fn main() -> Result<(), Error> {
|
||||
for camera in config.cameras {
|
||||
s.spawn(move |_| {
|
||||
// TODO handle these errors
|
||||
let mut format :&str = &camera.format;
|
||||
if format == "h265" {
|
||||
format = "! h265parse ! rtph265pay name=pay0";
|
||||
} else if format == "h264" {
|
||||
format = "! h264parse ! rtph264pay name=pay0";
|
||||
} else {
|
||||
if format.trim().starts_with("!") {
|
||||
warn!("Using custom format: {}.", format);
|
||||
} else {
|
||||
error!("Unrecognised format: {}.", format);
|
||||
}
|
||||
}
|
||||
let mut output = rtsp.add_stream(&camera.name, &format).unwrap();
|
||||
let cam_format :&str = &camera.format;
|
||||
let stream_format = match cam_format {
|
||||
"h264"|"H264" => StreamFormat::H264,
|
||||
"h265"|"H265" => StreamFormat::H265,
|
||||
custom_format @ _ => StreamFormat::Custom(custom_format.to_string())
|
||||
};
|
||||
let mut output = rtsp.add_stream(&camera.name, &stream_format).unwrap();
|
||||
camera_loop(&camera, &mut output)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user