24constexpr size_t kSlotCount = 4;
30 uint32_t sequence = 0;
33enum class AbortReason : uint8_t { Oversize, Corrupt, CaptureFailed };
39 virtual void release_slot(
size_t slot) = 0;
55 : owner_(std::exchange(other.owner_,
nullptr)), slot_(other.slot_), meta_(other.meta_)
64 owner_ = std::exchange(other.owner_,
nullptr);
75 if (owner_ !=
nullptr)
77 owner_->release_slot(slot_);
82 size_t slot()
const {
return slot_; }
83 const FrameMeta& meta()
const {
return meta_; }
84 bool valid()
const {
return owner_ !=
nullptr; }
98 for (
size_t i = 0; i < kSlotCount; ++i)
100 if (slots_[i].state == State::Free)
102 slots_[i].state = State::Writing;
113 meta.sequence = ++sequence_;
114 slots_[slot].state = State::Published;
115 slots_[slot].meta = meta;
116 if (latest_ && *latest_ != slot && slots_[*latest_].readers == 0)
118 slots_[*latest_].state = State::Free;
127 slots_[slot].state = State::Free;
128 if (reason == AbortReason::Oversize)
131 }
else if (reason == AbortReason::Corrupt)
137 std::optional<FrameLease> acquire_latest() {
return acquire_latest(*
this); }
146 Slot& slot = slots_[*latest_];
148 return FrameLease(releaser, *latest_, slot.meta);
151 void release_slot(
size_t slot)
override
153 Slot& s = slots_[slot];
158 if (s.readers == 0 && s.state == State::Published && latest_ != slot)
160 s.state = State::Free;
164 uint32_t frames_published()
const {
return published_; }
165 uint32_t frames_dropped_no_slot()
const {
return dropped_no_slot_; }
166 uint32_t frames_dropped_oversize()
const {
return dropped_oversize_; }
167 uint32_t frames_dropped_corrupt()
const {
return dropped_corrupt_; }
170 enum class State : uint8_t { Free, Writing, Published };
173 State state = State::Free;
178 std::array<Slot, kSlotCount> slots_{};
179 std::optional<size_t> latest_;
180 uint32_t sequence_ = 0;
181 uint32_t published_ = 0;
182 uint32_t dropped_no_slot_ = 0;
183 uint32_t dropped_oversize_ = 0;
184 uint32_t dropped_corrupt_ = 0;
Move-only handle on a published frame. Releases its slot exactly once, on release() or destruction.
Definition frame_slots.h:47
Definition frame_slots.h:93
void abort_write(size_t slot, AbortReason reason)
Give up a slot taken by begin_write(). Oversize and Corrupt are counted.
Definition frame_slots.h:125
void publish(size_t slot, FrameMeta meta)
Make a written slot the latest frame. Assigns the next sequence number.
Definition frame_slots.h:111
std::optional< FrameLease > acquire_latest(SlotReleaser &releaser)
Lease the latest frame; the lease will call releaser.release_slot() when done.
Definition frame_slots.h:140
std::optional< size_t > begin_write()
A slot that is not latest, not leased and not being written; nullopt (and a counted drop) if none.
Definition frame_slots.h:96
Whatever a FrameLease must notify when it is released (FrameSlots natively, FrameStore on device).
Definition frame_slots.h:37