MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ get_frame_pixels()

std::span< const uint8_t > MayaFlux::Kakshya::VideoStreamContainer::get_frame_pixels ( uint64_t  frame_index) const

Get raw pixel data for a single frame as a byte span.

Parameters
frame_indexZero-based frame index.
Returns
Span of pixel bytes for the frame, empty if out of range.

Definition at line 238 of file VideoStreamContainer.cpp.

239{
240 const size_t frame_bytes = get_frame_byte_size();
241 if (frame_bytes == 0 || frame_index >= m_num_frames)
242 return {};
243
244 if (m_ring_capacity == 0) {
245 std::span<const uint8_t> result;
247 if (m_data.empty())
248 return;
249
250 auto [ptr, bytes] = variant_bytes(m_data[0]);
251 if (!ptr)
252 return;
253
254 const size_t offset = frame_index * frame_bytes;
255 if (offset + frame_bytes > bytes)
256 return;
257
258 result = { ptr + offset, frame_bytes };
259 });
260 return result;
261 }
262
263 const uint32_t slot = slot_for(frame_index);
264 if (m_slot_frame[slot].load(std::memory_order_acquire) == frame_index) {
265 if (m_data.empty())
266 return {};
267
268 auto [ptr, bytes] = variant_bytes(m_data[0]);
269 if (!ptr)
270 return {};
271
272 const size_t offset = static_cast<size_t>(slot) * frame_bytes;
273 if (offset + frame_bytes > bytes)
274 return {};
275
276 return { ptr + offset, frame_bytes };
277 }
278
279 return {};
280}
const uint8_t * ptr
float offset
std::vector< std::atomic< uint64_t > > m_slot_frame
uint32_t slot_for(uint64_t frame_index) const
size_t get_frame_byte_size() const
Total byte size of one frame: width * height * bytes_per_pixel.
std::pair< const uint8_t *, size_t > variant_bytes(const DataVariant &v)
Get a pointer to the raw bytes of a DataVariant and its size.
Definition DataUtils.cpp:95
bool seqlock_read_void(const Seqlock &lock, uint32_t max_attempts, Fn &&fn)
Invoke a void read functor under a Seqlock with a bounded retry count.
Definition SeqLock.hpp:222

References get_frame_byte_size(), m_data, m_data_lock, m_num_frames, m_ring_capacity, m_slot_frame, offset, ptr, slot_for(), and MayaFlux::Kakshya::variant_bytes().

Referenced by get_frame_typed(), and get_frames_typed_as().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: