MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Kakshya::DynamicVideoStream Class Reference

Video container that frames are appended to at runtime, the counterpart of DynamicSoundStream. More...

#include <DynamicVideoStream.hpp>

+ Inheritance diagram for MayaFlux::Kakshya::DynamicVideoStream:
+ Collaboration diagram for MayaFlux::Kakshya::DynamicVideoStream:

Public Member Functions

bool append_frame (const ImageData &image)
 Write one image, for example one read back from a GPU image.
 
bool append_frame (const std::shared_ptr< Core::VKImage > &image, const std::shared_ptr< Buffers::VKBuffer > &staging=nullptr)
 Download a GPU image straight into the next frame slot.
 
bool append_frame (std::span< const uint8_t > pixels)
 Write one frame at the write head and advance it.
 
void clear () override
 Drop every frame and restart the write head at zero.
 
void create_default_processor () override
 Install a FrameSeekProcessor as the default processor.
 
 DynamicVideoStream (const VideoStreamSpec &spec)
 Build a stream from a spec, enabling the ring when it asks for one.
 
void enable_circular_buffer (uint64_t capacity)
 Keep only the most recent capacity frames.
 
void ensure_capacity (uint64_t frames)
 Pre-allocate room for frames in linear mode.
 
uint64_t get_write_head () const
 Index of the next frame append_frame will write.
 
void lag_behind_head (double frames)
 Play back a fixed number of frames behind the write head.
 
std::shared_ptr< FrameSeekProcessor > seek_processor ()
 The FrameSeekProcessor that reads this stream, installed on first use.
 
std::shared_ptr< DynamicVideoStream > snapshot (uint64_t frames) const
 Copy the most recent frames into a new linear stream, oldest first.
 
- Public Member Functions inherited from MayaFlux::Kakshya::VideoStreamContainer
void add_region_group (const RegionGroup &group) override
 Add a named group of regions to the container.
 
void advance_cache_head (uint64_t frame_index)
 Advance the container's view of how many frames have been decoded.
 
void advance_read_position (const std::vector< uint64_t > &frames) override
 Advance the read position by a specified amount.
 
std::vector< DataAccess > all_channel_data () override
 Get all channel data as accessors.
 
bool all_dimensions_consumed () const override
 Check if all active dimensions have been consumed in this cycle.
 
DataAccess channel_data (size_t channel) override
 Get channel data with semantic interpretation.
 
void clear () override
 Clear all data in the container.
 
void commit_frame (uint64_t frame_index)
 Publish a decoded frame.
 
uint64_t coordinates_to_linear_index (const std::vector< uint64_t > &coordinates) const override
 Convert coordinates to linear index based on current memory layout.
 
void create_default_processor () override
 Create and configure a default processor for this container.
 
std::unordered_map< std::string, RegionGroup > get_all_region_groups () const override
 Get all region groups in the container.
 
size_t get_bytes_per_pixel () const
 Bytes occupied by one pixel across all channels.
 
uint64_t get_cache_head () const
 Total frame count known at construction / setup_ring() time.
 
uint32_t get_channels () const
 Component channels per pixel.
 
const std::vector< DataVariant > & get_data () override
 Get a reference to the raw data stored in the container.
 
std::shared_ptr< DataProcessor > get_default_processor () const override
 Get the current default data processor.
 
std::vector< DataDimension > get_dimensions () const override
 Get the dimensions describing the structure of the data.
 
ImageFormat get_format () const
 Pixel format governing storage type, channel count, and modality.
 
size_t get_frame_byte_size () const
 Total byte size of one frame: width * height * bytes_per_pixel.
 
size_t get_frame_element_count () const
 Elements in one frame: width * height * channels.
 
std::span< const uint8_t > get_frame_pixels (uint64_t frame_index) const
 Get raw pixel data for a single frame as a byte span.
 
double get_frame_rate () const
 
uint64_t get_frame_size () const override
 Get the number of elements that constitute one "frame".
 
uint32_t get_height () const
 
Region get_loop_region () const override
 Get the current loop region.
 
MemoryLayout get_memory_layout () const override
 Get the memory layout used by this container.
 
uint64_t get_num_frames () const override
 Get the number of frames in the primary (temporal) dimension.
 
const std::vector< DataVariant > & get_processed_data () const override
 Get a const reference to the processed data buffer.
 
std::vector< DataVariant > & get_processed_data () override
 Get a mutable reference to the processed data buffer.
 
std::shared_ptr< DataProcessingChain > get_processing_chain () override
 Get the current processing chain for this container.
 
ProcessingState get_processing_state () const override
 Get the current processing state of the container.
 
const void * get_raw_data () const override
 Get a raw pointer to the underlying data storage.
 
const std::vector< uint64_t > & get_read_position () const override
 Get the current read position.
 
std::vector< DataVariant > get_region_data (const Region &region) const override
 Get data for a specific region.
 
RegionGroup get_region_group (const std::string &name) const override
 Get a region group by name.
 
std::vector< DataVariant > get_region_group_data (const RegionGroup &group) const override
 Get data for multiple regions efficiently.
 
std::vector< uint64_t > get_remaining_frames () const override
 Get the number of remaining frames from the current position, per channel.
 
uint32_t get_ring_capacity () const
 
std::vector< DataVariant > get_segments_data (const std::vector< RegionSegment > &segment) const override
 Get data for multiple region segments efficiently.
 
const ContainerDataStructure & get_structure () const override
 
ContainerDataStructure & get_structure () override
 Get the data structure defining this container's layout.
 
uint64_t get_temporal_rate () const override
 Get the temporal rate (e.g., sample rate, frame rate) of the stream.
 
uint64_t get_total_elements () const override
 Get the total number of elements in the container.
 
uint64_t get_total_source_frames () const
 
uint32_t get_width () const
 
bool has_active_readers () const override
 Check if any dimensions currently have active readers.
 
bool has_data () const override
 Check if the container currently holds any data.
 
bool has_processing_token (int channel) const override
 
void invalidate_float_frame_cache (uint32_t slot_index=0)
 
void invalidate_ring ()
 Invalidate all ring slots.
 
bool is_at_end () const override
 Check if read position has reached the end of the stream.
 
bool is_frame_available (uint64_t frame_index) const
 Check if a frame is currently valid in the ring.
 
bool is_looping () const override
 Check if looping is enabled for the stream.
 
bool is_ready () const override
 Check if the stream is ready for reading.
 
bool is_ready_for_processing () const override
 Check if the container is ready for processing.
 
bool is_region_loaded (const Region &region) const override
 Check if a region is loaded in memory.
 
bool is_ring_mode () const
 True if the container is operating in ring mode.
 
std::vector< uint64_t > linear_index_to_coordinates (uint64_t linear_index) const override
 Convert linear index to coordinates based on current memory layout.
 
void load_region (const Region &region) override
 Load a region into memory.
 
void mark_buffers_for_processing (bool) override
 Mark associated buffers for processing in the next cycle.
 
void mark_buffers_for_removal () override
 Mark associated buffers for removal from the system.
 
void mark_dimension_consumed (uint32_t dimension_index, uint32_t reader_id) override
 Mark a dimension as consumed for the current processing cycle.
 
void mark_ready_for_processing (bool ready) override
 Mark the container as ready or not ready for processing.
 
uint8_t * mutable_slot_ptr (uint64_t frame_index)
 Mutable pointer into m_data[0] for the decode thread to write into.
 
uint64_t peek_sequential (std::span< double > output, uint64_t count, uint64_t offset) const override
 Peek at data without advancing the read position.
 
double position_to_time (uint64_t position) const override
 Convert from position units (e.g., frame/sample index) to time (seconds).
 
void process_default () override
 Process the container's data using the default processor.
 
std::span< const float > processed_frame_as_float (uint64_t frame_index=0) const
 Processed frame at frame_index as a normalised float span.
 
uint64_t read_sequential (std::span< double > output, uint64_t count) override
 Read data sequentially from the current position.
 
uint32_t register_dimension_reader (uint32_t dimension_index) override
 Register a reader for a specific dimension.
 
void register_state_change_callback (std::function< void(const std::shared_ptr< SignalSourceContainer > &, ProcessingState)> callback) override
 Register a callback to be invoked on processing state changes.
 
void remove_region_group (const std::string &name) override
 Remove a region group by name.
 
void reset_processing_token () override
 
void reset_read_position () override
 Reset read position to the beginning of the stream.
 
void set_default_processor (const std::shared_ptr< DataProcessor > &processor) override
 Set the default data processor for this container.
 
void set_loop_region (const Region &region) override
 Set the loop region using a Region.
 
void set_looping (bool enable) override
 Enable or disable looping behavior for the stream.
 
void set_memory_layout (MemoryLayout layout) override
 Set the memory layout for this container.
 
void set_processing_chain (const std::shared_ptr< DataProcessingChain > &chain) override
 Set the processing chain for this container.
 
void set_read_position (const std::vector< uint64_t > &position) override
 Set the current read position in the primary temporal dimension per channel.
 
void set_refill_threshold (uint32_t threshold)
 Set the number of frames below which the refill callback fires.
 
void set_region_data (const Region &region, const std::vector< DataVariant > &data) override
 Set data for a specific region.
 
void set_structure (ContainerDataStructure structure) override
 Set the data structure for this container.
 
void setup_ring (uint64_t total_frames, uint32_t ring_capacity, uint32_t width, uint32_t height, 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.
 
uint64_t time_to_position (double time) const override
 Convert from time (seconds) to position units (e.g., frame/sample index).
 
bool try_acquire_processing_token (int channel) override
 
void unload_region (const Region &region) override
 Unload a region from memory.
 
void unregister_dimension_reader (uint32_t dimension_index) override
 Unregister a reader for a specific dimension.
 
void unregister_state_change_callback () override
 Unregister the state change callback, if any.
 
void update_processing_state (ProcessingState new_state) override
 Update the processing state of the container.
 
void update_read_position_for_channel (size_t channel, uint64_t frame) override
 Update the read position for a specific channel.
 
std::type_index value_element_type () const override
 Runtime query for the native scalar element type of this container.
 
 VideoStreamContainer (uint32_t width=0, uint32_t height=0, ImageFormat format=ImageFormat::RGBA8, double frame_rate=0.0)
 Construct a VideoStreamContainer with specified parameters.
 
 ~VideoStreamContainer () override=default
 
- Public Member Functions inherited from MayaFlux::Kakshya::StreamContainer
virtual ~StreamContainer ()=default
 
- Public Member Functions inherited from MayaFlux::Kakshya::SignalSourceContainer
 ~SignalSourceContainer () override=default
 
- Public Member Functions inherited from MayaFlux::Kakshya::NDDataContainer< DataVariant >
auto get_frame (uint64_t frame_index) const -> FrameView
 Get a single frame of data efficiently.
 
auto get_frame_as (uint64_t frame_index) const -> std::span< const ValueT >
 Get a single frame of data as a typed span.
 
void get_frames (std::span< ValueT > output, uint64_t start_frame, uint64_t num_frames) const
 Get multiple frames efficiently.
 
void get_frames_as (std::vector< ValueT > &output, uint64_t start_frame, uint64_t num_frames) const
 Get multiple frames efficiently as a typed span.
 
ValueT get_value_at (const std::vector< uint64_t > &coordinates) const
 Read a single element at the given N-dimensional coordinates.
 
void set_value_at (const std::vector< uint64_t > &coordinates, ValueT value)
 Write a single element at the given N-dimensional coordinates.
 
virtual ~NDDataContainer ()=default
 

Private Member Functions

uint8_t * claim_frame_slot ()
 
void finish_frame ()
 
std::vector< uint8_t > & flat_bytes ()
 
void publish_frame_count ()
 

Private Attributes

uint64_t m_write_head {}
 

Additional Inherited Members

- Protected Member Functions inherited from MayaFlux::Kakshya::VideoStreamContainer
DataSpanVariant get_frame_span_impl (uint64_t frame_index) const override
 Implementation-specific method to retrieve a frame span.
 
void get_frames_impl (void *output, size_t count, uint64_t start_frame, uint64_t num_frames, const std::type_info &type) const override
 Implementation-specific method to retrieve multiple frames.
 
void get_value_impl (const std::vector< uint64_t > &coords, void *out, const std::type_info &type) const override
 Type-erased single-element read.
 
void notify_state_change (ProcessingState new_state)
 
void set_value_impl (const std::vector< uint64_t > &coords, const void *in, const std::type_info &type) override
 Type-erased single-element write.
 
void setup_dimensions ()
 
uint32_t slot_for (uint64_t frame_index) const
 
- Protected Attributes inherited from MayaFlux::Kakshya::VideoStreamContainer
size_t m_bpp = 4
 
std::atomic< uint64_t > m_cache_head { 0 }
 Highest frame index committed by the decode thread.
 
Memory::Seqlock m_cb_lock
 
uint32_t m_channels = 4
 
std::atomic< uint32_t > m_consumed_readers { 0 }
 
std::vector< DataVariant > m_data
 
Memory::Seqlock m_data_lock
 
std::shared_ptr< DataProcessor > m_default_processor
 
ImageFormat m_format = ImageFormat::RGBA8
 
double m_frame_rate = 0.0
 
uint32_t m_height = 0
 
uint64_t m_io_reader_id { 0 }
 
Registry::Service::IOService * m_io_service { nullptr }
 
Region m_loop_region
 
bool m_looping_enabled {}
 
uint64_t m_num_frames = 0
 
std::vector< DataVariant > m_processed_data
 
std::shared_ptr< DataProcessingChain > m_processing_chain
 
std::atomic< ProcessingState > m_processing_state { ProcessingState::IDLE }
 
std::atomic< int > m_processing_token_channel { -1 }
 
std::atomic< uint64_t > m_read_position { 0 }
 
Memory::LockFreeQueue< uint64_t, READY_QUEUE_CAPACITY > m_ready_queue
 
uint32_t m_refill_threshold { 0 }
 Trigger refill when (m_cache_head - read_position) drops below this.
 
std::unordered_map< std::string, RegionGroup > m_region_groups
 
Memory::Seqlock m_region_lock
 
std::atomic< uint32_t > m_registered_readers { 0 }
 
uint32_t m_ring_capacity { 0 }
 
std::vector< std::atomic< uint64_t > > m_slot_frame
 
std::function< void(const std::shared_ptr< SignalSourceContainer > &, ProcessingState)> m_state_callback
 
ContainerDataStructure m_structure
 
uint64_t m_total_source_frames { 0 }
 
uint32_t m_width = 0
 
- Static Protected Attributes inherited from MayaFlux::Kakshya::VideoStreamContainer
static constexpr uint32_t READY_QUEUE_CAPACITY = 256
 

Detailed Description

Video container that frames are appended to at runtime, the counterpart of DynamicSoundStream.

Frames arrive through append_frame instead of being decoded from a file. In linear mode the stream grows with each frame. In circular mode (enable_circular_buffer) it keeps only the most recent frames.

Frame indices are absolute. Frame i is stored in slot i % capacity and stays readable until a later frame overwrites it, so get_write_head keeps counting past the capacity and is_frame_available says whether an older frame is still there. Reading is unchanged: get_frame_pixels and FrameAccessProcessor work as for any VideoStreamContainer. A FrameAccessProcessor playhead that falls more than the capacity behind the head finds its frames overwritten.

Pixels are stored as bytes whatever the format.

Definition at line 52 of file DynamicVideoStream.hpp.


The documentation for this class was generated from the following files: