Log errors in camera_loop()
This commit is contained in:
1 parent
d653a84e5d
commit
934caa20b0
3 files changed
+18
-10
No files matched your search
+1
-1
@@ -18,7 +18,7 @@ gstreamer-app = "0.15"
|
||||
gstreamer-player = "0.15"
|
||||
gstreamer-rtsp = "0.15"
|
||||
gstreamer-rtsp-server = "0.15"
|
||||
log = { version = "0.4", features = ["release_max_level_warn"] }
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
indoc = "0.3"
|
||||
md5 = "0.7"
|
||||
nom = "5.1"
|
||||
|
||||
@@ -48,16 +48,14 @@ impl BcConnection {
|
||||
let mut context = BcContext::new();
|
||||
while let Ok(_) = BcConnection::poll(&mut context, &mut conn, &mut subs) {}
|
||||
});
|
||||
// TODO join on drop
|
||||
|
||||
Ok(bc_conn)
|
||||
}
|
||||
|
||||
pub fn subscribe(&self, msg_id: u32) -> Result<BcSubscription> {
|
||||
let (tx, rx) = channel();
|
||||
{
|
||||
let mut locked_subs = self.subscribers.lock().unwrap();
|
||||
locked_subs.insert(msg_id, tx);
|
||||
}
|
||||
self.subscribers.lock().unwrap().insert(msg_id, tx);
|
||||
Ok(BcSubscription { rx, conn: self, msg_id })
|
||||
}
|
||||
|
||||
@@ -90,6 +88,8 @@ impl BcConnection {
|
||||
|
||||
impl<'a> BcSubscription<'a> {
|
||||
pub fn send(&self, bc: Bc) -> Result<()> {
|
||||
assert!(bc.meta.msg_id == self.msg_id);
|
||||
|
||||
// TODO Use channel for writing, too
|
||||
bc.serialize(&*self.conn.connection)?;
|
||||
Ok(())
|
||||
|
||||
+13
-5
@@ -6,12 +6,13 @@ mod config;
|
||||
mod cmdline;
|
||||
mod gst;
|
||||
|
||||
use backoff::{ExponentialBackoff, Operation};
|
||||
use backoff::{Error::*, ExponentialBackoff, Operation};
|
||||
use bc_protocol::BcCamera;
|
||||
use config::{Config, CameraConfig};
|
||||
use cmdline::Opt;
|
||||
use err_derive::Error;
|
||||
use gst::RtspServer;
|
||||
use log::error;
|
||||
use std::fs;
|
||||
use std::time::Duration;
|
||||
use std::io::Write;
|
||||
@@ -60,8 +61,14 @@ fn camera_loop(camera_config: &CameraConfig, output: &mut dyn Write) -> Result<(
|
||||
};
|
||||
op.retry(&mut backoff).map_err(|backoff_err| -> Error {
|
||||
match backoff_err {
|
||||
backoff::Error::Transient(e) |
|
||||
backoff::Error::Permanent(e) => e.into()
|
||||
Transient(e) => {
|
||||
error!("Error streaming from camera {}, will retry: {}", camera_config.name, e);
|
||||
e.into()
|
||||
}
|
||||
Permanent(e) => {
|
||||
error!("Permanent error sreaming from camera {}: {}", camera_config.name, e);
|
||||
e.into()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -72,10 +79,11 @@ fn camera_main(camera_config: &CameraConfig, output: &mut dyn Write) -> Result<(
|
||||
println!("{}: Connecting to camera at {}", camera_config.name, camera_config.camera_addr);
|
||||
camera.connect()?;
|
||||
|
||||
// Authentication failures are permanent; we retry everything else
|
||||
camera.login(&camera_config.username, camera_config.password.as_deref()).map_err(|e| {
|
||||
match e {
|
||||
bc_protocol::Error::AuthFailed => backoff::Error::Permanent(e),
|
||||
_ => backoff::Error::Transient(e)
|
||||
bc_protocol::Error::AuthFailed => Permanent(e),
|
||||
_ => Transient(e)
|
||||
}
|
||||
})?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user