193 Commits

Author SHA1 Message Date
Scott Lamb
1817931c6f update a few Rust deps 2025-04-04 11:48:19 -07:00
Scott Lamb
39b6f6c49c build releases with mimalloc 2025-04-03 10:06:50 -07:00
Scott Lamb
0ccc6d0769 wrap Mutex and Condvar to handle poison
This centralizes a major source of `.unwrap()` throughout the code,
and one that would otherwise grow with upcoming changes. The new
error message should be more clear.
2025-04-03 09:16:44 -07:00
Scott Lamb
2903b680df clippy fixes to tests 2025-04-03 09:16:44 -07:00
Scott Lamb
2985214d87 reduce per-slice allocations
`slices::Slices::get_range` was too closely following the example of
`http_serve::Entity::get_range`:

The latter is once-per-request, so just boxing is low-cost and makes
sense to easily avoid monomorphization bloat when there are potentially
many types of entity streams in one program. In Moonfire, it's used with
different streams defined in the `moonfire_nvr::web::mp4`,
`moonfire_nvr::bundled_ui`, and `http_serve::file` modules. Putting them
all into a single boxless enum would be a pain. In particular, the last
one is not a nameable type today and would need more generic parameters
to implement the caller-demanded `Entity` definition.

The former is once-per-slice, there are tons of slices per request, and
it's easy to define a two-case enum right where it's needed. So the
trade-off is quite different.

Also fix up some out-of-date comments.
2025-03-07 18:54:41 -08:00
Scott Lamb
3cc9603ff3 resurrect benches
Because these require nightly, CI isn't configured to fail if they're
broken. And they have been broken since the conversion to hyper 1.x.
2025-03-07 09:26:35 -08:00
Scott Lamb
f894f889be log full error chain in a couple spots 2025-03-06 21:05:43 -08:00
Scott Lamb
0bfa09b1f1 drop ulid dependency
...and use v7 UUIDs exclusively. It's useful to have the timestamp in
request ids in particular, and no reason we _need_ v4 anywhere.
2025-02-07 10:04:29 -08:00
Scott Lamb
738ad9a558 get rid of UnsafeCell usage 2025-01-28 21:36:00 -08:00
Scott Lamb
b4836f3abb v0.7.18: support H.265
There's no transcoding, so if the browser/player doesn't support these
formats, they don't play. But it will record and allow downloads, and
it seems to be working with Chrome on macOS at least.

Fixes #33
2025-01-28 09:05:10 -08:00
Scott Lamb
dd30d5bcf8 update Rust dependencies
This pulls in a duplicate version of `thiserror` for now, but oh well.
2025-01-25 10:40:21 -08:00
Scott Lamb
cbb2c30b56 use jiff crate 2025-01-22 14:16:31 -08:00
Scott Lamb
c46832369a automated clippy fixes 2025-01-22 09:40:25 -08:00
Scott Lamb
904842cc2d improve error msg on timeout opening stream
Before, it'd look like the following, as mentioned in
https://github.com/scottlamb/moonfire-nvr/issues/331:

```
2024-12-09T20:53:24.853572 WARN s-CP3PRO-main streamer{stream="CP3PRO-main"}: moonfire_nvr::streamer: sleeping for 1 s after error err=UNKNOWN
caused by: deadline has elapsed
```

...which isn't as clear as it could be, particularly if you don't notice
the `caused by` bit. After, it should look more like the following:

```
2024-12-09T20:53:24.853572 WARN s-CP3PRO-main streamer{stream="CP3PRO-main"}: moonfire_nvr::streamer: sleeping for 1 s after error err=DEADLINE_EXCEEDED unable to play stream and get first frame within PT30S
caused by: deadline has elapsed
```
2024-12-11 15:06:28 -08:00
Scott Lamb
9256561362 fix a couple clippy errors
...with Rust 1.82.
2024-12-11 15:03:31 -08:00
Scott Lamb
3efff2cfd6 improve end reason in list ui
* in backend, save the full reason, not just the most direct error,
  which is often the useless `UNKNOWN`

* in UI, instead of wrapping in `<Typography>` which just resorts in
  a weird ransom-note mixed size look, reserve space for or actually
  use an icon.
2024-09-01 22:18:01 -07:00
Scott Lamb
1473e79e96 upgrade to hyper/http 1.0
In the process, no longer wait for pending HTTP requests on shutdown.
This just extended the time Moonfire was running without streaming.
2024-08-31 20:07:33 -07:00
Scott Lamb
8b951200c9 print usage on no args again
This regressed with f9e3fb56b3ee89097a5f38c035acc491f6ed2d22 due to
<https://github.com/pacak/bpaf/issues/385>.
2024-08-31 07:18:18 -07:00
Scott Lamb
06f942582c update cursive
`cursive` now requires `Send + Sync` bounds, so I had to switch from
`Rc<RefCell<...>>` to `Arc<Mutex<...>>`. I also coalesced some
lock calls together, hopefully without introducing any deadlocks.
I don't see any calls into the UI that would need the model while these
are held, and it seemed fine in a quick test.
2024-08-24 13:13:52 -07:00
Scott Lamb
140f625a80 clippy 2024-08-19 08:13:35 -07:00
Scott Lamb
dad664c244 upgrade to retina 0.4.9
This is a step toward H.265 recording support (#33) by using Retina
for the `VisualSampleEncoding` instead of the prior H.264-specific
logic. The only further change to Moonfire itself needed for H.265 is to
add `| "h265"` to the check for the right video stream.

This also adds support for recording MJPEG, although browser playback
almost certainly won't work.
2024-08-19 08:13:32 -07:00
Scott Lamb
89f230004e avoid unbounded channels in live streams
It's cleaner anyway to use `tokio::broadcast::channel` than the list
of callbacks.

Also make it send pings only on long pauses between frames, as when
the camera is disconnected.
2024-08-15 17:32:08 -07:00
Scott Lamb
d43e09d959 build fixes 2024-08-15 16:12:04 -07:00
Scott Lamb
0422593ec6 ui list view: tool tip to see why recording ended
Users are often puzzled why there are short recordings. Previously
the only way to see this was to examine Moonfire's logs. This should
be a much better experience to find it right in the UI where you're
wondering, and without the potential the logs are gone.

Fixes #302
2024-06-01 07:46:11 -07:00
Scott Lamb
c20c644747 fix some Rust 1.78.0 clippy warnings 2024-06-01 06:00:28 -07:00
Scott Lamb
e6c7b800fe tolerate bad sps/pps, continued 2024-05-30 18:19:58 -07:00
Scott Lamb
1ae61b4c64 fix some warnings 2024-05-30 18:19:16 -07:00
Scott Lamb
1f7c4c184a seamlessly merge minor VSE changes
Improves #302.
2024-02-12 17:35:27 -08:00
Scott Lamb
f385215d6e clippy 2024-02-12 17:32:37 -08:00
Scott Lamb
86816e862a update some Rust dependencies
I didn't go to quite the latest version of everything, in an effort to
minimize duplicates in the cargo tree.
2024-01-06 11:41:28 -08:00
Scott Lamb
38eba846f8 use unix-excl sqlite3 vfs 2023-12-29 16:41:11 -08:00
Scott Lamb
7d12e8033d upgrade Rust deps including Retina 2023-12-29 15:30:17 -08:00
Scott Lamb
a2d243d3a4 support systemd socket activation 2023-10-20 21:44:34 -07:00
Scott Lamb
89ee2d0269 systemd Ready/Stopping notification 2023-10-20 11:51:55 -07:00
Scott Lamb
ee98bf5236 no more Docker!
* use `termion` rather than `ncurses` to limit runtime deps
* cross-compile with `cross` instead of our own dockerfiles/scripts
* update instructions
* update release procedure and GitHub actions to match
* prep changelog for `v0.7.8`

Fixes #160
Closes #265
2023-10-18 21:55:47 -07:00
Scott Lamb
a76483a912 stop using cargo pkg version
One fewer thing to manage at release time.
2023-10-17 09:44:30 -07:00
Scott Lamb
33e6a18e63 fix benches broken with 02824353 2023-10-16 15:21:51 -07:00
Scott Lamb
1944f95974 fix moonfire-nvr ts subcommand 2023-10-16 15:18:33 -07:00
Scott Lamb
b4eb573ca2 cargo fmt
...necessary to pass CI since changes to stable Rust's formatting.
2023-09-30 16:15:02 -07:00
Scott Lamb
faba358925 bundle UI files into the binary
This is optional but now enabled for release builds.

Why?

* It shrinks the release docker images a bit, as the binary
  includes only the gzipped version of files and uncompressed into RAM
  at startup (which should be fast).

* It's a step toward #160.
2023-08-06 08:16:27 -05:00
Scott Lamb
02ac1a5570 fix #289: crash on sample dir Add button press 2023-08-03 15:58:57 -05:00
Scott Lamb
b9db9c11cc improve some error logs
...in particular, pass the error as a tracing param rather than directly
in the main error message. The new behavior is nicer with e.g.
OpenTelemetry.
2023-08-03 15:46:36 -05:00
Scott Lamb
9d07d24bc7 camera test button: include full error chain
...otherwise this simply says `UNKNOWN`, discarding the details from
`retina`.
2023-08-03 15:29:02 -05:00
Scott Lamb
64ca096ff3 massive error overhaul
* fully stop using ancient `failure` crate in favor of own error type
* set an `ErrorKind` on everything
2023-07-09 22:04:17 -07:00
Scott Lamb
6a5b751bd6 log error messages in web paths
HTTP requests were only returning the error message to the caller, not
logging locally. In most cases the problem could be understood
client-side, but there are some exceptions. E.g. if Moonfire returns
a 403 on WebSocket update, even in the Chrome debug tools's network
tab the HTTP response body seems to be unavailable. And in general,
it's nice to have more context server-side.

Logging a `response::Body` isn't practical (it could be a stream), so
convert all the web stuff to use `base::Error` err returns.

Convert the `METHOD_NOT_ALLOWED` paths to return `Ok` for now. This is a
bit lame but punts on having some way of plumbing an explicit/overridden
status code in `base::Error`, as no gRPC error kind cleanly maps to
that.

Also convert `db::auth`, rather than making up an error kind in the web
layer.

This is also a small step toward getting rid of `failure::Error`.
2023-07-09 10:15:56 -07:00
Scott Lamb
aa60bc991c test and fix #282
Sessions' last use updates weren't getting persisted to the database
because the update statement wasn't passing through the hash.

Also address a TODO of tracing in tests by using the same tracing
setup as in production.
2023-07-04 20:53:53 -07:00
Scott Lamb
028243532a upgrade to Rust 1.70, use std::sync::OnceLock
The most notable part of this is that `db::auth` no longer holds a lock
during password hashing operations. That was probably never a great
idea...
2023-07-04 20:44:21 -07:00
Scott Lamb
ebcdd76084 switch from log to tracing
I think this is a big improvement in readability.

I removed the `lnav` config, which is a little sad, but I don't think it
supports this structured logging format well. Still seems worthwhile on
balance.
2023-07-04 16:51:22 -07:00
Skye
81ea7d8a87 Add "Copy config" option to "Add camera" dialog 2023-07-04 16:37:36 -07:00
Skye
1fde947f36 Tiny misc code improvements 2023-07-04 16:37:36 -07:00