diff --git a/demo/carla/sim/moq_carla_sim/publish.py b/demo/carla/sim/moq_carla_sim/publish.py index 2b2088dfedf..bdc496325f7 100644 --- a/demo/carla/sim/moq_carla_sim/publish.py +++ b/demo/carla/sim/moq_carla_sim/publish.py @@ -177,14 +177,17 @@ def status_payload(status: Status) -> dict[str, Any]: class StatusPublisher: - """The `status` track: JSON snapshots on a compressed track. + """The `status` track: JSON snapshots on a compressed, timed track. Snapshot rather than stream, because a late joiner wants the truck's current - state, not the history of every command it ever accepted. + state, not the history of every command it ever accepted. Every update is + stamped from the broadcast clock, the same epoch the media tracks use, so + the catalog never reads the JSON track's timeline as a delay. """ def __init__(self, broadcast: moq.BroadcastProducer) -> None: - track = broadcast.publish_track("status", moq.TrackInfo(compress=True)) + track = broadcast.publish_track("status", moq.TrackInfo(timescale=1_000, compress=True)) + self._catalog = moq.media.CatalogProducer(broadcast) self._producer = moq.json.SnapshotProducer(broadcast, track) # Weak: watching demand neither keeps the track open nor locks it. self._demand = self._producer.demand() @@ -199,7 +202,7 @@ def publish(self, payload: dict[str, Any]) -> None: truck that cannot answer is not one anybody should be steering: let it reach the session, exactly as the video pump does with its own track. """ - self._producer.update(payload) + self._producer.update(payload, self._catalog.now()) async def used(self) -> None: while await self._demand.wanted_changed() is None: diff --git a/demo/carla/sim/tests/conftest.py b/demo/carla/sim/tests/conftest.py index bd3eef5702c..64c01c0c189 100644 --- a/demo/carla/sim/tests/conftest.py +++ b/demo/carla/sim/tests/conftest.py @@ -43,7 +43,7 @@ def __init__(self, broadcast: object, track: SimpleNamespace) -> None: def demand(self) -> object: return self.track.demand() - def update(self, value: object) -> None: + def update(self, value: object, timestamp: object) -> None: self.values.append(value) @@ -73,6 +73,19 @@ async def __aiter__(self): moq.json = moq_json moq_media = ModuleType("moq.media") + + +class CatalogProducer: + """A broadcast clock fixed at zero, like the runtime's shared epoch.""" + + def __init__(self, broadcast: object) -> None: + pass + + def now(self) -> SimpleNamespace: + return SimpleNamespace(value=0, scale=1_000) + + +moq_media.CatalogProducer = CatalogProducer moq_media.VideoFormat = SimpleNamespace(AVC3="avc3") moq_media.VideoInit = lambda **kwargs: SimpleNamespace(**kwargs) moq_media.VideoHint = lambda **kwargs: SimpleNamespace(**kwargs) diff --git a/demo/carla/sim/tests/test_publish.py b/demo/carla/sim/tests/test_publish.py index 6cd1881faf3..2ed3994dedd 100644 --- a/demo/carla/sim/tests/test_publish.py +++ b/demo/carla/sim/tests/test_publish.py @@ -165,10 +165,11 @@ def test_status_omits_only_the_collision_a_truck_has_not_had() -> None: def test_a_closed_status_track_fails_the_session() -> None: """Status republishes on a timer, so a swallowed failure would spin forever.""" - def closed(_payload: object) -> None: + def closed(_payload: object, _timestamp: object) -> None: raise moq.Error("track closed") publisher = publish.StatusPublisher.__new__(publish.StatusPublisher) + publisher._catalog = SimpleNamespace(now=lambda: SimpleNamespace(value=0, scale=1_000)) publisher._producer = SimpleNamespace(update=closed) with pytest.raises(moq.Error):