diff --git a/spa/plugins/libcamera/libcamera-source.cpp b/spa/plugins/libcamera/libcamera-source.cpp index f9a1adbcb..b33c7ace5 100644 --- a/spa/plugins/libcamera/libcamera-source.cpp +++ b/spa/plugins/libcamera/libcamera-source.cpp @@ -69,6 +69,7 @@ struct port { StreamConfiguration streamConfig; uint32_t memtype = 0; + uint32_t buffers_blocks = 1; struct buffer buffers[MAX_BUFFERS]; uint32_t n_buffers = 0; @@ -553,7 +554,7 @@ next: param = (struct spa_pod*)spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamBuffers, id, SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(n_buffers, n_buffers, n_buffers), - SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), + SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(port->buffers_blocks), SPA_PARAM_BUFFERS_size, SPA_POD_Int(port->streamConfig.frameSize), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->streamConfig.stride)); break; diff --git a/spa/plugins/libcamera/libcamera-utils.cpp b/spa/plugins/libcamera/libcamera-utils.cpp index 5efb79a5f..d7b467898 100644 --- a/spa/plugins/libcamera/libcamera-utils.cpp +++ b/spa/plugins/libcamera/libcamera-utils.cpp @@ -109,6 +109,30 @@ static int allocBuffers(struct impl *impl, struct port *port, unsigned int count } impl->requestPool.push_back(std::move(request)); } + + /* Some devices require data for each output video frame to be + * placed in discontiguous memory buffers. In such cases, one + * video frame has to be addressed using more than one memory. + * address. Therefore, need calculate the number of discontiguous + * memory and allocate the specified amount of memory */ + Stream *stream = impl->config->at(0).stream(); + const std::vector> &bufs = + impl->allocator->buffers(stream); + const std::vector &planes = bufs[0]->planes(); + int fd = -1; + uint32_t buffers_blocks = 0; + + for (const FrameBuffer::Plane &plane : planes) { + const int current_fd = plane.fd.get(); + if (current_fd >= 0 && current_fd != fd) { + buffers_blocks += 1; + fd = current_fd; + } + } + + if (buffers_blocks > 0) { + port->buffers_blocks = buffers_blocks; + } return res; }