fix(viewer): make recorded layers deterministic
This commit is contained in:
@@ -55,48 +55,58 @@ class _RecordedBlueprintStream:
|
||||
def __init__(
|
||||
self,
|
||||
application_id: str,
|
||||
recording_id: str,
|
||||
*,
|
||||
view_reset_generation: Literal[0, 1],
|
||||
) -> None:
|
||||
self.view_reset_generation = view_reset_generation
|
||||
self._lock = Lock()
|
||||
self._pending: list[bytes] = []
|
||||
self._initial_payload: bytes | None = None
|
||||
self._latest_payload = b""
|
||||
self._sequence = 0
|
||||
self._closed = False
|
||||
native = bindings.new_blueprint(
|
||||
application_id=application_id,
|
||||
make_default=False,
|
||||
make_thread_default=False,
|
||||
default_enabled=True,
|
||||
)
|
||||
self._recording = rr.RecordingStream._from_native(native)
|
||||
bindings.set_callback_sink_blueprint(
|
||||
lambda chunk: self._pending.append(bytes(chunk)),
|
||||
True,
|
||||
False,
|
||||
native,
|
||||
self._blueprint_recording = rr.RecordingStream._from_native(native)
|
||||
self._blueprint_memory = self._blueprint_recording.memory_recording()
|
||||
self._transport_recording = rr.RecordingStream(
|
||||
application_id,
|
||||
recording_id=recording_id,
|
||||
send_properties=False,
|
||||
)
|
||||
self._recording.set_time("blueprint", sequence=0)
|
||||
self._transport = rr.binary_stream(self._transport_recording)
|
||||
|
||||
def render(self, blueprint: rrb.Blueprint) -> bytes:
|
||||
with self._lock:
|
||||
if self._initial_payload is not None:
|
||||
self._pending.clear()
|
||||
blueprint._log_to_stream(self._recording)
|
||||
self._recording.flush(timeout_sec=5.0)
|
||||
delta = b"".join(self._pending)
|
||||
if not delta:
|
||||
if self._closed:
|
||||
raise RecordedBlueprintError("stable blueprint stream is closed")
|
||||
self._blueprint_recording.set_time(
|
||||
"blueprint",
|
||||
sequence=self._sequence,
|
||||
)
|
||||
self._sequence += 1
|
||||
blueprint._log_to_stream(self._blueprint_recording)
|
||||
self._blueprint_recording.flush(timeout_sec=5.0)
|
||||
bindings.send_blueprint(
|
||||
self._blueprint_memory.storage,
|
||||
True,
|
||||
False,
|
||||
self._transport_recording.to_native(),
|
||||
)
|
||||
payload = self._transport.read(flush=True, flush_timeout_sec=5.0)
|
||||
if not payload:
|
||||
raise RecordedBlueprintError("stable blueprint stream produced no data")
|
||||
if self._initial_payload is None:
|
||||
self._initial_payload = delta
|
||||
self._latest_payload = b""
|
||||
else:
|
||||
self._latest_payload = delta
|
||||
return self._initial_payload + self._latest_payload
|
||||
return payload
|
||||
|
||||
def close(self) -> None:
|
||||
with suppress(Exception):
|
||||
self._recording.disconnect()
|
||||
with self._lock:
|
||||
self._closed = True
|
||||
with suppress(Exception):
|
||||
self._blueprint_recording.disconnect()
|
||||
with suppress(Exception):
|
||||
self._transport_recording.disconnect()
|
||||
|
||||
|
||||
_MAX_RECORDED_BLUEPRINT_STREAMS = 32
|
||||
@@ -123,6 +133,7 @@ def _stable_recorded_blueprint_stream(
|
||||
if stream is None:
|
||||
stream = _RecordedBlueprintStream(
|
||||
application_id,
|
||||
recording_id,
|
||||
view_reset_generation=view_reset_generation,
|
||||
)
|
||||
_recorded_blueprint_streams[key] = stream
|
||||
@@ -197,7 +208,13 @@ def recorded_blueprint(
|
||||
# object-history trail when the operator widens the cloud window.
|
||||
"/world/points": point_overrides,
|
||||
"/world/trajectory": trajectory_overrides,
|
||||
"/world/perception": rrb.EntityBehavior(visible=False),
|
||||
"/world/perception": rrb.EntityBehavior(visible=show_cuboids_3d),
|
||||
"/world/perception/lidar": rrb.EntityBehavior(visible=False),
|
||||
"/world/perception/support": rrb.EntityBehavior(visible=False),
|
||||
"/world/perception/semantic_points": rrb.EntityBehavior(visible=False),
|
||||
"/world/perception/boxes3d": rrb.EntityBehavior(
|
||||
visible=show_cuboids_3d,
|
||||
),
|
||||
},
|
||||
# Log an explicit empty range set so a previous accumulated blueprint
|
||||
# for this stable view id is cleared instead of surviving in Rerun.
|
||||
|
||||
Reference in New Issue
Block a user