From patchwork Fri Jan 10 19:38:03 2020 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: 2575 Return-Path: Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 636C66069A for ; Fri, 10 Jan 2020 20:39:07 +0100 (CET) X-Halon-ID: daa4d8a3-33e0-11ea-b6d8-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p54ac5d7b.dip0.t-ipconnect.de [84.172.93.123]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id daa4d8a3-33e0-11ea-b6d8-005056917f90; Fri, 10 Jan 2020 20:39:03 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 10 Jan 2020 20:38:03 +0100 Message-Id: <20200110193808.2266294-29-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200110193808.2266294-1-niklas.soderlund@ragnatech.se> References: <20200110193808.2266294-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 28/33] libcamera: v4l2_videodevice: Use FileDescriptor where appropriate 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: Fri, 10 Jan 2020 19:39:07 -0000 From: Laurent Pinchart Return a FileDescriptor instead of a numerical fd from exportDmabufFd(). Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_videodevice.h | 2 +- src/libcamera/v4l2_videodevice.cpp | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 6959b87a35496b9a..172d670c328b2345 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -217,7 +217,7 @@ private: int requestBuffers(unsigned int count); std::unique_ptr createBuffer(const struct v4l2_buffer &buf); - int exportDmabufFd(unsigned int index, unsigned int plane); + FileDescriptor exportDmabufFd(unsigned int index, unsigned int plane); void bufferAvailable(EventNotifier *notifier); FrameBuffer *dequeueBuffer(); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 59a6d1b5537d776f..c0381d3980063799 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -1041,24 +1041,22 @@ V4L2VideoDevice::createBuffer(const struct v4l2_buffer &buf) std::vector planes; for (unsigned int nplane = 0; nplane < numPlanes; nplane++) { - int fd = exportDmabufFd(buf.index, nplane); - if (fd < 0) + FileDescriptor fd = exportDmabufFd(buf.index, nplane); + if (fd.fd() < 0) return nullptr; FrameBuffer::Plane plane; - plane.fd = FileDescriptor(fd); + plane.fd = std::move(fd); plane.length = multiPlanar ? buf.m.planes[nplane].length : buf.length; planes.push_back(std::move(plane)); - - ::close(fd); } return utils::make_unique(std::move(planes)); } -int V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane) +FileDescriptor V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane) { struct v4l2_exportbuffer expbuf = {}; int ret; @@ -1072,10 +1070,10 @@ int V4L2VideoDevice::exportDmabufFd(unsigned int index, unsigned int plane) if (ret < 0) { LOG(V4L2, Error) << "Failed to export buffer: " << strerror(-ret); - return ret; + return FileDescriptor(); } - return expbuf.fd; + return FileDescriptor(expbuf.fd); } /**