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

◆ decide_transfer()

DistributionDecision MayaFlux::Buffers::BufferTokenDistributor::decide_transfer ( const std::shared_ptr< Buffer > &  source,
ProcessingToken  src_token,
const std::shared_ptr< Buffer > &  target,
ProcessingToken  tgt_token 
)
staticprivate

Definition at line 244 of file BufferTokenDistributor.cpp.

249{
250 auto audio_src = std::dynamic_pointer_cast<AudioBuffer>(source);
251 auto audio_tgt = std::dynamic_pointer_cast<AudioBuffer>(target);
252 auto vk_src = std::dynamic_pointer_cast<VKBuffer>(source);
253 auto vk_tgt = std::dynamic_pointer_cast<VKBuffer>(target);
254
255 // Pattern: Audio(SAMPLE_RATE|CPU) → VK(GPU) → Audio(SAMPLE_RATE|CPU)
256 if (audio_src && audio_tgt && has_sample_rate(src_token) && has_gpu(src_token) && has_sample_rate(tgt_token) && has_cpu(tgt_token)) {
257 // This would be Audio→GPU→Audio, which is forbidden
258 // But the distribute() call on each would catch this
259 // Just prevent if someone tries to route them together
260 }
261
262 if (!can_transfer(source, src_token, target, tgt_token)) {
263 return DistributionDecision {
265 .transfer_processor = nullptr,
266 .transfer_direction = ProcessingToken::AUDIO_BACKEND,
267 .reason = "Transfer not supported between these buffer types and tokens"
268 };
269 }
270
271 std::shared_ptr<TransferProcessor> processor;
273
274 if (audio_src && vk_tgt) {
276 processor = std::make_shared<TransferProcessor>(audio_src, vk_tgt, direction);
277 } else if (vk_src && audio_tgt) {
279 processor = std::make_shared<TransferProcessor>(audio_tgt, vk_src, direction);
280 } else if (audio_src && audio_tgt) {
281 direction = TransferDirection::AUDIO_TO_GPU; // Reuse as "copy" semantics
282 processor = std::make_shared<TransferProcessor>();
283 processor->connect_audio_to_gpu(audio_src, nullptr); // Placeholder, will be copy
284 } else if (vk_src && vk_tgt) {
285 direction = TransferDirection::AUDIO_TO_GPU; // Reuse enum, semantically "copy"
286 processor = std::make_shared<TransferProcessor>();
287 }
288
289 if (!processor) {
290 return DistributionDecision {
292 .transfer_processor = nullptr,
293 .transfer_direction = ProcessingToken::AUDIO_BACKEND,
294 .reason = "Failed to create transfer processor"
295 };
296 }
297
298 if (audio_tgt) {
299 audio_tgt->force_internal_usage(false);
300 }
301
302 return DistributionDecision {
304 .transfer_processor = processor,
305 .transfer_direction = tgt_token,
306 .reason = "Transfer processor created"
307 };
308}
static bool can_transfer(const std::shared_ptr< Buffer > &source, ProcessingToken src_token, const std::shared_ptr< Buffer > &target, ProcessingToken tgt_token)
static bool has_gpu(ProcessingToken token)
static bool has_cpu(ProcessingToken token)
static bool has_sample_rate(ProcessingToken token)
@ AUDIO_BACKEND
Standard audio processing backend configuration.
TransferDirection
Specifies the direction of data transfer.

References MayaFlux::Buffers::AUDIO_BACKEND, MayaFlux::Buffers::AUDIO_TO_GPU, can_transfer(), MayaFlux::Buffers::GPU_TO_AUDIO, has_cpu(), has_gpu(), has_sample_rate(), MayaFlux::Buffers::REJECTED, MayaFlux::Buffers::DistributionDecision::result, and MayaFlux::Buffers::TRANSFER_ONLY.

Referenced by distribute_with_transfer().

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