2023-02-08 18:12:00 +01:00
|
|
|
/* Spa libcamera support */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2020 collabora */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2020-04-20 12:26:50 +05:30
|
|
|
|
2026-06-19 11:14:51 +02:00
|
|
|
#include <memory>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
|
|
#include <libcamera/camera_manager.h>
|
|
|
|
|
|
2020-04-20 12:26:50 +05:30
|
|
|
#include <spa/support/plugin.h>
|
2021-10-03 12:26:00 +02:00
|
|
|
#include <spa/support/log.h>
|
2020-04-20 12:26:50 +05:30
|
|
|
|
2026-06-19 11:00:26 +02:00
|
|
|
#include "libcamera.hpp"
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
2020-04-20 12:26:50 +05:30
|
|
|
|
2023-12-23 21:07:45 +02:00
|
|
|
SPA_LOG_TOPIC_DEFINE(libcamera_log_topic, "spa.libcamera");
|
|
|
|
|
|
|
|
|
|
SPA_LOG_TOPIC_ENUM_DEFINE_REGISTERED;
|
2021-10-03 12:26:00 +02:00
|
|
|
|
2020-04-20 12:26:50 +05:30
|
|
|
SPA_EXPORT
|
|
|
|
|
int spa_handle_factory_enum(const struct spa_handle_factory **factory,
|
|
|
|
|
uint32_t *index)
|
|
|
|
|
{
|
|
|
|
|
spa_return_val_if_fail(factory != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
switch (*index) {
|
|
|
|
|
case 0:
|
2021-11-02 17:24:19 +01:00
|
|
|
*factory = &spa_libcamera_manager_factory;
|
2020-04-20 12:26:50 +05:30
|
|
|
break;
|
|
|
|
|
case 1:
|
2021-11-02 17:24:19 +01:00
|
|
|
*factory = &spa_libcamera_device_factory;
|
2020-04-20 12:26:50 +05:30
|
|
|
break;
|
|
|
|
|
case 2:
|
2021-11-02 17:24:19 +01:00
|
|
|
*factory = &spa_libcamera_source_factory;
|
2020-04-20 12:26:50 +05:30
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
(*index)++;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2026-06-19 11:00:26 +02:00
|
|
|
|
|
|
|
|
}
|
2026-06-19 11:14:51 +02:00
|
|
|
|
|
|
|
|
std::shared_ptr<libcamera::CameraManager> libcamera_manager_acquire(int& res)
|
|
|
|
|
{
|
|
|
|
|
static std::weak_ptr<libcamera::CameraManager> global_manager;
|
|
|
|
|
static std::mutex lock;
|
|
|
|
|
|
|
|
|
|
std::lock_guard guard(lock);
|
|
|
|
|
|
|
|
|
|
if (auto manager = global_manager.lock())
|
|
|
|
|
return manager;
|
|
|
|
|
|
|
|
|
|
auto manager = std::make_shared<libcamera::CameraManager>();
|
|
|
|
|
if ((res = manager->start()) < 0)
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
global_manager = manager;
|
|
|
|
|
|
|
|
|
|
return manager;
|
|
|
|
|
}
|