2020-03-02 01:53:41 -05:00
|
|
|
// This file is part of Moonfire NVR, a security camera network video recorder.
|
2021-02-17 16:28:48 -05:00
|
|
|
// Copyright (C) 2020 The Moonfire NVR Authors; see AUTHORS and LICENSE.txt.
|
|
|
|
// SPDX-License-Identifier: GPL-v3.0-or-later WITH GPL-3.0-linking-exception.
|
2016-11-25 17:34:00 -05:00
|
|
|
|
2021-02-17 01:15:54 -05:00
|
|
|
#![cfg_attr(all(feature = "nightly", test), feature(test))]
|
2016-11-25 17:34:00 -05:00
|
|
|
|
2021-02-11 13:45:56 -05:00
|
|
|
use log::{debug, error};
|
2020-04-22 01:19:17 -04:00
|
|
|
use std::str::FromStr;
|
2020-04-18 01:41:55 -04:00
|
|
|
use structopt::StructOpt;
|
2018-03-04 15:24:24 -05:00
|
|
|
|
2020-04-14 02:03:49 -04:00
|
|
|
#[cfg(feature = "analytics")]
|
|
|
|
mod analytics;
|
|
|
|
|
|
|
|
/// Stub implementation of analytics module when not compiled with TensorFlow Lite.
|
|
|
|
#[cfg(not(feature = "analytics"))]
|
|
|
|
mod analytics {
|
2021-02-17 01:15:54 -05:00
|
|
|
use failure::{bail, Error};
|
2020-04-14 02:03:49 -04:00
|
|
|
|
|
|
|
pub struct ObjectDetector;
|
|
|
|
|
|
|
|
impl ObjectDetector {
|
|
|
|
pub fn new() -> Result<std::sync::Arc<ObjectDetector>, Error> {
|
|
|
|
bail!("Recompile with --features=analytics for object detection.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ObjectDetectorStream;
|
|
|
|
|
|
|
|
impl ObjectDetectorStream {
|
2021-02-17 01:15:54 -05:00
|
|
|
pub fn new(
|
|
|
|
_par: ffmpeg::avcodec::InputCodecParameters<'_>,
|
|
|
|
_detector: &ObjectDetector,
|
|
|
|
) -> Result<Self, Error> {
|
2020-04-14 02:03:49 -04:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
2021-02-17 01:15:54 -05:00
|
|
|
pub fn process_frame(
|
|
|
|
&mut self,
|
|
|
|
_pkt: &ffmpeg::avcodec::Packet<'_>,
|
|
|
|
_detector: &ObjectDetector,
|
|
|
|
) -> Result<(), Error> {
|
2020-04-14 02:03:49 -04:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:26:19 -04:00
|
|
|
mod body;
|
2017-01-16 15:50:47 -05:00
|
|
|
mod cmds;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod h264;
|
2017-02-05 23:13:51 -05:00
|
|
|
mod json;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod mp4;
|
2017-02-21 22:37:36 -05:00
|
|
|
mod slices;
|
2016-11-25 17:34:00 -05:00
|
|
|
mod stream;
|
|
|
|
mod streamer;
|
|
|
|
mod web;
|
|
|
|
|
2020-04-18 01:41:55 -04:00
|
|
|
#[derive(StructOpt)]
|
2021-02-17 01:15:54 -05:00
|
|
|
#[structopt(
|
|
|
|
name = "moonfire-nvr",
|
|
|
|
about = "security camera network video recorder"
|
|
|
|
)]
|
2020-04-18 01:41:55 -04:00
|
|
|
enum Args {
|
|
|
|
/// Checks database integrity (like fsck).
|
|
|
|
Check(cmds::check::Args),
|
2016-11-25 17:34:00 -05:00
|
|
|
|
2020-04-18 01:41:55 -04:00
|
|
|
/// Interactively edits configuration.
|
|
|
|
Config(cmds::config::Args),
|
2017-01-16 15:50:47 -05:00
|
|
|
|
2020-04-18 01:41:55 -04:00
|
|
|
/// Initializes a database.
|
|
|
|
Init(cmds::init::Args),
|
2016-11-25 17:34:00 -05:00
|
|
|
|
2020-04-18 01:41:55 -04:00
|
|
|
/// Logs in a user, returning the session cookie.
|
|
|
|
///
|
|
|
|
/// This is a privileged command that directly accesses the database. It doesn't check the
|
|
|
|
/// user's password and even can be used to create sessions with permissions the user doesn't
|
|
|
|
/// have.
|
|
|
|
Login(cmds::login::Args),
|
|
|
|
|
|
|
|
/// Runs the server, saving recordings and allowing web access.
|
|
|
|
Run(cmds::run::Args),
|
|
|
|
|
|
|
|
/// Runs a SQLite3 shell on Moonfire NVR's index database.
|
|
|
|
///
|
|
|
|
/// Note this locks the database to prevent simultaneous access with a running server. The
|
|
|
|
/// server maintains cached state which could be invalidated otherwise.
|
|
|
|
Sql(cmds::sql::Args),
|
|
|
|
|
|
|
|
/// Translates between integer and human-readable timestamps.
|
|
|
|
Ts(cmds::ts::Args),
|
|
|
|
|
|
|
|
/// Upgrades to the latest database schema.
|
|
|
|
Upgrade(cmds::upgrade::Args),
|
2017-01-16 15:50:47 -05:00
|
|
|
}
|
|
|
|
|
2020-04-18 01:41:55 -04:00
|
|
|
impl Args {
|
2021-02-11 13:45:56 -05:00
|
|
|
fn run(&self) -> Result<i32, failure::Error> {
|
2020-04-18 01:41:55 -04:00
|
|
|
match self {
|
|
|
|
Args::Check(ref a) => cmds::check::run(a),
|
|
|
|
Args::Config(ref a) => cmds::config::run(a),
|
|
|
|
Args::Init(ref a) => cmds::init::run(a),
|
|
|
|
Args::Login(ref a) => cmds::login::run(a),
|
|
|
|
Args::Run(ref a) => cmds::run::run(a),
|
|
|
|
Args::Sql(ref a) => cmds::sql::run(a),
|
|
|
|
Args::Ts(ref a) => cmds::ts::run(a),
|
|
|
|
Args::Upgrade(ref a) => cmds::upgrade::run(a),
|
|
|
|
}
|
2017-01-16 15:50:47 -05:00
|
|
|
}
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2020-04-18 01:41:55 -04:00
|
|
|
let args = Args::from_args();
|
2017-03-26 03:01:48 -04:00
|
|
|
let mut h = mylog::Builder::new()
|
2021-02-17 01:15:54 -05:00
|
|
|
.set_format(
|
|
|
|
::std::env::var("MOONFIRE_FORMAT")
|
|
|
|
.map_err(|_| ())
|
|
|
|
.and_then(|s| mylog::Format::from_str(&s))
|
|
|
|
.unwrap_or(mylog::Format::Google),
|
|
|
|
)
|
2017-03-26 03:01:48 -04:00
|
|
|
.set_spec(&::std::env::var("MOONFIRE_LOG").unwrap_or("info".to_owned()))
|
|
|
|
.build();
|
|
|
|
h.clone().install().unwrap();
|
|
|
|
|
2021-02-11 13:45:56 -05:00
|
|
|
let r = {
|
|
|
|
let _a = h.async_scope();
|
|
|
|
args.run()
|
|
|
|
};
|
|
|
|
match r {
|
|
|
|
Err(e) => {
|
|
|
|
error!("Exiting due to error: {}", base::prettify_failure(&e));
|
|
|
|
::std::process::exit(1);
|
2021-02-17 01:15:54 -05:00
|
|
|
}
|
2021-02-11 13:45:56 -05:00
|
|
|
Ok(rv) => {
|
|
|
|
debug!("Exiting with status {}", rv);
|
|
|
|
std::process::exit(rv)
|
2021-02-17 01:15:54 -05:00
|
|
|
}
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|
|
|
|
}
|