lose "extern crate" everywhere (Rust 2018 edition)
This commit is contained in:
parent
f5703b9968
commit
b5387af3d4
|
@ -882,7 +882,6 @@ dependencies = [
|
|||
"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)",
|
||||
"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)",
|
||||
"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)",
|
||||
|
@ -1514,6 +1513,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
name = "serde"
|
||||
version = "1.0.83"
|
||||
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]]
|
||||
name = "serde_bytes"
|
||||
|
|
12
Cargo.toml
12
Cargo.toml
|
@ -2,12 +2,13 @@
|
|||
name = "moonfire-nvr"
|
||||
version = "0.1.0"
|
||||
authors = ["Scott Lamb <slamb@slamb.org>"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
|
||||
# The nightly feature is used within moonfire-nvr itself to gate the
|
||||
# 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
|
||||
# native libraries where possible.
|
||||
|
@ -17,11 +18,14 @@ bundled = ["rusqlite/bundled"]
|
|||
members = ["base", "db", "ffmpeg"]
|
||||
|
||||
[dependencies]
|
||||
base = { package = "moonfire-base", path = "base" }
|
||||
base64 = "0.10.0"
|
||||
bytes = "0.4.6"
|
||||
byteorder = "1.0"
|
||||
db = { package = "moonfire-db", path = "db" }
|
||||
docopt = "1.0"
|
||||
failure = "0.1.1"
|
||||
ffmpeg = { package = "moonfire-ffmpeg", path = "ffmpeg" }
|
||||
futures = "0.1"
|
||||
futures-cpupool = "0.1"
|
||||
fnv = "1.0"
|
||||
|
@ -33,9 +37,6 @@ libc = "0.2"
|
|||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
memchr = "2.0.2"
|
||||
memmap = "0.7"
|
||||
moonfire-base = { path = "base" }
|
||||
moonfire-db = { path = "db" }
|
||||
moonfire-ffmpeg = { path = "ffmpeg" }
|
||||
mylog = { git = "https://github.com/scottlamb/mylog" }
|
||||
openssl = "0.10"
|
||||
parking_lot = { version = "0.7", features = [] }
|
||||
|
@ -43,8 +44,7 @@ reffers = "0.5.1"
|
|||
regex = "1.0"
|
||||
ring = "0.12.1"
|
||||
rusqlite = "0.16"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
smallvec = "0.6"
|
||||
time = "0.1"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod clock;
|
||||
#[macro_use] mod error;
|
||||
mod error;
|
||||
pub mod strutil;
|
||||
|
||||
pub use crate::error::{Error, ErrorKind, ResultExt};
|
||||
|
|
|
@ -12,6 +12,7 @@ nightly = []
|
|||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
base = { package = "moonfire-base", path = "../base" }
|
||||
base64 = "0.10.0"
|
||||
blake2-rfc = "0.2.18"
|
||||
failure = "0.1.1"
|
||||
|
@ -21,7 +22,6 @@ libc = "0.2"
|
|||
libpasta = "0.1.0-rc2"
|
||||
log = "0.4"
|
||||
lru-cache = "0.1"
|
||||
moonfire-base = { path = "../base" }
|
||||
mylog = { git = "https://github.com/scottlamb/mylog" }
|
||||
openssl = "0.10"
|
||||
parking_lot = { version = "0.7", features = [] }
|
||||
|
|
|
@ -28,13 +28,15 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// 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 failure::Error;
|
||||
use failure::{Error, bail, format_err};
|
||||
use fnv::FnvHashMap;
|
||||
use lazy_static::lazy_static;
|
||||
use libpasta;
|
||||
use parking_lot::Mutex;
|
||||
use rusqlite::{self, Connection, Transaction, types::ToSql};
|
||||
use rusqlite::{Connection, Transaction, types::ToSql};
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt;
|
||||
use std::net::IpAddr;
|
||||
|
|
|
@ -32,11 +32,12 @@
|
|||
|
||||
use crate::db::{self, CompositeId, FromSqlUuid};
|
||||
use crate::dir;
|
||||
use failure::Error;
|
||||
use fnv::FnvHashMap;
|
||||
use crate::raw;
|
||||
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 std::os::unix::ffi::OsStrExt;
|
||||
use std::fs;
|
||||
|
|
19
db/db.rs
19
db/db.rs
|
@ -52,18 +52,19 @@
|
|||
//! A list of mutations is built up in-memory and occasionally flushed to reduce SSD write
|
||||
//! cycles.
|
||||
|
||||
use base::clock::{self, Clocks};
|
||||
use crate::auth;
|
||||
use crate::base::clock::{self, Clocks};
|
||||
use crate::dir;
|
||||
use failure::Error;
|
||||
use fnv::{self, FnvHashMap, FnvHashSet};
|
||||
use crate::raw;
|
||||
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 openssl::hash;
|
||||
use parking_lot::{Mutex,MutexGuard};
|
||||
use crate::raw;
|
||||
use crate::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use crate::schema;
|
||||
use rusqlite::types::ToSql;
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
|
@ -1922,9 +1923,7 @@ impl<'db, C: Clocks + Clone> ::std::ops::DerefMut for DatabaseGuard<'db, C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tempdir;
|
||||
|
||||
use crate::base::clock;
|
||||
use base::clock;
|
||||
use crate::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use rusqlite::Connection;
|
||||
use std::collections::BTreeMap;
|
||||
|
|
|
@ -33,9 +33,10 @@
|
|||
//! This includes opening files for serving, rotating away old files, and saving new files.
|
||||
|
||||
use crate::db::CompositeId;
|
||||
use failure::{Error, Fail};
|
||||
use libc::{self, c_char};
|
||||
use protobuf::{self, Message};
|
||||
use failure::{Error, Fail, bail, format_err};
|
||||
use libc::c_char;
|
||||
use log::warn;
|
||||
use protobuf::Message;
|
||||
use crate::schema;
|
||||
use std::ffi;
|
||||
use std::fs;
|
||||
|
|
20
db/lib.rs
20
db/lib.rs
|
@ -30,26 +30,6 @@
|
|||
|
||||
#![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 check;
|
||||
mod coding;
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
//! Raw database access: SQLite statements which do not touch any cached state.
|
||||
|
||||
use crate::db::{self, CompositeId, FromSqlUuid};
|
||||
use failure::{Error, ResultExt};
|
||||
use failure::{Error, ResultExt, bail};
|
||||
use fnv::FnvHashSet;
|
||||
use crate::recording;
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use rusqlite::types::ToSql;
|
||||
use std::ops::Range;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
|
@ -30,7 +30,9 @@
|
|||
|
||||
use crate::coding::{append_varint32, decode_varint32, unzigzag32, zigzag32};
|
||||
use crate::db;
|
||||
use failure::Error;
|
||||
use failure::{Error, bail, format_err};
|
||||
use lazy_static::lazy_static;
|
||||
use log::trace;
|
||||
use regex::Regex;
|
||||
use std::ops;
|
||||
use std::fmt;
|
||||
|
@ -505,7 +507,7 @@ impl Segment {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::base::clock::RealClocks;
|
||||
use base::clock::RealClocks;
|
||||
use super::*;
|
||||
use crate::testutil::{self, TestDb};
|
||||
|
||||
|
@ -743,12 +745,12 @@ mod tests {
|
|||
#[cfg(all(test, feature="nightly"))]
|
||||
mod bench {
|
||||
extern crate test;
|
||||
use self::test::Bencher;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Benchmarks the decoder, which is performance-critical for .mp4 serving.
|
||||
#[bench]
|
||||
fn bench_decoder(b: &mut Bencher) {
|
||||
fn bench_decoder(b: &mut test::Bencher) {
|
||||
let data = include_bytes!("testdata/video_sample_index.bin");
|
||||
b.bytes = data.len() as u64;
|
||||
b.iter(|| {
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// 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::dir;
|
||||
use fnv::FnvHashMap;
|
||||
|
|
|
@ -33,8 +33,9 @@
|
|||
/// See `guide/schema.md` for more information.
|
||||
|
||||
use crate::db;
|
||||
use failure::Error;
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use failure::{Error, bail};
|
||||
use log::info;
|
||||
use rusqlite::types::ToSql;
|
||||
|
||||
mod v0_to_v1;
|
||||
mod v1_to_v2;
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
/// Upgrades a version 0 schema to a version 1 schema.
|
||||
|
||||
use crate::db;
|
||||
use failure::Error;
|
||||
use crate::recording;
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use failure::Error;
|
||||
use log::warn;
|
||||
use rusqlite::types::ToSql;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> {
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
/// Upgrades a version 1 schema to a version 2 schema.
|
||||
|
||||
use crate::dir;
|
||||
use failure::Error;
|
||||
use failure::{Error, bail, format_err};
|
||||
use libc;
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use rusqlite::types::ToSql;
|
||||
use crate::schema::DirMeta;
|
||||
use std::fs;
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
|
|
|
@ -40,7 +40,7 @@ use crate::schema;
|
|||
use std::io::{self, Write};
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use rusqlite::{self, types::ToSql};
|
||||
use rusqlite::types::ToSql;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Opens the sample file dir.
|
||||
|
|
12
db/writer.rs
12
db/writer.rs
|
@ -32,13 +32,14 @@
|
|||
//!
|
||||
//! 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::dir;
|
||||
use failure::Error;
|
||||
use crate::recording;
|
||||
use failure::{Error, bail, format_err};
|
||||
use fnv::FnvHashMap;
|
||||
use parking_lot::Mutex;
|
||||
use crate::recording;
|
||||
use log::{debug, info, trace, warn};
|
||||
use openssl::hash;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
|
@ -741,10 +742,11 @@ impl<'a, C: Clocks + Clone, D: DirWriter> Drop for Writer<'a, C, D> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::base::clock::SimulatedClocks;
|
||||
use base::clock::SimulatedClocks;
|
||||
use crate::db::{self, CompositeId};
|
||||
use parking_lot::Mutex;
|
||||
use crate::recording;
|
||||
use parking_lot::Mutex;
|
||||
use log::warn;
|
||||
use std::collections::VecDeque;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate cc;
|
||||
extern crate pkg_config;
|
||||
|
||||
fn main() {
|
||||
let libraries = [
|
||||
pkg_config::Config::new().atleast_version("54.1").probe("libavutil").unwrap(),
|
||||
|
|
|
@ -28,9 +28,7 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
use log::info;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::{self, Write};
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
//! Tools for implementing a `http_serve::Entity` body composed from many "slices".
|
||||
|
||||
use crate::base::Error;
|
||||
use base::Error;
|
||||
use failure::Fail;
|
||||
use futures::{Stream, stream};
|
||||
use hyper::body::Payload;
|
||||
|
|
|
@ -30,8 +30,9 @@
|
|||
|
||||
//! Subcommand to check the database and sample file dir for errors.
|
||||
|
||||
use crate::db::check;
|
||||
use db::check;
|
||||
use failure::Error;
|
||||
use serde::Deserialize;
|
||||
|
||||
static USAGE: &'static str = r#"
|
||||
Checks database integrity.
|
||||
|
|
|
@ -28,17 +28,15 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate cursive;
|
||||
|
||||
use self::cursive::Cursive;
|
||||
use self::cursive::traits::{Boxable, Identifiable, Finder};
|
||||
use self::cursive::views;
|
||||
use crate::db::{self, writer};
|
||||
use crate::stream::{self, Opener, Stream};
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::{Boxable, Identifiable, Finder};
|
||||
use cursive::views;
|
||||
use db::writer;
|
||||
use failure::Error;
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use crate::stream::{self, Opener, Stream};
|
||||
use super::{decode_size, encode_size};
|
||||
|
||||
/// Builds a `CameraChange` from an active `edit_camera_dialog`.
|
||||
|
|
|
@ -28,13 +28,12 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate cursive;
|
||||
|
||||
use self::cursive::Cursive;
|
||||
use self::cursive::traits::{Boxable, Identifiable};
|
||||
use self::cursive::views;
|
||||
use crate::db::{self, writer};
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::{Boxable, Identifiable};
|
||||
use cursive::views;
|
||||
use db::writer;
|
||||
use failure::Error;
|
||||
use log::{debug, trace};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::rc::Rc;
|
||||
|
|
|
@ -33,14 +33,14 @@
|
|||
//! 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.
|
||||
|
||||
extern crate cursive;
|
||||
|
||||
use self::cursive::Cursive;
|
||||
use self::cursive::views;
|
||||
use crate::clock;
|
||||
use crate::db;
|
||||
use base::clock;
|
||||
use cursive::Cursive;
|
||||
use cursive::views;
|
||||
use db;
|
||||
use failure::Error;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use std::fmt::Write;
|
||||
use std::str::FromStr;
|
||||
|
|
|
@ -28,12 +28,9 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate cursive;
|
||||
|
||||
use self::cursive::Cursive;
|
||||
use self::cursive::traits::{Boxable, Identifiable};
|
||||
use self::cursive::views;
|
||||
use crate::db;
|
||||
use cursive::Cursive;
|
||||
use cursive::traits::{Boxable, Identifiable};
|
||||
use cursive::views;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Builds a `UserChange` from an active `edit_user_dialog`.
|
||||
|
|
|
@ -28,8 +28,9 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::db;
|
||||
use failure::Error;
|
||||
use log::info;
|
||||
use serde::Deserialize;
|
||||
|
||||
static USAGE: &'static str = r#"
|
||||
Initializes a database.
|
||||
|
|
|
@ -28,11 +28,12 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::db::dir;
|
||||
use db::dir;
|
||||
use docopt;
|
||||
use failure::{Error, Fail};
|
||||
use libc;
|
||||
use rusqlite;
|
||||
use serde::Deserialize;
|
||||
use std::path::Path;
|
||||
|
||||
mod check;
|
||||
|
|
|
@ -28,20 +28,22 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::clock;
|
||||
use crate::db::{self, dir, writer};
|
||||
use failure::Error;
|
||||
use base::clock;
|
||||
use crate::stream;
|
||||
use crate::streamer;
|
||||
use crate::web;
|
||||
use db::{dir, writer};
|
||||
use failure::{Error, bail};
|
||||
use fnv::FnvHashMap;
|
||||
use futures::{Future, Stream};
|
||||
use log::{error, info, warn};
|
||||
use serde::Deserialize;
|
||||
use std::error::Error as StdError;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::thread;
|
||||
use crate::stream;
|
||||
use crate::streamer;
|
||||
use tokio;
|
||||
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).
|
||||
// They seem to be correct for Linux and macOS at least.
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::db::recording;
|
||||
use failure::Error;
|
||||
use serde::Deserialize;
|
||||
|
||||
const USAGE: &'static str = r#"
|
||||
Usage: moonfire-nvr ts <ts>...
|
||||
|
@ -44,7 +44,7 @@ struct Args {
|
|||
pub fn run() -> Result<(), Error> {
|
||||
let arg: Args = super::parse_args(&USAGE)?;
|
||||
for timestamp in &arg.arg_ts {
|
||||
let t = recording::Time::parse(timestamp)?;
|
||||
let t = db::recording::Time::parse(timestamp)?;
|
||||
println!("{} == {}", t, t.0);
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
///
|
||||
/// See `guide/schema.md` for more information.
|
||||
|
||||
use crate::db;
|
||||
use failure::Error;
|
||||
use serde::Deserialize;
|
||||
|
||||
const USAGE: &'static str = r#"
|
||||
Upgrade to the latest database schema.
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
//! would be more trouble than it's worth.
|
||||
|
||||
use byteorder::{BigEndian, WriteBytesExt};
|
||||
use failure::Error;
|
||||
use failure::{Error, bail};
|
||||
use lazy_static::lazy_static;
|
||||
use regex::bytes::Regex;
|
||||
|
||||
// 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)]
|
||||
mod tests {
|
||||
use crate::db::testutil;
|
||||
use db::testutil;
|
||||
|
||||
const ANNEX_B_TEST_INPUT: [u8; 35] = [
|
||||
0x00, 0x00, 0x00, 0x01, 0x67, 0x4d, 0x00, 0x1f,
|
||||
|
|
|
@ -28,8 +28,9 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::db::{self, auth::SessionHash};
|
||||
use failure::Error;
|
||||
use db::auth::SessionHash;
|
||||
use failure::{Error, format_err};
|
||||
use serde::Serialize;
|
||||
use serde::ser::{SerializeMap, SerializeSeq, Serializer};
|
||||
use std::collections::BTreeMap;
|
||||
use std::ops::Not;
|
||||
|
|
40
src/main.rs
40
src/main.rs
|
@ -30,44 +30,8 @@
|
|||
|
||||
#![cfg_attr(all(feature="nightly", test), feature(test))]
|
||||
|
||||
extern crate base64;
|
||||
extern crate bytes;
|
||||
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;
|
||||
use log::{error, info};
|
||||
use serde::Deserialize;
|
||||
|
||||
mod body;
|
||||
mod cmds;
|
||||
|
|
36
src/mp4.rs
36
src/mp4.rs
|
@ -76,19 +76,18 @@
|
|||
//! * mdat (media data container)
|
||||
//! ```
|
||||
|
||||
extern crate time;
|
||||
|
||||
use crate::base::{strutil, Error, ErrorKind, ResultExt, bail_t, format_err_t};
|
||||
use base::{strutil, Error, ErrorKind, ResultExt, bail_t, format_err_t};
|
||||
use bytes::{Buf, BytesMut};
|
||||
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
|
||||
use crate::body::{Chunk, BoxedError, wrap_error};
|
||||
use crate::db::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use crate::db::{self, dir};
|
||||
use db::dir;
|
||||
use db::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use futures::Stream;
|
||||
use futures::stream;
|
||||
use http;
|
||||
use http::header::HeaderValue;
|
||||
use http_serve;
|
||||
use log::{debug, error, trace, warn};
|
||||
use memmap;
|
||||
use openssl::hash;
|
||||
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.
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::base::strutil;
|
||||
use base::{clock::RealClocks, strutil};
|
||||
use bytes::Buf;
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use crate::clock::RealClocks;
|
||||
use crate::db::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use crate::db::testutil::{self, TestDb, TEST_STREAM_ID};
|
||||
use crate::db::writer;
|
||||
use crate::stream::{self, Opener, Stream};
|
||||
use db::recording::{self, TIME_UNITS_PER_SEC};
|
||||
use db::testutil::{self, TestDb, TEST_STREAM_ID};
|
||||
use db::writer;
|
||||
use futures::Future;
|
||||
use futures::Stream as FuturesStream;
|
||||
use log::info;
|
||||
use openssl::hash;
|
||||
use http_serve::{self, Entity};
|
||||
use std::fs;
|
||||
|
@ -1552,7 +1552,6 @@ mod tests {
|
|||
use std::path::Path;
|
||||
use std::str;
|
||||
use super::*;
|
||||
use crate::stream::{self, Opener, Stream};
|
||||
|
||||
fn fill_slice<E: http_serve::Entity>(slice: &mut [u8], e: &E, start: u64)
|
||||
where E::Error : ::std::fmt::Debug {
|
||||
|
@ -2215,7 +2214,6 @@ mod tests {
|
|||
|
||||
#[cfg(all(test, feature="nightly"))]
|
||||
mod bench {
|
||||
extern crate reqwest;
|
||||
extern crate test;
|
||||
|
||||
use base::clock::RealClocks;
|
||||
|
@ -2225,7 +2223,7 @@ mod bench {
|
|||
use hyper;
|
||||
use http::header;
|
||||
use http_serve;
|
||||
use self::test::Bencher;
|
||||
use lazy_static::lazy_static;
|
||||
use std::error::Error as StdError;
|
||||
use super::tests::create_mp4_from_db;
|
||||
use url::Url;
|
||||
|
@ -2268,9 +2266,9 @@ mod bench {
|
|||
struct MyService(super::File);
|
||||
|
||||
impl hyper::service::Service for MyService {
|
||||
type ReqBody = ::hyper::Body;
|
||||
type ResBody = ::body::Body;
|
||||
type Error = ::body::BoxedError;
|
||||
type ReqBody = hyper::Body;
|
||||
type ResBody = crate::body::Body;
|
||||
type Error = crate::body::BoxedError;
|
||||
type Future = future::FutureResult<::http::Response<Self::ResBody>, Self::Error>;
|
||||
|
||||
fn call(&mut self, req: ::http::Request<Self::ReqBody>) -> Self::Future {
|
||||
|
@ -2283,7 +2281,7 @@ mod bench {
|
|||
}
|
||||
|
||||
#[bench]
|
||||
fn build_index(b: &mut Bencher) {
|
||||
fn build_index(b: &mut test::Bencher) {
|
||||
testutil::init();
|
||||
let db = TestDb::new(RealClocks {});
|
||||
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).
|
||||
#[bench]
|
||||
fn serve_generated_bytes(b: &mut Bencher) {
|
||||
fn serve_generated_bytes(b: &mut test::Bencher) {
|
||||
testutil::init();
|
||||
let server = &*SERVER;
|
||||
let p = server.generated_len;
|
||||
|
@ -2333,7 +2331,7 @@ mod bench {
|
|||
}
|
||||
|
||||
#[bench]
|
||||
fn mp4_construction(b: &mut Bencher) {
|
||||
fn mp4_construction(b: &mut test::Bencher) {
|
||||
testutil::init();
|
||||
let db = TestDb::new(RealClocks {});
|
||||
testutil::add_dummy_recordings_to_db(&db.db, 60);
|
||||
|
|
|
@ -30,11 +30,10 @@
|
|||
|
||||
//! 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 failure::Error;
|
||||
use futures::stream;
|
||||
use futures::Stream;
|
||||
use failure::{Error, bail};
|
||||
use futures::{Stream, stream};
|
||||
use std::fmt;
|
||||
use std::ops::Range;
|
||||
|
||||
|
@ -151,9 +150,10 @@ impl<S> Slices<S> where S: Slice {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::body::BoxedError;
|
||||
use crate::db::testutil;
|
||||
use db::testutil;
|
||||
use futures::{Future, Stream};
|
||||
use futures::stream;
|
||||
use lazy_static::lazy_static;
|
||||
use std::ops::Range;
|
||||
use super::{Slice, Slices};
|
||||
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use failure::Error;
|
||||
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::ffi::{CStr, CString};
|
||||
use std::result::Result;
|
||||
|
@ -55,7 +57,7 @@ pub trait Opener<S : Stream> : Sync {
|
|||
|
||||
pub trait Stream {
|
||||
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 {}
|
||||
|
@ -63,7 +65,7 @@ pub struct Ffmpeg {}
|
|||
impl Ffmpeg {
|
||||
fn new() -> Ffmpeg {
|
||||
START.call_once(|| {
|
||||
moonfire_ffmpeg::Ffmpeg::new();
|
||||
ffmpeg::Ffmpeg::new();
|
||||
//ffmpeg::init().unwrap();
|
||||
//ffmpeg::format::network::init();
|
||||
});
|
||||
|
@ -79,11 +81,11 @@ macro_rules! c_str {
|
|||
|
||||
impl Opener<FfmpegStream> for Ffmpeg {
|
||||
fn open(&self, src: Source) -> Result<FfmpegStream, Error> {
|
||||
use moonfire_ffmpeg::InputFormatContext;
|
||||
use ffmpeg::InputFormatContext;
|
||||
let (mut input, discard_first) = match src {
|
||||
#[cfg(test)]
|
||||
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
|
||||
open_options.set(c_str!("advanced_editlist"), c_str!("false")).unwrap();
|
||||
|
@ -97,7 +99,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
|
|||
(i, false)
|
||||
}
|
||||
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();
|
||||
// https://trac.ffmpeg.org/ticket/5018 workaround attempt.
|
||||
open_options.set(c_str!("probesize"), c_str!("262144")).unwrap();
|
||||
|
@ -147,7 +149,7 @@ impl Opener<FfmpegStream> for Ffmpeg {
|
|||
}
|
||||
|
||||
pub struct FfmpegStream {
|
||||
input: moonfire_ffmpeg::InputFormatContext,
|
||||
input: ffmpeg::InputFormatContext,
|
||||
video_i: usize,
|
||||
}
|
||||
|
||||
|
@ -166,7 +168,7 @@ impl Stream for FfmpegStream {
|
|||
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 {
|
||||
let p = self.input.read_frame()?;
|
||||
if p.stream_index() == self.video_i {
|
||||
|
|
|
@ -28,14 +28,15 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::clock::{Clocks, TimerGuard};
|
||||
use crate::db::{Camera, Database, Stream, dir, recording, writer};
|
||||
use failure::Error;
|
||||
use base::clock::{Clocks, TimerGuard};
|
||||
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::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use crate::stream;
|
||||
use time;
|
||||
|
||||
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)]
|
||||
mod tests {
|
||||
use crate::clock::{self, Clocks};
|
||||
use crate::db::{self, CompositeId};
|
||||
use crate::db::recording;
|
||||
use crate::db::testutil;
|
||||
use failure::Error;
|
||||
use base::clock::{self, Clocks};
|
||||
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 std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use crate::stream::{self, Opener, Stream};
|
||||
use time;
|
||||
|
||||
struct ProxyingStream<'a> {
|
||||
|
@ -227,9 +226,9 @@ mod tests {
|
|||
}
|
||||
|
||||
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 {
|
||||
return Err(moonfire_ffmpeg::Error::eof());
|
||||
return Err(ffmpeg::Error::eof());
|
||||
}
|
||||
self.pkts_left -= 1;
|
||||
|
||||
|
|
37
src/web.rs
37
src/web.rs
|
@ -28,26 +28,26 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate hyper;
|
||||
|
||||
use crate::base::clock::Clocks;
|
||||
use crate::base::{ErrorKind, strutil};
|
||||
use base::clock::Clocks;
|
||||
use base::{ErrorKind, strutil};
|
||||
use crate::body::{Body, BoxedError};
|
||||
use crate::json;
|
||||
use crate::mp4;
|
||||
use base64;
|
||||
use bytes::{BufMut, BytesMut};
|
||||
use core::borrow::Borrow;
|
||||
use core::str::FromStr;
|
||||
use crate::db::{self, auth, recording};
|
||||
use crate::db::dir::SampleFileDir;
|
||||
use failure::Error;
|
||||
use db::{auth, recording};
|
||||
use db::dir::SampleFileDir;
|
||||
use failure::{Error, bail, format_err};
|
||||
use fnv::FnvHashMap;
|
||||
use futures::{Future, Stream, future};
|
||||
use futures_cpupool;
|
||||
use crate::json;
|
||||
use http::{self, Request, Response, status::StatusCode};
|
||||
use http::{Request, Response, status::StatusCode};
|
||||
use http_serve;
|
||||
use http::header::{self, HeaderValue};
|
||||
use crate::mp4;
|
||||
use lazy_static::lazy_static;
|
||||
use log::{debug, info, warn};
|
||||
use regex::Regex;
|
||||
use serde_json;
|
||||
use std::collections::HashMap;
|
||||
|
@ -849,18 +849,16 @@ impl ::hyper::service::Service for Service {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate reqwest;
|
||||
|
||||
use crate::db;
|
||||
use crate::db::testutil::{self, TestDb};
|
||||
use db::testutil::{self, TestDb};
|
||||
use futures::Future;
|
||||
use http::{self, header};
|
||||
use http::header;
|
||||
use log::info;
|
||||
use std::collections::HashMap;
|
||||
use std::error::Error as StdError;
|
||||
use super::Segments;
|
||||
|
||||
struct Server {
|
||||
db: TestDb<crate::base::clock::RealClocks>,
|
||||
db: TestDb<base::clock::RealClocks>,
|
||||
base_url: String,
|
||||
//test_camera_uuid: Uuid,
|
||||
handle: Option<::std::thread::JoinHandle<()>>,
|
||||
|
@ -869,7 +867,7 @@ mod tests {
|
|||
|
||||
impl 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 addr = "127.0.0.1:0".parse().unwrap();
|
||||
let service = super::Service::new(super::Config {
|
||||
|
@ -1077,13 +1075,12 @@ mod tests {
|
|||
|
||||
#[cfg(all(test, feature="nightly"))]
|
||||
mod bench {
|
||||
extern crate reqwest;
|
||||
extern crate test;
|
||||
|
||||
use db::testutil::{self, TestDb};
|
||||
use futures::Future;
|
||||
use hyper;
|
||||
use self::test::Bencher;
|
||||
use lazy_static::lazy_static;
|
||||
use std::error::Error as StdError;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -1125,7 +1122,7 @@ mod bench {
|
|||
}
|
||||
|
||||
#[bench]
|
||||
fn serve_stream_recordings(b: &mut Bencher) {
|
||||
fn serve_stream_recordings(b: &mut test::Bencher) {
|
||||
testutil::init();
|
||||
let server = &*SERVER;
|
||||
let url = reqwest::Url::parse(&format!("{}/api/cameras/{}/main/recordings", server.base_url,
|
||||
|
|
Loading…
Reference in New Issue