spa: libcamera: move CameraManager acquisition

Now that there is a "libcamera.cpp", move `libcamera_manager_acquire()` into
that file since it is a common function used by all three factories.
This commit is contained in:
Barnabás Pőcze 2026-06-19 11:14:51 +02:00 committed by Wim Taymans
parent 390a4ce432
commit 6dc55d2cb4
6 changed files with 30 additions and 31 deletions

View file

@ -22,7 +22,6 @@
#include <spa/param/param.h> #include <spa/param/param.h>
#include "libcamera.hpp" #include "libcamera.hpp"
#include "libcamera-manager.hpp"
#include <libcamera/camera.h> #include <libcamera/camera.h>
#include <libcamera/property_ids.h> #include <libcamera/property_ids.h>

View file

@ -26,7 +26,6 @@ using namespace libcamera;
#include <spa/monitor/utils.h> #include <spa/monitor/utils.h>
#include "libcamera.hpp" #include "libcamera.hpp"
#include "libcamera-manager.hpp"
namespace { namespace {
@ -388,22 +387,3 @@ const struct spa_handle_factory spa_libcamera_manager_factory = {
impl_enum_interface_info, impl_enum_interface_info,
}; };
} }
std::shared_ptr<CameraManager> libcamera_manager_acquire(int& res)
{
static std::weak_ptr<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<CameraManager>();
if ((res = manager->start()) < 0)
return {};
global_manager = manager;
return manager;
}

View file

@ -1,9 +0,0 @@
/* Spa libcamera support */
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <memory>
#include <libcamera/camera_manager.h>
std::shared_ptr<libcamera::CameraManager> libcamera_manager_acquire(int& res);

View file

@ -43,7 +43,6 @@
#include <libcamera/framebuffer_allocator.h> #include <libcamera/framebuffer_allocator.h>
#include "libcamera.hpp" #include "libcamera.hpp"
#include "libcamera-manager.hpp"
using namespace libcamera; using namespace libcamera;

View file

@ -2,6 +2,11 @@
/* SPDX-FileCopyrightText: Copyright © 2020 collabora */ /* SPDX-FileCopyrightText: Copyright © 2020 collabora */
/* SPDX-License-Identifier: MIT */ /* SPDX-License-Identifier: MIT */
#include <memory>
#include <mutex>
#include <libcamera/camera_manager.h>
#include <spa/support/plugin.h> #include <spa/support/plugin.h>
#include <spa/support/log.h> #include <spa/support/log.h>
@ -38,3 +43,22 @@ int spa_handle_factory_enum(const struct spa_handle_factory **factory,
} }
} }
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;
}

View file

@ -4,6 +4,10 @@
#pragma once #pragma once
#include <memory>
#include <libcamera/camera_manager.h>
#include <spa/support/log.h> #include <spa/support/log.h>
extern "C" { extern "C" {
@ -22,3 +26,5 @@ static inline void libcamera_log_topic_init(struct spa_log *log)
{ {
spa_log_topic_init(log, &libcamera_log_topic); spa_log_topic_init(log, &libcamera_log_topic);
} }
std::shared_ptr<libcamera::CameraManager> libcamera_manager_acquire(int& res);