Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sample_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
50 changes: 34 additions & 16 deletions src/rtsp/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct StreamConfig {
fps_table: Vec<u32>,
vid_type: Option<VideoType>,
aud_type: Option<AudioType>,
enable_low_latency: bool,
}
impl StreamConfig {
async fn new(instance: &NeoInstance, name: StreamKind) -> AnyResult<Self> {
Expand Down Expand Up @@ -84,6 +85,8 @@ impl StreamConfig {
})
.await?;

let enable_low_latency = instance.config().await?.borrow().enable_low_latency;

Ok(StreamConfig {
resolution,
bitrate,
Expand All @@ -92,6 +95,7 @@ impl StreamConfig {
bitrate_table,
vid_type: None,
aud_type: None,
enable_low_latency,
})
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -522,7 +530,9 @@ fn pipe_h264(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {

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);
Expand Down Expand Up @@ -573,7 +583,9 @@ fn pipe_h265(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {
.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);
Expand Down Expand Up @@ -626,7 +638,9 @@ fn pipe_aac(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {

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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -784,7 +800,9 @@ fn pipe_silence(bin: &Element, stream_config: &StreamConfig) -> Result<Linked> {

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);
Expand Down