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
11 changes: 7 additions & 4 deletions demo/carla/sim/moq_carla_sim/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion demo/carla/sim/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion demo/carla/sim/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down