feat(live): one port, a router, and a phrase per session (stage 1)
The session-stream web app: a single HTTP listener (9988) that serves a page
per enabled session, keyed by a spoken phrase.
src/hhstream_live/phrase.py four EFF-large words + a 5-char base-36 tail
(~77.5 bits); the phrase is the password
src/hhstream_live/publisher.py one capture thread + one frame slot per
output, one slot/no queue, capture paused at
zero viewers
src/hhstream_live/server.py the router: /, /<phrase>/, /stream.mjpg,
/frame.jpg, /status.json; unknown phrase is
an empty 404, rate-limited
src/hhstream_live/pages.py the built-in dark pages (no CDN, no build)
src/hhstream_live/__main__.py hhstream-live serve|phrase, standalone
The root page is a form, never a list: the phrase is known only by whoever
enabled the stream. Tests: tests/live (51), all green with the full suite
(958). Not yet wired to the broker -- that is stage 2.
This commit is contained in:
1 parent
edbf15f259
commit
d770bcd298
17 files changed
+9330
-18
No files matched your search
@@ -0,0 +1,31 @@
|
||||
"""A tiny real JPEG, for tests that need decodable image bytes.
|
||||
|
||||
The frame server's tests use a fake that writes a PNG (zlib is in the standard
|
||||
library). MJPEG needs *JPEG* parts, and there is no JPEG encoder in the stdlib,
|
||||
so the smallest honest thing is one real 1x1 JPEG embedded as base64 and reused.
|
||||
|
||||
`jpeg_bytes(marker)` rewrites one *quantisation-table* byte, so two frames differ
|
||||
byte-for-byte (a test can prove "a new frame arrived") while the image stays
|
||||
valid: the EOI marker, the headers and the scan data are untouched.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
|
||||
#: A 1x1 JPEG. Real enough that `hhstream.capture.image_size` reports (1, 1).
|
||||
_ONE_PIXEL = (
|
||||
"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRof"
|
||||
"Hh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/wAALCAABAAEBAREA/8QAFAAB"
|
||||
"AAAAAAAAAAAAAAAAAAAACf/EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAD8AVN//2Q=="
|
||||
)
|
||||
#: The start of the quantisation table: `FFDB`, length `0043`, precision/id `00`.
|
||||
_DQT = b"\xff\xdb\x00C\x00"
|
||||
|
||||
|
||||
def jpeg_bytes(marker: int = 0) -> bytes:
|
||||
"""The 1x1 JPEG with one table byte varied by `marker` (0..249)."""
|
||||
data = bytearray(base64.b64decode(_ONE_PIXEL))
|
||||
start = data.index(_DQT) + len(_DQT)
|
||||
data[start + 63] = (marker % 250) + 1 # a nonzero quantiser keeps it decodable
|
||||
return bytes(data)
|
||||
Reference in new issue
Block a user