mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-03-08 05:34:03 -04:00
spa: libcamera: source: keep libcamera::FrameBufferAllocator
Instantiate it once and keep it instead of always dynamically allocating it when the camera is acquired.
This commit is contained in:
parent
c517e712ed
commit
1f60cd291f
1 changed files with 10 additions and 9 deletions
|
|
@ -152,7 +152,7 @@ struct impl {
|
||||||
std::shared_ptr<Camera> camera;
|
std::shared_ptr<Camera> camera;
|
||||||
const std::unique_ptr<CameraConfiguration> config;
|
const std::unique_ptr<CameraConfiguration> config;
|
||||||
|
|
||||||
FrameBufferAllocator *allocator = nullptr;
|
FrameBufferAllocator allocator;
|
||||||
std::vector<std::unique_ptr<libcamera::Request>> requestPool;
|
std::vector<std::unique_ptr<libcamera::Request>> requestPool;
|
||||||
spa_ringbuffer completed_requests_rb = SPA_RINGBUFFER_INIT();
|
spa_ringbuffer completed_requests_rb = SPA_RINGBUFFER_INIT();
|
||||||
std::array<libcamera::Request *, MAX_BUFFERS> completed_requests;
|
std::array<libcamera::Request *, MAX_BUFFERS> completed_requests;
|
||||||
|
|
@ -212,7 +212,7 @@ int spa_libcamera_open(struct impl *impl)
|
||||||
if (int res = impl->camera->acquire(); res < 0)
|
if (int res = impl->camera->acquire(); res < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
impl->allocator = new FrameBufferAllocator(impl->camera);
|
spa_assert(!impl->allocator.allocated());
|
||||||
|
|
||||||
const ControlInfoMap &controls = impl->camera->controls();
|
const ControlInfoMap &controls = impl->camera->controls();
|
||||||
setup_initial_controls(controls, impl->initial_controls);
|
setup_initial_controls(controls, impl->initial_controls);
|
||||||
|
|
@ -230,8 +230,8 @@ int spa_libcamera_close(struct impl *impl)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
spa_log_info(impl->log, "close camera %s", impl->camera->id().c_str());
|
spa_log_info(impl->log, "close camera %s", impl->camera->id().c_str());
|
||||||
delete impl->allocator;
|
|
||||||
impl->allocator = nullptr;
|
spa_assert(!impl->allocator.allocated());
|
||||||
|
|
||||||
impl->camera->release();
|
impl->camera->release();
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ int spa_libcamera_buffer_recycle(struct impl *impl, struct port *port, uint32_t
|
||||||
void freeBuffers(struct impl *impl, struct port *port)
|
void freeBuffers(struct impl *impl, struct port *port)
|
||||||
{
|
{
|
||||||
impl->requestPool.clear();
|
impl->requestPool.clear();
|
||||||
std::ignore = impl->allocator->free(port->streamConfig.stream());
|
std::ignore = impl->allocator.free(port->streamConfig.stream());
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|
@ -298,10 +298,10 @@ int allocBuffers(struct impl *impl, struct port *port, unsigned int count)
|
||||||
if (!impl->requestPool.empty())
|
if (!impl->requestPool.empty())
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
if ((res = impl->allocator->allocate(stream)) < 0)
|
if ((res = impl->allocator.allocate(stream)) < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
const auto& bufs = impl->allocator->buffers(stream);
|
const auto& bufs = impl->allocator.buffers(stream);
|
||||||
if (bufs.empty() || bufs.size() != count) {
|
if (bufs.empty() || bufs.size() != count) {
|
||||||
res = -ENOBUFS;
|
res = -ENOBUFS;
|
||||||
goto err;
|
goto err;
|
||||||
|
|
@ -1183,7 +1183,7 @@ spa_libcamera_alloc_buffers(struct impl *impl, struct port *port,
|
||||||
|
|
||||||
Stream *stream = impl->config->at(0).stream();
|
Stream *stream = impl->config->at(0).stream();
|
||||||
const std::vector<std::unique_ptr<FrameBuffer>> &bufs =
|
const std::vector<std::unique_ptr<FrameBuffer>> &bufs =
|
||||||
impl->allocator->buffers(stream);
|
impl->allocator.buffers(stream);
|
||||||
|
|
||||||
if (n_buffers > 0) {
|
if (n_buffers > 0) {
|
||||||
if (bufs.size() != n_buffers)
|
if (bufs.size() != n_buffers)
|
||||||
|
|
@ -2171,7 +2171,8 @@ impl::impl(spa_log *log, spa_loop *data_loop, spa_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))
|
config(std::move(config)),
|
||||||
|
allocator(this->camera)
|
||||||
{
|
{
|
||||||
libcamera_log_topic_init(log);
|
libcamera_log_topic_init(log);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue