BB.Camera.EstimatorSource (bb_camera v0.3.0)

Copy Markdown View Source

Delivers a camera's frames to the estimators nested inside it.

Every camera names this as its BB.Sensor.estimator_source/0, through use BB.Camera, so an estimator declared inside a camera sensor receives each frame in BB.Estimator.handle_input/2, as a %BB.Message{} whose payload is a BB.Message.Camera.Frame:

sensor :eye, {BB.Camera.Synthetic, width: 640, height: 480} do
  estimator :detector, MyDetector
end

It is a consumer like any other, over BB.Camera.subscribe/3 and BB.Camera.request/1. The estimator asks for a frame only when it has finished with the last, so one that falls behind is handed the newest frame when it is ready rather than a backlog, and nothing it hasn't asked for reaches its mailbox.

The envelope's monotonic_time is when the frame was captured, not when it was delivered, so max_input_age and the estimator's input-to-output latency are measured from capture. lost_after counts from the last frame that passed intake, and latency_budget from how long handle_input/2 took, as for any other estimator.

The estimator stays subscribed through the end of a capture, and through a failed one. The hub restarts a capture that ended cleanly while anyone is still subscribed, so a clean end is only a pause, and the estimator asks again. A failed capture is retried by the hub after a backoff, which can grow to tens of seconds, so it is reported as {:failed, error}: the estimator goes :lost with reason :source_failed, firing its on_lost, and asks again, recovering when frames resume. An estimator whose camera has stopped producing for any other reason is told so by lost_after, as one whose sensor has stopped publishing is.

A camera whose hub has gone is a different matter - the subscription is dead - so the source reports it ended and the estimator goes :lost with reason :source_ended. It doesn't stop itself. The hub is linked to its driver, so the driver has gone too, and BB.SensorEstimatorSupervisor restarts the driver and then the estimator, which subscribes to the new driver's hub.