MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferTokenDistributor.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7
8class AudioBuffer;
9class VKBuffer;
10class TransferProcessor;
11
12/**
13 * @enum DistributionResult
14 * @brief Outcome of token distribution decision
15 */
16enum class DistributionResult : uint8_t {
17 DIRECT_ROOT, // Buffer goes directly to root (normal audio)
18 TRANSFER_TO_ROOT, // Buffer transfers to root (GPU→Audio)
19 TRANSFER_ONLY, // Buffer transfers to another domain (Audio→GPU, no root)
20 INTERNAL_ONLY, // Buffer marked internal, no root aggregation (AUDIO_PARALLEL)
21 REJECTED // Invalid combination, error
22};
23
24/**
25 * @struct DistributionDecision
26 * @brief Routing decision for a buffer with a given token
27 */
30
31 // If TRANSFER_ONLY or TRANSFER_TO_ROOT:
32 std::shared_ptr<TransferProcessor> transfer_processor;
33 ProcessingToken transfer_direction; // Which buffer gets the processor
34
35 // Diagnostic
36 std::string reason; // Error message if REJECTED
37};
38
39/**
40 * @class BufferTokenDistributor
41 * @brief Determines routing for buffers based on type + token combination
42 *
43 * Decision tree:
44 * 1) DIRECT_ROOT - Buffer goes to normal root aggregation
45 * 2) TRANSFER_ONLY - Create transfer processor, attach to target, no root
46 * 3) INTERNAL_ONLY - Mark internal, no root aggregation
47 * 4) REJECTED - Invalid combination
48 */
50public:
51 /**
52 * @brief Distribute a buffer based on its type and requested token
53 * @param buffer The buffer to distribute
54 * @param requested_token The token being requested
55 * @return Distribution decision with routing instructions
56 */
58 const std::shared_ptr<Buffer>& buffer,
59 ProcessingToken requested_token);
60
61 /**
62 * @brief Distribute with optional transfer target (for cross-domain routing)
63 * @param buffer Source buffer
64 * @param requested_token Token for the source buffer
65 * @param transfer_target Optional target for cross-domain transfer
66 * @param transfer_target_token Token for the target (if transferring)
67 * @return Distribution decision with transfer processor if applicable
68 */
70 const std::shared_ptr<Buffer>& buffer,
71 ProcessingToken requested_token,
72 const std::shared_ptr<Buffer>& transfer_target,
73 ProcessingToken transfer_target_token);
74
75private:
76 // Helper: Validate buffer type matches token
79
80 // Helper: Extract token components
83 static bool has_cpu(ProcessingToken token);
84 static bool has_gpu(ProcessingToken token);
85
86 // Decision tree functions
88 const std::shared_ptr<AudioBuffer>& audio,
90
92 const std::shared_ptr<VKBuffer>& vk,
94
96 const std::shared_ptr<Buffer>& source,
97 ProcessingToken src_token,
98 const std::shared_ptr<Buffer>& target,
99 ProcessingToken tgt_token);
100
101 static bool can_transfer(
102 const std::shared_ptr<Buffer>& source,
103 ProcessingToken src_token,
104 const std::shared_ptr<Buffer>& target,
105 ProcessingToken tgt_token);
106};
107
108} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
static bool has_frame_rate(ProcessingToken token)
static bool can_transfer(const std::shared_ptr< Buffer > &source, ProcessingToken src_token, const std::shared_ptr< Buffer > &target, ProcessingToken tgt_token)
static bool is_valid_vk_token(ProcessingToken token)
static bool is_valid_audio_token(ProcessingToken token)
static DistributionDecision decide_transfer(const std::shared_ptr< Buffer > &source, ProcessingToken src_token, const std::shared_ptr< Buffer > &target, ProcessingToken tgt_token)
static DistributionDecision distribute(const std::shared_ptr< Buffer > &buffer, ProcessingToken requested_token)
Distribute a buffer based on its type and requested token.
static bool has_gpu(ProcessingToken token)
static DistributionDecision decide_vk_buffer(const std::shared_ptr< VKBuffer > &vk, ProcessingToken token)
static DistributionDecision distribute_with_transfer(const std::shared_ptr< Buffer > &buffer, ProcessingToken requested_token, const std::shared_ptr< Buffer > &transfer_target, ProcessingToken transfer_target_token)
Distribute with optional transfer target (for cross-domain routing)
static DistributionDecision decide_audio_buffer(const std::shared_ptr< AudioBuffer > &audio, ProcessingToken token)
static bool has_cpu(ProcessingToken token)
static bool has_sample_rate(ProcessingToken token)
Determines routing for buffers based on type + token combination.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.
DistributionResult
Outcome of token distribution decision.
std::shared_ptr< TransferProcessor > transfer_processor
Routing decision for a buffer with a given token.