Reconnect streams when media type changes

This commit is contained in:
QuantumEntangledAndy committed 2023-05-01 18:37:57 +07:00
1 parent 048af92808
commit 31ac6e4707
2 files changed
+35 -1

No files matched your search

+28 -1
View File
@@ -13,7 +13,7 @@ use gstreamer_rtsp_server::{
gio::{TlsAuthenticationMode, TlsCertificate},
prelude::*,
subclass::prelude::*,
RTSPAuth, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE,
RTSPAuth, RTSPFilterResult, RTSPServer, RTSPToken, RTSP_TOKEN_MEDIA_FACTORY_ROLE,
};
use log::*;
use neolink_core::bcmedia::model::*;
@@ -168,6 +168,33 @@ impl NeoRtspServer {
pub(crate) async fn buffer_ready<T: Into<String>>(&self, tag: T) -> Option<bool> {
self.imp().buffer_ready(tag).await
}
pub(crate) async fn clear_session<T: Into<String>>(&self, tag: T) {
let tag: String = tag.into();
if let Some(media) = self.imp().medias.read().await.get(&tag) {
self.clear_session_paths(media.paths.iter());
}
}
fn clear_session_paths<T: AsRef<str>>(&self, paths: impl Iterator<Item = T>) {
let paths: Vec<_> = paths.collect();
for client in self.client_filter(None) {
for session in client.session_filter(None) {
session.filter(Some(&mut |_session, session_media| {
if paths.iter().any(|p| {
session_media
.matches(p.as_ref())
.map(|amt| amt > 0)
.unwrap_or(false)
}) {
RTSPFilterResult::Remove
} else {
RTSPFilterResult::Keep
}
}));
}
}
}
}
unsafe impl Send for NeoRtspServer {}
+7
View File
@@ -201,6 +201,13 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
break;
}
}
// Clear all current media and force a reconnect
// This shoudld stop them from watching the "Stream Not Ready Thing"
tags.iter()
.map(|tag| rtsp_thread.clear_session(tag))
.collect::<FuturesUnordered<_>>()
.collect::<Vec<_>>()
.await;
log::info!("{}: Buffers prepared", name);
// tokio::task::spawn(async move {