2020-03-02 01:53:41 -05:00
|
|
|
// This file is part of Moonfire NVR, a security camera network video recorder.
|
2020-04-18 01:41:55 -04:00
|
|
|
// Copyright (C) 2016-2020 The Moonfire NVR Authors
|
2016-11-25 17:34:00 -05:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// In addition, as a special exception, the copyright holders give
|
|
|
|
// permission to link the code of portions of this program with the
|
|
|
|
// OpenSSL library under certain conditions as described in each
|
|
|
|
// individual source file, and distribute linked combinations including
|
|
|
|
// the two.
|
|
|
|
//
|
|
|
|
// You must obey the GNU General Public License in all respects for all
|
|
|
|
// of the code used other than OpenSSL. If you modify file(s) with this
|
|
|
|
// exception, you may extend this exception to your version of the
|
|
|
|
// file(s), but you are not obligated to do so. If you do not wish to do
|
|
|
|
// so, delete this exception statement from your version. If you delete
|
|
|
|
// this exception statement from all source files in the program, then
|
|
|
|
// also delete it here.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-01-08 17:22:35 -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 {
|
|
|
|
use failure::{Error, bail};
|
|
|
|
|
|
|
|
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 {
|
|
|
|
pub fn new(_par: ffmpeg::avcodec::InputCodecParameters<'_>,
|
|
|
|
_detector: &ObjectDetector) -> Result<Self, Error> {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn process_frame(&mut self, _pkt: &ffmpeg::avcodec::Packet<'_>,
|
|
|
|
_detector: &ObjectDetector) -> Result<(), Error> {
|
|
|
|
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)]
|
|
|
|
#[structopt(name="moonfire-nvr", about="security camera network video recorder")]
|
|
|
|
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()
|
|
|
|
.set_format(::std::env::var("MOONFIRE_FORMAT")
|
2020-04-22 01:19:17 -04:00
|
|
|
.map_err(|_| ())
|
|
|
|
.and_then(|s| mylog::Format::from_str(&s))
|
2017-03-26 03:01:48 -04:00
|
|
|
.unwrap_or(mylog::Format::Google))
|
|
|
|
.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);
|
|
|
|
},
|
|
|
|
Ok(rv) => {
|
|
|
|
debug!("Exiting with status {}", rv);
|
|
|
|
std::process::exit(rv)
|
|
|
|
},
|
2016-11-25 17:34:00 -05:00
|
|
|
}
|
|
|
|
}
|