lose "extern crate" everywhere (Rust 2018 edition)

This commit is contained in:
Scott Lamb 2018-12-28 21:53:29 -06:00
parent f5703b9968
commit b5387af3d4
38 changed files with 166 additions and 219 deletions

4
Cargo.lock generated
View File

@ -882,7 +882,6 @@ dependencies = [
"ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rusqlite 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "rusqlite 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1514,6 +1513,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "serde" name = "serde"
version = "1.0.83" version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.83 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "serde_bytes" name = "serde_bytes"

View File

@ -2,12 +2,13 @@
name = "moonfire-nvr" name = "moonfire-nvr"
version = "0.1.0" version = "0.1.0"
authors = ["Scott Lamb <slamb@slamb.org>"] authors = ["Scott Lamb <slamb@slamb.org>"]
edition = "2018"
[features] [features]
# The nightly feature is used within moonfire-nvr itself to gate the # The nightly feature is used within moonfire-nvr itself to gate the
# benchmarks. Also pass it along to crates that can benefit from it. # benchmarks. Also pass it along to crates that can benefit from it.
nightly = ["moonfire-db/nightly", "parking_lot/nightly"] nightly = ["db/nightly", "parking_lot/nightly"]
# The bundled feature includes bundled (aka statically linked) versions of # The bundled feature includes bundled (aka statically linked) versions of
# native libraries where possible. # native libraries where possible.
@ -17,11 +18,14 @@ bundled = ["rusqlite/bundled"]
members = ["base", "db", "ffmpeg"] members = ["base", "db", "ffmpeg"]
[dependencies] [dependencies]
base = { package = "moonfire-base", path = "base" }
base64 = "0.10.0" base64 = "0.10.0"
bytes = "0.4.6" bytes = "0.4.6"
byteorder = "1.0" byteorder = "1.0"
db = { package = "moonfire-db", path = "db" }
docopt = "1.0" docopt = "1.0"
failure = "0.1.1" failure = "0.1.1"
ffmpeg = { package = "moonfire-ffmpeg", path = "ffmpeg" }
futures = "0.1" futures = "0.1"
futures-cpupool = "0.1" futures-cpupool = "0.1"
fnv = "1.0" fnv = "1.0"
@ -33,9 +37,6 @@ libc = "0.2"
log = { version = "0.4", features = ["release_max_level_info"] } log = { version = "0.4", features = ["release_max_level_info"] }
memchr = "2.0.2" memchr = "2.0.2"
memmap = "0.7" memmap = "0.7"
moonfire-base = { path = "base" }
moonfire-db = { path = "db" }
moonfire-ffmpeg = { path = "ffmpeg" }
mylog = { git = "https://github.com/scottlamb/mylog" } mylog = { git = "https://github.com/scottlamb/mylog" }
openssl = "0.10" openssl = "0.10"
parking_lot = { version = "0.7", features = [] } parking_lot = { version = "0.7", features = [] }
@ -43,8 +44,7 @@ reffers = "0.5.1"
regex = "1.0" regex = "1.0"
ring = "0.12.1" ring = "0.12.1"
rusqlite = "0.16" rusqlite = "0.16"
serde = "1.0" serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0" serde_json = "1.0"
smallvec = "0.6" smallvec = "0.6"
time = "0.1" time = "0.1"

View File

@ -29,7 +29,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
pub mod clock; pub mod clock;
#[macro_use] mod error; mod error;
pub mod strutil; pub mod strutil;
pub use crate::error::{Error, ErrorKind, ResultExt}; pub use crate::error::{Error, ErrorKind, ResultExt};

View File

@ -12,6 +12,7 @@ nightly = []
path = "lib.rs" path = "lib.rs"
[dependencies] [dependencies]
base = { package = "moonfire-base", path = "../base" }
base64 = "0.10.0" base64 = "0.10.0"
blake2-rfc = "0.2.18" blake2-rfc = "0.2.18"
failure = "0.1.1" failure = "0.1.1"
@ -21,7 +22,6 @@ libc = "0.2"
libpasta = "0.1.0-rc2" libpasta = "0.1.0-rc2"
log = "0.4" log = "0.4"
lru-cache = "0.1" lru-cache = "0.1"
moonfire-base = { path = "../base" }
mylog = { git = "https://github.com/scottlamb/mylog" } mylog = { git = "https://github.com/scottlamb/mylog" }
openssl = "0.10" openssl = "0.10"
parking_lot = { version = "0.7", features = [] } parking_lot = { version = "0.7", features = [] }

View File

@ -28,13 +28,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::base::strutil; use log::info;
use base::strutil;
use blake2_rfc::blake2b::blake2b; use blake2_rfc::blake2b::blake2b;
use failure::Error; use failure::{Error, bail, format_err};
use fnv::FnvHashMap; use fnv::FnvHashMap;
use lazy_static::lazy_static;
use libpasta; use libpasta;
use parking_lot::Mutex; use parking_lot::Mutex;
use rusqlite::{self, Connection, Transaction, types::ToSql}; use rusqlite::{Connection, Transaction, types::ToSql};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fmt; use std::fmt;
use std::net::IpAddr; use std::net::IpAddr;

View File

@ -32,11 +32,12 @@
use crate::db::{self, CompositeId, FromSqlUuid}; use crate::db::{self, CompositeId, FromSqlUuid};
use crate::dir; use crate::dir;
use failure::Error;
use fnv::FnvHashMap;
use crate::raw; use crate::raw;
use crate::recording; use crate::recording;
use rusqlite::{self, types::ToSql}; use failure::Error;
use fnv::FnvHashMap;
use log::error;
use rusqlite::types::ToSql;
use crate::schema; use crate::schema;
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
use std::fs; use std::fs;

View File

@ -52,18 +52,19 @@
//! A list of mutations is built up in-memory and occasionally flushed to reduce SSD write //! A list of mutations is built up in-memory and occasionally flushed to reduce SSD write
//! cycles. //! cycles.
use base::clock::{self, Clocks};
use crate::auth; use crate::auth;
use crate::base::clock::{self, Clocks};
use crate::dir; use crate::dir;
use failure::Error; use crate::raw;
use fnv::{self, FnvHashMap, FnvHashSet}; use crate::recording::{self, TIME_UNITS_PER_SEC};
use crate::schema;
use failure::{Error, bail, format_err};
use fnv::{FnvHashMap, FnvHashSet};
use log::{error, info, trace};
use lru_cache::LruCache; use lru_cache::LruCache;
use openssl::hash; use openssl::hash;
use parking_lot::{Mutex,MutexGuard}; use parking_lot::{Mutex,MutexGuard};
use crate::raw; use rusqlite::types::ToSql;
use crate::recording::{self, TIME_UNITS_PER_SEC};
use rusqlite::{self, types::ToSql};
use crate::schema;
use std::collections::{BTreeMap, VecDeque}; use std::collections::{BTreeMap, VecDeque};
use std::cell::RefCell; use std::cell::RefCell;
use std::cmp; use std::cmp;
@ -1922,9 +1923,7 @@ impl<'db, C: Clocks + Clone> ::std::ops::DerefMut for DatabaseGuard<'db, C> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate tempdir; use base::clock;
use crate::base::clock;
use crate::recording::{self, TIME_UNITS_PER_SEC}; use crate::recording::{self, TIME_UNITS_PER_SEC};
use rusqlite::Connection; use rusqlite::Connection;
use std::collections::BTreeMap; use std::collections::BTreeMap;

View File

@ -33,9 +33,10 @@
//! This includes opening files for serving, rotating away old files, and saving new files. //! This includes opening files for serving, rotating away old files, and saving new files.
use crate::db::CompositeId; use crate::db::CompositeId;
use failure::{Error, Fail}; use failure::{Error, Fail, bail, format_err};
use libc::{self, c_char}; use libc::c_char;
use protobuf::{self, Message}; use log::warn;
use protobuf::Message;
use crate::schema; use crate::schema;
use std::ffi; use std::ffi;
use std::fs; use std::fs;

View File

@ -30,26 +30,6 @@
#![cfg_attr(all(feature="nightly", test), feature(test))] #![cfg_attr(all(feature="nightly", test), feature(test))]
extern crate base64;
extern crate blake2_rfc;
#[macro_use] extern crate failure;
extern crate fnv;
#[macro_use] extern crate lazy_static;
extern crate libc;
extern crate libpasta;
#[macro_use] extern crate log;
extern crate lru_cache;
extern crate moonfire_base as base;
extern crate mylog;
extern crate openssl;
extern crate parking_lot;
extern crate protobuf;
extern crate regex;
extern crate rusqlite;
extern crate tempdir;
extern crate time;
extern crate uuid;
pub mod auth; pub mod auth;
pub mod check; pub mod check;
mod coding; mod coding;

View File

@ -31,10 +31,10 @@
//! Raw database access: SQLite statements which do not touch any cached state. //! Raw database access: SQLite statements which do not touch any cached state.
use crate::db::{self, CompositeId, FromSqlUuid}; use crate::db::{self, CompositeId, FromSqlUuid};
use failure::{Error, ResultExt}; use failure::{Error, ResultExt, bail};
use fnv::FnvHashSet; use fnv::FnvHashSet;
use crate::recording; use crate::recording;
use rusqlite::{self, types::ToSql}; use rusqlite::types::ToSql;
use std::ops::Range; use std::ops::Range;
use uuid::Uuid; use uuid::Uuid;

View File

@ -30,7 +30,9 @@
use crate::coding::{append_varint32, decode_varint32, unzigzag32, zigzag32}; use crate::coding::{append_varint32, decode_varint32, unzigzag32, zigzag32};
use crate::db; use crate::db;
use failure::Error; use failure::{Error, bail, format_err};
use lazy_static::lazy_static;
use log::trace;
use regex::Regex; use regex::Regex;
use std::ops; use std::ops;
use std::fmt; use std::fmt;
@ -505,7 +507,7 @@ impl Segment {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::base::clock::RealClocks; use base::clock::RealClocks;
use super::*; use super::*;
use crate::testutil::{self, TestDb}; use crate::testutil::{self, TestDb};
@ -743,12 +745,12 @@ mod tests {
#[cfg(all(test, feature="nightly"))] #[cfg(all(test, feature="nightly"))]
mod bench { mod bench {
extern crate test; extern crate test;
use self::test::Bencher;
use super::*; use super::*;
/// Benchmarks the decoder, which is performance-critical for .mp4 serving. /// Benchmarks the decoder, which is performance-critical for .mp4 serving.
#[bench] #[bench]
fn bench_decoder(b: &mut Bencher) { fn bench_decoder(b: &mut test::Bencher) {
let data = include_bytes!("testdata/video_sample_index.bin"); let data = include_bytes!("testdata/video_sample_index.bin");
b.bytes = data.len() as u64; b.bytes = data.len() as u64;
b.iter(|| { b.iter(|| {

View File

@ -28,7 +28,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::base::clock::Clocks; use base::clock::Clocks;
use crate::db; use crate::db;
use crate::dir; use crate::dir;
use fnv::FnvHashMap; use fnv::FnvHashMap;

View File

@ -33,8 +33,9 @@
/// See `guide/schema.md` for more information. /// See `guide/schema.md` for more information.
use crate::db; use crate::db;
use failure::Error; use failure::{Error, bail};
use rusqlite::{self, types::ToSql}; use log::info;
use rusqlite::types::ToSql;
mod v0_to_v1; mod v0_to_v1;
mod v1_to_v2; mod v1_to_v2;

View File

@ -31,9 +31,10 @@
/// Upgrades a version 0 schema to a version 1 schema. /// Upgrades a version 0 schema to a version 1 schema.
use crate::db; use crate::db;
use failure::Error;
use crate::recording; use crate::recording;
use rusqlite::{self, types::ToSql}; use failure::Error;
use log::warn;
use rusqlite::types::ToSql;
use std::collections::HashMap; use std::collections::HashMap;
pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> { pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> {

View File

@ -31,9 +31,9 @@
/// Upgrades a version 1 schema to a version 2 schema. /// Upgrades a version 1 schema to a version 2 schema.
use crate::dir; use crate::dir;
use failure::Error; use failure::{Error, bail, format_err};
use libc; use libc;
use rusqlite::{self, types::ToSql}; use rusqlite::types::ToSql;
use crate::schema::DirMeta; use crate::schema::DirMeta;
use std::fs; use std::fs;
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;

View File

@ -40,7 +40,7 @@ use crate::schema;
use std::io::{self, Write}; use std::io::{self, Write};
use std::mem; use std::mem;
use std::sync::Arc; use std::sync::Arc;
use rusqlite::{self, types::ToSql}; use rusqlite::types::ToSql;
use uuid::Uuid; use uuid::Uuid;
/// Opens the sample file dir. /// Opens the sample file dir.

View File

@ -32,13 +32,14 @@
//! //!
//! This includes opening files for serving, rotating away old files, and saving new files. //! This includes opening files for serving, rotating away old files, and saving new files.
use crate::base::clock::{self, Clocks}; use base::clock::{self, Clocks};
use crate::db::{self, CompositeId}; use crate::db::{self, CompositeId};
use crate::dir; use crate::dir;
use failure::Error; use crate::recording;
use failure::{Error, bail, format_err};
use fnv::FnvHashMap; use fnv::FnvHashMap;
use parking_lot::Mutex; use parking_lot::Mutex;
use crate::recording; use log::{debug, info, trace, warn};
use openssl::hash; use openssl::hash;
use std::cmp; use std::cmp;
use std::io; use std::io;
@ -741,10 +742,11 @@ impl<'a, C: Clocks + Clone, D: DirWriter> Drop for Writer<'a, C, D> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::base::clock::SimulatedClocks; use base::clock::SimulatedClocks;
use crate::db::{self, CompositeId}; use crate::db::{self, CompositeId};
use parking_lot::Mutex;
use crate::recording; use crate::recording;
use parking_lot::Mutex;
use log::warn;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::io; use std::io;
use std::sync::Arc; use std::sync::Arc;

View File

@ -28,9 +28,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate cc;
extern crate pkg_config;
fn main() { fn main() {
let libraries = [ let libraries = [
pkg_config::Config::new().atleast_version("54.1").probe("libavutil").unwrap(), pkg_config::Config::new().atleast_version("54.1").probe("libavutil").unwrap(),

View File

@ -28,9 +28,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate libc; use log::info;
#[macro_use] extern crate log;
use std::cell::{Ref, RefCell}; use std::cell::{Ref, RefCell};
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt::{self, Write}; use std::fmt::{self, Write};

View File

@ -30,7 +30,7 @@
//! Tools for implementing a `http_serve::Entity` body composed from many "slices". //! Tools for implementing a `http_serve::Entity` body composed from many "slices".
use crate::base::Error; use base::Error;
use failure::Fail; use failure::Fail;
use futures::{Stream, stream}; use futures::{Stream, stream};
use hyper::body::Payload; use hyper::body::Payload;

View File

@ -30,8 +30,9 @@
//! Subcommand to check the database and sample file dir for errors. //! Subcommand to check the database and sample file dir for errors.
use crate::db::check; use db::check;
use failure::Error; use failure::Error;
use serde::Deserialize;
static USAGE: &'static str = r#" static USAGE: &'static str = r#"
Checks database integrity. Checks database integrity.

View File

@ -28,17 +28,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate cursive; use crate::stream::{self, Opener, Stream};
use cursive::Cursive;
use self::cursive::Cursive; use cursive::traits::{Boxable, Identifiable, Finder};
use self::cursive::traits::{Boxable, Identifiable, Finder}; use cursive::views;
use self::cursive::views; use db::writer;
use crate::db::{self, writer};
use failure::Error; use failure::Error;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use crate::stream::{self, Opener, Stream};
use super::{decode_size, encode_size}; use super::{decode_size, encode_size};
/// Builds a `CameraChange` from an active `edit_camera_dialog`. /// Builds a `CameraChange` from an active `edit_camera_dialog`.

View File

@ -28,13 +28,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate cursive; use cursive::Cursive;
use cursive::traits::{Boxable, Identifiable};
use self::cursive::Cursive; use cursive::views;
use self::cursive::traits::{Boxable, Identifiable}; use db::writer;
use self::cursive::views;
use crate::db::{self, writer};
use failure::Error; use failure::Error;
use log::{debug, trace};
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::rc::Rc; use std::rc::Rc;

View File

@ -33,14 +33,14 @@
//! This code is a bit messy, but it's essentially a prototype. Eventually Moonfire NVR's //! This code is a bit messy, but it's essentially a prototype. Eventually Moonfire NVR's
//! configuration will likely be almost entirely done through a web-based UI. //! configuration will likely be almost entirely done through a web-based UI.
extern crate cursive; use base::clock;
use cursive::Cursive;
use self::cursive::Cursive; use cursive::views;
use self::cursive::views; use db;
use crate::clock;
use crate::db;
use failure::Error; use failure::Error;
use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use serde::Deserialize;
use std::sync::Arc; use std::sync::Arc;
use std::fmt::Write; use std::fmt::Write;
use std::str::FromStr; use std::str::FromStr;

View File

@ -28,12 +28,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate cursive; use cursive::Cursive;
use cursive::traits::{Boxable, Identifiable};
use self::cursive::Cursive; use cursive::views;
use self::cursive::traits::{Boxable, Identifiable};
use self::cursive::views;
use crate::db;
use std::sync::Arc; use std::sync::Arc;
/// Builds a `UserChange` from an active `edit_user_dialog`. /// Builds a `UserChange` from an active `edit_user_dialog`.

View File

@ -28,8 +28,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::db;
use failure::Error; use failure::Error;
use log::info;
use serde::Deserialize;
static USAGE: &'static str = r#" static USAGE: &'static str = r#"
Initializes a database. Initializes a database.

View File

@ -28,11 +28,12 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::db::dir; use db::dir;
use docopt; use docopt;
use failure::{Error, Fail}; use failure::{Error, Fail};
use libc; use libc;
use rusqlite; use rusqlite;
use serde::Deserialize;
use std::path::Path; use std::path::Path;
mod check; mod check;

View File

@ -28,20 +28,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::clock; use base::clock;
use crate::db::{self, dir, writer}; use crate::stream;
use failure::Error; use crate::streamer;
use crate::web;
use db::{dir, writer};
use failure::{Error, bail};
use fnv::FnvHashMap; use fnv::FnvHashMap;
use futures::{Future, Stream}; use futures::{Future, Stream};
use log::{error, info, warn};
use serde::Deserialize;
use std::error::Error as StdError; use std::error::Error as StdError;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::thread; use std::thread;
use crate::stream;
use crate::streamer;
use tokio; use tokio;
use tokio_signal::unix::{Signal, SIGINT, SIGTERM}; use tokio_signal::unix::{Signal, SIGINT, SIGTERM};
use crate::web;
// These are used in a hack to get the name of the current time zone (e.g. America/Los_Angeles). // These are used in a hack to get the name of the current time zone (e.g. America/Los_Angeles).
// They seem to be correct for Linux and macOS at least. // They seem to be correct for Linux and macOS at least.

View File

@ -28,8 +28,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::db::recording;
use failure::Error; use failure::Error;
use serde::Deserialize;
const USAGE: &'static str = r#" const USAGE: &'static str = r#"
Usage: moonfire-nvr ts <ts>... Usage: moonfire-nvr ts <ts>...
@ -44,7 +44,7 @@ struct Args {
pub fn run() -> Result<(), Error> { pub fn run() -> Result<(), Error> {
let arg: Args = super::parse_args(&USAGE)?; let arg: Args = super::parse_args(&USAGE)?;
for timestamp in &arg.arg_ts { for timestamp in &arg.arg_ts {
let t = recording::Time::parse(timestamp)?; let t = db::recording::Time::parse(timestamp)?;
println!("{} == {}", t, t.0); println!("{} == {}", t, t.0);
} }
Ok(()) Ok(())

View File

@ -32,8 +32,8 @@
/// ///
/// See `guide/schema.md` for more information. /// See `guide/schema.md` for more information.
use crate::db;
use failure::Error; use failure::Error;
use serde::Deserialize;
const USAGE: &'static str = r#" const USAGE: &'static str = r#"
Upgrade to the latest database schema. Upgrade to the latest database schema.

View File

@ -41,7 +41,8 @@
//! would be more trouble than it's worth. //! would be more trouble than it's worth.
use byteorder::{BigEndian, WriteBytesExt}; use byteorder::{BigEndian, WriteBytesExt};
use failure::Error; use failure::{Error, bail};
use lazy_static::lazy_static;
use regex::bytes::Regex; use regex::bytes::Regex;
// See ISO/IEC 14496-10 table 7-1 - NAL unit type codes, syntax element categories, and NAL unit // See ISO/IEC 14496-10 table 7-1 - NAL unit type codes, syntax element categories, and NAL unit
@ -248,7 +249,7 @@ pub fn transform_sample_data(annexb_sample: &[u8], avc_sample: &mut Vec<u8>) ->
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::db::testutil; use db::testutil;
const ANNEX_B_TEST_INPUT: [u8; 35] = [ const ANNEX_B_TEST_INPUT: [u8; 35] = [
0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, 0x1f,

View File

@ -28,8 +28,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::db::{self, auth::SessionHash}; use db::auth::SessionHash;
use failure::Error; use failure::{Error, format_err};
use serde::Serialize;
use serde::ser::{SerializeMap, SerializeSeq, Serializer}; use serde::ser::{SerializeMap, SerializeSeq, Serializer};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::ops::Not; use std::ops::Not;

View File

@ -30,44 +30,8 @@
#![cfg_attr(all(feature="nightly", test), feature(test))] #![cfg_attr(all(feature="nightly", test), feature(test))]
extern crate base64; use log::{error, info};
extern crate bytes; use serde::Deserialize;
extern crate byteorder;
extern crate core;
extern crate docopt;
extern crate futures;
extern crate futures_cpupool;
#[macro_use] extern crate failure;
extern crate fnv;
extern crate http;
extern crate http_serve;
extern crate hyper;
#[macro_use] extern crate lazy_static;
extern crate libc;
#[macro_use] extern crate log;
extern crate reffers;
extern crate rusqlite;
extern crate memchr;
extern crate memmap;
extern crate moonfire_base as base;
extern crate moonfire_db as db;
extern crate moonfire_ffmpeg;
extern crate mylog;
extern crate openssl;
extern crate parking_lot;
extern crate regex;
extern crate ring;
extern crate serde;
#[macro_use] extern crate serde_derive;
extern crate serde_json;
extern crate smallvec;
extern crate time;
extern crate tokio;
extern crate tokio_signal;
extern crate url;
extern crate uuid;
use crate::base::clock as clock;
mod body; mod body;
mod cmds; mod cmds;

View File

@ -76,19 +76,18 @@
//! * mdat (media data container) //! * mdat (media data container)
//! ``` //! ```
extern crate time; use base::{strutil, Error, ErrorKind, ResultExt, bail_t, format_err_t};
use crate::base::{strutil, Error, ErrorKind, ResultExt, bail_t, format_err_t};
use bytes::{Buf, BytesMut}; use bytes::{Buf, BytesMut};
use byteorder::{BigEndian, ByteOrder, WriteBytesExt}; use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use crate::body::{Chunk, BoxedError, wrap_error}; use crate::body::{Chunk, BoxedError, wrap_error};
use crate::db::recording::{self, TIME_UNITS_PER_SEC}; use db::dir;
use crate::db::{self, dir}; use db::recording::{self, TIME_UNITS_PER_SEC};
use futures::Stream; use futures::Stream;
use futures::stream; use futures::stream;
use http; use http;
use http::header::HeaderValue; use http::header::HeaderValue;
use http_serve; use http_serve;
use log::{debug, error, trace, warn};
use memmap; use memmap;
use openssl::hash; use openssl::hash;
use parking_lot::{Once, ONCE_INIT}; use parking_lot::{Once, ONCE_INIT};
@ -1536,15 +1535,16 @@ impl http_serve::Entity for File {
/// to verify the output is byte-for-byte as expected. /// to verify the output is byte-for-byte as expected.
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::base::strutil; use base::{clock::RealClocks, strutil};
use bytes::Buf; use bytes::Buf;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use crate::clock::RealClocks; use crate::stream::{self, Opener, Stream};
use crate::db::recording::{self, TIME_UNITS_PER_SEC}; use db::recording::{self, TIME_UNITS_PER_SEC};
use crate::db::testutil::{self, TestDb, TEST_STREAM_ID}; use db::testutil::{self, TestDb, TEST_STREAM_ID};
use crate::db::writer; use db::writer;
use futures::Future; use futures::Future;
use futures::Stream as FuturesStream; use futures::Stream as FuturesStream;
use log::info;
use openssl::hash; use openssl::hash;
use http_serve::{self, Entity}; use http_serve::{self, Entity};
use std::fs; use std::fs;
@ -1552,7 +1552,6 @@ mod tests {
use std::path::Path; use std::path::Path;
use std::str; use std::str;
use super::*; use super::*;
use crate::stream::{self, Opener, Stream};
fn fill_slice<E: http_serve::Entity>(slice: &mut [u8], e: &E, start: u64) fn fill_slice<E: http_serve::Entity>(slice: &mut [u8], e: &E, start: u64)
where E::Error : ::std::fmt::Debug { where E::Error : ::std::fmt::Debug {
@ -2215,7 +2214,6 @@ mod tests {
#[cfg(all(test, feature="nightly"))] #[cfg(all(test, feature="nightly"))]
mod bench { mod bench {
extern crate reqwest;
extern crate test; extern crate test;
use base::clock::RealClocks; use base::clock::RealClocks;
@ -2225,7 +2223,7 @@ mod bench {
use hyper; use hyper;
use http::header; use http::header;
use http_serve; use http_serve;
use self::test::Bencher; use lazy_static::lazy_static;
use std::error::Error as StdError; use std::error::Error as StdError;
use super::tests::create_mp4_from_db; use super::tests::create_mp4_from_db;
use url::Url; use url::Url;
@ -2268,9 +2266,9 @@ mod bench {
struct MyService(super::File); struct MyService(super::File);
impl hyper::service::Service for MyService { impl hyper::service::Service for MyService {
type ReqBody = ::hyper::Body; type ReqBody = hyper::Body;
type ResBody = ::body::Body; type ResBody = crate::body::Body;
type Error = ::body::BoxedError; type Error = crate::body::BoxedError;
type Future = future::FutureResult<::http::Response<Self::ResBody>, Self::Error>; type Future = future::FutureResult<::http::Response<Self::ResBody>, Self::Error>;
fn call(&mut self, req: ::http::Request<Self::ReqBody>) -> Self::Future { fn call(&mut self, req: ::http::Request<Self::ReqBody>) -> Self::Future {
@ -2283,7 +2281,7 @@ mod bench {
} }
#[bench] #[bench]
fn build_index(b: &mut Bencher) { fn build_index(b: &mut test::Bencher) {
testutil::init(); testutil::init();
let db = TestDb::new(RealClocks {}); let db = TestDb::new(RealClocks {});
testutil::add_dummy_recordings_to_db(&db.db, 1); testutil::add_dummy_recordings_to_db(&db.db, 1);
@ -2310,7 +2308,7 @@ mod bench {
/// Benchmarks serving the generated part of a `.mp4` file (up to the first byte from disk). /// Benchmarks serving the generated part of a `.mp4` file (up to the first byte from disk).
#[bench] #[bench]
fn serve_generated_bytes(b: &mut Bencher) { fn serve_generated_bytes(b: &mut test::Bencher) {
testutil::init(); testutil::init();
let server = &*SERVER; let server = &*SERVER;
let p = server.generated_len; let p = server.generated_len;
@ -2333,7 +2331,7 @@ mod bench {
} }
#[bench] #[bench]
fn mp4_construction(b: &mut Bencher) { fn mp4_construction(b: &mut test::Bencher) {
testutil::init(); testutil::init();
let db = TestDb::new(RealClocks {}); let db = TestDb::new(RealClocks {});
testutil::add_dummy_recordings_to_db(&db.db, 60); testutil::add_dummy_recordings_to_db(&db.db, 60);

View File

@ -30,11 +30,10 @@
//! Tools for implementing a `http_serve::Entity` body composed from many "slices". //! Tools for implementing a `http_serve::Entity` body composed from many "slices".
use crate::base::format_err_t; use base::format_err_t;
use crate::body::{BoxedError, wrap_error}; use crate::body::{BoxedError, wrap_error};
use failure::Error; use failure::{Error, bail};
use futures::stream; use futures::{Stream, stream};
use futures::Stream;
use std::fmt; use std::fmt;
use std::ops::Range; use std::ops::Range;
@ -151,9 +150,10 @@ impl<S> Slices<S> where S: Slice {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::body::BoxedError; use crate::body::BoxedError;
use crate::db::testutil; use db::testutil;
use futures::{Future, Stream}; use futures::{Future, Stream};
use futures::stream; use futures::stream;
use lazy_static::lazy_static;
use std::ops::Range; use std::ops::Range;
use super::{Slice, Slices}; use super::{Slice, Slices};

View File

@ -28,9 +28,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use failure::Error;
use crate::h264; use crate::h264;
use moonfire_ffmpeg; use failure::{Error, bail};
use ffmpeg;
use lazy_static::lazy_static;
use log::{debug, info, warn};
use std::os::raw::c_char; use std::os::raw::c_char;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::result::Result; use std::result::Result;
@ -55,7 +57,7 @@ pub trait Opener<S : Stream> : Sync {
pub trait Stream { pub trait Stream {
fn get_extra_data(&self) -> Result<h264::ExtraData, Error>; fn get_extra_data(&self) -> Result<h264::ExtraData, Error>;
fn get_next<'p>(&'p mut self) -> Result<moonfire_ffmpeg::Packet<'p>, moonfire_ffmpeg::Error>; fn get_next<'p>(&'p mut self) -> Result<ffmpeg::Packet<'p>, ffmpeg::Error>;
} }
pub struct Ffmpeg {} pub struct Ffmpeg {}
@ -63,7 +65,7 @@ pub struct Ffmpeg {}
impl Ffmpeg { impl Ffmpeg {
fn new() -> Ffmpeg { fn new() -> Ffmpeg {
START.call_once(|| { START.call_once(|| {
moonfire_ffmpeg::Ffmpeg::new(); ffmpeg::Ffmpeg::new();
//ffmpeg::init().unwrap(); //ffmpeg::init().unwrap();
//ffmpeg::format::network::init(); //ffmpeg::format::network::init();
}); });
@ -79,11 +81,11 @@ macro_rules! c_str {
impl Opener<FfmpegStream> for Ffmpeg { impl Opener<FfmpegStream> for Ffmpeg {
fn open(&self, src: Source) -> Result<FfmpegStream, Error> { fn open(&self, src: Source) -> Result<FfmpegStream, Error> {
use moonfire_ffmpeg::InputFormatContext; use ffmpeg::InputFormatContext;
let (mut input, discard_first) = match src { let (mut input, discard_first) = match src {
#[cfg(test)] #[cfg(test)]
Source::File(filename) => { Source::File(filename) => {
let mut open_options = moonfire_ffmpeg::Dictionary::new(); let mut open_options = ffmpeg::Dictionary::new();
// Work around https://github.com/scottlamb/moonfire-nvr/issues/10 // Work around https://github.com/scottlamb/moonfire-nvr/issues/10
open_options.set(c_str!("advanced_editlist"), c_str!("false")).unwrap(); open_options.set(c_str!("advanced_editlist"), c_str!("false")).unwrap();
@ -97,7 +99,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
(i, false) (i, false)
} }
Source::Rtsp(url) => { Source::Rtsp(url) => {
let mut open_options = moonfire_ffmpeg::Dictionary::new(); let mut open_options = ffmpeg::Dictionary::new();
open_options.set(c_str!("rtsp_transport"), c_str!("tcp")).unwrap(); open_options.set(c_str!("rtsp_transport"), c_str!("tcp")).unwrap();
// https://trac.ffmpeg.org/ticket/5018 workaround attempt. // https://trac.ffmpeg.org/ticket/5018 workaround attempt.
open_options.set(c_str!("probesize"), c_str!("262144")).unwrap(); open_options.set(c_str!("probesize"), c_str!("262144")).unwrap();
@ -147,7 +149,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
} }
pub struct FfmpegStream { pub struct FfmpegStream {
input: moonfire_ffmpeg::InputFormatContext, input: ffmpeg::InputFormatContext,
video_i: usize, video_i: usize,
} }
@ -166,7 +168,7 @@ impl Stream for FfmpegStream {
h264::ExtraData::parse(codec.extradata(), codec.width() as u16, codec.height() as u16) h264::ExtraData::parse(codec.extradata(), codec.width() as u16, codec.height() as u16)
} }
fn get_next<'i>(&'i mut self) -> Result<moonfire_ffmpeg::Packet<'i>, moonfire_ffmpeg::Error> { fn get_next<'i>(&'i mut self) -> Result<ffmpeg::Packet<'i>, ffmpeg::Error> {
loop { loop {
let p = self.input.read_frame()?; let p = self.input.read_frame()?;
if p.stream_index() == self.video_i { if p.stream_index() == self.video_i {

View File

@ -28,14 +28,15 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::clock::{Clocks, TimerGuard}; use base::clock::{Clocks, TimerGuard};
use crate::db::{Camera, Database, Stream, dir, recording, writer};
use failure::Error;
use crate::h264; use crate::h264;
use crate::stream;
use db::{Camera, Database, Stream, dir, recording, writer};
use failure::{Error, bail, format_err};
use log::{debug, info, trace, warn};
use std::result::Result; use std::result::Result;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc; use std::sync::Arc;
use crate::stream;
use time; use time;
pub static ROTATE_INTERVAL_SEC: i64 = 60; pub static ROTATE_INTERVAL_SEC: i64 = 60;
@ -186,18 +187,16 @@ impl<'a, C, S> Streamer<'a, C, S> where C: 'a + Clocks + Clone, S: 'a + stream::
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::clock::{self, Clocks}; use base::clock::{self, Clocks};
use crate::db::{self, CompositeId};
use crate::db::recording;
use crate::db::testutil;
use failure::Error;
use crate::h264; use crate::h264;
use moonfire_ffmpeg; use crate::stream::{self, Opener, Stream};
use db::{CompositeId, recording, testutil};
use failure::{Error, bail};
use log::trace;
use parking_lot::Mutex; use parking_lot::Mutex;
use std::cmp; use std::cmp;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use crate::stream::{self, Opener, Stream};
use time; use time;
struct ProxyingStream<'a> { struct ProxyingStream<'a> {
@ -227,9 +226,9 @@ mod tests {
} }
impl<'a> Stream for ProxyingStream<'a> { impl<'a> Stream for ProxyingStream<'a> {
fn get_next(&mut self) -> Result<moonfire_ffmpeg::Packet, moonfire_ffmpeg::Error> { fn get_next(&mut self) -> Result<ffmpeg::Packet, ffmpeg::Error> {
if self.pkts_left == 0 { if self.pkts_left == 0 {
return Err(moonfire_ffmpeg::Error::eof()); return Err(ffmpeg::Error::eof());
} }
self.pkts_left -= 1; self.pkts_left -= 1;

View File

@ -28,26 +28,26 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
extern crate hyper; use base::clock::Clocks;
use base::{ErrorKind, strutil};
use crate::base::clock::Clocks;
use crate::base::{ErrorKind, strutil};
use crate::body::{Body, BoxedError}; use crate::body::{Body, BoxedError};
use crate::json;
use crate::mp4;
use base64; use base64;
use bytes::{BufMut, BytesMut}; use bytes::{BufMut, BytesMut};
use core::borrow::Borrow; use core::borrow::Borrow;
use core::str::FromStr; use core::str::FromStr;
use crate::db::{self, auth, recording}; use db::{auth, recording};
use crate::db::dir::SampleFileDir; use db::dir::SampleFileDir;
use failure::Error; use failure::{Error, bail, format_err};
use fnv::FnvHashMap; use fnv::FnvHashMap;
use futures::{Future, Stream, future}; use futures::{Future, Stream, future};
use futures_cpupool; use futures_cpupool;
use crate::json; use http::{Request, Response, status::StatusCode};
use http::{self, Request, Response, status::StatusCode};
use http_serve; use http_serve;
use http::header::{self, HeaderValue}; use http::header::{self, HeaderValue};
use crate::mp4; use lazy_static::lazy_static;
use log::{debug, info, warn};
use regex::Regex; use regex::Regex;
use serde_json; use serde_json;
use std::collections::HashMap; use std::collections::HashMap;
@ -849,18 +849,16 @@ impl ::hyper::service::Service for Service {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate reqwest; use db::testutil::{self, TestDb};
use crate::db;
use crate::db::testutil::{self, TestDb};
use futures::Future; use futures::Future;
use http::{self, header}; use http::header;
use log::info;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error as StdError; use std::error::Error as StdError;
use super::Segments; use super::Segments;
struct Server { struct Server {
db: TestDb<crate::base::clock::RealClocks>, db: TestDb<base::clock::RealClocks>,
base_url: String, base_url: String,
//test_camera_uuid: Uuid, //test_camera_uuid: Uuid,
handle: Option<::std::thread::JoinHandle<()>>, handle: Option<::std::thread::JoinHandle<()>>,
@ -869,7 +867,7 @@ mod tests {
impl Server { impl Server {
fn new(require_auth: bool) -> Server { fn new(require_auth: bool) -> Server {
let db = TestDb::new(crate::base::clock::RealClocks {}); let db = TestDb::new(base::clock::RealClocks {});
let (shutdown_tx, shutdown_rx) = futures::sync::oneshot::channel::<()>(); let (shutdown_tx, shutdown_rx) = futures::sync::oneshot::channel::<()>();
let addr = "127.0.0.1:0".parse().unwrap(); let addr = "127.0.0.1:0".parse().unwrap();
let service = super::Service::new(super::Config { let service = super::Service::new(super::Config {
@ -1077,13 +1075,12 @@ mod tests {
#[cfg(all(test, feature="nightly"))] #[cfg(all(test, feature="nightly"))]
mod bench { mod bench {
extern crate reqwest;
extern crate test; extern crate test;
use db::testutil::{self, TestDb}; use db::testutil::{self, TestDb};
use futures::Future; use futures::Future;
use hyper; use hyper;
use self::test::Bencher; use lazy_static::lazy_static;
use std::error::Error as StdError; use std::error::Error as StdError;
use uuid::Uuid; use uuid::Uuid;
@ -1125,7 +1122,7 @@ mod bench {
} }
#[bench] #[bench]
fn serve_stream_recordings(b: &mut Bencher) { fn serve_stream_recordings(b: &mut test::Bencher) {
testutil::init(); testutil::init();
let server = &*SERVER; let server = &*SERVER;
let url = reqwest::Url::parse(&format!("{}/api/cameras/{}/main/recordings", server.base_url, let url = reqwest::Url::parse(&format!("{}/api/cameras/{}/main/recordings", server.base_url,