From patchwork Tue Nov 26 23:35:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 2356 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5128A61C62 for ; Wed, 27 Nov 2019 00:39:31 +0100 (CET) X-Halon-ID: fd52620a-10a5-11ea-a0b9-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5865.dip0.t-ipconnect.de [84.172.88.101]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id fd52620a-10a5-11ea-a0b9-005056917f90; Wed, 27 Nov 2019 00:39:29 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Nov 2019 00:35:58 +0100 Message-Id: <20191126233620.1695316-9-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191126233620.1695316-1-niklas.soderlund@ragnatech.se> References: <20191126233620.1695316-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/30] libcamera: buffer: Switch from Plane to Dmabuf X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Nov 2019 23:39:31 -0000 Dmabug and Plane serves similar functions in the two buffer interfaces Buffer and FrameBuffer and share many function signatures. Replace all usages of Plane with Dmabuf to prepare for dropping the Buffer interface. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- include/libcamera/buffer.h | 6 +++--- src/cam/buffer_writer.cpp | 6 +++--- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 4 ++-- src/libcamera/stream.cpp | 3 +-- src/libcamera/v4l2_videodevice.cpp | 14 ++++++-------- src/qcam/main_window.cpp | 4 ++-- test/camera/buffer_import.cpp | 2 +- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index fe5195327b540f5c..2dd5bcf3b49c4ee8 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -101,11 +101,11 @@ private: class BufferMemory final { public: - const std::vector &planes() const { return planes_; } - std::vector &planes() { return planes_; } + const std::vector &planes() const { return planes_; } + std::vector &planes() { return planes_; } private: - std::vector planes_; + std::vector planes_; }; class BufferPool final diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp index c33e99c5f8173db8..5967efca07254666 100644 --- a/src/cam/buffer_writer.cpp +++ b/src/cam/buffer_writer.cpp @@ -43,9 +43,9 @@ int BufferWriter::write(Buffer *buffer, const std::string &streamName) return -errno; BufferMemory *mem = buffer->mem(); - for (Plane &plane : mem->planes()) { - void *data = plane.mem(); - unsigned int length = plane.length(); + for (Dmabuf &dmabuf : mem->planes()) { + void *data = dmabuf.mem(); + unsigned int length = dmabuf.length(); ret = ::write(fd, data, length); if (ret < 0) { diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 00fa4d4f19cb4aa4..e8b6a278e97b0ba0 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -689,7 +689,7 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera, for (unsigned int i = 0; i < stream->configuration().bufferCount + 1; i++) { std::vector planes; planes.push_back({ - .fd = paramPool_.buffers()[i].planes()[0].dmabuf(), + .fd = paramPool_.buffers()[i].planes()[0].fd(), .length = paramPool_.buffers()[i].planes()[0].length(), }); @@ -701,7 +701,7 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera, for (unsigned int i = 0; i < stream->configuration().bufferCount + 1; i++) { std::vector planes; planes.push_back({ - .fd = statPool_.buffers()[i].planes()[0].dmabuf(), + .fd = statPool_.buffers()[i].planes()[0].fd(), .length = statPool_.buffers()[i].planes()[0].length(), }); diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 45f31ae1e2daeb53..e70a1e307ecaa5ba 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -577,8 +577,7 @@ int Stream::mapBuffer(const Buffer *buffer) if (dmabufs[i] == -1) break; - mem->planes().emplace_back(); - mem->planes().back().setDmabuf(dmabufs[i], 0); + mem->planes().emplace_back(dmabufs[i], 0); } /* Remove the buffer from the cache and return its index. */ diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index dbb5c3982334e243..166b0abc1b101f88 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -921,9 +921,7 @@ int V4L2VideoDevice::createPlane(BufferMemory *buffer, unsigned int index, return ret; } - buffer->planes().emplace_back(); - Plane &plane = buffer->planes().back(); - plane.setDmabuf(expbuf.fd, length); + buffer->planes().emplace_back(expbuf.fd, length); ::close(expbuf.fd); return 0; @@ -986,19 +984,19 @@ int V4L2VideoDevice::queueBuffer(Buffer *buffer) bool multiPlanar = V4L2_TYPE_IS_MULTIPLANAR(buf.type); BufferMemory *mem = &bufferPool_->buffers()[buf.index]; - const std::vector &planes = mem->planes(); + const std::vector &dmabufs = mem->planes(); if (buf.memory == V4L2_MEMORY_DMABUF) { if (multiPlanar) { - for (unsigned int p = 0; p < planes.size(); ++p) - v4l2Planes[p].m.fd = planes[p].dmabuf(); + for (unsigned int p = 0; p < dmabufs.size(); ++p) + v4l2Planes[p].m.fd = dmabufs[p].fd(); } else { - buf.m.fd = planes[0].dmabuf(); + buf.m.fd = dmabufs[0].fd(); } } if (multiPlanar) { - buf.length = planes.size(); + buf.length = dmabufs.size(); buf.m.planes = v4l2Planes; } diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 0c7ca61ac12ec41c..a828a176cbbf4854 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -300,8 +300,8 @@ int MainWindow::display(Buffer *buffer) if (mem->planes().size() != 1) return -EINVAL; - Plane &plane = mem->planes().front(); - unsigned char *raw = static_cast(plane.mem()); + Dmabuf &dmabuf = mem->planes().front(); + unsigned char *raw = static_cast(dmabuf.mem()); viewfinder_->display(raw, buffer->bytesused()); return 0; diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp index 3efe02704c02f691..8b0d1c167bd2bbe8 100644 --- a/test/camera/buffer_import.cpp +++ b/test/camera/buffer_import.cpp @@ -178,7 +178,7 @@ private: uint64_t cookie = index; BufferMemory &mem = pool_.buffers()[index]; - int dmabuf = mem.planes()[0].dmabuf(); + int dmabuf = mem.planes()[0].fd(); requestReady.emit(cookie, dmabuf);