feat(video): recover camera previews and reduce encoding and playout cost
Improve camera recovery, shared preview lifecycle and receiver playout diagnostics. Preserve qualified X4 runtime changes and restore async admission in loopback media tests.
This commit is contained in:
@@ -91,6 +91,57 @@ def bindings():
|
||||
return {ident: value for ident, value in found.items() if ident not in duplicates}
|
||||
|
||||
|
||||
def reconcile(known, startup=False):
|
||||
observed = bindings()
|
||||
current = {
|
||||
ident: {
|
||||
"port": item.port,
|
||||
"bus": item.bus,
|
||||
"address": item.address,
|
||||
"revision": active().name,
|
||||
}
|
||||
for ident, item in observed.items()
|
||||
}
|
||||
changed = False
|
||||
for ident in list(known):
|
||||
if current.get(ident) != known[ident]:
|
||||
systemctl("stop", PREFIX + ident + ".service")
|
||||
path = UNITS / (PREFIX + ident + ".service")
|
||||
if path.exists():
|
||||
trusted(path).unlink()
|
||||
del known[ident]
|
||||
changed = True
|
||||
additions = [ident for ident in current if ident not in known]
|
||||
for ident in additions:
|
||||
item = observed[ident]
|
||||
try:
|
||||
if read_binding(item.port) != item:
|
||||
continue
|
||||
except (OSError, ValueError):
|
||||
# Enumeration and revalidation are separate sysfs reads.
|
||||
continue
|
||||
write(UNITS / (PREFIX + ident + ".service"), unit(item))
|
||||
known[ident] = current[ident]
|
||||
changed = True
|
||||
if changed:
|
||||
write(CONTROL / "bindings.json", json.dumps(known, sort_keys=True).encode())
|
||||
systemctl("daemon-reload")
|
||||
for ident in list(current) if startup else additions:
|
||||
if ident in known:
|
||||
try:
|
||||
systemctl("start", PREFIX + ident + ".service")
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as exc:
|
||||
# A disappearing BindPaths node can fail unit setup. Keep supervising
|
||||
# other cameras; retry this one only after its USB binding changes.
|
||||
# A timed-out start may still succeed, so never replay it blindly.
|
||||
print(
|
||||
f"X4 worker start on USB {observed[ident].port} failed "
|
||||
f"({type(exc).__name__}); waiting for a new USB binding",
|
||||
file=sys.stderr,
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
if os.geteuid() or len(sys.argv) != 1:
|
||||
raise RuntimeError("Use the fixed installed supervisor unit")
|
||||
@@ -116,39 +167,7 @@ def main():
|
||||
raise RuntimeError("Invalid previous camera binding")
|
||||
known[ident] = info
|
||||
while not stopping:
|
||||
observed = bindings()
|
||||
current = {
|
||||
ident: {
|
||||
"port": item.port,
|
||||
"bus": item.bus,
|
||||
"address": item.address,
|
||||
"revision": active().name,
|
||||
}
|
||||
for ident, item in observed.items()
|
||||
}
|
||||
changed = False
|
||||
for ident in list(known):
|
||||
if current.get(ident) != known[ident]:
|
||||
systemctl("stop", PREFIX + ident + ".service")
|
||||
path = UNITS / (PREFIX + ident + ".service")
|
||||
if path.exists():
|
||||
trusted(path).unlink()
|
||||
del known[ident]
|
||||
changed = True
|
||||
additions = [ident for ident in current if ident not in known]
|
||||
for ident in additions:
|
||||
item = observed[ident]
|
||||
if read_binding(item.port) != item:
|
||||
continue
|
||||
write(UNITS / (PREFIX + ident + ".service"), unit(item))
|
||||
known[ident] = current[ident]
|
||||
changed = True
|
||||
if changed:
|
||||
write(record, json.dumps(known, sort_keys=True).encode())
|
||||
systemctl("daemon-reload")
|
||||
for ident in list(current) if startup else additions:
|
||||
if ident in known:
|
||||
systemctl("start", PREFIX + ident + ".service")
|
||||
reconcile(known, startup=startup)
|
||||
startup = False
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user