From patchwork Mon Sep 5 16:46:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17304 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 035E5C0DA4 for ; Mon, 5 Sep 2022 16:46:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DC42662070; Mon, 5 Sep 2022 18:46:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1662396377; bh=sX+SW364UOIb7hY51DBBrAkECF0kgay59qUwzGuH7Ks=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NJ2E7oRakEcNrk3BqgzDY/ekhWKEsU/2tbeQbilkas2selBYYXgm5LP8+7bUVE5Vr eU6GYU2/9ihVyqt2LrX+f1uOTpPtFk9fWe0w71lEZKF0R85sKP09m95fl8aFR7qqtv x65hlmjyDk1zYLZbxY6wsmJkTt7G0kMpThC5Y+jepvlth03Igy2aMoemXw5y5m8ahC QGH1LNU9Nk1gJQbEKHtiNR2Eeim5PA0zF4x9lc1lulfLznxnJBKwC8QQZ5HNeLCPZj +xJPb33mHbnwFfUEnOUiaV81LtvH5wDwzzkcRQiO8KPyB9/FjkeTKCL97cTP9LW6kE 2JM7m6Ll+0pQg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D4E061F9B for ; Mon, 5 Sep 2022 18:46:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KZpzdgZU"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CB5CE6BC; Mon, 5 Sep 2022 18:46:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1662396376; bh=sX+SW364UOIb7hY51DBBrAkECF0kgay59qUwzGuH7Ks=; h=From:To:Cc:Subject:Date:From; b=KZpzdgZUuyA0S8kQVixjy24PCxBevjWsEpJnmbx+XLlLpCsSy10PDytGtEpmeO+2w B55NCqUpPkaq6ZOsb/+7J0kCAaKRi2uKBgK45wkzlYPJTunyqgQNSMRpUEAT68NCiU uo6HJzZZmexq1VfTri9CSJP8sadwmCaeiZN/Gfik= To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Sep 2022 19:46:00 +0300 Message-Id: <20220905164600.31629-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: v4l2_subdevice: Silence warning for unknown metadata formats 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-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Commit e297673e7686 ("libcamera: v4l2_device: Adjust colorspace based on pixel format") has introduced a warning when trying to convert a color space from V4L2 to libcamera if the media bus code is unknown. This was meant to catch unknown image formats, but turned out to be also triggered for metadata formats. Color spaces are not applicable to metadata formats, there should thus be no warning. Fix it by skipping the color space translation and returning std::nullopt directly if the kernel reports V4L2_COLORSPACE_DEFAULT. This doesn't introduce any change in behaviour other than getting rid of the warning, as the V4L2Device::toColorSpace() function returns std::nullopt alread in that case. Fixes: e297673e7686 ("libcamera: v4l2_device: Adjust colorspace based on pixel format") Reported-by: Naushir Patuck Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Tested-by: Naushir Patuck Reviewed-by: Naushir Patuck --- include/libcamera/internal/v4l2_subdevice.h | 3 ++ src/libcamera/v4l2_subdevice.cpp | 51 ++++++++++----------- 2 files changed, 26 insertions(+), 28 deletions(-) base-commit: da9bb8dea6821edcfd3464e8cba37ad4a91087d6 diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index 00be17bb1465..69862de0585a 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -101,6 +101,9 @@ protected: private: LIBCAMERA_DISABLE_COPY(V4L2Subdevice) + std::optional + toColorSpace(const v4l2_mbus_framefmt &format) const; + std::vector enumPadCodes(unsigned int pad); std::vector enumPadSizes(unsigned int pad, unsigned int code); diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 95bfde340d8c..f3a9a0096c6c 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -477,6 +477,27 @@ V4L2Subdevice::Formats V4L2Subdevice::formats(unsigned int pad) return formats; } +std::optional V4L2Subdevice::toColorSpace(const v4l2_mbus_framefmt &format) const +{ + if (format.colorspace == V4L2_COLORSPACE_DEFAULT) + return std::nullopt; + + PixelFormatInfo::ColourEncoding colourEncoding; + auto iter = formatInfoMap.find(format.code); + if (iter != formatInfoMap.end()) { + colourEncoding = iter->second.colourEncoding; + } else { + LOG(V4L2, Warning) + << "Unknown subdev format " + << utils::hex(format.code, 4) + << ", defaulting to RGB encoding"; + + colourEncoding = PixelFormatInfo::ColourEncodingRGB; + } + + return V4L2Device::toColorSpace(format, colourEncoding); +} + /** * \brief Retrieve the image format set on one of the V4L2 subdevice pads * \param[in] pad The 0-indexed pad number the format is to be retrieved from @@ -503,20 +524,7 @@ int V4L2Subdevice::getFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.width = subdevFmt.format.width; format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; - - PixelFormatInfo::ColourEncoding colourEncoding; - auto iter = formatInfoMap.find(subdevFmt.format.code); - if (iter != formatInfoMap.end()) { - colourEncoding = iter->second.colourEncoding; - } else { - LOG(V4L2, Warning) - << "Unknown subdev format " - << utils::hex(subdevFmt.format.code, 4) - << ", defaulting to RGB encoding"; - - colourEncoding = PixelFormatInfo::ColourEncodingRGB; - } - format->colorSpace = toColorSpace(subdevFmt.format, colourEncoding); + format->colorSpace = toColorSpace(subdevFmt.format); return 0; } @@ -562,20 +570,7 @@ int V4L2Subdevice::setFormat(unsigned int pad, V4L2SubdeviceFormat *format, format->size.width = subdevFmt.format.width; format->size.height = subdevFmt.format.height; format->mbus_code = subdevFmt.format.code; - - PixelFormatInfo::ColourEncoding colourEncoding; - auto iter = formatInfoMap.find(subdevFmt.format.code); - if (iter != formatInfoMap.end()) { - colourEncoding = iter->second.colourEncoding; - } else { - LOG(V4L2, Warning) - << "Unknown subdev format " - << utils::hex(subdevFmt.format.code, 4) - << ", defaulting to RGB encoding"; - - colourEncoding = PixelFormatInfo::ColourEncodingRGB; - } - format->colorSpace = toColorSpace(subdevFmt.format, colourEncoding); + format->colorSpace = toColorSpace(subdevFmt.format); return 0; }