spa: libcamera: source: generate camera config right away

Currently the plugin uses a single configuration during its entire lifetime.
So generate that configuration during initialization and hold on to it.

This makes the code a bit simpler, and also fixes issues stemming from missed
calls to `spa_libcamera_get_config()` as well as no error checking of
`libcamera::Camera::generateConfiguration()`.

(cherry picked from commit 49be2a1c52)
This commit is contained in:
Barnabás Pőcze 2025-07-25 15:52:59 +02:00 committed by Robert Mader
parent 1774249bdb
commit 21a61b2194

View file

@ -148,6 +148,7 @@ struct impl {
std::shared_ptr<CameraManager> manager;
std::shared_ptr<Camera> camera;
const std::unique_ptr<CameraConfiguration> config;
FrameBufferAllocator *allocator = nullptr;
std::vector<std::unique_ptr<libcamera::Request>> requestPool;
@ -155,8 +156,6 @@ struct impl {
void requestComplete(libcamera::Request *request);
std::unique_ptr<CameraConfiguration> config;
struct spa_source source = {};
ControlList ctrls;
@ -165,7 +164,8 @@ struct impl {
bool acquired = false;
impl(spa_log *log, spa_loop *data_loop, spa_system *system,
std::shared_ptr<CameraManager> manager, std::shared_ptr<Camera> camera);
std::shared_ptr<CameraManager> manager, std::shared_ptr<Camera> camera,
std::unique_ptr<CameraConfiguration> config);
struct spa_dll dll;
};
@ -236,14 +236,6 @@ int spa_libcamera_close(struct impl *impl)
return 0;
}
void spa_libcamera_get_config(struct impl *impl)
{
if (impl->config)
return;
impl->config = impl->camera->generateConfiguration({ StreamRole::VideoRecording });
}
int spa_libcamera_buffer_recycle(struct impl *impl, struct port *port, uint32_t buffer_id)
{
struct buffer *b = &port->buffers[buffer_id];
@ -506,8 +498,6 @@ spa_libcamera_enum_format(struct impl *impl, struct port *port, int seq,
struct spa_result_node_params result;
uint32_t count = 0;
spa_libcamera_get_config(impl);
const StreamConfiguration& streamConfig = impl->config->at(0);
const StreamFormats &formats = streamConfig.formats();
const auto &pixel_formats = formats.pixelformats();
@ -2050,14 +2040,16 @@ int impl_clear(struct spa_handle *handle)
}
impl::impl(spa_log *log, spa_loop *data_loop, spa_system *system,
std::shared_ptr<CameraManager> manager, std::shared_ptr<Camera> camera)
std::shared_ptr<CameraManager> manager, std::shared_ptr<Camera> camera,
std::unique_ptr<CameraConfiguration> config)
: handle({ SPA_VERSION_HANDLE, impl_get_interface, impl_clear }),
log(log),
data_loop(data_loop),
system(system),
out_ports{{this}},
manager(std::move(manager)),
camera(std::move(camera))
camera(std::move(camera)),
config(std::move(config))
{
libcamera_log_topic_init(log);
@ -2131,8 +2123,15 @@ impl_init(const struct spa_handle_factory *factory,
return -ENOENT;
}
auto config = camera->generateConfiguration({ libcamera::StreamRole::VideoRecording });
if (!config) {
spa_log_error(log, "cannot generate configuration for camera");
return -EINVAL;
}
new (handle) impl(log, data_loop, system,
std::move(manager), std::move(camera));
std::move(manager), std::move(camera),
std::move(config));
return 0;
}