Allowing custom gst-launches and specification of format in the camera

This commit is contained in:
QuantumEntangledAndy committed 2020-06-30 11:30:24 +07:00
1 parent 63875d1175
commit 826814abd7
3 files changed
+24 -6

No files matched your search

+7
View File
@@ -21,8 +21,15 @@ pub struct CameraConfig {
pub password: Option<String>,
pub timeout: Option<Duration>,
#[serde(default = "default_format")]
pub format: String,
}
fn default_bind_addr() -> String {
"0.0.0.0".to_string()
}
fn default_format() -> String {
"h265".to_string()
}
+4 -5
View File
@@ -26,7 +26,7 @@ impl RtspServer {
}
}
pub fn add_stream(&self, name: &str) -> Result<MaybeAppSrc> {
pub fn add_stream(&self, name: &str, launch: &str) -> Result<MaybeAppSrc> {
let mounts = self
.server
.get_mount_points()
@@ -34,11 +34,10 @@ impl RtspServer {
let factory = RTSPMediaFactory::new();
//factory.set_protocols(RTSPLowerTrans::TCP);
factory.set_launch(concat!(
factory.set_launch(&format!("{}{}{}{}",
"( ",
"appsrc name=writesrc is-live=true block=true emit-signals=false max-bytes=0",
" ! h265parse",
" ! rtph265pay name=pay0",
"appsrc name=writesrc is-live=true block=true emit-signals=false max-bytes=0 ",
launch,
" )"
));
factory.set_shared(true);
+13 -1
View File
@@ -43,7 +43,19 @@ fn main() -> Result<(), Error> {
for camera in config.cameras {
s.spawn(move |_| {
// TODO handle these errors
let mut output = rtsp.add_stream(&camera.name).unwrap();
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();
camera_loop(&camera, &mut output)
});
}