From patchwork Sat Jul 4 13:31:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 8628 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 BA7DFBD792 for ; Sat, 4 Jul 2020 13:32:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 86FBD60E1F; Sat, 4 Jul 2020 15:32:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Gx78/MYj"; dkim-atps=neutral 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 2955D60E1F for ; Sat, 4 Jul 2020 15:32:09 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A9383296; Sat, 4 Jul 2020 15:32:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593869528; bh=xd10mEY+pQVIjwMRdM2jBnYvFVRcSb1QerJ6VSiYrLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gx78/MYjirbYxAaaf9uKNqoIZlKFLMyodOkkcwUdkuw3J+csTKUskkBOOdWdSPMgl d0G8BfnY/GSitaKygU9bmwVCivFrV/MKjyf4e3Xyyi6hyds8s1H26DOVdq2UaEWjUm uo5ikPGUHd0ZaUhDM6AdA6HynStLLLIhttTv5y8A= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Sat, 4 Jul 2020 22:31:25 +0900 Message-Id: <20200704133140.1738660-8-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200704133140.1738660-1-paul.elder@ideasonboard.com> References: <20200704133140.1738660-1-paul.elder@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 07/22] v4l2: v4l2_camera: Add validateConfiguration 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" In V4L2CameraProxy, we need a way to validate formats and sizes, to implement try_fmt. Instead of manually checking it against the cached list of formats and sizes, add V4L2Camera::validateConfiguration that we can use to implement try_fmt. Signed-off-by: Paul Elder --- New in v3 --- src/v4l2/v4l2_camera.cpp | 29 +++++++++++++++++++++++++++++ src/v4l2/v4l2_camera.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp index ffc1230..326e1c2 100644 --- a/src/v4l2/v4l2_camera.cpp +++ b/src/v4l2/v4l2_camera.cpp @@ -138,6 +138,35 @@ int V4L2Camera::configure(StreamConfiguration *streamConfigOut, return 0; } +int V4L2Camera::validateConfiguration(StreamConfiguration *streamConfigOut, + const Size &size, + const PixelFormat &pixelFormat) +{ + if (!streamConfigOut) + return -EINVAL; + + std::unique_ptr config = + camera_->generateConfiguration({ StreamRole::Viewfinder }); + StreamConfiguration &cfg = config->at(0); + cfg.size.width = size.width; + cfg.size.height = size.height; + cfg.pixelFormat = pixelFormat; + cfg.bufferCount = 1; + + CameraConfiguration::Status validation = config->validate(); + if (validation == CameraConfiguration::Invalid) + return -EINVAL; + + streamConfigOut->pixelFormat = cfg.pixelFormat; + streamConfigOut->size.width = cfg.size.width; + streamConfigOut->size.height = cfg.size.height; + streamConfigOut->bufferCount = cfg.bufferCount; + streamConfigOut->stride = cfg.stride; + streamConfigOut->frameSize = cfg.frameSize; + + return 0; +} + int V4L2Camera::allocBuffers(unsigned int count) { Stream *stream = *camera_->streams().begin(); diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h index 515e906..15a9363 100644 --- a/src/v4l2/v4l2_camera.h +++ b/src/v4l2/v4l2_camera.h @@ -47,6 +47,9 @@ public: int configure(StreamConfiguration *streamConfigOut, const Size &size, const PixelFormat &pixelformat, unsigned int bufferCount); + int validateConfiguration(StreamConfiguration *streamConfigOut, + const Size &size, + const PixelFormat &pixelformat); int allocBuffers(unsigned int count); void freeBuffers();