mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-04-09 08:21:08 -04:00
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:
parent
1774249bdb
commit
21a61b2194
1 changed files with 15 additions and 16 deletions
|
|
@ -148,6 +148,7 @@ struct impl {
|
||||||
|
|
||||||
std::shared_ptr<CameraManager> manager;
|
std::shared_ptr<CameraManager> manager;
|
||||||
std::shared_ptr<Camera> camera;
|
std::shared_ptr<Camera> camera;
|
||||||
|
const std::unique_ptr<CameraConfiguration> config;
|
||||||
|
|
||||||
FrameBufferAllocator *allocator = nullptr;
|
FrameBufferAllocator *allocator = nullptr;
|
||||||
std::vector<std::unique_ptr<libcamera::Request>> requestPool;
|
std::vector<std::unique_ptr<libcamera::Request>> requestPool;
|
||||||
|
|
@ -155,8 +156,6 @@ struct impl {
|
||||||
|
|
||||||
void requestComplete(libcamera::Request *request);
|
void requestComplete(libcamera::Request *request);
|
||||||
|
|
||||||
std::unique_ptr<CameraConfiguration> config;
|
|
||||||
|
|
||||||
struct spa_source source = {};
|
struct spa_source source = {};
|
||||||
|
|
||||||
ControlList ctrls;
|
ControlList ctrls;
|
||||||
|
|
@ -165,7 +164,8 @@ struct impl {
|
||||||
bool acquired = false;
|
bool acquired = false;
|
||||||
|
|
||||||
impl(spa_log *log, spa_loop *data_loop, spa_system *system,
|
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;
|
struct spa_dll dll;
|
||||||
};
|
};
|
||||||
|
|
@ -236,14 +236,6 @@ int spa_libcamera_close(struct impl *impl)
|
||||||
return 0;
|
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)
|
int spa_libcamera_buffer_recycle(struct impl *impl, struct port *port, uint32_t buffer_id)
|
||||||
{
|
{
|
||||||
struct buffer *b = &port->buffers[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;
|
struct spa_result_node_params result;
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
|
||||||
spa_libcamera_get_config(impl);
|
|
||||||
|
|
||||||
const StreamConfiguration& streamConfig = impl->config->at(0);
|
const StreamConfiguration& streamConfig = impl->config->at(0);
|
||||||
const StreamFormats &formats = streamConfig.formats();
|
const StreamFormats &formats = streamConfig.formats();
|
||||||
const auto &pixel_formats = formats.pixelformats();
|
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,
|
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 }),
|
: handle({ SPA_VERSION_HANDLE, impl_get_interface, impl_clear }),
|
||||||
log(log),
|
log(log),
|
||||||
data_loop(data_loop),
|
data_loop(data_loop),
|
||||||
system(system),
|
system(system),
|
||||||
out_ports{{this}},
|
out_ports{{this}},
|
||||||
manager(std::move(manager)),
|
manager(std::move(manager)),
|
||||||
camera(std::move(camera))
|
camera(std::move(camera)),
|
||||||
|
config(std::move(config))
|
||||||
{
|
{
|
||||||
libcamera_log_topic_init(log);
|
libcamera_log_topic_init(log);
|
||||||
|
|
||||||
|
|
@ -2131,8 +2123,15 @@ impl_init(const struct spa_handle_factory *factory,
|
||||||
return -ENOENT;
|
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,
|
new (handle) impl(log, data_loop, system,
|
||||||
std::move(manager), std::move(camera));
|
std::move(manager), std::move(camera),
|
||||||
|
std::move(config));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue