From 6572be1d95014d329d5c9daf636ee91b11a0beba Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 16 Apr 2024 10:09:43 +0700 Subject: [PATCH] Change latency and queue buffers --- src/rtsp/factory.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rtsp/factory.rs b/src/rtsp/factory.rs index ef2720d..4b5b4a1 100644 --- a/src/rtsp/factory.rs +++ b/src/rtsp/factory.rs @@ -172,7 +172,7 @@ fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result { source.set_is_live(false); source.set_block(false); - source.set_min_latency(0); + 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); @@ -206,7 +206,7 @@ fn build_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(0); + 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); @@ -228,7 +228,7 @@ fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result { Ok(source) } -fn build_aac(bin: &Element, _stream_config: &StreamConfig) -> Result { +fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result { let buffer_size = 512 * 6; let bin = bin .clone() @@ -241,7 +241,7 @@ fn build_aac(bin: &Element, _stream_config: &StreamConfig) -> Result { source.set_is_live(false); source.set_block(false); - source.set_min_latency(0); + 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); @@ -293,7 +293,7 @@ fn build_aac(bin: &Element, _stream_config: &StreamConfig) -> Result { Ok(source) } -fn build_adpcm(bin: &Element, block_size: u32, _stream_config: &StreamConfig) -> Result { +fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result { let buffer_size = 512 * 6; let bin = bin .clone() @@ -312,7 +312,7 @@ fn build_adpcm(bin: &Element, block_size: u32, _stream_config: &StreamConfig) -> .map_err(|_| anyhow!("Cannot cast to appsrc."))?; source.set_is_live(false); source.set_block(false); - source.set_min_latency(0); + 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); @@ -447,5 +447,5 @@ fn make_queue(name: &str, buffer_size: u32) -> AnyResult { fn buffer_size(bitrate: u32) -> u32 { // 0.1 seconds (according to bitrate) or 4kb what ever is larger - std::cmp::max(bitrate / 10u32 / 8u32, 4u32 * 1024u32) + std::cmp::max(bitrate * 2 / 8u32, 4u32 * 1024u32) }