39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Deterministic synthetic RGB input for isolated tests and smoke runs."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random
|
|
from collections.abc import Iterator
|
|
|
|
from yovision_brain.config import BrainInputConfig
|
|
|
|
from .models import CancellationToken, InputPacket
|
|
|
|
|
|
class SyntheticInput:
|
|
def __init__(self, config: BrainInputConfig) -> None:
|
|
if config.source.kind != "synthetic":
|
|
raise ValueError("SyntheticInput requires a synthetic source config")
|
|
self._config = config
|
|
|
|
def packets(self, cancellation: CancellationToken | None = None) -> Iterator[InputPacket]:
|
|
source = self._config.source
|
|
assert source.seed is not None and source.frame_count is not None
|
|
randomizer = random.Random(source.seed)
|
|
profile = self._config.profile
|
|
frame_size = profile.width * profile.height * 3
|
|
interval_ns = round(1_000_000_000 / profile.fps)
|
|
for sequence in range(source.frame_count):
|
|
if cancellation is not None and cancellation.cancelled:
|
|
return
|
|
yield InputPacket(
|
|
sequence=sequence,
|
|
timestamp_ns=sequence * interval_ns,
|
|
logical_device_id=self._config.logical_device_id,
|
|
profile_id=profile.profile_id,
|
|
width=profile.width,
|
|
height=profile.height,
|
|
media_format="rgb24",
|
|
payload=randomizer.randbytes(frame_size),
|
|
)
|