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

◆ choose_camera()

MAYAFLUX_API std::shared_ptr< Kakshya::CameraContainer > MayaFlux::choose_camera ( bool  choose_mode = true)

Let the user pick a camera, and optionally a capture mode, then open it via IOManager::open_camera().

The pickers are Portal::Forma windows driven by the engine. Blocks until the user chooses or closes a window. Returns the opened container, ready for IOManager::hook_camera_to_buffer(), or nullptr on cancellation, when no camera is found, or if the camera fails to open. Portal::Forma must be initialized and the engine running.

Modes come from the camera source's presets. A mode is a request: the source falls back to the nearest mode the device accepts.

Parameters
choose_modeIf false, skip the mode picker and open with the default CameraConfig size and frame rate.

Definition at line 302 of file Depot.cpp.

303{
304 auto promise = std::make_shared<std::promise<std::shared_ptr<Kakshya::CameraContainer>>>();
305 auto future = promise->get_future();
306
307 const IO::FFmpegCameraReader reader;
308 auto configs = reader.enumerate_configs();
309 if (configs.empty()) {
310 MF_ERROR(Journal::Component::API, Journal::Context::Runtime,
311 "choose_camera: no cameras found");
312 return nullptr;
313 }
314
315 Portal::Forma::pick("Choose a camera", std::move(configs),
316 [](const IO::CameraConfig& config) {
317 return config.display_name.empty() ? config.device_name : config.display_name;
318 },
319 [promise, choose_mode, modes = reader.preset_modes()](std::optional<IO::CameraConfig> camera) {
320 if (!camera) {
321 promise->set_value(nullptr);
322 return;
323 }
324 if (!choose_mode) {
325 promise->set_value(get_io_manager()->open_camera(*camera));
326 return;
327 }
328 Portal::Forma::pick("Choose a mode", modes,
329 [](const IO::CameraMode& mode) { return mode.label; },
330 [promise, config = *camera](std::optional<IO::CameraMode> mode) mutable {
331 if (!mode) {
332 promise->set_value(nullptr);
333 return;
334 }
335 mode->apply(config);
336 promise->set_value(get_io_manager()->open_camera(config));
337 });
338 });
339
340 return Parallel::await_future(std::move(future));
341}
#define MF_ERROR(comp, ctx,...)
uint32_t mode
std::vector< CameraMode > preset_modes() const override
Capture modes this source offers as defaults, ordered from safest to most demanding.
std::vector< CameraConfig > enumerate_configs() const override
Discover ready-to-open camera configurations without starting capture.
Platform-specific FFmpeg input format string for camera devices.
std::shared_ptr< IO::IOManager > get_io_manager()
Retrieves the global IOManager instance for file loading and buffer management.
Definition Depot.cpp:575

References MayaFlux::Journal::API, MayaFlux::Parallel::await_future(), MayaFlux::IO::CameraConfig::device_name, MayaFlux::IO::CameraConfig::display_name, MayaFlux::IO::FFmpegCameraReader::enumerate_configs(), get_io_manager(), MF_ERROR, mode, MayaFlux::Portal::Forma::pick(), MayaFlux::IO::FFmpegCameraReader::preset_modes(), and MayaFlux::Journal::Runtime.

Referenced by MayaFlux::Creator::read_camera().

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