From 44fc744dcdf152b171d69d501ff160aacd188e2d Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Tue, 3 Oct 2023 08:46:41 +0700 Subject: [PATCH] Variable openssl path for windows --- .github/workflows/build.yml | 3 ++ src/rtsp/mod.rs | 58 +++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff3b968..43051cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,6 +51,9 @@ jobs: Add-Content -Path $env:GITHUB_PATH -Value "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64\bin" Add-Content -Path $env:GITHUB_PATH -Value "%GSTREAMER_1_0_ROOT_MSVC_X86_64%\bin" $env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL-Win64\' + if (-not (Test-Path -Path "$env:OPENSSL_DIR" -PathType Container)) { + $env:OPENSSL_DIR=$env:SYSTEMDRIVE + '\Program Files\OpenSSL\' + } dir "$env:GSTREAMER_1_0_ROOT_MSVC_X86_64" dir "$env:OPENSSL_DIR" Add-Content -Path $env:GITHUB_ENV -Value "OPENSSL_DIR=$env:OPENSSL_DIR" diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index 6d3665a..ee049eb 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -469,6 +469,8 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> { enum StreamData { Media { data: Arc>, ts: Duration }, Seek { ts: Duration, reply: MpscSender<()> }, + Enough { ts: Instant }, + Need { ts: Instant }, } struct ClientSourceData { @@ -929,6 +931,7 @@ async fn stream_run( // Handles sending the video data into gstreamer let thread_stream_cancel = stream_cancel.clone(); + let thread_stream_canceler = stream_cancel.clone(); 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(); @@ -938,7 +941,10 @@ async fn stream_run( _ = thread_stream_cancel.cancelled() => { AnyResult::Ok(()) }, - v = handle_data(thread_vid.as_ref(), vid_data_rx) => v, + v = handle_data(thread_vid.as_ref(), vid_data_rx) => { + thread_stream_canceler.cancel(); + v + }, }; drop(thread_client_count); log::trace!("Vid Thread End: {:?}", r); @@ -947,6 +953,7 @@ async fn stream_run( // Handles the audio data into gstreamer let thread_stream_cancel = stream_cancel.clone(); + let thread_stream_canceler = stream_cancel.clone(); let aud_data_rx = BroadcastStream::new(aud_data_rx).filter(|f| f.is_ok()); // Filter to ignore lagged let thread_aud = aud.clone(); set.spawn(async move { @@ -954,7 +961,10 @@ async fn stream_run( _ = thread_stream_cancel.cancelled() => { AnyResult::Ok(()) }, - v = handle_data(thread_aud.as_ref(), aud_data_rx) => v, + v = handle_data(thread_aud.as_ref(), aud_data_rx) => { + thread_stream_canceler.cancel(); + v + }, }; log::trace!("Aud Thread End: {:?}", r); r @@ -980,6 +990,8 @@ async fn make_factory( clear_bin(&element)?; let (vid_seek_tx, vid_seek_rx) = mpsc(10); let (aud_seek_tx, aud_seek_rx) = mpsc(10); + let vid_enough_tx = vid_seek_tx.clone(); + let vid_need_tx = vid_seek_tx.clone(); let vid = match stream_config.vid_format { VidFormat::None => { build_unknown(&element)?; @@ -1000,12 +1012,23 @@ async fn make_factory( .is_ok() && reply_rx.blocking_recv().is_some() }) + .enough_data(move |_| { + log::trace!("enough_data:"); + let _ = vid_enough_tx + .blocking_send(StreamData::Enough { ts: Instant::now() }); + }) + .need_data(move |_, _| { + log::trace!("need_data:"); + let _ = vid_need_tx + .blocking_send(StreamData::Need { ts: Instant::now() }); + }) .build(), ); AnyResult::Ok(Some(app)) } VidFormat::H265 => { let app = build_h265(&element, &stream_config)?; + app.set_callbacks( AppSrcCallbacks::builder() .seek_data(move |_, seek_pos| { @@ -1019,6 +1042,16 @@ async fn make_factory( .is_ok() && reply_rx.blocking_recv().is_some() }) + .enough_data(move |_| { + log::trace!("enough_data:"); + let _ = vid_enough_tx + .blocking_send(StreamData::Enough { ts: Instant::now() }); + }) + .need_data(move |_, _| { + log::trace!("need_data:"); + let _ = vid_need_tx + .blocking_send(StreamData::Need { ts: Instant::now() }); + }) .build(), ); AnyResult::Ok(Some(app)) @@ -1115,9 +1148,28 @@ async fn handle_data> + Unpin, E>( AnyResult::Ok(()) }); + let mut last_need: Option = None; + let mut last_enough: Option = None; while let Some(Ok(data)) = data_rx.next().await { check_live(app)?; // Stop if appsrc is dropped // Cache the last runtime + // Check for buffer over full + // for >15s + if let (Some(rlast_enough), Some(rlast_need)) = (last_enough, last_need) { + if rlast_need > rlast_enough { + last_enough = None; + last_need = None; + } + } + if let Some(rlast_enough) = last_enough { + if rlast_enough.elapsed() > Duration::from_secs(15) { + let _ = app.end_of_stream(); + log::debug!( + "Client has not used any stream data for over 15s disconnecting the client" + ); + return Ok(()); + } + } match data { StreamData::Seek { ts, reply } => { rt = ts; @@ -1171,6 +1223,8 @@ async fn handle_data> + Unpin, E>( let send = (push_at, buf); tx.send(send).await?; } + StreamData::Enough { ts: when } => last_enough = Some(when), + StreamData::Need { ts: when } => last_need = Some(when), } } }