Debug logging cleanup
This commit is contained in:
17 files changed
+32
-186
No files matched your search
@@ -23,7 +23,6 @@ pub(crate) use cmdline::Opt;
|
||||
/// Opt is the command line options
|
||||
pub(crate) async fn main(opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
let camera = reactor.get(&opt.camera).await?;
|
||||
log::debug!("Battery: Instance aquired");
|
||||
|
||||
let state = camera
|
||||
.run_task(|cam| {
|
||||
|
||||
@@ -49,11 +49,9 @@ impl NeoCamThread {
|
||||
// Now we wait for a disconnect
|
||||
tokio::select! {
|
||||
_ = cancel_check.cancelled() => {
|
||||
log::debug!("{name}: Camera Cancelled");
|
||||
AnyResult::Ok(())
|
||||
}
|
||||
v = camera.join() => {
|
||||
log::debug!("{name}: Camera Join: {:?}", v);
|
||||
v?;
|
||||
Ok(())
|
||||
},
|
||||
@@ -152,7 +150,6 @@ impl NeoCamThread {
|
||||
match result {
|
||||
Ok(()) => {
|
||||
// Normal shutdown
|
||||
log::debug!("Cancel:: NeoCamThread::NormalShutdown");
|
||||
self.cancel.cancel();
|
||||
return Ok(());
|
||||
}
|
||||
@@ -164,7 +161,6 @@ impl NeoCamThread {
|
||||
Some(neolink_core::Error::CameraLoginFail) => {
|
||||
// Fatal
|
||||
log::error!("{name}: Login credentials were not accepted");
|
||||
log::debug!("NeoCamThread::run Login Cancel");
|
||||
self.cancel.cancel();
|
||||
return Err(e);
|
||||
}
|
||||
@@ -184,7 +180,6 @@ impl NeoCamThread {
|
||||
|
||||
impl Drop for NeoCamThread {
|
||||
fn drop(&mut self) {
|
||||
log::debug!("Cancel:: NeoCamThread::drop");
|
||||
self.cancel.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
+14
-17
@@ -123,7 +123,7 @@ impl NeoInstance {
|
||||
for _ in 0..5 {
|
||||
r = task(cam_ref).await;
|
||||
if let Err(e) = &r {
|
||||
log::debug!("- Task Result: {e:?}");
|
||||
log::trace!("- Task Result: {e:?}");
|
||||
}
|
||||
if let Err(Some(neolink_core::Error::CameraServiceUnavailable(400))) = r.as_ref().map_err(|e| e.downcast_ref::<neolink_core::Error>()) {
|
||||
// Retryable without a reconnect
|
||||
@@ -147,73 +147,70 @@ impl NeoInstance {
|
||||
Err(e) => {
|
||||
match e.downcast::<neolink_core::Error>() {
|
||||
Ok(neolink_core::Error::DroppedConnection) | Ok(neolink_core::Error::TimeoutDisconnected) => {
|
||||
log::debug!(" - Neolink error continue");
|
||||
continue;
|
||||
},
|
||||
Ok(neolink_core::Error::TokioBcSendError) => {
|
||||
log::debug!(" - Neolink Send Error continue");
|
||||
continue;
|
||||
},
|
||||
Ok(neolink_core::Error::Io(e)) => {
|
||||
log::debug!(" - Neolink Std IO Error");
|
||||
use std::io::ErrorKind::*;
|
||||
if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() {
|
||||
// Resetable IO
|
||||
log::debug!(" - Neolink Std IO Error: Continue");
|
||||
log::trace!(" - Neolink Std IO Error: Continue");
|
||||
continue;
|
||||
} else {
|
||||
// Check if the inner error is the Other type and then the discomnect
|
||||
let is_dropped = e.get_ref().is_some_and(|e| {
|
||||
log::debug!("Std IO Error: Inner: {:?}", e);
|
||||
log::trace!("Std IO Error: Inner: {:?}", e);
|
||||
matches!(e.downcast_ref::<neolink_core::Error>(),
|
||||
Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected)
|
||||
)
|
||||
});
|
||||
if is_dropped {
|
||||
// Retry is a None
|
||||
log::debug!(" - Neolink Std IO Error => Neolink: Continue");
|
||||
log::trace!(" - Neolink Std IO Error => Neolink: Continue");
|
||||
continue;
|
||||
} else {
|
||||
log::debug!(" - Neolink Std IO Error: Other");
|
||||
log::trace!(" - Neolink Std IO Error: Other");
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(e) => {
|
||||
log::debug!(" - Neolink Error: Other");
|
||||
log::trace!(" - Neolink Error: Other");
|
||||
Err(e.into())
|
||||
},
|
||||
Err(e) => {
|
||||
// Check if it is an io error
|
||||
log::debug!(" - Other Error: {:?}", e);
|
||||
log::trace!(" - Other Error: {:?}", e);
|
||||
match e.downcast::<std::io::Error>() {
|
||||
Ok(e) => {
|
||||
log::debug!(" - Std IO Error");
|
||||
log::trace!(" - Std IO Error");
|
||||
// Check if the inner error is the Other type and then the discomnect
|
||||
use std::io::ErrorKind::*;
|
||||
if let ConnectionReset | ConnectionAborted | BrokenPipe | TimedOut = e.kind() {
|
||||
// Resetable IO
|
||||
log::debug!(" - Std IO Error: Continue");
|
||||
log::trace!(" - Std IO Error: Continue");
|
||||
continue;
|
||||
} else {
|
||||
let is_dropped = e.get_ref().is_some_and(|e| {
|
||||
log::debug!("Std IO Error: Inner: {:?}", e);
|
||||
log::trace!("Std IO Error: Inner: {:?}", e);
|
||||
matches!(e.downcast_ref::<neolink_core::Error>(),
|
||||
Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) | Some(neolink_core::Error::TokioBcSendError)
|
||||
)
|
||||
});
|
||||
if is_dropped {
|
||||
// Retry is a None
|
||||
log::debug!(" - Std IO Error => Neolink Error: Continue");
|
||||
log::trace!(" - Std IO Error => Neolink Error: Continue");
|
||||
continue;
|
||||
} else {
|
||||
log::debug!(" - Std IO Error: Other");
|
||||
log::trace!(" - Std IO Error: Other");
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
log::debug!(" - Other Error: {:?}", e);
|
||||
log::trace!(" - Other Error: {:?}", e);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
@@ -289,7 +286,7 @@ impl NeoInstance {
|
||||
.await
|
||||
{
|
||||
Ok(pn) => {
|
||||
log::debug!("Forwarding push notification about {}", uid);
|
||||
log::trace!("Forwarding push notification about {}", uid);
|
||||
let _ = fwatch_tx.send_replace(pn.clone());
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
+1
-23
@@ -91,14 +91,12 @@ impl NeoCam {
|
||||
let thread_cancel = sender_cancel.clone();
|
||||
let res = tokio::select! {
|
||||
_ = sender_cancel.cancelled() => {
|
||||
log::debug!("Control thread Cancelled");
|
||||
Result::Ok(())
|
||||
},
|
||||
v = async {
|
||||
while let Some(command) = commander_rx.next().await {
|
||||
match command {
|
||||
NeoCamCommand::HangUp => {
|
||||
log::debug!("Cancel:: NeoCamCommand::HangUp");
|
||||
sender_cancel.cancel();
|
||||
return Result::<(), anyhow::Error>::Ok(());
|
||||
}
|
||||
@@ -153,14 +151,12 @@ impl NeoCam {
|
||||
NeoCamCommand::Connect(sender) => {
|
||||
if !matches!(*state_tx.borrow(), NeoCamThreadState::Connected) {
|
||||
state_tx.send_replace(NeoCamThreadState::Connected);
|
||||
log::debug!("{}: Connect On Request", thread_watch_config_rx.borrow().name);
|
||||
}
|
||||
let _ = sender.send(());
|
||||
}
|
||||
NeoCamCommand::Disconnect(sender) => {
|
||||
if !matches!(*state_tx.borrow(), NeoCamThreadState::Disconnected) {
|
||||
state_tx.send_replace(NeoCamThreadState::Disconnected);
|
||||
log::debug!("{}: Disconnect On Request", thread_watch_config_rx.borrow().name);
|
||||
}
|
||||
let _ = sender.send(());
|
||||
}
|
||||
@@ -187,14 +183,11 @@ impl NeoCam {
|
||||
},
|
||||
}
|
||||
}
|
||||
log::debug!("Control thread Senders dropped");
|
||||
Ok(())
|
||||
} => {
|
||||
log::debug!("Camera Control Thread Ended; {:?}", v);
|
||||
v
|
||||
}
|
||||
};
|
||||
log::debug!("Control thread terminated");
|
||||
res
|
||||
});
|
||||
|
||||
@@ -216,11 +209,7 @@ impl NeoCam {
|
||||
me.cancel.clone(),
|
||||
)
|
||||
.await;
|
||||
me.set.spawn(async move {
|
||||
let v = cam_thread.run().await;
|
||||
log::debug!("Camera MAIN thread ended; {:?}", v);
|
||||
v
|
||||
});
|
||||
me.set.spawn(async move { cam_thread.run().await });
|
||||
|
||||
// This thread maintains the streams
|
||||
let stream_instance = instance.subscribe().await?;
|
||||
@@ -230,7 +219,6 @@ impl NeoCam {
|
||||
tokio::select! {
|
||||
_ = stream_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = stream_thread.run() => {
|
||||
log::debug!("Camera Stream thread ended; {:?}", v);
|
||||
v
|
||||
},
|
||||
}
|
||||
@@ -244,7 +232,6 @@ impl NeoCam {
|
||||
tokio::select! {
|
||||
_ = md_cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = md_thread.run() => {
|
||||
log::debug!("MD thread ended; {:?}", v);
|
||||
v
|
||||
},
|
||||
}
|
||||
@@ -277,7 +264,6 @@ impl NeoCam {
|
||||
for encode in stream_info.stream_infos.iter().flat_map(|stream_info| stream_info.encode_tables.clone()) {
|
||||
supported_streams.push(std::format!(" {}: {}x{}", encode.name, encode.resolution.width, encode.resolution.height));
|
||||
}
|
||||
log::debug!("{}: Listing Camera Supported Streams\n{}", report_name, supported_streams.join("\n"));
|
||||
|
||||
|
||||
Ok(())
|
||||
@@ -345,13 +331,11 @@ impl NeoCam {
|
||||
},
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Push notifications stopped: {:?}", r);
|
||||
break r;
|
||||
}
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
log::debug!("Push notification thread ended; {:?}", v);
|
||||
v
|
||||
},
|
||||
}
|
||||
@@ -380,7 +364,6 @@ impl NeoCam {
|
||||
}
|
||||
}
|
||||
} => {
|
||||
log::debug!("MD Wake Up thread ended; {:?}", v);
|
||||
v
|
||||
},
|
||||
}
|
||||
@@ -393,7 +376,6 @@ impl NeoCam {
|
||||
// notifications are observed
|
||||
let connect_instance = instance.subscribe().await?;
|
||||
let connect_cancel = me.cancel.clone();
|
||||
let connect_name = config.name.clone();
|
||||
me.set.spawn(async move {
|
||||
tokio::select!{
|
||||
_ = connect_cancel.cancelled() => {
|
||||
@@ -418,16 +400,13 @@ impl NeoCam {
|
||||
permit.deactivate().await?; // Watching only from here
|
||||
loop {
|
||||
permit.aquired_users().await?;
|
||||
log::debug!("{connect_name}: InUse");
|
||||
connect_instance.connect().await?;
|
||||
permit.dropped_users().await?;
|
||||
log::debug!("{connect_name}: Idle Wait");
|
||||
// Wait 30s or if we hit another use then go back and wait again
|
||||
tokio::select! {
|
||||
_ = sleep(Duration::from_secs(30)) => {},
|
||||
_ = permit.aquired_users() => continue,
|
||||
};
|
||||
log::debug!("{connect_name}: Idle");
|
||||
connect_instance.disconnect().await?;
|
||||
}
|
||||
} => v,
|
||||
@@ -438,7 +417,6 @@ impl NeoCam {
|
||||
}?;
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
log::debug!("Idle Disconnect thread ended; {:?}", v);
|
||||
v
|
||||
},
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ impl NeoReactor {
|
||||
match command {
|
||||
NeoReactorCommand::HangUp => {
|
||||
instances.clear();
|
||||
log::debug!("Cancel:: NeoReactorCommand::HangUp");
|
||||
cancel2.cancel();
|
||||
return Result::<(), anyhow::Error>::Ok(());
|
||||
}
|
||||
@@ -72,11 +71,9 @@ impl NeoReactor {
|
||||
let new = match instances.entry(name.clone()) {
|
||||
Entry::Occupied(occ) => Result::Ok(Some(occ.get().subscribe().await?)),
|
||||
Entry::Vacant(vac) => {
|
||||
log::debug!("Inserting new insance");
|
||||
let current_config: Config = (*thread_config_tx.borrow()).clone();
|
||||
if let Some(config) = current_config.cameras.iter().find(|cam| cam.name == name).cloned() {
|
||||
let cam = NeoCam::new(config, push_noti.clone()).await?;
|
||||
log::debug!("New instance created");
|
||||
Result::Ok(Some(
|
||||
vac.insert(
|
||||
cam,
|
||||
@@ -89,7 +86,6 @@ impl NeoReactor {
|
||||
}
|
||||
}
|
||||
};
|
||||
log::debug!("Got instance from reactor");
|
||||
let _ = sender.send(new);
|
||||
},
|
||||
NeoReactorCommand::UpdateConfig(new_conf, reply) => {
|
||||
@@ -129,7 +125,7 @@ impl NeoReactor {
|
||||
thread_config_rx.wait_for(|c| c.cameras.iter().any(|cam| cam.push_notifications)).await?; // Wait until PN are enabled
|
||||
let r = tokio::select!{
|
||||
v = pn.run(&pn_tx, &mut pn_rx) => {v},
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Wait until PN are enabled => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
_ = thread_config_rx.wait_for(|c| c.cameras.iter().all(|cam| !cam.push_notifications)) => AnyResult::Ok(()), // Quit if PN is turned off
|
||||
};
|
||||
if r.is_err() {
|
||||
log::debug!("Issue with push notifier: {r:?}");
|
||||
@@ -140,7 +136,6 @@ impl NeoReactor {
|
||||
}
|
||||
} => v,
|
||||
};
|
||||
log::debug!("Push notifier ended: {r:?}");
|
||||
r
|
||||
});
|
||||
|
||||
|
||||
@@ -185,7 +185,6 @@ impl NeoCamStreamThread {
|
||||
|
||||
impl Drop for NeoCamStreamThread {
|
||||
fn drop(&mut self) {
|
||||
log::debug!("NeoCamStreamThread::drop Cancel");
|
||||
self.cancel.cancel();
|
||||
for stream in self.streams.values() {
|
||||
stream.cancel.cancel()
|
||||
@@ -422,7 +421,6 @@ impl StreamData {
|
||||
//
|
||||
// This should stop one branch of the select from waking the other
|
||||
// too often
|
||||
let watchdog_print_name = print_name.clone();
|
||||
tokio::task::spawn(async move {
|
||||
let mut check_timeout = timeout(Duration::from_secs(15), watchdog_rx.recv()).await; // Wait longer for the first feed
|
||||
loop {
|
||||
@@ -430,15 +428,12 @@ impl StreamData {
|
||||
Err(_) => {
|
||||
// Timeout
|
||||
// Break with Ok to trigger the restart
|
||||
log::debug!("{watchdog_print_name}: Watchdog kicking the stream");
|
||||
break;
|
||||
},
|
||||
Ok(None) => {
|
||||
log::debug!("{watchdog_print_name}: Watchdog dropped the stream");
|
||||
break;
|
||||
}
|
||||
Ok(_) => {
|
||||
// log::debug!("{print_name}: Good Doggo");
|
||||
check_timeout = timeout(Duration::from_secs(10), watchdog_rx.recv()).await;
|
||||
}
|
||||
}
|
||||
@@ -450,12 +445,10 @@ impl StreamData {
|
||||
tokio::select! {
|
||||
v = thread_inuse.dropped_users() => {
|
||||
// Handles the stop and restart when no active users
|
||||
log::debug!("{print_name}: Streaming STOP");
|
||||
permit.deactivate().await?;
|
||||
v?;
|
||||
thread_inuse.aquired_users().await?; // Wait for new users of the stream
|
||||
permit.activate().await?;
|
||||
log::debug!("{print_name}: Streaming START");
|
||||
AnyResult::Ok(())
|
||||
},
|
||||
_ = watchdog_eat_rx => {
|
||||
@@ -470,9 +463,7 @@ impl StreamData {
|
||||
let aud_history = aud_history.clone();
|
||||
let watchdog_tx = watchdog_tx.clone();
|
||||
let fps_table = fps_table.clone();
|
||||
let print_name = print_name.clone();
|
||||
|
||||
log::debug!("{print_name}: Running Stream Instance Task");
|
||||
Box::pin(async move {
|
||||
// use std::io::Write;
|
||||
// let mut file = std::fs::File::create("reference.h264")?;
|
||||
@@ -483,11 +474,8 @@ impl StreamData {
|
||||
let mut prev_ts = Duration::ZERO;
|
||||
let mut stream_data = camera.start_video(name, 0, strict).await?;
|
||||
loop {
|
||||
log::debug!("{print_name}: Waiting for frame");
|
||||
let data = stream_data.get_data().await??;
|
||||
log::debug!("{print_name}: Waiting for Watchdog");
|
||||
watchdog_tx.send(()).await?; // Feed the watchdog
|
||||
log::debug!("{print_name}: Got frame");
|
||||
|
||||
// Update the stream config with any information
|
||||
match &data {
|
||||
@@ -573,7 +561,6 @@ impl StreamData {
|
||||
match data {
|
||||
BcMedia::Iframe(BcMediaIframe{data, microseconds, ..}) => {
|
||||
prev_ts = Duration::from_micros(microseconds as u64);
|
||||
// log::debug!("IFrame: {prev_ts:?}");
|
||||
let d = StampedData{
|
||||
keyframe: true,
|
||||
data: Arc::new(data),
|
||||
@@ -593,8 +580,6 @@ impl StreamData {
|
||||
},
|
||||
BcMedia::Pframe(BcMediaPframe{data, microseconds,..}) if recieved_iframe => {
|
||||
prev_ts = Duration::from_micros(microseconds as u64);
|
||||
// log::debug!("PFrame: {prev_ts:?}");
|
||||
// log::debug!("data: {data:02X?}");
|
||||
let d = StampedData{
|
||||
keyframe: false,
|
||||
data: Arc::new(data),
|
||||
@@ -611,7 +596,6 @@ impl StreamData {
|
||||
log::trace!("Sent Vid Frame");
|
||||
}
|
||||
BcMedia::Aac(BcMediaAac{data, ..}) | BcMedia::Adpcm(BcMediaAdpcm{data,..}) if recieved_iframe => {
|
||||
// log::debug!("Audio: {prev_ts:?}");
|
||||
let d = StampedData{
|
||||
keyframe: aud_keyframe,
|
||||
data: Arc::new(data),
|
||||
@@ -654,7 +638,6 @@ impl StreamData {
|
||||
}
|
||||
} => v,
|
||||
};
|
||||
log::debug!("{print_name}: Stream Thead Stopped: {:?}", r);
|
||||
r
|
||||
}));
|
||||
|
||||
@@ -662,7 +645,6 @@ impl StreamData {
|
||||
}
|
||||
|
||||
async fn shutdown(&mut self) -> Result<()> {
|
||||
log::debug!("StreamData::shutdown Cancel");
|
||||
self.cancel.cancel();
|
||||
if let Some(handle) = self.handle.take() {
|
||||
let _ = handle.await;
|
||||
|
||||
@@ -150,7 +150,6 @@ pub(crate) async fn main(_: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
if let Ok(()) = &r {
|
||||
break r
|
||||
} else {
|
||||
log::debug!("listen_on_camera stopped: {:?}", r);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +159,6 @@ pub(crate) async fn main(_: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
|
||||
for (running_name, token) in cameras.iter() {
|
||||
if ! config_names.contains(running_name) {
|
||||
log::debug!("Mqtt::main Cancel");
|
||||
token.cancel();
|
||||
}
|
||||
}
|
||||
@@ -329,7 +327,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
tokio::select!{
|
||||
_ = cancel_msg.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
// log::debug!("Got message: {msg:?}");
|
||||
let res = handle_mqtt_message(msg, &mqtt_msg, &camera_msg).await;
|
||||
if res.is_err() {
|
||||
tx.send(res).await?;
|
||||
@@ -339,14 +336,11 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}
|
||||
});
|
||||
}
|
||||
log::debug!("STOPPED Listening to message on {}", mqtt_msg.get_name());
|
||||
AnyResult::Ok(())
|
||||
} => {
|
||||
log::debug!("MQTT Command Returned: {v:?}");
|
||||
v
|
||||
},
|
||||
v = rx.recv() => {
|
||||
log::debug!("MQTT Task Returned: {v:?}");
|
||||
v.ok_or(anyhow!("All error senders were dropped"))?
|
||||
},
|
||||
}?;
|
||||
@@ -370,7 +364,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
})?;
|
||||
}
|
||||
} => {
|
||||
log::debug!("CamConnection returned: {v:?}");
|
||||
v
|
||||
},
|
||||
// Handle the floodlight
|
||||
@@ -413,7 +406,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
AnyResult::Ok(())
|
||||
} => v,
|
||||
};
|
||||
log::debug!("Flood light returned: {v:?}");
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
@@ -441,7 +433,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
})?;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
log::debug!("Motion returned: {v:?}");
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
@@ -485,7 +476,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
log::debug!("Snap returned: {v:?}");
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
@@ -530,7 +520,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
}
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
log::debug!("Battery returned: {v:?}");
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
@@ -554,7 +543,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
prev_noti = noti;
|
||||
AnyResult::Ok(())
|
||||
}.await;
|
||||
log::debug!("PushNoti returned: {v:?}");
|
||||
match v.map_err(|e| e.downcast::<neolink_core::Error>()) {
|
||||
Err(Ok(neolink_core::Error::UnintelligibleReply{..})) => futures::future::pending().await,
|
||||
Ok(()) => AnyResult::Ok(()),
|
||||
@@ -608,7 +596,6 @@ async fn listen_on_camera(camera: NeoInstance, mqtt_instance: MqttInstance) -> R
|
||||
};
|
||||
};
|
||||
|
||||
log::debug!("Mqtt::listen_on_camera Cancel: {r:?}");
|
||||
drop(drop_cancel);
|
||||
r?;
|
||||
Ok(())
|
||||
@@ -1057,10 +1044,8 @@ async fn handle_mqtt_message(
|
||||
.run_task(|_cam| Box::pin(async move { AnyResult::Ok(()) }))
|
||||
.await;
|
||||
|
||||
log::debug!("Wakeup counting down");
|
||||
sleep(Duration::from_secs(secs * 60)).await;
|
||||
|
||||
log::debug!("Wakeup complete");
|
||||
drop(permit);
|
||||
});
|
||||
"OK"
|
||||
|
||||
@@ -114,7 +114,6 @@ fn clear_bin(bin: &Element) -> Result<()> {
|
||||
.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)?;
|
||||
}
|
||||
@@ -158,7 +157,6 @@ fn build_unknown(bin: &Element, pattern: &str) -> Result<()> {
|
||||
|
||||
fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::debug!("buffer_size: {buffer_size}");
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
@@ -194,7 +192,6 @@ fn build_h264(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
|
||||
fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::debug!("buffer_size: {buffer_size}");
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
@@ -229,7 +226,6 @@ fn build_h265(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
|
||||
fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::debug!("buffer_size: {buffer_size}");
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
@@ -295,7 +291,6 @@ fn build_aac(bin: &Element, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
|
||||
fn build_adpcm(bin: &Element, block_size: u32, stream_config: &StreamConfig) -> Result<AppSrc> {
|
||||
let buffer_size = buffer_size(stream_config.bitrate);
|
||||
log::debug!("buffer_size: {buffer_size}");
|
||||
let bin = bin
|
||||
.clone()
|
||||
.dynamic_cast::<Bin>()
|
||||
|
||||
@@ -186,7 +186,6 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
|
||||
for (running_name, token) in cameras.iter() {
|
||||
if ! config_names.contains(running_name) {
|
||||
log::debug!("Rtsp::main Cancel!");
|
||||
token.cancel();
|
||||
}
|
||||
}
|
||||
@@ -217,7 +216,6 @@ pub(crate) async fn main(_opt: Opt, reactor: NeoReactor) -> Result<()> {
|
||||
// Panicked or error in task
|
||||
// Cancel all and await terminate
|
||||
log::error!("Error: {e}");
|
||||
log::debug!("Rtsp::main Cancel2");
|
||||
global_cancel.cancel();
|
||||
rtsp.quit().await?;
|
||||
}
|
||||
@@ -291,8 +289,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> {
|
||||
AnyResult::Ok(())
|
||||
});
|
||||
|
||||
log::debug!("{name}: Camera Main::Loop");
|
||||
|
||||
let mut camera_config = camera.config().await?.clone();
|
||||
loop {
|
||||
let prev_stream_config = camera_config.borrow_and_update().stream;
|
||||
@@ -316,7 +312,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> {
|
||||
},
|
||||
v = async {
|
||||
// This select handles enabling the right stream
|
||||
log::debug!("{name}: Camera Main::Select Stream");
|
||||
// and setting up the users
|
||||
let all_users = rtsp.get_users().await?.iter().filter(|a| *a != "anyone" && *a != "anonymous").cloned().collect::<HashSet<_>>();
|
||||
let permitted_users: HashSet<String> = match &prev_stream_users {
|
||||
@@ -340,7 +335,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> {
|
||||
let mut supported_streams_3 = supported_streams.clone();
|
||||
tokio::select! {
|
||||
v = async {
|
||||
log::debug!("{name}: Camera Main::Select Main");
|
||||
let name = camera.config().await?.borrow().name.clone();
|
||||
let mut paths = vec![
|
||||
format!("/{name}/main"),
|
||||
@@ -371,7 +365,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> {
|
||||
stream_main(camera.stream(StreamKind::Main).await?, camera.clone(), rtsp, &permitted_users, &paths).await
|
||||
}, if active_streams.contains(&StreamKind::Main) => v,
|
||||
v = async {
|
||||
log::debug!("{name}: Camera Main::Select Sub");
|
||||
let name = camera.config().await?.borrow().name.clone();
|
||||
let mut paths = vec![
|
||||
format!("/{name}/sub"),
|
||||
@@ -406,7 +399,6 @@ async fn camera_main(camera: NeoInstance, rtsp: &NeoRtspServer) -> Result<()> {
|
||||
stream_main(camera.stream(StreamKind::Sub).await?,camera.clone(), rtsp, &permitted_users, &paths).await
|
||||
}, if active_streams.contains(&StreamKind::Sub) => v,
|
||||
v = async {
|
||||
log::debug!("{name}: Camera Main::Select Extern");
|
||||
let name = camera.config().await?.borrow().name.clone();
|
||||
let mut paths = vec![
|
||||
format!("/{name}/extern"),
|
||||
|
||||
+3
-35
@@ -43,27 +43,18 @@ pub(super) async fn stream_main(
|
||||
let this_loop_cancel = CancellationToken::new();
|
||||
let _drop_guard = this_loop_cancel.clone().drop_guard();
|
||||
|
||||
log::debug!("{}: Activating Stream", &name);
|
||||
stream_instance.activate().await?;
|
||||
|
||||
// Wait for a valid stream format to be detected
|
||||
log::debug!("{}: Waiting for Valid Stream", &name);
|
||||
stream_instance
|
||||
.config
|
||||
.wait_for(|config| {
|
||||
log::debug!("{:?}", config);
|
||||
config.vid_ready()
|
||||
})
|
||||
.wait_for(|config| config.vid_ready())
|
||||
.await?;
|
||||
log::debug!("{}: Waiting for Valid Audio", &name);
|
||||
// After vid give it 1s to look for audio
|
||||
// Ignore timeout but check err
|
||||
if let Ok(v) = tokio::time::timeout(
|
||||
Duration::from_secs(1),
|
||||
stream_instance.config.wait_for(|config| {
|
||||
log::debug!("{:?}", config);
|
||||
config.aud_ready()
|
||||
}),
|
||||
stream_instance.config.wait_for(|config| config.aud_ready()),
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -83,7 +74,6 @@ pub(super) async fn stream_main(
|
||||
let pause_affector_tx = Arc::new(pause_affector_tx);
|
||||
|
||||
let mut set = JoinSet::<AnyResult<()>>::new();
|
||||
log::debug!("{}: Creating Client Counters", &name);
|
||||
// Handles the on off of the stream with the client pause
|
||||
let client_counter = UseCounter::new().await;
|
||||
let client_count = client_counter.create_deactivated().await?;
|
||||
@@ -98,7 +88,6 @@ pub(super) async fn stream_main(
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
log::debug!("{}: Activating Client Pause", thread_name);
|
||||
loop {
|
||||
client_count.aquired_users().await?;
|
||||
log::info!("{}: Enabling Client", thread_name);
|
||||
@@ -130,7 +119,6 @@ pub(super) async fn stream_main(
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
log::debug!("{}: Activating Motion Pause", &thread_name);
|
||||
loop {
|
||||
motion
|
||||
.wait_for(|md| matches!(md, crate::common::MdState::Start(_)))
|
||||
@@ -155,7 +143,6 @@ pub(super) async fn stream_main(
|
||||
});
|
||||
|
||||
// Push notfications
|
||||
log::debug!("{}: Activating Push Notification Pause", &name);
|
||||
let mut pn = camera.push_notifications().await?;
|
||||
let mut curr_pn = None;
|
||||
let thread_name = name.clone();
|
||||
@@ -260,14 +247,12 @@ pub(super) async fn stream_main(
|
||||
let cancel = this_loop_cancel.clone();
|
||||
let counter = client_counter.create_deactivated().await?;
|
||||
let mut cur_count = 0;
|
||||
let thread_name = name.clone();
|
||||
set.spawn(async move {
|
||||
tokio::select! {
|
||||
_ = cancel.cancelled() => AnyResult::Ok(()),
|
||||
v = async {
|
||||
loop {
|
||||
cur_count = *counter.get_counter().wait_for(|v| v != &cur_count).await?;
|
||||
log::debug!("{thread_name}: Number of rtsp clients: {cur_count}");
|
||||
}
|
||||
} => v,
|
||||
}
|
||||
@@ -275,7 +260,6 @@ pub(super) async fn stream_main(
|
||||
|
||||
// This runs the actual stream.
|
||||
// The select will restart if the stream's config updates
|
||||
log::debug!("{}: Stream Activated", &name);
|
||||
break tokio::select! {
|
||||
v = thread_stream_config.wait_for(|new_conf| new_conf != &last_stream_config) => {
|
||||
let v = v?;
|
||||
@@ -330,7 +314,6 @@ async fn stream_run(
|
||||
let mut set = JoinSet::new();
|
||||
// Wait for new media client data to come in from the factory
|
||||
while let Some(mut client_data) = client_rx.recv().await {
|
||||
log::debug!("New media");
|
||||
// New media created
|
||||
let vid = client_data.vid.take().map(|data| data.app);
|
||||
let aud = client_data.aud.take().map(|data| data.app);
|
||||
@@ -429,7 +412,6 @@ async fn stream_run(
|
||||
let thread_vid = vid.clone();
|
||||
let mut thread_client_count = client_count.subscribe();
|
||||
let thread_format = stream_config.vid_format;
|
||||
log::debug!("stream_config.fps: {}", stream_config.fps);
|
||||
// let fallback_time = Duration::from_secs(3);
|
||||
let framerate =
|
||||
Duration::from_millis(1000u64 / std::cmp::max(stream_config.fps as u64, 5u64));
|
||||
@@ -459,7 +441,6 @@ async fn stream_run(
|
||||
};
|
||||
drop(thread_client_count);
|
||||
let _ = thread_vid.end_of_stream();
|
||||
log::debug!("Vid Thread End: {:?}", r);
|
||||
r
|
||||
});
|
||||
}
|
||||
@@ -489,12 +470,10 @@ async fn stream_run(
|
||||
},
|
||||
};
|
||||
let _ = thread_aud.end_of_stream();
|
||||
log::debug!("Aud Thread End: {:?}", r);
|
||||
r
|
||||
});
|
||||
}
|
||||
}
|
||||
log::debug!("Cleaning up streams");
|
||||
// At this point the factory has been destroyed
|
||||
// Cancel any remaining threads that are trying to send data
|
||||
// Although it should be finished already when the appsrcs are dropped
|
||||
@@ -506,7 +485,6 @@ async fn stream_run(
|
||||
}
|
||||
|
||||
fn check_live(app: &AppSrc) -> Result<()> {
|
||||
// log::debug!("Checking Live: {:?}", app.bus());
|
||||
app.bus().ok_or(anyhow!("App source is closed"))?;
|
||||
app.pads()
|
||||
.iter()
|
||||
@@ -518,11 +496,8 @@ fn check_live(app: &AppSrc) -> Result<()> {
|
||||
fn get_runtime(app: &AppSrc) -> Option<Duration> {
|
||||
if let Some(clock) = app.clock() {
|
||||
if let Some(time) = clock.time() {
|
||||
// log::debug!("time: {time:?}");
|
||||
if let Some(base_time) = app.base_time() {
|
||||
// log::debug!("base_time: {base_time:?}");
|
||||
let runtime = time.saturating_sub(base_time);
|
||||
// log::debug!("runtime: {runtime:?}");
|
||||
return Some(Duration::from_micros(runtime.useconds()));
|
||||
}
|
||||
}
|
||||
@@ -560,11 +535,9 @@ fn hold_stream<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
if let Ok(frame) = frame {
|
||||
if frame.keyframe {
|
||||
// Release
|
||||
// log::debug!("Yielding: {}", held_frames.len());
|
||||
for held_frame in held_frames.drain(..) {
|
||||
yield Ok(held_frame);
|
||||
}
|
||||
// log::debug!("Yielded");
|
||||
yield Ok(frame);
|
||||
} else {
|
||||
// Hold
|
||||
@@ -589,7 +562,6 @@ fn ensure_order<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
// Buffer until keyframe and reorder
|
||||
let mut reorder_buffer = vec![];
|
||||
while frame_buffer.last().is_some_and(|v| v.ts > frame.ts) {
|
||||
log::debug!("Reorder: {:?}", frame.ts);
|
||||
reorder_buffer.push(frame_buffer.pop().unwrap());
|
||||
}
|
||||
frame_buffer.push(frame);
|
||||
@@ -642,7 +614,7 @@ fn h264_filler(size: usize) -> Vec<u8> {
|
||||
buf
|
||||
}
|
||||
|
||||
/// Takes a stream and pads it with filler blocks up to 4kb in h265 format
|
||||
/// Takes a stream and pads it with filler blocks up to 4kb in h265 or h264 format
|
||||
fn pad_vid<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
mut stream: T,
|
||||
format: VidFormat,
|
||||
@@ -700,7 +672,6 @@ fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
while let Some(frame) = stream.next().await {
|
||||
if let Ok(frame) = frame {
|
||||
if frame.keyframe {
|
||||
// log::debug!("Key Frame");
|
||||
let repeater = frame.clone();
|
||||
yield Ok(frame);
|
||||
|
||||
@@ -712,7 +683,6 @@ fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
if let Some(frame) = v {
|
||||
if let Ok(frame) = frame {
|
||||
if was_repeating {
|
||||
log::debug!("Key Frame: Resume");
|
||||
was_repeating = false;
|
||||
}
|
||||
yield Ok(frame);
|
||||
@@ -725,7 +695,6 @@ fn repeat_keyframe<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
_ = sleep(fallback_time) => {
|
||||
if !was_repeating {
|
||||
// This way we only print once
|
||||
log::debug!("Inserting Skip Frames");
|
||||
was_repeating = true;
|
||||
}
|
||||
fallback_time = frame_rate;
|
||||
@@ -787,7 +756,6 @@ async fn send_to_appsrc<E, T: Stream<Item = Result<StampedData, E>> + Unpin>(
|
||||
// let mut gst_buf = gstreamer::Buffer::with_size(data.data.len()).unwrap();
|
||||
{
|
||||
let gst_buf_mut = gst_buf.get_mut().unwrap();
|
||||
// log::debug!("Setting PTS: {ts:?}, Runtime: {ts:?}");
|
||||
let time = ClockTime::from_useconds(rt.as_micros() as u64);
|
||||
gst_buf_mut.set_dts(ClockTime::from_useconds(dts));
|
||||
dts += 1;
|
||||
|
||||
Reference in new issue
Block a user