Include docs for neolink_rtsp and neolink

This commit is contained in:
QuantumEntangledAndy committed 2021-07-31 18:57:55 +07:00
1 parent 4a773886ae
commit 13792fe014
6 files changed
+43 -3

No files matched your search

+4
View File
@@ -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<std::sync::mpsc::RecvTimeoutError> for Error {
+2
View File
@@ -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,
}
+7
View File
@@ -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),
}
+8 -2
View File
@@ -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)?;
+13 -1
View File
@@ -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)?)?;
+9
View File
@@ -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;