From 227d04549e6db7317d7363ef950697c64ff6ce8a Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Tue, 30 Jun 2020 22:33:53 -0500 Subject: [PATCH 1/4] Also execute build on pull requests --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a8ee505..e1c21f8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: [push, pull_request] jobs: ubuntu: From 558331339447ef8385095f74445282f28c41a8ea Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 2 Jul 2020 08:44:03 -0500 Subject: [PATCH 2/4] Refactor creating multiple-path streams This way, we don't stream from the Reolink camera more than once, and simply create multiple Gstreamer mountpoints for the underlying factory. --- src/gst.rs | 6 +++-- src/main.rs | 67 +++++++++++++++++++++++------------------------------ 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src/gst.rs b/src/gst.rs index 525ccfe..6c23509 100644 --- a/src/gst.rs +++ b/src/gst.rs @@ -32,7 +32,7 @@ impl RtspServer { } } - pub fn add_stream(&self, name: &str, stream_format: &StreamFormat) -> Result { + pub fn add_stream(&self, names: &[&str], stream_format: &StreamFormat) -> Result { let mounts = self .server .get_mount_points() @@ -77,7 +77,9 @@ impl RtspServer { let _ = tx.send(app_src); // Receiver may be dropped, don't panic if so }); - mounts.add_factory(&format!("/{}", name), &factory); + for name in names { + mounts.add_factory(&format!("/{}", name), &factory); + } Ok(maybe_app_src) } diff --git a/src/main.rs b/src/main.rs index ec7f9f1..d6cbc54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use neolink::gst::{MaybeAppSrc, RtspServer, StreamFormat}; use neolink::Never; use std::fs; use std::io::Write; +use std::sync::Arc; use std::time::Duration; use structopt::StructOpt; use validator::Validate; @@ -41,54 +42,44 @@ fn main() -> Result<(), Error> { ); let opt = Opt::from_args(); - let mut config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; + let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; match config.validate() { Ok(_) => (), Err(e) => return Err(Error::ValidationError(e)), }; - // Setup auto sub streams, we do this by looping the cameras - // If the stream type is both we clone the config - // On one of the clones we set stream_source to "mainStream" on the other "subStream" - // We also change the mount name by appending "/mainStream" or "/subStream" - // On the original uncloned config we change the stream from "both" to "mainStream" and leave the mount name unchanged - let mut new_cam_configs = vec![]; - - for camera_config in &mut config.cameras { - if camera_config.stream == "both" { - let mut main_camera_config = camera_config.clone(); - let mut sub_camera_config = camera_config.clone(); - - camera_config.stream = "mainStream".to_string(); - - main_camera_config.stream = "mainStream".to_string(); - main_camera_config.name = format!("{}/{}", main_camera_config.name, main_camera_config.stream); - new_cam_configs.push(main_camera_config); - - sub_camera_config.stream = "subStream".to_string(); - sub_camera_config.name = format!("{}/{}", sub_camera_config.name, sub_camera_config.stream); - sub_camera_config.format = "h264".to_string(); // Assuming always H264 on subStream: TODO: Autodetect - new_cam_configs.push(sub_camera_config); - } - } - config.cameras.append(&mut new_cam_configs); - let rtsp = &RtspServer::new(); crossbeam::scope(|s| { for camera in config.cameras { - s.spawn(move |_| { - // TODO handle these errors - 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) - }); + let stream_format = match &*camera.format { + "h264"|"H264" => StreamFormat::H264, + "h265"|"H265" => StreamFormat::H265, + custom_format @ _ => StreamFormat::Custom(custom_format.to_string()) + }; + + // Let subthreads share the camera object; in principle I think they could share + // the object as it sits in the config.cameras block, but I have not figured out the + // syntax for that. + let arc_cam = Arc::new(camera); + + // Set up each main and substream according to all the RTSP mount paths we support + if arc_cam.stream == "both" || arc_cam.stream == "mainStream" { + let paths = &[ + &arc_cam.name, + &*format!("{}/mainStream", arc_cam.name), + ]; + let mut output = rtsp.add_stream(paths, &stream_format).unwrap(); + let main_camera = arc_cam.clone(); + s.spawn(move |_| camera_loop(&*main_camera, &mut output)); + } + if arc_cam.stream == "both" || arc_cam.stream == "subStream" { + let paths = &[&*format!("{}/subStream", arc_cam.name)]; + let mut output = rtsp.add_stream(paths, &stream_format).unwrap(); + let sub_camera = arc_cam.clone(); + s.spawn(move |_| camera_loop(&*sub_camera, &mut output)); + } } rtsp.run(&config.bind_addr, config.bind_port); From a562dcdba28a1b7f7571d500cfd8ad411d615b7e Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 2 Jul 2020 08:49:00 -0500 Subject: [PATCH 3/4] Reword readme --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b26233c..aabf432 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,12 @@ Copy and modify the `sample_config.toml` to specify the address, username, and p Each `[[cameras]]` block creates a new camera; the `name` determines the RTSP path you should connect your client to. Currently Neolink cannot auto-detect cameras like the official clients do; you must specify their IP addresses directly. -By default the h265 streaming format is used. Some cameras, for example E1, provide h264 streams, to use these you must specify `format = "h264"` in the `[[cameras]]` config. +By default the H265 video format is used. Some cameras, for example E1, provide H264 streams. To use these you must specify `format = "h264"` in the `[[cameras]]` config. +Soon this will be auto-detected, and you will not have to know or care about the format. -By default the HD stream is mounted at `name` and at `name/mainStream` and the SD stream is mounted at `name/subStream`. You can specify mounting only one by adding `stream = "subStream"` to the `[[cameras]]` config. You may also need to use `h264` format while using the SD stream. +By default, the HD stream is available at the RTSP path `/name` or `/name/mainStream`, and the SD stream is available at `/name/subStream`. +You can disable the HD stream by adding `stream = "subStream"` to the `[[cameras]]` config. +You may also need to use `h264` format while using the SD stream. By default Neolink serves on all IP addresses on port 8554. You can modify this by changing the `bind` and the `bind_port` parameter. From 22e2dfbed3088bdaa36303d7801fded686c5930b Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Thu, 2 Jul 2020 08:55:50 -0500 Subject: [PATCH 4/4] Hooray, E1 is officially tested, and VLC is happy --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index aabf432..d0e858b 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Neolink intends to support all Reolink cameras that do not provide native RTSP. Currently it has been tested on the following cameras: - B800/D800 +- E1 It *should* support the following cameras, but this has not yet been tested. Please test if you have them, and [open an issue](https://github.com/thirtythreeforty/neolink/issues/new/choose) if you encounter problems: - B400/D400 -- E1 - Lumus Neolink does not support other cameras such as the RLC-420, since they already [provide native RTSP](https://support.reolink.com/hc/en-us/articles/360007010473-How-to-Live-View-Reolink-Cameras-via-VLC-Media-Player). @@ -89,14 +89,11 @@ export RUST_LOG=debug Connect your RTSP client to the stream with the name you provided in the configuration file. Again, the default URL is `rtsp://127.0.0.1:8554/your_camera_name` if you're running it on the same computer as the client. +The smaller SD video is `rtsp://127.0.0.1:8554/your_camera_name/subStream`. 4K cameras send large video "key frames" once every few seconds and the client must have a receive buffer large enough to store the entire frame. If your client's buffer size is configurable (like Blue Iris), ensure it's set to 20MB, which should ensure plenty of headroom. -Note that some RTSP clients, especially VLC, have trouble handling the stream. -Currently this seems to be related to receive buffer sizes but the exact cause remains unclear. -Blue Iris is known to work well. - ## Stability Neolink has had minimal testing, but it seems to be very reliable in multiple users' testing.