mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -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()`.
This commit is contained in:
parent
8c4f60af48
commit
49be2a1c52
1 changed files with 15 additions and 16 deletions
|
|
@ -149,6 +149,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;
|
||||
|
|
@ -156,8 +157,6 @@ struct impl {
|
|||
|
||||
void requestComplete(libcamera::Request *request);
|
||||
|
||||
std::unique_ptr<CameraConfiguration> config;
|
||||
|
||||
struct spa_source source = {};
|
||||
|
||||
ControlList ctrls;
|
||||
|
|
@ -166,7 +165,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;
|
||||
};
|
||||
|
|
@ -237,14 +237,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];
|
||||
|
|
@ -507,8 +499,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();
|
||||
|
|
@ -2066,14 +2056,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);
|
||||
|
||||
|
|
@ -2147,8 +2139,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue