Change the fps of the repeat iframes

This commit is contained in:
QuantumEntangledAndy committed 2023-10-17 10:42:13 +07:00
1 parent 5871d0566d
commit c8f8f2bd9d
4 files changed
+34 -10

No files matched your search

+1
View File
@@ -35,6 +35,7 @@ RUN echo "TARGETPLATFORM: ${TARGETPLATFORM}"; \
apt-get install -y --no-install-recommends \
build-essential \
openssl \
libssl-dev \
ca-certificates \
libgstrtspserver-1.0-dev \
libgstreamer1.0-dev \
+18 -4
View File
@@ -257,6 +257,7 @@ pub(crate) struct StreamConfig {
pub(crate) vid_format: VidFormat,
pub(crate) aud_format: AudFormat,
pub(crate) bitrate: u32,
pub(crate) fps: u32,
}
impl StreamConfig {
@@ -323,7 +324,7 @@ impl StreamData {
let vid_history = Arc::new(vid_history);
let (aud_history, _) = watch::<VecDeque<StampedData>>(VecDeque::new());
let aud_history = Arc::new(aud_history);
let (resolution, bitrate) = instance
let (resolution, bitrate, fps, fps_table) = instance
.run_passive_task(|cam| {
Box::pin(async move {
let infos = cam
@@ -344,9 +345,15 @@ impl StreamData {
.copied()
.unwrap_or(encode.default_bitrate)
* 1024,
encode
.framerate_table
.get(encode.default_framerate as usize)
.copied()
.unwrap_or(encode.default_framerate),
encode.framerate_table.clone(),
))
} else {
Ok(([0, 0], 0))
Ok(([0, 0], 0, 0, vec![]))
}
})
})
@@ -356,6 +363,7 @@ impl StreamData {
vid_format: VidFormat::None,
aud_format: AudFormat::None,
bitrate,
fps,
});
let mut me = Self {
name,
@@ -421,6 +429,7 @@ impl StreamData {
let vid_history = vid_history.clone();
let aud_history = aud_history.clone();
let watchdog_tx = watchdog_tx.clone();
let fps_table = fps_table.clone();
log::debug!("Running Stream Instance Task");
Box::pin(async move {
@@ -428,6 +437,7 @@ impl StreamData {
// let mut file = std::fs::File::create("reference.h264")?;
let mut recieved_iframe = false;
let mut aud_keyframe = false;
let res = async {
let mut prev_ts = Duration::ZERO;
let mut stream_data = camera.start_video(name, 0, strict).await?;
@@ -440,9 +450,11 @@ impl StreamData {
match &data {
BcMedia::InfoV1(info) => {
stream_config.send_if_modified(|state| {
if state.resolution[0] != info.video_width || state.resolution[1] != info.video_height {
let new_fps = fps_table.get(info.fps as usize).copied().unwrap_or(info.fps as u32);
if state.resolution[0] != info.video_width || state.resolution[1] != info.video_height || new_fps != state.fps {
state.resolution[0] = info.video_width;
state.resolution[1] = info.video_height;
state.fps = new_fps;
true
} else {
false
@@ -451,9 +463,11 @@ impl StreamData {
},
BcMedia::InfoV2(info) => {
stream_config.send_if_modified(|state| {
if state.resolution[0] != info.video_width || state.resolution[1] != info.video_height {
let new_fps = fps_table.get(info.fps as usize).copied().unwrap_or(info.fps as u32);
if state.resolution[0] != info.video_width || state.resolution[1] != info.video_height || new_fps != state.fps {
state.resolution[0] = info.video_width;
state.resolution[1] = info.video_height;
state.fps = new_fps;
true
} else {
false
+6 -5
View File
@@ -177,10 +177,10 @@ fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
.map_err(|_| anyhow!("Cannot cast back"))?;
let queue = make_queue("source_queue", buffer_size)?;
let parser = make_element("h264parse", "parser")?;
// parser.set_property("config-interval", -1i32); // Send SPS and PPS every Iframe to imporove joining frame late
let stamper = make_element("h264timestamper", "stamper")?;
let payload = make_element("rtph264pay", "pay0")?;
bin.add_many([&source, &queue, &parser, &payload])?;
Element::link_many([&source, &queue, &parser, &payload])?;
bin.add_many([&source, &queue, &parser, &stamper, &payload])?;
Element::link_many([&source, &queue, &parser, &stamper, &payload])?;
let source = source
.dynamic_cast::<AppSrc>()
@@ -212,9 +212,10 @@ fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
.map_err(|_| anyhow!("Cannot cast back"))?;
let queue = make_queue("source_queue", buffer_size)?;
let parser = make_element("h265parse", "parser")?;
let stamper = make_element("h265timestamper", "stamper")?;
let payload = make_element("rtph265pay", "pay0")?;
bin.add_many([&source, &queue, &parser, &payload])?;
Element::link_many([&source, &queue, &parser, &payload])?;
bin.add_many([&source, &queue, &parser, &stamper, &payload])?;
Element::link_many([&source, &queue, &parser, &stamper, &payload])?;
let source = source
.dynamic_cast::<AppSrc>()
+9 -1
View File
@@ -390,6 +390,10 @@ async fn stream_run(
let vid_data_rx = BroadcastStream::new(vid_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged
let thread_vid = vid.clone();
let mut thread_client_count = client_count.subscribe();
log::debug!("stream_config.fps: {}", stream_config.fps);
let fallback_time = Duration::from_secs(3);
let fallback_framerate =
Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64));
if let Some(thread_vid) = thread_vid {
set.spawn(async move {
thread_client_count.activate().await?;
@@ -406,7 +410,8 @@ async fn stream_run(
)
)
),
Duration::from_secs(3)
fallback_time,
fallback_framerate,
),
&thread_vid) => {
v
@@ -565,6 +570,7 @@ fn frametime_stream<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
mut stream: T,
fallback_time: Duration,
frame_rate: Duration,
) -> impl Stream<Item = Result<StampedData, E>> + Unpin {
Box::pin(async_stream::stream! {
while let Some(frame) = stream.next().await {
@@ -575,6 +581,7 @@ fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
yield Ok(frame);
// Wait for either timeout or a new frame
let mut fallback_time = fallback_time;
loop {
tokio::select!{
v = stream.next() => {
@@ -589,6 +596,7 @@ fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
}
},
_ = sleep(fallback_time) => {
fallback_time = frame_rate;
log::debug!("Inserting Skip Frame");
yield Ok(repeater.clone());
}