Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ Video is deliberately independent of the MAVLink session: it survives a
telemetry dropout, and with a publish password it needs no MAVLink at
all.

**Ports.** Up to five per entry, allocated by an admin from the web UI
(suggested from 40001). Each carries one stream, on TCP and UDP.
**Ports.** Up to five per entry, allocated by the entry's owner or an
admin from the web UI (suggested from 40001). A port an owner picks must
be 40001 or above; admins can pick any free port. Each carries one
stream, on TCP and UDP.
**These are public listening ports and must be open in the firewall.**

**Publishing.**
Expand Down Expand Up @@ -212,8 +214,11 @@ reverse proxy in front of `/watch/`: segments are marked cacheable for a
minute, and everyone given the same link requests the same URLs.

**Disk.** Video has its own budget, separate from telemetry, so a busy
camera can never evict a user's tlogs. Set it per entry in the web UI;
a free-space floor stops recording before the disk fills.
camera can never evict a user's tlogs. Set it per entry in the web UI:
turning video on starts an entry at 1 GB, owners can go up to 4 GB, and
only an admin can set more. Turning video or recording on also sets the
entry's retention to 7 days if it was "keep forever". A free-space floor
stops recording before the disk fills.

**Log rotation.** The daemon's own log is not rotated by default.
Install the supplied config once, as root:
Expand Down
19 changes: 17 additions & 2 deletions keydb_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
}

DEFAULT_LOG_RETENTION_DAYS = 7.0
# Per-entry video disk budget the web UI seeds when video is turned on,
# so an entry does not start on the larger server-wide default.
DEFAULT_VIDEO_QUOTA_MB = 1024
RESERVED_WORDS = 12
RESERVED2_WORDS = 9

Expand Down Expand Up @@ -602,13 +605,15 @@ def ports_in_use(db, exclude_port2=None):
return used


def suggest_video_ports(db, ke, count, keep=None):
def suggest_video_ports(db, ke, count, keep=None, avoid=None):
"""Pick `count` free video ports for `ke`, counting up from
VIDEO_PORT_BASE.

`keep` is the entry's current ports; an already-allocated slot keeps
its port rather than being renumbered, so opening the edit page and
saving it does not silently move a running stream to a new port.
`avoid(port)`, if given, rules out further ports, e.g. ones another
service on the host holds.
Returns a MAX_VIDEO_PORTS-long list, 0 for slots beyond `count`.
"""
keep = list(keep or [])
Expand All @@ -628,7 +633,8 @@ def suggest_video_ports(db, ke, count, keep=None):
if keep[slot]:
out.append(keep[slot])
continue
while nxt in used and nxt <= VIDEO_PORT_MAX:
while nxt <= VIDEO_PORT_MAX and (
nxt in used or (avoid is not None and avoid(nxt))):
nxt += 1
if nxt > VIDEO_PORT_MAX:
# Nothing free above the base. Leave it for the operator to
Expand Down Expand Up @@ -730,6 +736,15 @@ def _flag_bit(flag_name):
return FLAG_NAMES[flag_name]


def seed_video_defaults(ke):
"""Give an entry turning video on a bounded disk budget and retention
(recordings share the log retention), unless already set."""
if ke.video_quota_mb == 0:
ke.video_quota_mb = DEFAULT_VIDEO_QUOTA_MB
if ke.log_retention_days == 0.0:
ke.log_retention_days = DEFAULT_LOG_RETENTION_DAYS


def set_flag(db, port2, flag_name):
bit = _flag_bit(flag_name)
ke = KeyEntry(port2)
Expand Down
52 changes: 33 additions & 19 deletions tests/webadmin/test_tooltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ def test_specific_help_text_reaches_the_page(self, client, keydb_path):
assert 'keeps them forever' in html # retention
assert 'replays' in html # reset timestamp

def test_the_whole_row_is_the_target_not_a_marker(self, client,
keydb_path):
def test_no_question_mark_marker(self, client, keydb_path):
"""Aiming at a one-em "?" to read a sentence is more work than
the sentence is worth."""
login_as(client, BOB_PORT1, BOB_PASS)
Expand All @@ -115,12 +114,29 @@ def test_the_whole_row_is_the_target_not_a_marker(self, client,
assert '>?<' not in html

def test_reachable_without_a_pointer(self, client, keydb_path):
"""Focusing the input is what shows it for keyboard users, and
aria-describedby ties the text to the control."""
"""aria-describedby ties the text to the control, so a screen
reader announces it on focus without the tip covering anything."""
login_as(client, BOB_PORT1, BOB_PASS)
html = client.get('/admin/%d' % ALICE_PORT2).get_data(as_text=True)
assert 'aria-describedby=' in html
assert ':focus-within' in _css_rules(client)

def test_slot_option_text_is_a_label(self, client, keydb_path):
"""The option text is the hover cue, and clicking it toggles the
box."""
login_as(client, BOB_PORT1, BOB_PASS)
html = client.get('/admin/%d' % ALICE_PORT2).get_data(as_text=True)
assert '<label for="video_srt_1">SRT</label>' in html
assert '<label for="video_rtmp_1">RTMP</label>' in html

def test_slot_controls_are_described(self, client, keydb_path):
"""The hand-written slot tips reach screen readers on focus."""
login_as(client, BOB_PORT1, BOB_PASS)
html = client.get('/admin/%d' % ALICE_PORT2).get_data(as_text=True)
for name in ('srt', 'record', 'rawtcp', 'sessok', 'openpub',
'rtmp', 'port'):
fid = 'video_%s_1' % name
assert 'aria-describedby="%s-tip"' % fid in html, fid
assert 'id="%s-tip"' % fid in html, fid

def test_video_slot_options_are_documented_in_the_template(
self, client, keydb_path):
Expand Down Expand Up @@ -195,25 +211,23 @@ def _css_rules(client):


class TestStylesheet:
def test_tip_rules_are_present(self, client):
css = _css_rules(client)
assert '.field:hover > .tip' in css
assert ':focus' in css, 'tooltip must open on keyboard focus'

def test_row_selector_is_direct_child_only(self, client):
"""The per-slot video row holds several separately documented
checkboxes; a descendant selector would throw all of their
tooltips up at once when the row is hovered."""
def test_the_label_is_the_target(self, client):
"""The tip drops over the rows below, so it must come from the
label only: shown for the whole row, or on focus, it sat over the
next field while an input was being filled in."""
css = _css_rules(client)
assert '.field:hover > .tip' in css
assert '.field:hover .tip' not in css.replace('.field:hover > .tip', '')
assert '.field > label:hover ~ .tip' in css
assert '.opt > label:hover ~ .tip' in css
assert '.field:hover' not in css
assert '.opt:hover' not in css
assert ':focus-within' not in css

def test_appearing_is_delayed(self, client):
"""Without a delay, every row crossed on the way to the wanted
"""Without a delay, every label crossed on the way to the wanted
one flashes a tooltip."""
css = _css_rules(client)
m = re.search(r'\.field:hover > \.tip[^{]*\{([^}]*)\}', css)
assert m, 'no .field:hover > .tip rule'
m = re.search(r'label:hover ~ \.tip[^{]*\{([^}]*)\}', css)
assert m, 'no label:hover ~ .tip rule'
assert 'transition' in m.group(1)
assert '0.4s' in m.group(1), 'no delay before the tooltip appears'

Expand Down
28 changes: 25 additions & 3 deletions tests/webadmin/test_video_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,25 +584,30 @@ def _fresh_hls_slots(monkeypatch):
class _FakeVideoChild:
"""Answers the two requests the watch page proxies, on a free port."""

def __init__(self, playlist_status=200, truncate_segment=False):
def __init__(self, playlist_status=200, truncate_segment=False,
foreign=False):
import http.server
import threading
outer = self
outer.requests = []
outer.playlist_status = playlist_status
outer.truncate_segment = truncate_segment
outer.foreign = foreign

class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass

def do_GET(self):
outer.requests.append(self.path)
if self.path.startswith('/v1.m3u8') and outer.playlist_status == 200:
if outer.foreign:
# 'G' passes a one-byte check; the next sync byte must not
body, code = b'GET? some other service' + b'.' * 400, 200
elif self.path.startswith('/v1.m3u8') and outer.playlist_status == 200:
body = b'#EXTM3U\n#EXTINF:2.0,\nv1-5-1.ts?t=12.abc\n'
code = 200
elif self.path.startswith('/v1-5-7.ts'):
body, code = b'\x47' + b'\0' * 187, 200
body, code = (b'\x47' + b'\0' * 187) * 3, 200
else:
body, code = b'no\n', 503
self.send_response(code)
Expand Down Expand Up @@ -816,6 +821,23 @@ def test_hls_is_proxied_from_the_video_port(self, app, keydb_path):
finally:
up.close()

def test_hls_relays_nothing_but_hls(self, app, keydb_path):
"""Owners pick their ports; another service answering on one
must not be relayed to viewers."""
up = _FakeVideoChild(foreign=True)
try:
_enable_video(keydb_path, ALICE_PORT2, ports=(up.port,))
ke = fetch_entry(keydb_path, ALICE_PORT2)
tok = videotoken.mint_share(ke.secret_key, ALICE_PORT2, 0, 3600)
base = '/watch/%d/0/%s/' % (ALICE_PORT2, tok)
c = app.test_client()
for path in ('index.m3u8', 'v1-5-7.ts'):
r = c.get(base + path)
assert r.status_code == 503
assert b'other service' not in r.get_data()
finally:
up.close()

def test_hls_reports_an_idle_stream_as_retryable(self, app, keydb_path):
up = _FakeVideoChild(playlist_status=503)
try:
Expand Down
Loading
Loading