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

◆ setup_ring()

void MayaFlux::Kakshya::VideoStreamContainer::setup_ring ( uint64_t  total_frames,
uint32_t  ring_capacity,
uint32_t  width,
uint32_t  height,
Portal::Graphics::ImageFormat  format,
double  frame_rate,
uint32_t  refill_threshold,
uint64_t  reader_id = 0 
)

Allocate m_data[0] as a ring of ring_capacity frames.

Switches the container from flat mode to ring mode. m_data[0] is resized to ring_capacity x frame_byte_size. m_num_frames is set to total_frames so processors see the full temporal extent. Pixel data is indexed by frame_index % ring_capacity.

Parameters
total_framesTotal frames in the source (file, stream, etc).
ring_capacityNumber of frame slots (must be power of 2).
widthFrame width in pixels.
heightFrame height in pixels.
formatPixel format for the ring's frames.
frame_rateFrame rate in fps.
refill_thresholdFrames of look-ahead below which refill callback fires.
reader_idThe current class ID registered at the stream/file-read source

Definition at line 118 of file VideoStreamContainer.cpp.

126{
127 {
128 Memory::SeqlockWriteGuard g(m_data_lock);
129
130 m_width = width;
132 m_format = format;
138
139 m_frame_rate = frame_rate;
140 m_total_source_frames = total_frames;
141 m_ring_capacity = ring_capacity;
142 m_num_frames = total_frames;
143 m_cache_head.store(0, std::memory_order_relaxed);
144 m_refill_threshold = refill_threshold;
145 m_io_reader_id = reader_id;
146
148 .get_service<Registry::Service::IOService>();
149
150 const size_t frame_bytes = get_frame_byte_size();
151
152 m_data.resize(1);
153 auto& pixels = m_data[0].emplace<std::vector<uint8_t>>();
154 pixels.resize(frame_bytes * ring_capacity, 0);
155
156 m_slot_frame = std::vector<std::atomic<uint64_t>>(ring_capacity);
157 for (auto& sf : m_slot_frame)
158 sf.store(UINT64_MAX, std::memory_order_relaxed);
159
160 m_ready_queue.reset();
162 }
163
164 if (m_float_frame_cache.size() != ring_capacity) {
165 m_float_frame_cache.resize(ring_capacity);
166 m_float_frame_dirty = std::vector<std::atomic<bool>>(ring_capacity);
167
168 for (auto& flag : m_float_frame_dirty)
169 flag.store(true, std::memory_order_relaxed);
170 }
171
173}
const std::vector< float > * pixels
Definition Decoder.cpp:65
uint32_t width
uint32_t height
uint32_t m_refill_threshold
Trigger refill when (m_cache_head - read_position) drops below this.
std::vector< std::atomic< uint64_t > > m_slot_frame
Memory::LockFreeQueue< uint64_t, READY_QUEUE_CAPACITY > m_ready_queue
std::vector< std::atomic< bool > > m_float_frame_dirty
std::vector< std::vector< float > > m_float_frame_cache
std::atomic< uint64_t > m_cache_head
Highest frame index committed by the decode thread.
size_t get_frame_byte_size() const
Total byte size of one frame: width * height * bytes_per_pixel.
void update_processing_state(ProcessingState new_state) override
Update the processing state of the container.
Registry::Service::IOService * m_io_service
static size_t get_bytes_per_pixel(ImageFormat format)
Get bytes per pixel for a format.
static uint32_t get_channel_count(ImageFormat format)
Get the number of color channels for a given format.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ IDLE
Container is inactive with no data or not ready for processing.
@ VIDEO_DEPTH
[frames, height, width, components] - streaming range data
@ VIDEO_COLOR
4D video (time + 2D + color)
bool is_depth_format(ImageFormat format)
std::shared_ptr< T > store(std::shared_ptr< T > obj)
Transfer ownership of an existing object to the persistent store for process lifetime.
Definition Persist.hpp:28

References MayaFlux::Portal::Graphics::TextureLoom::get_bytes_per_pixel(), MayaFlux::Portal::Graphics::TextureLoom::get_channel_count(), get_frame_byte_size(), MayaFlux::Registry::BackendRegistry::get_service(), height, MayaFlux::Kakshya::IDLE, MayaFlux::Registry::BackendRegistry::instance(), MayaFlux::Kakshya::is_depth_format(), m_bpp, m_cache_head, m_channels, m_data, m_data_lock, m_float_frame_cache, m_float_frame_dirty, m_format, m_frame_rate, m_height, m_io_reader_id, m_io_service, m_num_frames, m_ready_queue, m_refill_threshold, m_ring_capacity, m_slot_frame, m_structure, m_total_source_frames, m_width, MayaFlux::Kakshya::ContainerDataStructure::modality, pixels, setup_dimensions(), update_processing_state(), MayaFlux::Kakshya::VIDEO_COLOR, MayaFlux::Kakshya::VIDEO_DEPTH, and width.

+ Here is the call graph for this function: