Commit Graph

109 Commits

Author SHA1 Message Date
Scott Lamb 4a7f22723c Merge branch 'master' into new-schema 2021-10-21 12:26:31 -07:00
Scott Lamb 7b0099fb4e use typed errors in /view.mp4 path
This fixes #178. Before, everything got translated to 5xx status;
now it produces the correct type in several cases.

Ideally I'd get rid of the untyped errors in all of web.rs; this is
a small step.
2021-10-21 10:31:54 -07:00
Scott Lamb 9c708ec557 cargo update, rusqlite major version bump 2021-10-20 18:09:16 -07:00
Scott Lamb 985f6e675f prepare v0.6.7 w/ Retina v0.3.3
This improves authentication over RTSP.
2021-10-20 14:59:33 -07:00
Scott Lamb ad35a1ca5e UNTESTED: note trailing zeros in /recordings reply 2021-10-20 14:55:06 -07:00
Scott Lamb 8da5c4aa56 update various Rust deps 2021-10-02 08:31:04 -07:00
Scott Lamb 0c0c0692f3 prepare version 0.6.6 2021-09-23 20:02:31 -07:00
Scott Lamb b41a6c43da shutdown better
After a frustrating search for a suitable channel to use for shutdown
(tokio::sync::Receiver and
futures::future::Shared<tokio::sync::oneshot::Receiver> didn't look
quite right) in which I rethought my life decisions, I finally just made
my own (server/base/shutdown.rs). We can easily poll it or wait for it
in async or sync contexts. Most importantly, it's convenient; not that
it really matters here, but it's also efficient.

We now do a slightly better job of propagating a "graceful" shutdown
signal, and this channel will give us tools to improve it over time.

* Shut down even when writer or syncer operations are stuck. Fixes #117
* Not done yet: streamers should instantly shut down without waiting for
  a connection attempt or frame or something. I'll probably
  implement that when removing --rtsp-library=ffmpeg. The code should be
  cleaner then.
* Not done yet: fix a couple places that sleep for up to a second when
  they could shut down immediately. I just need to do the plumbing for
  mock clocks to work.

I also implemented an immediate shutdown mode, activated by a second
signal. I think this will mitigate the streamer wait situation.
2021-09-23 16:33:29 -07:00
Scott Lamb 66f76079c0 improve error when db and dir meta don't match
I saw this recently while working on new-schema. It was probably due
to some manual upgrade or downgrade I did rather than an actual bug.
Improve debuggability a little nonetheless.
2021-09-22 12:39:02 -07:00
Scott Lamb f7aa71d2af record boot uuid on open
This can be used to match up with eg `journalctl --list-boots` for
debugging.
2021-09-22 12:35:17 -07:00
Scott Lamb f86f03cf59 end reason for recording runs
Part of #155
2021-09-16 16:24:17 -07:00
Scott Lamb dafd9041d6 json-based config for cameras and streams
for #155

The config interface code for changing cameras is quite messy but
seems to work for now.
2021-09-16 16:13:41 -07:00
Scott Lamb 070400095d simplify UI preferences change logic
I copied the example of the password field by introducing a setter.
But I forgot: it was only that way because the password field has
the complexity of hashing/salting. For fields where setting is
idempotent, it can be directly exposed.
2021-09-01 21:17:44 -07:00
Scott Lamb c42314edb5 UI preferences: #153 #155 2021-09-01 15:08:09 -07:00
Scott Lamb 33b3b669df start schema version 7 (#155)
This isn't yet any different than schema version 6.
2021-08-31 21:03:52 -07:00
Scott Lamb d53450dd3b bump versions of blake3, nom, tokio-tungstenite 2021-08-31 13:05:10 -07:00
Scott Lamb 71e5248c6b fix tests broken with 95dec97 2021-08-23 15:58:12 -07:00
Scott Lamb 95dec9791c config: validate more in cameras dialog box
Fixes #152

This won't win any awards for best UI or cleanest UI code, but it's an
improvement. Long-term I want the web config UI instead.
2021-08-23 15:55:47 -07:00
Scott Lamb 6270cc0ee4 adjust minimum SQLite version
"without rowid" was introduced in 3.8.2, not 3.14.0. The latter
was just "without rowid" virtual tables, a more obscure feature.
2021-08-19 10:59:38 -07:00
Scott Lamb 4e77a26410 document and check minimum SQLite version
Fixes #147
2021-08-19 10:08:53 -07:00
Scott Lamb 711071f003 prepare version 0.6.5 2021-08-13 12:08:19 -07:00
Scott Lamb 27395ecd4e UI: improve aspect ratio handling
As written in the changelog: Live streams formerly worked around a
Firefox pixel aspect ratio bug by forcing all videos to 16:9, which
dramatically distorted 9:16 camera views. Playback didn't, so anamorphic
videos looked correct on Chrome but slightly stretched on Firefox. Now
both live streams and playback are fully correct on all browsers.
2021-08-12 13:33:19 -07:00
Scott Lamb 1df55efc43 upgrade some server deps
I avoided rtcp 0.2.2->0.2.3 because of an accidental semver break.
2021-07-09 15:01:15 -07:00
Scott Lamb f078328935 prepare v0.6.4 2021-06-28 20:32:33 -07:00
Scott Lamb 92a365eb73 use released versions of a few deps 2021-06-09 14:36:14 -07:00
Scott Lamb 032bd76577 support --rtsp-library=retina (#37)
This isn't well-tested and doesn't yet support an initial connection
timeout. But in a quick test, it successfully returns video!

I'd like to do some more aggressive code restructuring for zero-copy
and to have only one writer thread per sample file directory (rather
than the syncer thread + one writer thread per RTSP stream). But I'll
likely wait until I drop support for ffmpeg entirely.
2021-06-07 14:40:26 -07:00
Scott Lamb bb69d1488e cargo fmt 2021-06-04 20:25:19 -07:00
Scott Lamb 23d77693de read sample files from dedicated threads
Reading from the mmap()ed region in the tokio threads could cause
them to stall:

*   That could affect UI serving when there were concurrent
    UI requests (i.e., not just requests that needed the reads in
    question anyway).
*   If there's a faulty disk, it could cause the UI to totally hang.
    Better to not mix disks between threads.
*   Soon, I want to handle RTSP from the tokio threads (#37). Similarly,
    we don't want RTSP streaming to block on operations from unrelated
    disks.

I went with just one thread per disk which I think is sufficient.
But it'd be possible to do a fixed-size pool instead which might improve
latency when some pages are already cached.

I also dropped the memmap dependency. I had to compute the page
alignment anyway to get mremap to work, and Moonfire NVR already is
Unix-specific, so there wasn't much value from the memmap or memmap2
crates.

Fixes #88
2021-06-04 19:50:13 -07:00
Scott Lamb 54bd068706 address some no-op clippy warnings 2021-05-17 15:00:51 -07:00
Scott Lamb 603f02b686 stop using old tempdir crate 2021-05-17 13:08:18 -07:00
Scott Lamb 8b37c77558 de-dupe prettydiff deps via a fork 2021-05-17 12:17:18 -07:00
Scott Lamb ef0bc8acf9 update various other deps 2021-05-17 11:05:54 -07:00
Scott Lamb f922afaa26 update rusqlite
The big difference here is query_named and execute_named have gone
away. Fair number of lines changes but straightforward.
2021-05-17 10:50:48 -07:00
Scott Lamb a1e78ea48b better debugging when unable to insert VSE
I saw this error once:

Apr 27 21:01:33 nuc moonfire-nvr[188570]: s-reolink-sub
moonfire_nvr::streamer] reolink-sub: sleeping for Duration { secs: 1,
nanos: 0 } after error: CHECK constraint failed: video_sample_entry

and would like to understand it better.
2021-04-27 22:52:47 -07:00
Scott Lamb 4ffb922805 fix request of death in /api/signals 2021-04-12 21:57:16 -07:00
Scott Lamb 2936c138c5 various doc improvements
I bumped the minimum Rust version because I'm taking advantage of
the rustdoc linking added in Rust 1.48:
https://blog.rust-lang.org/2020/11/19/Rust-1.48.html#easier-linking-in-rustdoc
2021-04-10 17:34:52 -07:00
Scott Lamb 8465b49cfa Prepare v0.6.3 release
...including changelog and new screenshots in the README.
2021-03-31 15:21:09 -07:00
Scott Lamb 560fe804d6 use SameSite=Lax instead of SameSite=Strict
To improve reliability of live streams (#59) on Safari.

Safari was dropping the cookie from websocket update requests.
(But it worked sometimes. I don't get why.) I saw folks on the Internet
thinking this related to HttpOnly:

*   https://developer.apple.com/forums/thread/104488
*   https://stackoverflow.com/q/47742807/23584

but I still see this behavior without HttpOnly. SameSite=Strict vs
SameSite=Lax appears to make a difference. Try that instead.
SameSite=Strict is pointless for us anyway as noted in a new comment.
Turning off HttpOnly would be more unfortunate security-wise.
2021-03-31 13:08:03 -07:00
Scott Lamb f9c46dca89 fix incorrect prev_media_duration_90k calculation
I spotted this by inspection: adding a media time and wall time didn't
look right. I also confirmed the brokenness on my primary NVR:

```
sqlite> .mode column
sqlite> select
   ...>   r1.composite_id,
   ...>   r1.prev_media_duration_90k,
   ...>   r1.wall_duration_90k,
   ...>   r1.media_duration_delta_90k,
   ...>   r2.composite_id,
   ...>   r2.prev_media_duration_90k
   ...> from
   ...>   recording r1 join recording r2 on (r1.composite_id = r2.composite_id - 1)
   ...> where
   ...>   r1.prev_media_duration_90k + r1.wall_duration_90k + r1.media_duration_delta_90k !=
   ...>     r2.prev_media_duration_90k
   ...> limit 5;
4296791095    2232623913716            5398956            154                       4296791096    2232629312672
4296791096    2232629312672            5400016            38                        4296791097    2232634712688
4296791097    2232634712688            5400729            105                       4296791098    2232640113417
4296791098    2232640113417            5399024            80                        4296791099    2232645512441
4296791099    2232645512441            5400770            124                       4296791100    2232650913211
```

In the first row, the second recording's prev_media_duration_90k is the
first's prev_media_duration_90k plus its wall time, not its media time.
2021-03-25 22:09:29 -07:00
Scott Lamb abcd650304 present signal days in API requests
I also enforced some invariants in the signals code, fixing a couple
bugs. The signals code is more complex than I'd like, but hopefully
is working now.
2021-03-23 21:07:07 -07:00
Scott Lamb caf65a045b use 90k units for signal days map
I'd once thought about using 1 second resolution for signals and wrote
this map to match that. But I decided to match signals to the timestamps
used elsewhere instead. Match that for the days map also.
2021-03-23 11:33:51 -07:00
Scott Lamb 7fb8cd7c6a day map datastructure for signals
Not yet actually used.
2021-03-23 10:58:07 -07:00
Scott Lamb 3ec60b85a3 extract & generalize calendar day indexes
My main goal is to support creating indexes for signals as well as
recordings. An additional goal is to just shrink db.rs a bit; it's
gotten quite large.
2021-03-23 09:40:52 -07:00
Scott Lamb e66a88a591 fix invariant violation on pts jump (#112)
Looks like a refactoring in 9d7cdc09 introduced the possibility this
could fail (where before it might produce a silly i32 pts) and forgot
to restore the invariant.
2021-03-10 12:45:32 -08:00
Scott Lamb 2d45799b7d better error handling for authentication 2021-03-06 05:49:49 -08:00
Scott Lamb cb4f30b5a2 rearrange check deletes to satisfy foreign key
Otherwise `moonfire-nvr check --delete-orphan-rows` can fail with this
error:

```
I0305 113848.655 main moonfire_db::check] Deleting 2 recording rows
E0305 113848.655 main moonfire_nvr] Exiting due to error: FOREIGN KEY constraint failed
```

The new order matches the online system's `db::raw::delete_recordings`.
2021-03-05 12:02:43 -08:00
Scott Lamb c547a49ac8 shorten per-file copyright headers
I'm tired of all the boilerplate, so use the new
GPL-3.0-linking-exception license identifier instead in all the server
components.

I left the ui stuff alone because I'm just going to replace it (#111).

Add a checker for the header because it's easy to forget.
2021-02-17 15:39:17 -08:00
Scott Lamb 97678f42e4 rustfmt everything
I want to make the project more accessible by not expecting folks to
match my idiosyncratic style. Now almost [1] everything is written
in the "standard" style. CI enforces this.

[1] "Almost": I used #[rustfmt::skip] in a few sections where I felt
aligning things in columns significantly improves readability.
2021-02-17 09:17:24 -08:00
Scott Lamb 64f8d38e01 0.6.1 2021-02-16 12:01:51 -08:00
Scott Lamb ed521521a4 fix SQLite3 integrity check 2021-02-11 20:27:12 -08:00
Scott Lamb fdb6603b5e also cleanup "Recording .. missing playback row" 2021-02-11 20:10:38 -08:00
Scott Lamb 7f711eedeb add some mutation flags to moonfire-nvr check
For recovering from corruption, as in #107. These should aid in
restoring database integrity without throwing away the entire database.
I only added the conditions that came up in #107, so far.

*   "Missing ... row" => --trash-orphan-sample-files
*   "Recording ... missing file" => --delete-orphan-rows
*   "bad video_index" => --trash-corrupt-rows
2021-02-11 20:03:28 -08:00
Scott Lamb 972f26f30a check SQLite database integrity 2021-02-11 15:24:24 -08:00
Scott Lamb cdd878f452 compare schema version on "moonfire-nvr check" 2021-02-11 15:21:05 -08:00
Scott Lamb 51f43e9124 suppress some "moonfire-nvr check" false positives
In particular, if there are recordings in progress when the process
dies, they may still be around when check runs. They are easily
identifiable by having an id > cum_recordings and get automatically
deleted on startup, so there's no reason to complain about them.
2021-02-11 15:06:04 -08:00
Scott Lamb 9a5957d5ef overhaul error messages
Inspired by the poor error message here:
https://github.com/scottlamb/moonfire-nvr/issues/107#issuecomment-777587727

*   print the friendlier Display version of the error rather than Debug.
    Eg, "EROFS: Read-only filesystem" rather than "Sys(EROFS)". Do this
    everywhere: on command exit, on syncer retries, and on stream
    retries.
*   print the most immediate problem and additional lines for each
    cause.
*   print the backtrace or an advertisement for RUST_BACKTRACE=1 if it's
    unavailable.
*   also mention RUST_BACKTRACE=1 in the troubleshooting guide.
*   add context in various places, including pathnames. There are surely
    many places more it'd be helpful, but this is a start.
*   allow subcommands to return failure without an Error.
    In particular, "moonfire-nvr check" does its own error printing
    because it wants to print all the errors it finds. Printing "see
    earlier errors" with a meaningless stack trace seems like it'd just
    confuse. But I also want to get rid of the misleading "Success" at
    the end and 0 return to the OS.
2021-02-11 10:57:09 -08:00
Scott Lamb ff1615a0b4 address database upgrade slowness (#107)
* give a rule of thumb for update time in the documentation
* log the SQLite3 version, which can affect performance
* do the vacuum in non-WAL mode, to correctly set the page size and to
  avoid very slow behavior on older SQLite3 versions. Larger page sizes
  are generally faster (including subsequent vacuum operations).
  This won't help much for the first vacuum after this change, but it
  will help afterward.
* likewise, set the page size properly on "moonfire-nvr init".
2021-02-10 22:28:40 -08:00
Scott Lamb 4e67af9909 upgrade some other deps 2021-01-27 12:42:29 -08:00
Scott Lamb dd66c7b0dd restructure into "server" and "ui" subdirs
Besides being more clear about what belongs to which, this helps with
docker caching. The server and ui parts are only rebuilt when their
respective subdirectories change.

Extend this a bit further by making the webpack build not depend on
the target architecture. And adding cache dirs so parts of the server
and ui build process can be reused when layer-wide caching fails.
2021-01-22 22:01:17 -08:00