From cd79cdfb406482c06dfc9309d1a481e9c8b302f1 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 15 Apr 2021 20:40:16 +0200 Subject: [PATCH] libcamera: use the data type mask to select a type In alloc_buffers we need to look at the data types mask. Select DmaBuf when not invalid and the DmaBuf flag is set, otherwise select memptr. See #1054 --- spa/plugins/libcamera/libcamera-utils.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/spa/plugins/libcamera/libcamera-utils.c b/spa/plugins/libcamera/libcamera-utils.c index c530f03e0..48246f0c9 100644 --- a/spa/plugins/libcamera/libcamera-utils.c +++ b/spa/plugins/libcamera/libcamera-utils.c @@ -756,7 +756,19 @@ mmap_init(struct impl *this, spa_log_info(this->log, "libcamera: In mmap_init()"); - port->memtype = SPA_DATA_DmaBuf; + if (n_buffers > 0) { + d = buffers[0]->datas; + + if (d[0].type != SPA_ID_INVALID && + d[0].type & (1u << SPA_DATA_DmaBuf)) { + port->memtype = SPA_DATA_DmaBuf; + } else if (d[0].type & (1u << SPA_DATA_MemPtr)) { + port->memtype = SPA_DATA_MemPtr; + } else { + spa_log_error(this->log, "v4l2: can't use buffers of type %d", d[0].type); + return -EINVAL; + } + } /* get n_buffers from libcamera */ uint32_t libcamera_nbuffers = libcamera_get_nbuffers(port->dev.camera); @@ -778,7 +790,7 @@ mmap_init(struct impl *this, d = buffers[i]->datas; for(j = 0; j < buffers[i]->n_datas; ++j) { - d[j].type = SPA_DATA_DmaBuf; + d[j].type = port->memtype; d[j].flags = SPA_DATA_FLAG_READABLE; d[j].mapoffset = 0; d[j].maxsize = libcamera_get_max_size(port->dev.camera); @@ -787,8 +799,6 @@ mmap_init(struct impl *this, d[j].chunk->stride = port->fmt.bytesperline; /* FIXME:: This needs to be appropriately filled */ d[j].chunk->flags = 0; - d[j].flags = SPA_DATA_FLAG_READABLE; - if(port->memtype == SPA_DATA_DmaBuf) { d[j].fd = libcamera_get_fd(port->dev.camera, i, j); spa_log_info(this->log, "libcamera: Got fd = %ld for buffer: #%d\n", d[j].fd, i);