From patchwork Tue Jul 21 13:55:41 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: 8907 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A0007C2E7B for ; Tue, 21 Jul 2020 13:55:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3BCBB60933; Tue, 21 Jul 2020 15:55:59 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A69DA608E0 for ; Tue, 21 Jul 2020 15:55:57 +0200 (CEST) X-Halon-ID: bedbcce0-cb59-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id bedbcce0-cb59-11ea-86ee-0050569116f7; Tue, 21 Jul 2020 15:54:51 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Jul 2020 15:55:41 +0200 Message-Id: <20200721135541.2931205-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200721135541.2931205-1-niklas.soderlund@ragnatech.se> References: <20200721135541.2931205-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] libcamera: v4l2_videodevice: Add using statement for format map 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Define a using statement for the format maps returned by V4L2Device::formats() and use it in all call sites. There is no functional change in this patch. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_videodevice.h | 4 +++- src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 13 ++++++------- src/libcamera/pipeline/simple/simple.cpp | 2 +- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 3 +-- src/libcamera/v4l2_videodevice.cpp | 9 +++++++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h index fb4c0aabdd46206c..40ed87e17cfa6d3c 100644 --- a/include/libcamera/internal/v4l2_videodevice.h +++ b/include/libcamera/internal/v4l2_videodevice.h @@ -168,6 +168,8 @@ public: class V4L2VideoDevice : public V4L2Device { public: + using Formats = std::map>; + explicit V4L2VideoDevice(const std::string &deviceNode); explicit V4L2VideoDevice(const MediaEntity *entity); V4L2VideoDevice(const V4L2VideoDevice &) = delete; @@ -188,7 +190,7 @@ public: int getFormat(V4L2DeviceFormat *format); int tryFormat(V4L2DeviceFormat *format); int setFormat(V4L2DeviceFormat *format); - std::map> formats(uint32_t code = 0); + Formats formats(uint32_t code = 0); int setSelection(unsigned int target, Rectangle *rect); diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index bf1c77144f855df9..82a0a4dfd6824fce 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -39,8 +39,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(RPI) -using V4L2PixFmtMap = std::map>; - namespace { bool isRaw(PixelFormat &pixFmt) @@ -69,7 +67,8 @@ double scoreFormat(double desired, double actual) return score; } -V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req) +V4L2DeviceFormat findBestMode(V4L2VideoDevice::Formats &formatsMap, + const Size &req) { double bestScore = std::numeric_limits::max(), score; V4L2DeviceFormat bestMode = {}; @@ -410,7 +409,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() * Calculate the best sensor mode we can use based on * the user request. */ - V4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats(); + V4L2VideoDevice::Formats fmts = data_->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size); int ret = data_->unicam_[Unicam::Image].dev()->tryFormat(&sensorFormat); if (ret) @@ -480,7 +479,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate() else dev = data_->isp_[Isp::Output1].dev(); - V4L2PixFmtMap fmts = dev->formats(); + V4L2VideoDevice::Formats fmts = dev->formats(); if (fmts.find(V4L2PixelFormat::fromPixelFormat(cfgPixFmt, false)) == fmts.end()) { /* If we cannot find a native format, use a default one. */ @@ -517,7 +516,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera, V4L2DeviceFormat sensorFormat; unsigned int bufferCount; PixelFormat pixelFormat; - V4L2PixFmtMap fmts; + V4L2VideoDevice::Formats fmts; Size size; if (roles.empty()) @@ -633,7 +632,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config) } /* First calculate the best sensor mode we can use based on the user request. */ - V4L2PixFmtMap fmts = data->unicam_[Unicam::Image].dev()->formats(); + V4L2VideoDevice::Formats fmts = data->unicam_[Unicam::Image].dev()->formats(); V4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize); /* diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 28d367883323d855..5221ff3384923f56 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -275,7 +275,7 @@ int SimpleCameraData::init() return ret; } - std::map> videoFormats = + V4L2VideoDevice::Formats videoFormats = video_->formats(format.mbus_code); LOG(SimplePipeline, Debug) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 47f383d1551d5193..93e3dc17e3a7105e 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -172,8 +172,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera, if (roles.empty()) return config; - std::map> v4l2Formats = - data->video_->formats(); + V4L2VideoDevice::Formats v4l2Formats = data->video_->formats(); std::map> deviceFormats; for (const auto &format : v4l2Formats) { PixelFormat pixelFormat = format.first.toPixelFormat(); diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index e0d2201269440795..9c4f3524af735598 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -461,6 +461,11 @@ const std::string V4L2DeviceFormat::toString() const * \context This class is \threadbound. */ +/** + * \typedef V4L2VideoDevice::Formats + * \brief A map of supported V4L2 pixel formats to frame sizes + */ + /** * \brief Construct a V4L2VideoDevice * \param[in] deviceNode The file-system path to the video device node @@ -951,9 +956,9 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set) * * \return A list of the supported video device formats */ -std::map> V4L2VideoDevice::formats(uint32_t code) +V4L2VideoDevice::Formats V4L2VideoDevice::formats(uint32_t code) { - std::map> formats; + V4L2VideoDevice::Formats formats; for (V4L2PixelFormat pixelFormat : enumPixelformats(code)) { std::vector sizes = enumSizes(pixelFormat);