use Blake3 instead of SHA-1 or Blake2b

Benefits:

* Blake3 is faster. This is most noticeable for the hashing of the
  sample file data.
* we no longer need OpenSSL, which helps with shrinking the binary size
  (#70). sha1 basically forced OpenSSL usage; ring deliberately doesn't
  support this old algorithm, and the pure-Rust sha1 crate is painfully
  slow. OpenSSL might still be a better choice than ring/rustls for TLS
  but it's nice to have the option.

For the video sample entries, I decided we don't need to hash at all. I
think the id number is sufficiently stable, and it's okay---perhaps even
desirable---if an existing init segment changes for fixes like e5b83c2.
This commit is contained in:
Scott Lamb
2020-03-20 20:52:30 -07:00
parent e5b83c21e1
commit 00991733f2
18 changed files with 248 additions and 187 deletions

View File

@@ -290,16 +290,13 @@ arbitrary order. Each recording object has the following properties:
greater than the requested `endTime90k` if this recording was ongoing at
the requested time.
* `videoSampleEntryId`: a reference to an entry in the `videoSampleEntries`
map. These ids are strings so that they can serve as JSON object keys.
map.mp4` URL.
* `videoSamples`: the number of samples (aka frames) of video in this
recording.
Under the property `videoSampleEntries`, an object mapping ids to objects with
the following properties:
* `sha1`: a SHA-1 hash of the ISO/IEC 14496-12 section 8.5.2
`VisualSampleEntry` bytes. The actual bytes can be retrieved, wrapped into
an initialization segment `.mp4`, at the URL `/api/init/<sha1>.mp4`.
* `width`: the stored width in pixels.
* `height`: the stored height in pixels.
* `pixelHSpacing`: the relative width of a pixel, as in a ISO/IEC 14496-12
@@ -307,6 +304,9 @@ the following properties:
* `pixelVSpacing`: the relative height of a pixel, as in a ISO/IEC 14496-12
section 12.1.4.3 `PixelAspectRatioBox`. If absent, assumed to be 1.
The full initialization segment data for a given video sample entry can be
retrieved at the URL `/api/init/<id>.mp4`.
Example request URI (with added whitespace between parameters):
```
@@ -335,7 +335,6 @@ Example response:
],
"videoSampleEntries": {
"1": {
"sha1": "81710c9c51a02cc95439caa8dd3bc12b77ffe767",
"width": 1280,
"height": 720
}
@@ -468,7 +467,7 @@ Content-Type: video/mp4; codecs="avc1.640028"
X-Recording-Id: 42.5680
X-Recording-Start: 130985461191810
X-Time-Range: 5220058-5400061
X-Video-Sample-Entry-Sha1: 25fad1b92c344dadc0473a783dff957b0d7d56bb
X-Video-Sample-Entry-Id: 4
binary mp4 data
```
@@ -478,7 +477,7 @@ Content-Type: video/mp4; codecs="avc1.640028"
X-Recording-Id: 42.5681
X-Recording-Start: 130985461191822
X-Time-Range: 0-180002
X-Video-Sample-Entry-Sha1: 25fad1b92c344dadc0473a783dff957b0d7d56bb
X-Video-Sample-Entry-Id: 4
binary mp4 data
```
@@ -488,7 +487,7 @@ Content-Type: video/mp4; codecs="avc1.640028"
X-Recording-Id: 42.5681
X-Recording-Start: 130985461191822
X-Time-Range: 180002-360004
X-Video-Sample-Entry-Sha1: 25fad1b92c344dadc0473a783dff957b0d7d56bb
X-Video-Sample-Entry-Id: 4
binary mp4 data
```
@@ -507,13 +506,13 @@ active HTTP/1.1 connections: six in Chrome's case. The WebSocket limit is much
higher (256), allowing browser-side Javascript to stream all active camera
streams simultaneously as well as making other simultaneous HTTP requests.
### `GET /api/init/<sha1>.mp4`
### `GET /api/init/<id>.mp4`
Returns a `.mp4` suitable for use as a [HTML5 Media Source Extensions
initialization segment][init-segment]. The MIME type will be `video/mp4`, with
a `codecs` parameter as specified in [RFC 6381][rfc-6381].
### `GET /api/init/<sha1>.mp4.txt`
### `GET /api/init/<id>.mp4.txt`
Returns a `text/plain` debugging string for the `.mp4` generated by the
same URL minus the `.txt` suffix.

View File

@@ -522,7 +522,7 @@ The snippet below is a illustrative excerpt of the SQLite schema; see
camera_id integer references camera (id) not null,
sample_file_uuid blob unique not null,
sample_file_sha1 blob,
sample_file_blake3 blob,
sample_file_size integer,
-- The starting time and duration of the recording, in 90 kHz units since
@@ -540,11 +540,10 @@ The snippet below is a illustrative excerpt of the SQLite schema; see
-- A concrete box derived from a ISO/IEC 14496-12 section 8.5.2
-- VisualSampleEntry box. Describes the codec, width, height, etc.
create table visual_sample_entry (
-- A SHA-1 hash of |bytes|.
sha1 blob primary key,
id integerprimary key,
-- The width and height in pixels; must match values within
|sample_entry_bytes|.
-- `sample_entry_bytes`.
width integer,
height integer,