From patchwork Sun Feb 3 11:00:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 489 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4594260B1B for ; Sun, 3 Feb 2019 12:01:07 +0100 (CET) Received: from localhost.localdomain (218.182-78-194.adsl-static.isp.belgacom.be [194.78.182.218]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DFEBBD4A; Sun, 3 Feb 2019 12:01:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1549191667; bh=nne7oU1/bxd+Fc8K/U1tQc528Ql3yyAVTq5vnd9egA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hs3gWRHjUo7ahm4JEEs50o/Q6NG7Lm2Jbrv9vDHQSVI65JXxNAnCpnKMoxq50Htdf Q8tSUGmkmdBidAyBmhSEl9HhGopMztuzoQSECJU38tiqbf8FLkBpb2DSeR+KfW70NZ 50qznOM39EqHqYwLKtHUXrWrO3wBXYn8R8fhQNQ4= From: Kieran Bingham To: LibCamera Devel Date: Sun, 3 Feb 2019 12:00:53 +0100 Message-Id: <20190203110102.5663-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> References: <20190203110102.5663-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/11] libcamera: buffer: Support v4l2_buffer construction X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Feb 2019 11:01:07 -0000 Provide a constructor to create a Buffer object directly from a v4l2_buffer as a V4L2Buffer type. This allows the Buffers to be created directly following a v4l2_reqbufs operation. Signed-off-by: Kieran Bingham --- include/libcamera/buffer.h | 2 +- src/libcamera/buffer.cpp | 27 +++++++++++++++++++++++++++ src/libcamera/include/v4l2_device.h | 8 ++++++++ src/libcamera/v4l2_device.cpp | 27 +++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/libcamera/buffer.h b/include/libcamera/buffer.h index afe99d5c4ab0..e730fc0f84fd 100644 --- a/include/libcamera/buffer.h +++ b/include/libcamera/buffer.h @@ -46,7 +46,7 @@ public: unsigned int index() const { return index_; }; const std::vector &planes() { return planes_; }; -private: +protected: unsigned int index_; unsigned int format_; diff --git a/src/libcamera/buffer.cpp b/src/libcamera/buffer.cpp index 887863b2af2e..c21994d7c035 100644 --- a/src/libcamera/buffer.cpp +++ b/src/libcamera/buffer.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include #include "log.h" @@ -241,6 +243,31 @@ int Buffer::munmap() * \brief Return a reference to the vector holding all Planes within the buffer */ +/** + * \enum Buffer::BufferType + * \brief Identify the type of buffer for derived types + * + * Buffers may be derived to support specific buffer type features on top of the + * generic interface. The BufferType is used internally to assert compatibility + * in the event of any generic Buffer object being upcast to a specific type. + */ + +/** + * \var Buffer::BufferTypeGeneric + * \brief The Buffer can only be supported through the public Buffer API + */ + +/** + * \var Buffer::BufferTypeV4L2 + * \brief The Buffer can supported through both the public Buffer API and the + * internal V4L2 API. + */ + +/** + * \var Buffer::type_ + * \brief An internal BufferType to describe the construction of the Buffer. + */ + /** * \class BufferPool * \brief A pool of buffers diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index f68b2b1df525..9e9eada94130 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -11,6 +11,8 @@ #include +#include + namespace libcamera { struct V4L2Capability final : v4l2_capability { @@ -53,6 +55,12 @@ struct V4L2Capability final : v4l2_capability { } }; +class V4L2Buffer : public Buffer +{ +public: + V4L2Buffer(struct v4l2_buffer &vb); +}; + class V4L2DeviceFormat { public: diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 5c415d0bddbc..d507ea9700b3 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -80,6 +80,33 @@ LOG_DEFINE_CATEGORY(V4L2) * \return True if the device provides Streaming I/O IOCTLs */ +/** + * \brief Construct a Buffer object from a v4l2_buffer description + * + * Buffers are abstracted in the same format regardless of using the single + * planar API or multi-planar API. The buffer object contains a Plane for each + * memory plane required to represent the buffer. + */ +V4L2Buffer::V4L2Buffer(struct v4l2_buffer &vb) + : Buffer() +{ + index_ = vb.index; + + if (V4L2_TYPE_IS_MULTIPLANAR(vb.type)) { + unsigned int i; + for (i = 0; i < vb.length; ++i) { + /* TODO: dmaBuf should retrieve FD here */ + Plane *plane = new Plane(vb.m.planes[i].length, + vb.m.planes[i].m.mem_offset); + planes_.push_back(plane); + } + } else { + /* TODO: dmaBuf should retrieve FD here */ + Plane *plane = new Plane(vb.length, vb.m.offset); + planes_.push_back(plane); + } +} + /** * \class V4L2DeviceFormat * \brief The V4L2 device image format and sizes