diff --git a/crates/core/src/bc_protocol.rs b/crates/core/src/bc_protocol.rs index b95ebef..02de3ef 100644 --- a/crates/core/src/bc_protocol.rs +++ b/crates/core/src/bc_protocol.rs @@ -74,6 +74,10 @@ pub enum Error { /// A generic catch all error #[error(display = "Other error")] Other(&'static str), + + /// A generic catch all error + #[error(display = "Other error")] + OtherString(String), } impl<'a> From for Error { diff --git a/crates/rtsp/src/cmdline.rs b/crates/rtsp/src/cmdline.rs index 227b315..4e9a3dd 100644 --- a/crates/rtsp/src/cmdline.rs +++ b/crates/rtsp/src/cmdline.rs @@ -1,8 +1,10 @@ use std::path::PathBuf; use structopt::StructOpt; +/// The command line for the rtsp subcommand #[derive(StructOpt, Debug)] pub struct Opt { + /// The path to the config file #[structopt(short, long, parse(from_os_str))] pub config: PathBuf, } diff --git a/crates/rtsp/src/errors.rs b/crates/rtsp/src/errors.rs index aa512a0..51c9e6d 100644 --- a/crates/rtsp/src/errors.rs +++ b/crates/rtsp/src/errors.rs @@ -1,16 +1,23 @@ use err_derive::Error; +/// The main error for the rtsp subcommand #[derive(Debug, Error)] #[allow(clippy::large_enum_variant)] pub enum Error { + /// Raised when the config file fails to deserlize #[error(display = "Configuration parsing error")] ConfigError(#[error(source)] toml::de::Error), + /// Raised when `neolink_core` raises an error #[error(display = "Communication error")] ProtocolError(#[error(source)] neolink_core::Error), + /// Raised when there is an IO error such as unable to find + /// config file #[error(display = "I/O error")] IoError(#[error(source)] std::io::Error), + /// Raised when the config file fails validataion #[error(display = "Validation error")] ValidationError(#[error(source)] validator::ValidationErrors), + /// Raised when there is an ADPCM decoding error #[error(display = "ADPCM Decoding Error")] AdpcmDecodingError(&'static str), } diff --git a/crates/rtsp/src/gst.rs b/crates/rtsp/src/gst.rs index ca3cf62..b75d8d6 100644 --- a/crates/rtsp/src/gst.rs +++ b/crates/rtsp/src/gst.rs @@ -2,6 +2,7 @@ //! data using an ordinary std::io::Write interface. pub(crate) use self::maybe_app_src::MaybeAppSrc; use super::adpcm::adpcm_to_pcm; +use super::errors::Error; use gstreamer::prelude::Cast; use gstreamer::{Bin, Structure}; use gstreamer_app::AppSrc; @@ -39,8 +40,13 @@ impl StreamOutput for GstOutputs { fn write_audio(&mut self, data: &[u8], format: StreamFormat) -> StreamOutputError { self.set_format(Some(format)); if let StreamFormat::ADPCM = format { - let pcm = adpcm_to_pcm(data) - .map_err(|_| neolink_core::Error::Other("ADPCM decoding error"))?; + let pcm = adpcm_to_pcm(data).map_err(|e| { + if let Error::AdpcmDecodingError(msg) = e { + neolink_core::Error::OtherString(format!("ADPCM decoding error: {}", msg)) + } else { + neolink_core::Error::Other("Generic error during ADPCM decoding") + } + })?; self.vidsrc.write_all(&pcm)?; } else { self.vidsrc.write_all(data)?; diff --git a/crates/rtsp/src/lib.rs b/crates/rtsp/src/lib.rs index 5ce39d0..a89b02a 100644 --- a/crates/rtsp/src/lib.rs +++ b/crates/rtsp/src/lib.rs @@ -1,3 +1,10 @@ +#![warn(missing_docs)] +//! +//! # Neolink RTSP +//! +//! This crate serves as the rtsp source for the +//! `neolink rtsp` subcommand +//! use gio::TlsAuthenticationMode; use log::*; use neolink_core::bc_protocol::BcCamera; @@ -9,8 +16,10 @@ use std::time::Duration; use validator::Validate; mod adpcm; +/// The command line parameters for this subcommand pub mod cmdline; -pub mod config; +mod config; +/// The errors this subcommand can raise pub mod errors; mod gst; @@ -19,6 +28,9 @@ use config::{CameraConfig, Config, UserConfig}; use errors::Error; use gst::{GstOutputs, RtspServer}; +/// Entry point for the rtsp subcommand +/// +/// Opt is the command line options pub fn main(opt: Opt) -> Result<(), Error> { let config: Config = toml::from_str(&fs::read_to_string(opt.config)?)?; diff --git a/src/main.rs b/src/main.rs index c656a91..8de7ba0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,12 @@ +#![warn(missing_docs)] +//! +//! # Neolink +//! +//! Neolink is a small program that acts a general contol interface for Reolink IP cameras. +//! +//! It contains sub commands for running an rtsp proxy which can be used on Reolink cameras +//! that do not nativly support RTSP. +//! use env_logger::Env; use log::*; use structopt::StructOpt;