From patchwork Fri May 17 23:06:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1227 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A22D60E53 for ; Sat, 18 May 2019 01:06:46 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BE4D8336 for ; Sat, 18 May 2019 01:06:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1558134405; bh=zvXB96Id6V1CoVvFd/HvN+v+pntl7HD3pxKx2o01h7M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lMcJlXzP2Ton5tkI4LPogFyN8LSVEsCgbfwC+iS/wBWLJhV9dGbojbtc2xkLTk27q ml61tpYmnIf6oj1wRJROcZajeEe7hSWjp2EpE8g5XwVTW4GAGTq+/E6uekA0g6ut7o YwrnU4Zd6OPRxrFQfqiFkcHVkv78KtD2drJPwpiw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 18 May 2019 02:06:19 +0300 Message-Id: <20190517230621.24668-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190517230621.24668-1-laurent.pinchart@ideasonboard.com> References: <20190517230621.24668-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH/RFC 10/12] libcamera: v4l2_device: Add method to enumerate all discrete frame sizes 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: Fri, 17 May 2019 23:06:49 -0000 From: Niklas Söderlund Allow the video device to be interrogated about which discrete frame sizes it supports. Signed-off-by: Niklas Söderlund --- src/libcamera/include/v4l2_device.h | 4 +++ src/libcamera/v4l2_device.cpp | 51 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h index 2e7bd1e7f4cc..481d63d9cc4c 100644 --- a/src/libcamera/include/v4l2_device.h +++ b/src/libcamera/include/v4l2_device.h @@ -8,6 +8,8 @@ #define __LIBCAMERA_V4L2_DEVICE_H__ #include +#include +#include #include #include @@ -126,6 +128,8 @@ public: int getFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); + std::map> + enumerateFrameSizes(std::set pixelformats); int exportBuffers(BufferPool *pool); int importBuffers(BufferPool *pool); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 8366ffc4db55..d26a89f4a27d 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -564,6 +564,57 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format) return 0; } +/** + * \brief Enumerate all discrete frame sizes for a set of pixel formats + * \param[in] pixelformats A set of pixel formats to enumerate sizes for + * + * Enumerate all discrete frame sizes reported by the video device. + * + * \return A map of pixel format to frame sizes + */ +std::map> +V4L2Device::enumerateFrameSizes(std::set pixelformats) +{ + std::map> sizes; + int ret; + + for (unsigned int pixelformat : pixelformats) { + struct v4l2_frmsizeenum frameSize = {}; + unsigned int index = 0; + + frameSize.pixel_format = pixelformat; + + while (true) { + frameSize.index = index; + + ret = ioctl(fd_, VIDIOC_ENUM_FRAMESIZES, &frameSize); + if (ret) { + ret = -errno; + + if (ret == -EINVAL) + break; + + if (ret != -ENOTTY) + LOG(V4L2, Error) + << "Unable to enumerate frame size" + << strerror(-ret); + + return {}; + } + + if (frameSize.type != V4L2_FRMSIZE_TYPE_DISCRETE) + return {}; + + sizes[pixelformat].push_back(Size(frameSize.discrete.width, + frameSize.discrete.height)); + + index++; + } + } + + return sizes; +} + int V4L2Device::requestBuffers(unsigned int count) { struct v4l2_requestbuffers rb = {};