Skip to content

Cache latest frame to support multiple concurrent consumers - #54

Open
oliviamiller wants to merge 2 commits into
mainfrom
latest-frame-cache
Open

Cache latest frame to support multiple concurrent consumers#54
oliviamiller wants to merge 2 commits into
mainfrom
latest-frame-cache

Conversation

@oliviamiller

@oliviamiller oliviamiller commented Aug 24, 2026

Copy link
Copy Markdown

Right now get_images pulls straight from the appsink, and pulling a sample
consumes it. So with more than one consumer, whoever asks first takes the
frame and everyone else sits waiting for the next one — at 1 fps that's seconds of
waiting per client.

This changes it so the appsink callback keeps the newest frame in a cache and
get_images just reads from that. Any number of clients can grab the latest
frame without stealing it from each other. Same approach as realsense and orbbec modules.

  • Not tested on hardware yet.

oliviamiller and others added 2 commits August 24, 2026 10:13
…rames

Previously every get_images call pulled a sample directly from the
appsink, which dequeues it: with N consumers each frame went to exactly
one caller and everyone else blocked until the next frame arrived (up to
1/frame_rate seconds). Now the appsink new-sample callback stores each
frame in a shared latest-frame cache and consumers read the cache, so
any number of clients get the most recent frame immediately.

Follows the pattern used by viam-camera-realsense: frames are stamped
with their actual capture time (now reported as captured_at), and
get_images throws if the cached frame is older than 3 frame intervals
so a stalled pipeline surfaces as an error instead of serving a stale
image.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@oliviamiller oliviamiller changed the title Implement Latest frame cache Cache latest frame to support multiple concurrent consumers Aug 24, 2026
@oliviamiller
oliviamiller marked this pull request as ready for review August 24, 2026 15:16
@njooma

Copy link
Copy Markdown

Don't have hardware, but code looks reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants