MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferOperation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Capture.hpp"
4
8
9namespace MayaFlux {
10
11namespace Core {
12 class VKImage;
13}
14
15namespace Buffers {
16 class BufferProcessor;
17 class BufferManager;
18 class TextureArrayBuffer;
19}
20
21namespace Kakshya {
22 class DynamicSoundStream;
23 class DynamicVideoStream;
24 class VideoStreamContainer;
25}
26
27namespace IO {
28 class IOManager;
29 struct CameraConfig;
30 struct VideoLoadConfig;
31}
32
33namespace Kriya {
34
35 using TransformVectorFunction = std::function<Kakshya::DataVariant(std::vector<Kakshya::DataVariant>&, uint32_t)>;
36
37 /**
38 * @enum ExecutionStrategy
39 * @brief Defines how operations in a pipeline are coordinated and executed
40 */
41 enum class ExecutionStrategy : uint8_t {
42 /**
43 * PHASED: Traditional phased execution (default)
44 * - All CAPTURE operations complete first (capture phase)
45 * - Then all processing operations execute (process phase)
46 * - Best for: accumulation, windowed analysis, batch processing
47 * - Predictable data availability, clear phase boundaries
48 */
49 PHASED,
50
51 /**
52 * STREAMING: Immediate flow-through execution
53 * - Each capture iteration flows immediately through dependent operations
54 * - Minimal latency, data processed as it arrives
55 * - Best for: real-time effects, low-latency processing, modify_buffer chains
56 * - Natural for operations that modify state continuously
57 */
59
60 /**
61 * PARALLEL: Concurrent capture with synchronization
62 * - Multiple capture operations can run concurrently
63 * - Explicit synchronization points coordinate data flow
64 * - Best for: multi-source capture, independent data streams
65 */
67
68 /**
69 * REACTIVE: Data-driven reactive execution
70 * - Operations execute when input data becomes available
71 * - Dynamic dependency resolution
72 * - Best for: event-driven workflows, complex dependencies
73 * - Non-deterministic execution order
74 */
76 };
77
78 class BufferPipeline;
79
80 /**
81 * @class BufferOperation
82 * @brief Fundamental unit of operation in buffer processing pipelines.
83 *
84 * BufferOperation encapsulates discrete processing steps that can be composed
85 * into complex data flow pipelines. Each operation represents a specific action
86 * such as capturing data, transforming it, routing to destinations, or applying
87 * conditional logic. Operations are designed to be chainable and support
88 * sophisticated scheduling and priority management.
89 *
90 * **Operation Types:**
91 * - **CAPTURE**: Extract data from a buffer using configurable capture strategies
92 * - **TRANSFORM**: Apply functional transformations to data variants
93 * - **ROUTE**: Direct data to audio or graphics buffers and streams
94 * - **LOAD**: Read data from containers into buffers with position control
95 * - **SYNC**: Coordinate timing and synchronization across pipeline stages
96 * - **CONDITION**: Apply conditional logic and branching to data flow
97 * - **DISPATCH**: Send data to external handlers and callback systems
98 * - **FUSE**: Combine multiple data sources using custom fusion functions
99 *
100 * **Example Usage:**
101 * ```cpp
102 * // Capture audio with windowed analysis
103 * auto capture_op = BufferOperation::capture_from(input_buffer)
104 * .with_window(512, 0.5f)
105 * .on_data_ready([](const auto& data, uint32_t cycle) {
106 * analyze_spectrum(data);
107 * });
108 *
109 * // Transform and route to output
110 * auto pipeline = BufferPipeline()
111 * >> capture_op
112 * >> BufferOperation::transform([](const auto& data, uint32_t cycle) {
113 * return apply_reverb(data);
114 * }, Buffers::ProcessingToken::AUDIO_BACKEND)
115 * >> BufferOperation::route_to_container(output_stream);
116 * ```
117 * @class BufferCapture
118 * ...existing intro...
119 *
120 * **Cycle Behavior:**
121 * The `for_cycles(N)` configuration controls how many times the capture operation
122 * executes within a single pipeline cycle. When a capture has `.for_cycles(20)`,
123 * the operation will capture 20 times sequentially, with each capture receiving
124 * incrementing cycle numbers (0, 1, 2... 19) and calling `on_data_ready()` for
125 * each iteration.
126 *
127 * This is distinct from pipeline-level cycle control:
128 * - `.for_cycles(20)` on capture → operation executes 20 times per pipeline cycle
129 * - `execute_scheduled(5, ...)` → pipeline runs 5 times total
130 * - Combined: 5 × 20 = 100 total capture executions
131 *
132 * **Example:**
133 * ```cpp
134 * auto pipeline = BufferPipeline::create(*scheduler);
135 * pipeline >> BufferOperation::capture_from(buffer)
136 * .for_cycles(10) // Capture 10 times per pipeline invocation
137 * .on_data_ready([](const auto& data, uint32_t cycle) {
138 * std::cout << "Capture #" << cycle << '\n'; // Prints 0-9
139 * });
140 * pipeline->execute_scheduled(3, 512); // Runs pipeline 3 times → 30 total captures
141 * ```
142 *
143 *
144 * @see BufferPipeline For pipeline construction and execution
145 * @see BufferCapture For flexible data capture strategies
146 */
147 class MAYAFLUX_API BufferOperation {
148 private:
149 enum class ExecutionPhase : uint8_t {
150 AUTO, // Automatically determined by operation type
151 CAPTURE, // Explicitly runs in capture phase
152 PROCESS // Explicitly runs in process phase
153 };
154
155 public:
156 /**
157 * @enum OpType
158 * @brief Defines the fundamental operation types in the processing pipeline.
159 */
160 enum class OpType : uint8_t {
161 CAPTURE, ///< Capture data from source buffer using BufferCapture strategy
162 TRANSFORM, ///< Apply transformation function to data variants
163 ROUTE, ///< Route data to destination (buffer or container)
164 LOAD, ///< Load data from container to buffer with position control
165 SYNC, ///< Synchronize with timing/cycles for coordination
166 CONDITION, ///< Conditional operation for branching logic
167 BRANCH, ///< Branch to sub-pipeline based on conditions
168 DISPATCH, ///< Dispatch to external handler for custom processing
169 FUSE, ///< Fuse multiple sources using custom fusion functions
170 MODIFY ///< Modify Buffer Data using custom quick process
171 };
172
173 /**
174 * @brief Create a capture operation using BufferCapture configuration.
175 * @param capture Configured BufferCapture with desired capture strategy
176 * @return BufferOperation configured for data capture
177 */
179 {
180 return { OpType::CAPTURE, std::move(capture) };
181 }
182
183 /**
184 * @brief Create capture operation from input channel using convenience API.
185 * Creates input buffer automatically and returns configured capture operation.
186 * @param buffer_manager System buffer manager
187 * @param input_channel Input channel to capture from
188 * @param mode Capture mode (default: ACCUMULATE)
189 * @param cycle_count Number of cycles (0 = continuous, default)
190 * @return BufferOperation configured for input capture with default settings
191 */
192 static BufferOperation capture_input(
193 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
194 uint32_t input_channel,
195 BufferCapture::CaptureMode mode = BufferCapture::CaptureMode::ACCUMULATE,
196 uint32_t cycle_count = 0);
197
198 /**
199 * @brief Create CaptureBuilder for input channel with fluent configuration.
200 * Uses the existing CaptureBuilder pattern but with input buffer creation.
201 * @param buffer_manager System buffer manager
202 * @param input_channel Input channel to capture from
203 * @return CaptureBuilder for fluent configuration
204 */
205 static CaptureBuilder capture_input_from(
206 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
207 uint32_t input_channel);
208
209 /**
210 * @brief Open and capture a camera through IOManager.
211 * @param render Draws the live camera when given; a camera buffer that
212 * already renders is left as it is. Without it the capture only
213 * routes the frames.
214 */
215 static BufferOperation capture_camera(
216 const std::shared_ptr<IO::IOManager>& io_manager,
217 const IO::CameraConfig& config,
218 BufferCapture::CaptureMode mode = BufferCapture::CaptureMode::TRANSIENT,
219 uint32_t cycle_count = 1,
220 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
221
222 /**
223 * @brief Open a camera and return its capture builder.
224 * @param render Draws the live camera when given.
225 */
226 static CaptureBuilder capture_camera_from(
227 const std::shared_ptr<IO::IOManager>& io_manager,
228 const IO::CameraConfig& config,
229 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
230
231 /**
232 * @brief Create a file capture operation that reads from file and stores in stream.
233 * @param io_manager IOManager for file loading
234 * @param filepath Path to audio file
235 * @param channel Channel index (default: 0)
236 * @param cycle_count Number of cycles to capture (0 = continuous)
237 * @return BufferOperation configured for file capture
238 */
239 static BufferOperation capture_file(
240 const std::shared_ptr<IO::IOManager>& io_manager,
241 const std::string& filepath,
242 uint32_t channel = 0,
243 uint32_t cycle_count = 0);
244
245 /**
246 * @brief Capture a video file with explicit video load configuration.
247 * @param render Draws the video when given.
248 */
249 static BufferOperation capture_file(
250 const std::shared_ptr<IO::IOManager>& io_manager,
251 const std::string& filepath,
252 IO::VideoLoadConfig config,
253 uint32_t cycle_count = 1,
254 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
255
256 /**
257 * @brief Create CaptureBuilder for file with fluent configuration.
258 * @param io_manager IOManager for file loading
259 * @param filepath Path to audio file
260 * @param channel Channel index (default: 0)
261 * @return CaptureBuilder for fluent configuration
262 */
263 static CaptureBuilder capture_file_from(
264 const std::shared_ptr<IO::IOManager>& io_manager,
265 const std::string& filepath,
266 uint32_t channel = 0);
267
268 /**
269 * @brief Create a capture builder for a video file.
270 * @param render Draws the video when given.
271 */
272 static CaptureBuilder capture_file_from(
273 const std::shared_ptr<IO::IOManager>& io_manager,
274 const std::string& filepath,
275 IO::VideoLoadConfig config,
276 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
277
278 /**
279 * @brief Create operation to route file data to DynamicSoundStream.
280 * @param io_manager IOManager for file loading
281 * @param filepath Path to audio file
282 * @param target_stream Target DynamicSoundStream
283 * @param cycle_count Number of cycles to read (0 = entire file)
284 * @return BufferOperation configured for file to stream routing
285 */
286 static BufferOperation file_to_stream(
287 const std::shared_ptr<IO::IOManager>& io_manager,
288 const std::string& filepath,
289 std::shared_ptr<Kakshya::DynamicSoundStream> target_stream,
290 uint32_t cycle_count = 0);
291
292 /**
293 * @brief Route frames from a video file to a dynamic video stream.
294 * @param render Draws the video file while it routes when given.
295 */
296 static BufferOperation file_to_stream(
297 const std::shared_ptr<IO::IOManager>& io_manager,
298 const std::string& filepath,
299 std::shared_ptr<Kakshya::DynamicVideoStream> target_stream,
300 IO::VideoLoadConfig config,
301 uint32_t cycle_count = 0,
302 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
303
304 /**
305 * @brief Capture a camera straight into a dynamic video stream it creates.
306 *
307 * One operation opens the camera, hooks it to a buffer, makes a ring sized
308 * from that buffer's real frame size and format, and each cycle appends the
309 * camera frame to it. The stream is reached through get_graphics_stream() so
310 * playback can be set up, for example lag_behind_head.
311 *
312 * @param ring_frames Frames the ring keeps; zero keeps three seconds at the
313 * registered frame rate.
314 * @param live Draws the live camera when given.
315 * @param display Draws the stream through the pipeline's IOManager when
316 * given; the pipeline needs one.
317 */
318 static BufferOperation capture_to_stream(
319 const std::shared_ptr<IO::IOManager>& io_manager,
320 const IO::CameraConfig& config,
321 uint64_t ring_frames = 0,
322 std::optional<Portal::Graphics::RenderConfig> live = std::nullopt,
323 std::optional<Portal::Graphics::RenderConfig> display = std::nullopt);
324
325 /**
326 * @brief Capture an opened camera or loaded video into a dynamic video stream it creates.
327 *
328 * The container form of the camera and file forms, which open the source
329 * and call this. A container already hooked, for example by piping it into
330 * Graphics, keeps its buffer; an unhooked one is hooked here. The ring is
331 * sized from that buffer. Audio extracted with the video is not touched:
332 * pipe the container into Graphics first to hear it.
333 *
334 * @param ring_frames Frames the ring keeps; zero keeps three seconds at the
335 * registered frame rate.
336 * @param live Draws the live source when given.
337 * @param display Draws the stream through the pipeline's IOManager when
338 * given; the pipeline needs one.
339 */
340 static BufferOperation capture_to_stream(
341 const std::shared_ptr<IO::IOManager>& io_manager,
342 const std::shared_ptr<Kakshya::VideoStreamContainer>& container,
343 uint64_t ring_frames = 0,
344 std::optional<Portal::Graphics::RenderConfig> live = std::nullopt,
345 std::optional<Portal::Graphics::RenderConfig> display = std::nullopt);
346
347 /**
348 * @brief Capture a video file straight into a dynamic video stream it creates.
349 *
350 * The video counterpart of the camera form: it loads the file, hooks it to
351 * a buffer and appends each played frame to a ring sized from that buffer.
352 *
353 * @param ring_frames Frames the ring keeps; zero keeps three seconds at the
354 * registered frame rate.
355 * @param live Draws the playing file when given.
356 * @param display Draws the stream through the pipeline's IOManager when
357 * given; the pipeline needs one.
358 */
359 static BufferOperation capture_to_stream(
360 const std::shared_ptr<IO::IOManager>& io_manager,
361 const std::string& filepath,
362 IO::VideoLoadConfig config,
363 uint64_t ring_frames = 0,
364 std::optional<Portal::Graphics::RenderConfig> live = std::nullopt,
365 std::optional<Portal::Graphics::RenderConfig> display = std::nullopt);
366
367 /**
368 * @brief The dynamic video stream this operation writes to.
369 *
370 * For capture_to_stream it is the stream the operation created; for a
371 * route it is the stream routed to. Null for other operations. The audio
372 * counterpart would be get_audio_stream.
373 */
374 [[nodiscard]] std::shared_ptr<Kakshya::DynamicVideoStream> get_graphics_stream() const
375 {
376 return m_target_graphics_stream;
377 }
378
379 /**
380 * @brief Create a transform operation with custom transformation function.
381 * @param transformer Function that transforms DataVariant with cycle information
382 * @param token Processing domain for the operation
383 * @return BufferOperation configured for data transformation
384 */
385 static BufferOperation transform(TransformationFunction transformer,
386 Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
387
388 /**
389 * @brief Create a routing operation to AudioBuffer destination.
390 * @param target Target AudioBuffer to receive data.
391 * @return BufferOperation configured for buffer routing.
392 *
393 * ROUTE is a batch output operation. It writes the accumulated or transformed
394 * result of a pipeline into a target buffer or container after processing is
395 * complete. It is not intended for live per-cycle routing: that is covered by
396 * supply, clone, and processing chains on individual buffers. The typical use
397 * is to accumulate or transform over N cycles via CAPTURE/TRANSFORM, then
398 * route the result to a buffer or DynamicSoundStream for playback or storage
399 * via SoundContainerBuffer.
400 */
401 static BufferOperation route_to_buffer(std::shared_ptr<Buffers::AudioBuffer> target);
402
403 /** @brief Route data to a graphics buffer. */
404 static BufferOperation route_to_buffer(std::shared_ptr<Buffers::VKBuffer> target);
405
406 /**
407 * @brief Route frames into one layer of a texture array buffer.
408 *
409 * A capture of an image buffer followed directly by this route is copied
410 * on the GPU with no host read, and the array buffer fits the frame to its
411 * layer. Raw bytes carry no extent and must already match the layer.
412 *
413 * @param target Array buffer that receives the frames.
414 * @param layer Layer that holds this source.
415 */
416 static BufferOperation route_to_buffer(
417 std::shared_ptr<Buffers::TextureArrayBuffer> target, uint32_t layer = 0);
418
419 /**
420 * @brief Route many GPU images into the layers of a texture array buffer.
421 *
422 * Each cycle images[i] is copied into layer i on the GPU, and the array
423 * buffer fits it to the layer. An image that stays the same object is copied
424 * again with whatever it holds that cycle.
425 *
426 * @param target Array buffer that receives the frames.
427 * @param images One image per layer, in layer order.
428 */
429 static BufferOperation route_to_buffer(
430 std::shared_ptr<Buffers::TextureArrayBuffer> target,
431 std::vector<std::shared_ptr<Core::VKImage>> images);
432
433 /**
434 * @brief Create a routing operation to DynamicSoundStream destination.
435 *
436 * Each routed block is appended at the stream's write head for
437 * @p channel, wrapping if the stream is circular, so repeated routing
438 * records a continuous signal.
439 *
440 * @param target Target container to receive data.
441 * @param channel Channel of the target that receives the data.
442 * @return BufferOperation configured for container routing.
443 *
444 * @see route_to_buffer for usage intent and constraints.
445 */
446 static BufferOperation route_to_container(std::shared_ptr<Kakshya::DynamicSoundStream> target, uint32_t channel = 0);
447
448 /**
449 * @brief Append frames to a dynamic video stream.
450 *
451 * @param render Draws the stream in a window when given. The pipeline
452 * hooks the stream to a display buffer through its IOManager when
453 * it starts, as the audio route attaches its writer through the
454 * BufferManager, so the pipeline needs an IOManager and the stream
455 * must already hold data or have its ring enabled.
456 */
457 static BufferOperation route_to_container(
458 std::shared_ptr<Kakshya::DynamicVideoStream> target,
459 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
460
461 /**
462 * @brief Create a load operation from container to buffer.
463 * @param source Source container to read from
464 * @param target Target buffer to write to
465 * @param start_frame Starting frame position (default: 0)
466 * @param length Number of frames to load (default: 0 = all)
467 * @return BufferOperation configured for container loading
468 */
469 static BufferOperation load_from_container(std::shared_ptr<Kakshya::DynamicSoundStream> source,
470 std::shared_ptr<Buffers::AudioBuffer> target,
471 uint64_t start_frame = 0,
472 uint32_t length = 0);
473
474 /** @brief Load video frames from a dynamic stream into a graphics buffer. */
475 static BufferOperation load_from_container(
476 std::shared_ptr<Kakshya::DynamicVideoStream> source,
477 std::shared_ptr<Buffers::VKBuffer> target,
478 uint64_t start_frame = 0,
479 uint32_t length = 0);
480
481 /**
482 * @brief Create a conditional operation for pipeline branching.
483 * @param condition Function that returns true when condition is met
484 * @param token Processing domain for the operation
485 * @return BufferOperation configured for conditional execution
486 */
487 static BufferOperation when(std::function<bool(uint32_t)> condition,
488 Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
489
490 /**
491 * @brief Create a dispatch operation for external processing.
492 * @param handler Function to handle data with cycle information
493 * @param token Processing domain for the operation
494 * @return BufferOperation configured for external dispatch
495 */
496 static BufferOperation dispatch_to(OperationFunction handler,
497 Buffers::ProcessingToken token = Buffers::ProcessingToken::AUDIO_BACKEND);
498
499 /**
500 * @brief Create a modify operation for direct buffer manipulation.
501 * @param buffer AudioBuffer to modify in-place
502 * @param modifier Function that modifies buffer data directly
503 * @return BufferOperation configured for buffer modification
504 *
505 * Unlike TRANSFORM which works on data copies, MODIFY attaches a processor
506 * to the buffer that modifies it in-place during buffer processing.
507 * The processor is automatically managed based on pipeline lifecycle.
508 */
509 static BufferOperation modify_buffer(
510 std::shared_ptr<Buffers::AudioBuffer> buffer,
512
513 /** @brief Attach a graphics quick processor to a Vulkan buffer. */
514 static BufferOperation modify_buffer(
515 std::shared_ptr<Buffers::VKBuffer> buffer,
517
518 /**
519 * @brief Create a fusion operation for multiple AudioBuffer sources.
520 * @param sources Vector of source buffers to fuse
521 * @param fusion_func Function that combines multiple DataVariants
522 * @param target Target buffer for fused result
523 * @return BufferOperation configured for buffer fusion
524 */
525 static BufferOperation fuse_data(std::vector<std::shared_ptr<Buffers::AudioBuffer>> sources,
526 TransformVectorFunction fusion_func,
527 std::shared_ptr<Buffers::AudioBuffer> target);
528
529 /** @brief Fuse graphics buffer data into a graphics destination. */
530 static BufferOperation fuse_data(
531 std::vector<std::shared_ptr<Buffers::VKBuffer>> sources,
532 TransformVectorFunction fusion_func,
533 std::shared_ptr<Buffers::VKBuffer> target);
534
535 /**
536 * @brief Create a fusion operation for multiple DynamicSoundStream sources.
537 * @param sources Vector of source containers to fuse
538 * @param fusion_func Function that combines multiple DataVariants
539 * @param target Target container for fused result
540 * @return BufferOperation configured for container fusion
541 */
542 static BufferOperation fuse_containers(std::vector<std::shared_ptr<Kakshya::DynamicSoundStream>> sources,
543 TransformVectorFunction fusion_func,
544 std::shared_ptr<Kakshya::DynamicSoundStream> target);
545
546 /** @brief Fuse video stream frames into a dynamic video stream. */
547 static BufferOperation fuse_containers(
548 std::vector<std::shared_ptr<Kakshya::DynamicVideoStream>> sources,
549 TransformVectorFunction fusion_func,
550 std::shared_ptr<Kakshya::DynamicVideoStream> target);
551
552 /**
553 * @brief Create a CaptureBuilder for fluent capture configuration.
554 * @param buffer Buffer to capture from
555 * @return CaptureBuilder for fluent operation construction
556 *
557 * @note Register the buffer with BufferManager before automatic processing.
558 */
559 static CaptureBuilder capture_from(std::shared_ptr<Buffers::AudioBuffer> buffer);
560 static CaptureBuilder capture_from(
561 std::shared_ptr<Buffers::VKBuffer> buffer,
562 std::optional<Portal::Graphics::RenderConfig> render = std::nullopt);
563 static CaptureBuilder capture_from(std::nullptr_t);
564
565 /**
566 * @brief Set execution priority for scheduler ordering.
567 * @param priority Priority value (0=highest, 255=lowest, default=128)
568 * @return Reference to this operation for chaining
569 */
570 BufferOperation& with_priority(uint8_t priority);
571
572 /**
573 * @brief Set processing token for execution context.
574 * @param token Processing token indicating execution context
575 * @return Reference to this operation for chaining
576 */
578
579 /**
580 * @brief Set cycle interval for periodic execution.
581 * @param n Execute every n cycles (default: 1)
582 * @return Reference to this operation for chaining
583 */
584 BufferOperation& every_n_cycles(uint32_t n);
585
586 /**
587 * @brief Assign identification tag.
588 * @param tag String identifier for debugging and organization
589 * @return Reference to this operation for chaining
590 */
591 BufferOperation& with_tag(const std::string& tag);
592
593 BufferOperation& for_cycles(uint32_t count);
594
595 /**
596 * @brief Getters for internal state (read-only)
597 */
598 inline OpType get_type() const { return m_type; }
599
600 /**
601 * @brief Getters for internal state (read-only)
602 */
603 inline uint8_t get_priority() const { return m_priority; }
604
605 /** @brief Return the operation's processing token. */
606 inline Buffers::ProcessingToken get_token() const { return m_token; }
607
608 /**
609 * @brief Getters for user defined tag
610 */
611 inline const std::string& get_tag() const { return m_tag; }
612
613 /**
614 * @brief Hint that this operation should execute in capture phase
615 * @return Reference to this operation for chaining
616 */
618 {
619 m_execution_phase = ExecutionPhase::CAPTURE;
620 return *this;
621 }
622
623 /**
624 * @brief Hint that this operation should execute in process phase
625 * @return Reference to this operation for chaining
626 */
627 BufferOperation& as_process_phase();
628
629 /**
630 * @brief Mark this operation as streaming (executes continuously)
631 * Useful for modify_buffer and similar stateful operations
632 * @return Reference to this operation for chaining
633 */
634 BufferOperation& as_streaming();
635
636 /**
637 * @brief Check if this operation is a streaming operation
638 */
639 inline bool is_streaming() const { return m_is_streaming; }
640
641 /**
642 * @brief Get the execution phase hint for this operation
643 */
644 ExecutionPhase get_execution_phase() const { return m_execution_phase; }
645
646 BufferOperation(OpType type, BufferCapture capture);
647
649
650 static bool is_capture_phase_operation(const BufferOperation& op);
651
652 static bool is_process_phase_operation(const BufferOperation& op);
653
654 private:
655 ExecutionPhase m_execution_phase { ExecutionPhase::AUTO };
658 uint32_t m_modify_cycle_count {};
659 bool m_is_streaming {};
660
664
665 std::shared_ptr<Buffers::AudioBuffer> m_target_audio_buffer;
666 std::shared_ptr<Buffers::VKBuffer> m_target_graphics_buffer;
667 std::shared_ptr<Kakshya::DynamicSoundStream> m_target_audio_stream;
668 std::shared_ptr<Kakshya::DynamicVideoStream> m_target_graphics_stream;
669 std::shared_ptr<Buffers::VKBuffer> m_source_graphics_buffer;
670 std::optional<Portal::Graphics::RenderConfig> m_render;
671 bool m_display_attached {};
672 uint32_t m_target_audio_channel {};
673 uint32_t m_target_layer {};
674 std::vector<std::shared_ptr<Core::VKImage>> m_source_images;
675
676 std::shared_ptr<Buffers::BufferProcessor> m_attached_processor;
677
678 std::shared_ptr<Kakshya::DynamicSoundStream> m_source_audio_stream;
679 std::shared_ptr<Kakshya::VideoStreamContainer> m_source_graphics_stream;
680 uint64_t m_start_frame {};
681 uint32_t m_load_length {};
682
683 std::function<bool(uint32_t)> m_condition;
685
686 std::vector<std::shared_ptr<Buffers::AudioBuffer>> m_source_audio_buffers;
687 std::vector<std::shared_ptr<Buffers::VKBuffer>> m_source_graphics_buffers;
688 std::vector<std::shared_ptr<Kakshya::DynamicSoundStream>> m_source_audio_streams;
689 std::vector<std::shared_ptr<Kakshya::DynamicVideoStream>> m_source_graphics_streams;
691
692 uint8_t m_priority = 128;
693 Buffers::ProcessingToken m_token { Buffers::ProcessingToken::AUDIO_BACKEND };
694 uint32_t m_cycle_interval = 1;
695 std::string m_tag;
696
697 friend class BufferPipeline;
698 };
699
700} // namespace Kriya
701
702} // namespace MayaFlux
std::shared_ptr< NetworkGeometryBuffer > buffer
uint32_t mode
vk::PhysicalDeviceType type
Definition VKDevice.cpp:126
size_t count
CaptureMode
Defines the data capture and retention strategy.
Definition Capture.hpp:61
Flexible data capture interface for buffer-based processing pipelines.
Definition Capture.hpp:55
std::function< bool(uint32_t)> m_condition
Buffers::GraphicsProcessingFunction m_graphics_buffer_modifier
uint8_t get_priority() const
Getters for internal state (read-only)
std::vector< std::shared_ptr< Buffers::AudioBuffer > > m_source_audio_buffers
std::vector< std::shared_ptr< Buffers::VKBuffer > > m_source_graphics_buffers
std::shared_ptr< Kakshya::DynamicVideoStream > m_target_graphics_stream
Buffers::AudioProcessingFunction m_audio_buffer_modifier
Buffers::ProcessingToken get_token() const
Return the operation's processing token.
std::shared_ptr< Buffers::VKBuffer > m_source_graphics_buffer
std::shared_ptr< Kakshya::DynamicVideoStream > get_graphics_stream() const
The dynamic video stream this operation writes to.
static BufferOperation capture(BufferCapture capture)
Create a capture operation using BufferCapture configuration.
std::shared_ptr< Buffers::AudioBuffer > m_target_audio_buffer
std::shared_ptr< Kakshya::VideoStreamContainer > m_source_graphics_stream
bool is_streaming() const
Check if this operation is a streaming operation.
TransformVectorFunction m_fusion_function
std::vector< std::shared_ptr< Core::VKImage > > m_source_images
std::shared_ptr< Buffers::BufferProcessor > m_attached_processor
OpType get_type() const
Getters for internal state (read-only)
std::vector< std::shared_ptr< Kakshya::DynamicVideoStream > > m_source_graphics_streams
std::shared_ptr< Kakshya::DynamicSoundStream > m_source_audio_stream
const std::string & get_tag() const
Getters for user defined tag.
std::vector< std::shared_ptr< Kakshya::DynamicSoundStream > > m_source_audio_streams
TransformationFunction m_transformer
std::shared_ptr< Kakshya::DynamicSoundStream > m_target_audio_stream
OpType
Defines the fundamental operation types in the processing pipeline.
std::shared_ptr< Buffers::VKBuffer > m_target_graphics_buffer
std::optional< Portal::Graphics::RenderConfig > m_render
BufferOperation & as_capture_phase()
Hint that this operation should execute in capture phase.
ExecutionPhase get_execution_phase() const
Get the execution phase hint for this operation.
Fundamental unit of operation in buffer processing pipelines.
Coroutine-based execution engine for composable, multi-strategy buffer processing.
Fluent builder interface for constructing BufferCapture configurations.
Definition Capture.hpp:249
std::function< void(const std::shared_ptr< AudioBuffer > &)> AudioProcessingFunction
Audio processing function - receives correctly-typed AudioBuffer.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
std::function< void(const std::shared_ptr< VKBuffer > &)> GraphicsProcessingFunction
Graphics processing function - receives correctly-typed VKBuffer.
@ Buffers
Buffers, Managers, processors and processing chains.
@ Core
Core engine, backend, subsystems.
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
@ IO
Networking, file handling, streaming.
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:70
std::function< Kakshya::DataVariant(std::vector< Kakshya::DataVariant > &, uint32_t)> TransformVectorFunction
ExecutionStrategy
Defines how operations in a pipeline are coordinated and executed.
@ PHASED
PHASED: Traditional phased execution (default)
@ STREAMING
STREAMING: Immediate flow-through execution.
@ PARALLEL
PARALLEL: Concurrent capture with synchronization.
@ REACTIVE
REACTIVE: Data-driven reactive execution.
std::function< Kakshya::DataVariant(Kakshya::DataVariant &, uint32_t)> TransformationFunction
Definition Capture.hpp:18
std::function< void(Kakshya::DataVariant &, uint32_t)> OperationFunction
Definition Capture.hpp:17
Main namespace for the Maya Flux audio engine.
Definition Runtime.cpp:12
Configuration for opening a camera device via FFmpeg.