ImageBuffer reader: give up on an image MAX_IMAGE_LAG (100) behind the newest, and a unit test

Images reach the buffer in order give or take a few, so one still missing when the buffer holds an
image 100 past it is lost, not late: the read returns false instead of waiting for the end of the
collection. The newest image number comes from ImageBuffer::GetStatus, which scans every slot under
the buffer's lock, so it is asked only every 100 polls (~10 Hz).

The test puts CBOR images into an ImageBuffer the way the receiver does and checks read-back of the
pixels, waiting for an image not yet there, the lag limit, the end of the collection and the bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-10-17 14:27:10 +02:00
1 parent 4e6d7c33b3
commit f215300a07
4 files changed
+108 -2

No files matched your search

+6 -1
View File
@@ -34,9 +34,14 @@ bool JFJochImageBufferReader::WaitForMessage(int64_t image_number, std::vector<u
if (image_number < 0 || static_cast<uint64_t>(image_number) >= number_of_images_)
throw JFJochException(JFJochExceptionCategory::ArrayOutOfBounds, "Image out of bounds");
// The buffer has no notification of its own; at 100 Hz a millisecond's poll costs nothing.
while (!buffer_.GetImage(cbor, image_number)) {
for (int poll = 1; !buffer_.GetImage(cbor, image_number); poll++) {
if (ended_)
return buffer_.GetImage(cbor, image_number); // one that came in just before the end
// Images arrive in order, give or take a few: one still missing when the buffer already holds
// an image MAX_IMAGE_LAG past it is lost, not late. GetStatus scans every slot under the
// buffer's lock, so it is asked only every 100 polls.
if (poll % 100 == 0 && buffer_.GetStatus().max_image_number >= image_number + MAX_IMAGE_LAG)
return buffer_.GetImage(cbor, image_number);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return true;