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

◆ process_to_stream()

Kriya::ChimeraBuilder MayaFlux::Yantra::Vision::VisionWorkflow::process_to_stream ( const WorkflowStreamConfig &  config)

Run config's matrix on its source live and return a Chimera builder over a new layer array, for any image the run produces.

Paced and sourced as process_to_buffer(). The layers, their sources and the rendering are declared on the returned builder, and the array itself, for a shader's mode, is its get_buffer(). Each analysis is handed to the matrix's extract(), so its analysis(), frame() and extraction() follow the run; the images of every sequence are read from its results() or, by intent, result(). Then each record entry appends its picked image, all together once per analysis, at the run's pace: one per interval, or as often as the work completes, which the matrix reports as analysis_rate(). The run stops as the other live runs do, and also once the Chimera that was started from the builder is stopped or dropped, or the builder is dropped unstarted. The Chimera outlives the run and keeps its last images.

Returns
The builder, or one without an array when the engine's managers are gone, the matrix is null or the stream cannot be hooked.

Definition at line 496 of file VisionWorkflow.cpp.

497{
498 if (!config.matrix) {
500 "VisionWorkflow::process_to_stream: no matrix");
501 return { nullptr, nullptr };
502 }
503
504 const auto frames = source_frames(config.source, "process_to_stream");
505 const auto buffers = m_buffer_manager.lock();
506 if (!frames || !buffers)
507 return { nullptr, nullptr };
508
509 auto array = buffers->create_graphics_buffer<Buffers::TextureArrayBuffer>(
510 Buffers::ProcessingToken::GRAPHICS_BACKEND, config.layers, config.fit);
511 auto pipeline = Kriya::BufferPipeline::create(*m_scheduler.lock(), buffers, m_io_manager.lock());
512
513 const auto name = run_name("stream");
514 start(config.source, frames, config.live.value_or(LiveConfig {}), config.matrix, name,
515 [matrix = config.matrix, record = config.record](const VisionIO& frame) {
516 const auto analysis = Kakshya::get_metadata_value<Kinesis::Vision::VisionAnalysis>(frame.metadata, "vision_analysis");
517 const auto image = Kakshya::get_metadata_value<std::shared_ptr<Core::VKImage>>(frame.metadata, "vision_image");
518 if (!analysis || !image)
519 return;
520
521 matrix->extract(*analysis, *image);
522
523 for (const auto& [collection, pick] : record) {
524 if (!collection || !pick)
525 continue;
526 if (const auto picked = pick(*matrix))
527 collection->append(picked);
528 }
529 },
530 [weak_pipeline = std::weak_ptr(pipeline), seen_running = std::make_shared<bool>(false)]() {
531 const auto chimera_pipeline = weak_pipeline.lock();
532 if (!chimera_pipeline)
533 return true;
534 if (chimera_pipeline->is_running()) {
535 *seen_running = true;
536 return false;
537 }
538 return *seen_running;
539 });
540
541 return { std::move(array), std::move(pipeline) };
542}
#define MF_WARN(comp, ctx,...)
std::string name
Definition VKDevice.cpp:123
static std::shared_ptr< BufferPipeline > create(Vruta::TaskScheduler &scheduler, std::shared_ptr< Buffers::BufferManager > buffer_manager=nullptr, std::shared_ptr< IO::IOManager > io_manager=nullptr)
std::shared_ptr< Buffers::TextureBuffer > source_frames(const std::shared_ptr< Kakshya::VideoStreamContainer > &source, std::string_view caller) const
void start(const std::shared_ptr< Kakshya::VideoStreamContainer > &source, const std::shared_ptr< Buffers::TextureBuffer > &frames, const LiveConfig &live, const std::shared_ptr< VisionMatrix > &matrix, const std::string &name, std::function< void(const VisionIO &)> consumer, std::function< bool()> stop_when={})
Subscribe consumer and start the producer named name, which stops the run at source's end,...
std::weak_ptr< Vruta::TaskScheduler > m_scheduler
std::weak_ptr< Buffers::BufferManager > m_buffer_manager
std::weak_ptr< IO::IOManager > m_io_manager
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.

References MayaFlux::Journal::ComputeMatrix, MayaFlux::Kriya::BufferPipeline::create(), MayaFlux::Yantra::Vision::WorkflowStreamConfig::fit, MayaFlux::Buffers::GRAPHICS_BACKEND, MayaFlux::Yantra::Vision::WorkflowStreamConfig::layers, MayaFlux::Yantra::Vision::WorkflowStreamConfig::live, m_buffer_manager, m_io_manager, m_scheduler, MayaFlux::Yantra::Vision::WorkflowStreamConfig::matrix, MF_WARN, name, MayaFlux::Yantra::Vision::WorkflowStreamConfig::record, MayaFlux::Yantra::Vision::WorkflowStreamConfig::source, source_frames(), start(), and MayaFlux::Journal::Yantra.

+ Here is the call graph for this function: