From patchwork Sun Jun 30 18:10:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 1534 Return-Path: Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 34E0460BC0 for ; Sun, 30 Jun 2019 20:09:38 +0200 (CEST) Received: from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id CD8EA200007; Sun, 30 Jun 2019 18:09:37 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Sun, 30 Jun 2019 20:10:42 +0200 Message-Id: <20190630181049.9548-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190630181049.9548-1-jacopo@jmondi.org> References: <20190630181049.9548-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/8] libcamera: v4l2_videodevice: Re-group operations 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, 30 Jun 2019 18:09:38 -0000 Group together operations to enumerate formats and operations to handle memory handling, alternating public and private operations but respecting the ordering within each group. Cosmetic change to prepare for a re-work of the memory handling operations. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/v4l2_videodevice.h | 6 +- src/libcamera/v4l2_videodevice.cpp | 170 +++++++++++------------ 2 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/libcamera/include/v4l2_videodevice.h b/src/libcamera/include/v4l2_videodevice.h index 734b34f1dc53..b92df882568f 100644 --- a/src/libcamera/include/v4l2_videodevice.h +++ b/src/libcamera/include/v4l2_videodevice.h @@ -160,13 +160,13 @@ private: int getFormatSingleplane(V4L2DeviceFormat *format); int setFormatSingleplane(V4L2DeviceFormat *format); + std::vector enumPixelformats(); + std::vector enumSizes(unsigned int pixelFormat); + int requestBuffers(unsigned int count); int createPlane(Buffer *buffer, unsigned int plane, unsigned int length); - std::vector enumPixelformats(); - std::vector enumSizes(unsigned int pixelFormat); - Buffer *dequeueBuffer(); void bufferAvailable(EventNotifier *notifier); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 12af3bd0639b..2d1e87a76c6f 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -627,6 +627,91 @@ ImageFormats V4L2VideoDevice::formats() return formats; } +std::vector V4L2VideoDevice::enumPixelformats() +{ + std::vector formats; + int ret; + + for (unsigned int index = 0; ; index++) { + struct v4l2_fmtdesc pixelformatEnum = {}; + pixelformatEnum.index = index; + pixelformatEnum.type = bufferType_; + + ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); + if (ret) + break; + + formats.push_back(pixelformatEnum.pixelformat); + } + + if (ret && ret != -EINVAL) { + LOG(V4L2, Error) + << "Unable to enumerate pixel formats: " + << strerror(-ret); + return {}; + } + + return formats; +} + +std::vector V4L2VideoDevice::enumSizes(unsigned int pixelFormat) +{ + std::vector sizes; + int ret; + + for (unsigned int index = 0;; index++) { + struct v4l2_frmsizeenum frameSize = {}; + frameSize.index = index; + frameSize.pixel_format = pixelFormat; + + ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); + if (ret) + break; + + if (index != 0 && + frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { + LOG(V4L2, Error) + << "Non-zero index for non discrete type"; + return {}; + } + + switch (frameSize.type) { + case V4L2_FRMSIZE_TYPE_DISCRETE: + sizes.emplace_back(frameSize.discrete.width, + frameSize.discrete.height); + break; + case V4L2_FRMSIZE_TYPE_CONTINUOUS: + sizes.emplace_back(frameSize.stepwise.min_width, + frameSize.stepwise.min_height, + frameSize.stepwise.max_width, + frameSize.stepwise.max_height); + break; + case V4L2_FRMSIZE_TYPE_STEPWISE: + sizes.emplace_back(frameSize.stepwise.min_width, + frameSize.stepwise.min_height, + frameSize.stepwise.max_width, + frameSize.stepwise.max_height, + frameSize.stepwise.step_width, + frameSize.stepwise.step_height); + break; + default: + LOG(V4L2, Error) + << "Unknown VIDIOC_ENUM_FRAMESIZES type " + << frameSize.type; + return {}; + } + } + + if (ret && ret != -EINVAL) { + LOG(V4L2, Error) + << "Unable to enumerate frame sizes: " + << strerror(-ret); + return {}; + } + + return sizes; +} + int V4L2VideoDevice::requestBuffers(unsigned int count) { struct v4l2_requestbuffers rb = {}; @@ -754,91 +839,6 @@ int V4L2VideoDevice::createPlane(Buffer *buffer, unsigned int planeIndex, return 0; } -std::vector V4L2VideoDevice::enumPixelformats() -{ - std::vector formats; - int ret; - - for (unsigned int index = 0; ; index++) { - struct v4l2_fmtdesc pixelformatEnum = {}; - pixelformatEnum.index = index; - pixelformatEnum.type = bufferType_; - - ret = ioctl(VIDIOC_ENUM_FMT, &pixelformatEnum); - if (ret) - break; - - formats.push_back(pixelformatEnum.pixelformat); - } - - if (ret && ret != -EINVAL) { - LOG(V4L2, Error) - << "Unable to enumerate pixel formats: " - << strerror(-ret); - return {}; - } - - return formats; -} - -std::vector V4L2VideoDevice::enumSizes(unsigned int pixelFormat) -{ - std::vector sizes; - int ret; - - for (unsigned int index = 0;; index++) { - struct v4l2_frmsizeenum frameSize = {}; - frameSize.index = index; - frameSize.pixel_format = pixelFormat; - - ret = ioctl(VIDIOC_ENUM_FRAMESIZES, &frameSize); - if (ret) - break; - - if (index != 0 && - frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) { - LOG(V4L2, Error) - << "Non-zero index for non discrete type"; - return {}; - } - - switch (frameSize.type) { - case V4L2_FRMSIZE_TYPE_DISCRETE: - sizes.emplace_back(frameSize.discrete.width, - frameSize.discrete.height); - break; - case V4L2_FRMSIZE_TYPE_CONTINUOUS: - sizes.emplace_back(frameSize.stepwise.min_width, - frameSize.stepwise.min_height, - frameSize.stepwise.max_width, - frameSize.stepwise.max_height); - break; - case V4L2_FRMSIZE_TYPE_STEPWISE: - sizes.emplace_back(frameSize.stepwise.min_width, - frameSize.stepwise.min_height, - frameSize.stepwise.max_width, - frameSize.stepwise.max_height, - frameSize.stepwise.step_width, - frameSize.stepwise.step_height); - break; - default: - LOG(V4L2, Error) - << "Unknown VIDIOC_ENUM_FRAMESIZES type " - << frameSize.type; - return {}; - } - } - - if (ret && ret != -EINVAL) { - LOG(V4L2, Error) - << "Unable to enumerate frame sizes: " - << strerror(-ret); - return {}; - } - - return sizes; -} - /** * \brief Import the externally allocated \a pool of buffers * \param[in] pool BufferPool of buffers to import