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:
DCCONSTRUCTIONS
2026-10-29 09:10:01 +03:00
parent e06ff9a214
commit fa8bde584f
94 changed files with 8892 additions and 375 deletions
+55
View File
@@ -0,0 +1,55 @@
"""Preview adaptation consumes new hardware frames, never repeats a stalled source."""
import asyncio
import importlib.util
import time
from pathlib import Path
from types import SimpleNamespace
import aioice.ice
import numpy as np
import pytest
from missioncore_plugin_sdk.media_budget import MediaBudget
def test_realsense_preview_changes_size_without_replaying_a_stalled_source(monkeypatch):
original = aioice.ice.get_host_addresses
monkeypatch.setattr(aioice.ice, "get_host_addresses", original)
path = Path(__file__).parents[2] / "apps/node-agent/sensors/media.py"
spec = importlib.util.spec_from_file_location("sensor_media_test", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
async def run():
device = SimpleNamespace(
images={"color": np.zeros((480, 640, 3), dtype=np.uint8)},
frames={"color": 1},
last_frame={"monotonic_ns": time.monotonic_ns()},
)
budget = MediaBudget("video")
budget.update(
{"schema": "missioncore.media-budget/v1", "allocation_bps": 800_000, "ttl_ms": 3000}
)
track = module.CameraTrack(device, "color", budget)
try:
first = await asyncio.wait_for(track.recv(), 0.5)
assert (first.width, first.height) == (640, 480)
with pytest.raises(TimeoutError):
await asyncio.wait_for(track.recv(), 0.15)
device.frames["color"] = 2
device.last_frame["monotonic_ns"] = time.monotonic_ns()
budget.update(
{"schema": "missioncore.media-budget/v1", "allocation_bps": 100_000, "ttl_ms": 3000}
)
second = await asyncio.wait_for(track.recv(), 0.5)
assert (second.width, second.height) == (160, 120) and second.pts > first.pts
assert device.images["color"].shape == (480, 640, 3)
device.frames["color"] = 3
device.last_frame["monotonic_ns"] = time.monotonic_ns() - 3_000_000_000
with pytest.raises(TimeoutError):
await asyncio.wait_for(track.recv(), 0.6)
finally:
track.stop()
budget.connection.close()
asyncio.run(run())
+20
View File
@@ -81,3 +81,23 @@ def test_disconnect_finalizes_failed_record_and_clears_live_frames(monkeypatch,
assert value["state"] == "failed" and value["sha256"]
device.disconnect()
assert stopped == [True]
def test_preview_point_bound_does_not_modify_depth_capture(monkeypatch, tmp_path):
import numpy as np
rs = types.ModuleType("pyrealsense2")
rs.rs2_deproject_pixel_to_point = lambda intrinsics, point, z: [*point, z]
monkeypatch.setitem(__import__("sys").modules, "pyrealsense2", rs)
path = Path(__file__).parents[2] / "apps/node-agent/sensors/device.py"
spec = importlib.util.spec_from_file_location("points_device", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
device = module.Device("synthetic-camera", tmp_path, {})
device.depth = np.ones((479, 641), dtype=np.uint16)
device.intrinsics = object()
device.depth_scale = 0.001
before = device.depth.copy()
assert len(device.points(7)) <= 21 and len(device.points(2000)) <= 6000
assert device.points(0) == []
assert np.array_equal(device.depth, before)