diff --git a/sample_config.toml b/sample_config.toml index 85a7ea843..64ff1d3fd 100644 --- a/sample_config.toml +++ b/sample_config.toml @@ -41,6 +41,10 @@ name = "driveway" username = "admin" password = "12345678" address = "192.168.1.187:9000" + +# enable_audio = true +# enable_low_latency = true + # MQTT Discovery: https://www.home-assistant.io/integrations/mqtt/#mqtt-discovery # mqtt.discovery.topic = "homeassistant" # Uncomment to enable # If using discovery, _ characters are replaced with spaces in the name and title case is applied @@ -90,6 +94,11 @@ name = "storage shed" username = "admin" password = "987654321" address = "192.168.1.245:9000" + +# Performance optimizations: reduce CPU overhead +# enable_audio = true +# enable_low_latency = true + # If you use a battery camera: **Instead** of an `address` supply the uid # as follows # uid = "ABCD01234567890EFG" diff --git a/src/config.rs b/src/config.rs index 6ca22ad2c..b535037ed 100644 --- a/src/config.rs +++ b/src/config.rs @@ -218,6 +218,12 @@ pub(crate) struct CameraConfig { #[serde(default = "default_false", alias = "idle", alias = "idle_disc")] pub(crate) idle_disconnect: bool, + + #[serde(default = "default_true", alias = "audio")] + pub(crate) enable_audio: bool, + + #[serde(default = "default_false", alias = "low_latency")] + pub(crate) enable_low_latency: bool, } #[derive(Debug, Deserialize, Serialize, Validate, Clone, PartialEq, Eq, Hash)] diff --git a/src/rtsp/factory.rs b/src/rtsp/factory.rs index 9ba058eed..a66f1b381 100644 --- a/src/rtsp/factory.rs +++ b/src/rtsp/factory.rs @@ -30,6 +30,7 @@ struct StreamConfig { fps_table: Vec, vid_type: Option, aud_type: Option, + enable_low_latency: bool, } impl StreamConfig { async fn new(instance: &NeoInstance, name: StreamKind) -> AnyResult { @@ -84,6 +85,8 @@ impl StreamConfig { }) .await?; + let enable_low_latency = instance.config().await?.borrow().enable_low_latency; + Ok(StreamConfig { resolution, bitrate, @@ -92,6 +95,7 @@ impl StreamConfig { bitrate_table, vid_type: None, aud_type: None, + enable_low_latency, }) } @@ -209,17 +213,21 @@ pub(super) async fn make_factory( }?; // Build the right audio pipeline - let aud_src = match stream_config.aud_type.as_ref() { - Some(AudioType::Aac) => { - let src = build_aac(&element, &stream_config)?; - AnyResult::Ok(Some(src)) - } - Some(AudioType::Adpcm(block_size)) => { - let src = build_adpcm(&element, *block_size, &stream_config)?; - AnyResult::Ok(Some(src)) - } - None => AnyResult::Ok(None), - }?; + let aud_src = if config.enable_audio { + match stream_config.aud_type.as_ref() { + Some(AudioType::Aac) => { + let src = build_aac(&element, &stream_config)?; + AnyResult::Ok(Some(src)) + } + Some(AudioType::Adpcm(block_size)) => { + let src = build_adpcm(&element, *block_size, &stream_config)?; + AnyResult::Ok(Some(src)) + } + None => AnyResult::Ok(None), + }? + } else { + None + }; if let Some(app) = vid_src.as_ref() { app.set_callbacks( @@ -522,7 +530,9 @@ fn pipe_h264(bin: &Element, stream_config: &StreamConfig) -> Result { source.set_is_live(false); source.set_block(false); - source.set_min_latency(1000 / (stream_config.fps as i64)); + if stream_config.enable_low_latency { + source.set_min_latency(1000 / (stream_config.fps as i64)); + } source.set_property("emit-signals", false); source.set_max_bytes(buffer_size as u64); source.set_do_timestamp(false); @@ -573,7 +583,9 @@ fn pipe_h265(bin: &Element, stream_config: &StreamConfig) -> Result { .map_err(|_| anyhow!("Cannot cast to appsrc."))?; source.set_is_live(false); source.set_block(false); - source.set_min_latency(1000 / (stream_config.fps as i64)); + if stream_config.enable_low_latency { + source.set_min_latency(1000 / (stream_config.fps as i64)); + } source.set_property("emit-signals", false); source.set_max_bytes(buffer_size as u64); source.set_do_timestamp(false); @@ -626,7 +638,9 @@ fn pipe_aac(bin: &Element, stream_config: &StreamConfig) -> Result { source.set_is_live(false); source.set_block(false); - source.set_min_latency(1000 / (stream_config.fps as i64)); + if stream_config.enable_low_latency { + source.set_min_latency(1000 / (stream_config.fps as i64)); + } source.set_property("emit-signals", false); source.set_max_bytes(buffer_size as u64); source.set_do_timestamp(false); @@ -712,7 +726,9 @@ fn pipe_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> R .map_err(|_| anyhow!("Cannot cast to appsrc."))?; source.set_is_live(false); source.set_block(false); - source.set_min_latency(1000 / (stream_config.fps as i64)); + if stream_config.enable_low_latency { + source.set_min_latency(1000 / (stream_config.fps as i64)); + } source.set_property("emit-signals", false); source.set_max_bytes(buffer_size as u64); source.set_do_timestamp(false); @@ -784,7 +800,9 @@ fn pipe_silence(bin: &Element, stream_config: &StreamConfig) -> Result { source.set_is_live(false); source.set_block(false); - source.set_min_latency(1000 / (stream_config.fps as i64)); + if stream_config.enable_low_latency { + source.set_min_latency(1000 / (stream_config.fps as i64)); + } source.set_property("emit-signals", false); source.set_max_bytes(buffer_size as u64); source.set_do_timestamp(false);