Wrapping appsrc in an Arc
This commit is contained in:
8 files changed
+29
-18
No files matched your search
@@ -52,7 +52,7 @@ fn bcudp_ack<'a, W: 'a + Write>(
|
||||
le_u32(0),
|
||||
le_u32(payload.group_id),
|
||||
le_u32(payload.packet_id),
|
||||
le_u32(0),
|
||||
le_u32(0xd7160000),
|
||||
le_u32(binary_payload.len() as u32),
|
||||
slice(binary_payload),
|
||||
))
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ pub(crate) async fn main(opt: Opt, config: Config) -> Result<()> {
|
||||
.await
|
||||
.context("Failed to connect to the camera, check credentials and network")?;
|
||||
|
||||
if (opt.use_stream) {
|
||||
if opt.use_stream {
|
||||
let mut stream_data = camera
|
||||
.start_video(StreamKind::Main, 0, camera_config.strict)
|
||||
.await
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::config::CameraConfig;
|
||||
use crate::utils::AddressOrUid;
|
||||
use crate::utils::{timeout, AddressOrUid};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use futures::stream::StreamExt;
|
||||
use log::*;
|
||||
@@ -193,10 +193,9 @@ impl EventCamThread {
|
||||
"aes" => MaxEncryption::Aes,
|
||||
_ => MaxEncryption::Aes,
|
||||
};
|
||||
camera
|
||||
.login_with_maxenc(max_encryption)
|
||||
timeout(camera.login_with_maxenc(max_encryption))
|
||||
.await
|
||||
.context("Failed to login to the camera")?;
|
||||
.context("Failed to login to the camera")??;
|
||||
info!("{}: Connected and logged in", camera_config.name);
|
||||
|
||||
self.tx.send(Messages::Login).await?;
|
||||
|
||||
@@ -51,7 +51,6 @@ impl NeoMediaFactory {
|
||||
factory.set_shared(false);
|
||||
factory.imp().shared.set_buffer_size(buffer_size);
|
||||
factory.imp().shared.set_use_smoothing(use_smoothing);
|
||||
// factory.set_do_retransmission(false); // Can't use as the method is missing on the 32bit docker gst dll
|
||||
factory.set_launch("videotestsrc pattern=\"snow\" ! video/x-raw,width=896,height=512,framerate=25/1 ! textoverlay name=\"inittextoverlay\" text=\"Stream not Ready\" valignment=top halignment=left font-desc=\"Sans, 32\" ! jpegenc ! rtpjpegpay name=pay0");
|
||||
factory.set_suspend_mode(RTSPSuspendMode::None);
|
||||
factory.set_transport_mode(RTSPTransportMode::PLAY);
|
||||
@@ -266,9 +265,11 @@ impl NeoMediaFactoryImpl {
|
||||
.dynamic_cast::<Bin>()
|
||||
.map_err(|_| anyhow!("Media source's element should be a bin"))?;
|
||||
// Clear the autogenerated ones
|
||||
log::debug!("Clearing old elements");
|
||||
for element in bin.iterate_elements().into_iter().flatten() {
|
||||
bin.remove(&element)?;
|
||||
}
|
||||
log::debug!("Cleared");
|
||||
|
||||
let mut client_data = NeoMediaSender::new(
|
||||
self.shared.get_buffer_size(),
|
||||
|
||||
@@ -444,8 +444,8 @@ pub(super) struct NeoMediaSender {
|
||||
start_time: Spring,
|
||||
live_offset: FrameTime,
|
||||
buffer: NeoBuffer,
|
||||
vid: Option<AppSrc>,
|
||||
aud: Option<AppSrc>,
|
||||
vid: Option<Arc<AppSrc>>,
|
||||
aud: Option<Arc<AppSrc>>,
|
||||
command_reciever: Receiver<NeoMediaSenderCommand>,
|
||||
command_sender: Sender<NeoMediaSenderCommand>,
|
||||
inited: bool,
|
||||
@@ -476,11 +476,11 @@ impl NeoMediaSender {
|
||||
}
|
||||
|
||||
pub(super) fn update_vid(&mut self, source: AppSrc) {
|
||||
self.vid.replace(source);
|
||||
self.vid.replace(Arc::new(source));
|
||||
}
|
||||
|
||||
pub(super) fn update_aud(&mut self, source: AppSrc) {
|
||||
self.aud.replace(source);
|
||||
self.aud.replace(Arc::new(source));
|
||||
}
|
||||
|
||||
pub(super) fn get_commader(&self) -> Sender<NeoMediaSenderCommand> {
|
||||
|
||||
+7
-3
@@ -174,10 +174,14 @@ async fn camera_main(camera: Camera<Disconnected>) -> Result<(), CameraFailureKi
|
||||
.await
|
||||
.with_context(|| format!("{}: Could not login to camera", name))
|
||||
.map_err(|e| {
|
||||
let e_inner = e.downcast_ref::<neolink_core::Error>().unwrap();
|
||||
let e_inner = e.downcast_ref::<neolink_core::Error>();
|
||||
match e_inner {
|
||||
neolink_core::Error::CameraLoginFail => CameraFailureKind::Fatal(e),
|
||||
_ => CameraFailureKind::Retry(e),
|
||||
Some(neolink_core::Error::CameraLoginFail) => CameraFailureKind::Fatal(e),
|
||||
Some(_) => CameraFailureKind::Retry(e),
|
||||
None => {
|
||||
// Timout error usually
|
||||
CameraFailureKind::Retry(e)
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// This state has formed the TCP/UDP tunnel
|
||||
// but has not logged in
|
||||
use super::{camera::Camera, disconnected::Disconnected, loggedin::LoggedIn};
|
||||
use crate::utils::timeout;
|
||||
use anyhow::Result;
|
||||
|
||||
use neolink_core::bc_protocol::{BcCamera, MaxEncryption};
|
||||
@@ -28,7 +29,7 @@ impl Camera<Connected> {
|
||||
_ => MaxEncryption::Aes,
|
||||
};
|
||||
|
||||
self.state.camera.login_with_maxenc(max_encryption).await?;
|
||||
timeout(self.state.camera.login_with_maxenc(max_encryption)).await??;
|
||||
Ok(Camera {
|
||||
shared: self.shared,
|
||||
state: LoggedIn {
|
||||
|
||||
+9
-3
@@ -13,6 +13,13 @@ use std::{
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
pub(crate) fn timeout<F>(future: F) -> tokio::time::Timeout<F>
|
||||
where
|
||||
F: std::future::Future,
|
||||
{
|
||||
tokio::time::timeout(tokio::time::Duration::from_secs(5), future)
|
||||
}
|
||||
|
||||
pub(crate) enum AddressOrUid {
|
||||
Address(String),
|
||||
Uid(String, DiscoveryMethods),
|
||||
@@ -133,10 +140,9 @@ pub(crate) async fn connect_and_login(camera_config: &CameraConfig) -> Result<Bc
|
||||
_ => MaxEncryption::Aes,
|
||||
};
|
||||
info!("{}: Logging in", camera_config.name);
|
||||
camera
|
||||
.login_with_maxenc(max_encryption)
|
||||
timeout(camera.login_with_maxenc(max_encryption))
|
||||
.await
|
||||
.with_context(|| format!("Failed to login to {}", camera_config.name))?;
|
||||
.with_context(|| format!("Failed to login to {}", camera_config.name))??;
|
||||
|
||||
info!("{}: Connected and logged in", camera_config.name);
|
||||
|
||||
|
||||
Reference in new issue
Block a user