MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
IOTransitions.cpp
Go to the documentation of this file.
1#include "IOTransitions.hpp"
2
5
14
19
22
24
27
29
31
33
35 const std::shared_ptr<Kakshya::VideoFileContainer>& container, uint32_t m_frame_rate)
36{
37 auto existing = std::dynamic_pointer_cast<Kakshya::FrameAccessProcessor>(
38 container->get_default_processor());
39
40 if (existing) {
41 existing->set_global_fps(m_frame_rate);
42 existing->set_auto_advance(true);
44 "Configured existing FrameAccessProcessor");
45 } else {
46 auto processor = std::make_shared<Kakshya::FrameAccessProcessor>();
47 processor->set_global_fps(m_frame_rate);
48 processor->set_auto_advance(true);
49 container->set_default_processor(processor);
51 "Created and set FrameAccessProcessor");
52 }
53}
54
56 const std::shared_ptr<Kakshya::SoundFileContainer>& container, uint32_t buffer_size)
57{
58 container->set_memory_layout(Kakshya::MemoryLayout::ROW_MAJOR);
59
60 const std::vector<uint64_t> output_shape = {
61 buffer_size,
62 container->get_num_channels()
63 };
64
65 auto existing = std::dynamic_pointer_cast<Kakshya::ContiguousAccessProcessor>(
66 container->get_default_processor());
67
68 if (existing) {
69 existing->set_output_size(output_shape);
70 existing->set_auto_advance(true);
72 "Configured existing ContiguousAccessProcessor");
73 } else {
74 auto processor = std::make_shared<Kakshya::ContiguousAccessProcessor>();
75 processor->set_output_size(output_shape);
76 processor->set_auto_advance(true);
77 container->set_default_processor(processor);
79 "Created and set ContiguousAccessProcessor");
80 }
81}
82
84 const std::shared_ptr<Kakshya::CameraContainer>& container, uint64_t reader_id)
85{
86 container->setup_io(reader_id);
87 container->mark_ready_for_processing(true);
88}
89
90TextureResolver make_default_resolver(const std::string& filepath)
91{
92 const auto base_dir = std::filesystem::path(filepath).parent_path();
93 return [base_dir](const std::string& raw) -> std::shared_ptr<Core::VKImage> {
94 auto tex_path = FileReader::resolve_path((base_dir / raw).generic_string());
95 return IO::ImageReader::load_texture(tex_path);
96 };
97}
98
99std::shared_ptr<Buffers::VideoContainerBuffer> create_video_container_buffer(
100 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
101 const std::shared_ptr<Kakshya::StreamContainer>& container)
102{
103 return buffer_manager->create_graphics_buffer<Buffers::VideoContainerBuffer>(
105 container);
106}
107
108std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> create_audio_container_buffers(
109 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
110 const std::shared_ptr<Kakshya::SoundFileContainer>& container)
111{
112 std::vector<std::shared_ptr<Buffers::SoundContainerBuffer>> created_buffers;
113
114 const uint32_t num_channels = container->get_num_channels();
115 created_buffers.reserve(num_channels);
116
117 for (uint32_t channel = 0; channel < num_channels; ++channel) {
118 auto container_buffer = buffer_manager->create_audio_buffer<Buffers::SoundContainerBuffer>(
120 channel,
121 container,
122 channel);
123
124 container_buffer->initialize();
125 created_buffers.push_back(std::move(container_buffer));
126 }
127
128 return created_buffers;
129}
130
131std::shared_ptr<Buffers::VolumeGridBuffer> create_volume_grid_buffer(
132 const std::shared_ptr<Buffers::BufferManager>& buffer_manager,
133 const Kakshya::VolumeData& volume_data)
134{
135 std::vector<Buffers::VolumeGridBuffer::FieldDecl> decls;
136 decls.reserve(volume_data.fields.size());
137 for (const auto& field : volume_data.fields) {
138 decls.push_back({
139 .name = field.name,
140 .stride_bytes = field.is_vector() ? sizeof(glm::vec4) : sizeof(float),
141 .double_buffered = true,
142 .semantics = field.semantics,
143 });
144 }
145
146 auto buffer = buffer_manager->create_graphics_buffer<Buffers::VolumeGridBuffer>(
148 volume_data.lattice, decls);
149
150 if (!buffer)
151 return nullptr;
152
153 if (!IO::upload_volume(volume_data, buffer))
154 return nullptr;
155
156 return buffer;
157}
158
160 const std::string& filepath,
161 const std::vector<Kakshya::MeshData>& meshes,
162 const ModelWriteOptions& options)
163{
164 auto writer = ModelWriterRegistry::instance().create_writer(filepath);
165 if (!writer) {
167 "save_mesh: no writer registered for '{}'", filepath);
168 return false;
169 }
170
171 const bool ok = writer->write(filepath, meshes, options);
172 if (!ok) {
174 "save_mesh: writer failed for '{}': {}", filepath, writer->get_last_error());
175 } else {
177 "save_mesh: wrote '{}'", filepath);
178 }
179 return ok;
180}
181
183 const std::string& filepath,
184 const ImageData& data,
185 const ImageWriteOptions& options)
186{
187 auto writer = ImageWriterRegistry::instance().create_writer(filepath);
188 if (!writer) {
190 "save_image task: no writer registered for '{}'", filepath);
191 return false;
192 }
193 const bool ok = writer->write(filepath, data, options);
194 if (!ok) {
196 "save_image task: writer failed for '{}': {}",
197 filepath, writer->get_last_error());
198 } else {
200 "save_image task: wrote '{}'", filepath);
201 }
202 return ok;
203}
204
206 const std::string& filepath,
207 const Kakshya::VolumeData& data,
208 const VolumeWriteOptions& options)
209{
210 auto writer = VolumeWriterRegistry::instance().create_writer(filepath);
211 if (!writer) {
213 "save_volume task: no writer registered for '{}'", filepath);
214 return false;
215 }
216 const bool ok = writer->write(filepath, data, options);
217 if (!ok) {
219 "save_volume task: writer failed for '{}': {}",
220 filepath, writer->get_last_error());
221 } else {
223 "save_volume task: wrote '{}'", filepath);
224 }
225 return ok;
226}
227
229 const std::shared_ptr<Buffers::ComputeMeshBuffer>& buffer,
230 const std::string& path_pattern,
231 const ModelWriteOptions& options)
232{
233 return IO::save_mesh_snapshot(buffer, path_pattern, options);
234}
235
237 const std::string& path_pattern,
238 const std::vector<SpatialCaptureSource>& sources)
239{
240 return IO::save_spatial_snapshot(path_pattern, sources);
241}
242
243std::unique_ptr<VolumeCapture> create_volume_capture(
244 Vruta::TaskScheduler& scheduler,
245 const std::shared_ptr<Buffers::VolumeGridBuffer>& volume,
246 const std::string& path_pattern,
247 const std::vector<std::string>& field_names,
248 const VolumeWriteOptions& options,
249 std::function<bool(Kakshya::VolumeData&&, const std::string&, const VolumeWriteOptions&)> save_fn,
250 uint32_t max_frames,
251 uint64_t frame_interval)
252{
253 auto capture = std::make_unique<VolumeCapture>(
254 scheduler, volume, path_pattern, field_names, options, std::move(save_fn));
255
256 capture->start(max_frames, frame_interval);
257 return capture;
258}
259
260std::unique_ptr<SpatialCapture> create_spatial_capture(
261 Vruta::TaskScheduler& scheduler,
262 const std::shared_ptr<SpatialCache>& cache,
263 std::vector<SpatialCaptureSource> sources,
264 uint32_t max_frames,
265 uint64_t frame_interval)
266{
267 auto capture = std::make_unique<SpatialCapture>(scheduler, cache, std::move(sources));
268 capture->start(max_frames, frame_interval);
269 return capture;
270}
271
272} // namespace MayaFlux::IO::Detail
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::shared_ptr< NetworkGeometryBuffer > buffer
Cycle Behavior: The for_cycles(N) configuration controls how many times the capture operation execute...
void initialize()
Initialize the buffer after construction.
AudioBuffer implementation backed by a StreamContainer.
TextureBuffer implementation backed by a VideoStreamContainer.
GPU-resident state for multi-field simulations evaluated over a fixed 3D topology: incompressible flu...
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
static std::shared_ptr< Core::VKImage > load_texture(const std::string &path, int desired_channels=4, std::optional< Kakshya::Region > region=std::nullopt)
Load image directly into GPU texture (static utility)
static WriterRegistry & instance()
std::unique_ptr< Writer > create_writer(const std::string &filepath) const
Token-based multimodal task scheduling system for unified coroutine processing.
Definition Scheduler.hpp:51
@ AUDIO_BACKEND
Standard audio processing backend configuration.
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
void configure_audio_container(const std::shared_ptr< Kakshya::SoundFileContainer > &container, uint32_t buffer_size)
bool execute_volume_write(const std::string &filepath, const Kakshya::VolumeData &data, const VolumeWriteOptions &options)
bool execute_mesh_snapshot(const std::shared_ptr< Buffers::ComputeMeshBuffer > &buffer, const std::string &path_pattern, const ModelWriteOptions &options)
std::vector< std::shared_ptr< Buffers::SoundContainerBuffer > > create_audio_container_buffers(const std::shared_ptr< Buffers::BufferManager > &buffer_manager, const std::shared_ptr< Kakshya::SoundFileContainer > &container)
void configure_video_container(const std::shared_ptr< Kakshya::VideoFileContainer > &container, uint32_t m_frame_rate)
bool execute_image_write(const std::string &filepath, const ImageData &data, const ImageWriteOptions &options)
bool execute_spatial_snapshot(const std::string &path_pattern, const std::vector< SpatialCaptureSource > &sources)
std::shared_ptr< Buffers::VolumeGridBuffer > create_volume_grid_buffer(const std::shared_ptr< Buffers::BufferManager > &buffer_manager, const Kakshya::VolumeData &volume_data)
std::unique_ptr< SpatialCapture > create_spatial_capture(Vruta::TaskScheduler &scheduler, const std::shared_ptr< SpatialCache > &cache, std::vector< SpatialCaptureSource > sources, uint32_t max_frames, uint64_t frame_interval)
std::unique_ptr< VolumeCapture > create_volume_capture(Vruta::TaskScheduler &scheduler, const std::shared_ptr< Buffers::VolumeGridBuffer > &volume, const std::string &path_pattern, const std::vector< std::string > &field_names, const VolumeWriteOptions &options, std::function< bool(Kakshya::VolumeData &&, const std::string &, const VolumeWriteOptions &)> save_fn, uint32_t max_frames, uint64_t frame_interval)
void configure_camera_container(const std::shared_ptr< Kakshya::CameraContainer > &container, uint64_t reader_id)
TextureResolver make_default_resolver(const std::string &filepath)
bool execute_mesh_write(const std::string &filepath, const std::vector< Kakshya::MeshData > &meshes, const ModelWriteOptions &options)
std::function< std::shared_ptr< Core::VKImage >(const std::string &path)> TextureResolver
std::shared_ptr< Buffers::VideoContainerBuffer > create_video_container_buffer(const std::shared_ptr< Buffers::BufferManager > &buffer_manager, const std::shared_ptr< Kakshya::StreamContainer > &container)
bool upload_volume(const Kakshya::VolumeData &data, const std::shared_ptr< Buffers::VolumeGridBuffer > &volume)
Upload every field of a host VolumeData into a GPU-resident volume.
bool save_spatial_snapshot(const std::string &path_pattern, const std::vector< SpatialCaptureSource > &sources)
Open a fresh SpatialCache, write every source once, then close it.
bool save_mesh_snapshot(const std::shared_ptr< Buffers::ComputeMeshBuffer > &buffer, const std::string &path_pattern, const ModelWriteOptions &options)
Save a ComputeMeshBuffer with a millisecond epoch timestamp spliced into the path.
@ ContainerProcessing
Container operations (Kakshya - file/stream/region processing)
@ FileIO
Filesystem I/O operations.
@ IO
Networking, file handling, streaming.
@ API
MayaFlux/API Wrapper and convenience functions.
@ ROW_MAJOR
C/C++ style (last dimension varies fastest)
Configuration for image writing.
Configuration for model writing.
Configuration for volume writing.
Raw image data loaded from file or read back from a GPU image.
Definition ImageData.hpp:55
std::vector< VolumeField > fields
A lattice and every field sampled over it, held in host memory.