[{"id":3355,"web_url":"https://patchwork.libcamera.org/comment/3355/","msgid":"<20200107170707.GM4871@pendragon.ideasonboard.com>","date":"2020-01-07T17:07:07","subject":"Re: [libcamera-devel] [PATCH 2/2] v4l2: camera_proxy: Break out\n\ttry_fmt","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Tue, Jan 07, 2020 at 05:50:38PM +0100, Jacopo Mondi wrote:\n> Calling vidioc_s_fmt() calls vidioc_try_fmt() duplicating prinouts.\n> \n> Breakout try format procedure and call it from both functions.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/v4l2/v4l2_camera_proxy.cpp | 53 +++++++++++++++++++---------------\n>  src/v4l2/v4l2_camera_proxy.h   |  1 +\n>  2 files changed, 30 insertions(+), 24 deletions(-)\n> \n> diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\n> index dbcf333a761f..a56318cb4fa3 100644\n> --- a/src/v4l2/v4l2_camera_proxy.cpp\n> +++ b/src/v4l2/v4l2_camera_proxy.cpp\n> @@ -236,13 +236,38 @@ int V4L2CameraProxy::vidioc_g_fmt(struct v4l2_format *arg)\n>  \treturn 0;\n>  }\n>  \n> +void V4L2CameraProxy::tryFmt(struct v4l2_format *arg)\n\nLet's name this tryFormat.\n\nI think we need to take this one step further and base the tryFormat()\nimplementation on generateConfiguration() + validate(), but for now,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +{\n> +\tPixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);\n> +\tconst std::vector<PixelFormat> &formats =\n> +\t\tstreamConfig_.formats().pixelformats();\n> +\tif (std::find(formats.begin(), formats.end(), format) == formats.end())\n> +\t\tformat = streamConfig_.formats().pixelformats()[0];\n> +\n> +\tSize size(arg->fmt.pix.width, arg->fmt.pix.height);\n> +\tconst std::vector<Size> &sizes = streamConfig_.formats().sizes(format);\n> +\tif (std::find(sizes.begin(), sizes.end(), size) == sizes.end())\n> +\t\tsize = streamConfig_.formats().sizes(format)[0];\n> +\n> +\targ->fmt.pix.width        = size.width;\n> +\targ->fmt.pix.height       = size.height;\n> +\targ->fmt.pix.pixelformat  = drmToV4L2(format);\n> +\targ->fmt.pix.field        = V4L2_FIELD_NONE;\n> +\targ->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *\n> +\t\t\t\t    arg->fmt.pix.width;\n> +\targ->fmt.pix.sizeimage    = imageSize(drmToV4L2(format),\n> +\t\t\t\t\t      arg->fmt.pix.width,\n> +\t\t\t\t\t      arg->fmt.pix.height);\n> +\targ->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;\n> +}\n> +\n>  int V4L2CameraProxy::vidioc_s_fmt(struct v4l2_format *arg)\n>  {\n>  \tLOG(V4L2Compat, Debug) << \"Servicing vidioc_s_fmt\";\n> +\tif (!validateBufferType(arg->type))\n> +\t\treturn -EINVAL;\n>  \n> -\tint ret = vidioc_try_fmt(arg);\n> -\tif (ret < 0)\n> -\t\treturn ret;\n> +\ttryFmt(arg);\n>  \n>  \tSize size(arg->fmt.pix.width, arg->fmt.pix.height);\n>  \tvcam_->invokeMethod(&V4L2Camera::configure, ConnectionTypeBlocking,\n> @@ -268,27 +293,7 @@ int V4L2CameraProxy::vidioc_try_fmt(struct v4l2_format *arg)\n>  \tif (!validateBufferType(arg->type))\n>  \t\treturn -EINVAL;\n>  \n> -\tPixelFormat format = v4l2ToDrm(arg->fmt.pix.pixelformat);\n> -\tconst std::vector<PixelFormat> &formats =\n> -\t\tstreamConfig_.formats().pixelformats();\n> -\tif (std::find(formats.begin(), formats.end(), format) == formats.end())\n> -\t\tformat = streamConfig_.formats().pixelformats()[0];\n> -\n> -\tSize size(arg->fmt.pix.width, arg->fmt.pix.height);\n> -\tconst std::vector<Size> &sizes = streamConfig_.formats().sizes(format);\n> -\tif (std::find(sizes.begin(), sizes.end(), size) == sizes.end())\n> -\t\tsize = streamConfig_.formats().sizes(format)[0];\n> -\n> -\targ->fmt.pix.width        = size.width;\n> -\targ->fmt.pix.height       = size.height;\n> -\targ->fmt.pix.pixelformat  = drmToV4L2(format);\n> -\targ->fmt.pix.field        = V4L2_FIELD_NONE;\n> -\targ->fmt.pix.bytesperline = bplMultiplier(drmToV4L2(format)) *\n> -\t\t\t\t    arg->fmt.pix.width;\n> -\targ->fmt.pix.sizeimage    = imageSize(drmToV4L2(format),\n> -\t\t\t\t\t      arg->fmt.pix.width,\n> -\t\t\t\t\t      arg->fmt.pix.height);\n> -\targ->fmt.pix.colorspace   = V4L2_COLORSPACE_SRGB;\n> +\ttryFmt(arg);\n>  \n>  \treturn 0;\n>  }\n> diff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\n> index bef0f0afab3b..d34de925cf29 100644\n> --- a/src/v4l2/v4l2_camera_proxy.h\n> +++ b/src/v4l2/v4l2_camera_proxy.h\n> @@ -39,6 +39,7 @@ private:\n>  \tvoid setFmtFromConfig(StreamConfiguration &streamConfig);\n>  \tunsigned int calculateSizeImage(StreamConfiguration &streamConfig);\n>  \tvoid querycap(std::shared_ptr<Camera> camera);\n> +\tvoid tryFmt(struct v4l2_format *arg);\n>  \tvoid updateBuffers();\n>  \tint freeBuffers();\n>","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B9FB6063B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Jan 2020 18:07:20 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 89E7652F;\n\tTue,  7 Jan 2020 18:07:19 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1578416840;\n\tbh=62zrhcxCE/D3NbwQVnYUWkuNTJoOWdUqMOrHF7J4ynA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=v4CPUzOAaQKU2nlkSvaXJrxZoZ9V2bLGAdO0ofekgZ3reAcCSzkzNu0mfkyjeipOu\n\tAfa2Ydl8iz408e43c9NFT9qK1mfgZNKo95MFpifkHw8l8ZLac/6ypw7tKqjn8nlYP1\n\tQpcsSYaGqdaeduUzimwrVq+UzY9uzkv3VyzHNp4c=","Date":"Tue, 7 Jan 2020 19:07:07 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200107170707.GM4871@pendragon.ideasonboard.com>","References":"<20200107165038.93041-1-jacopo@jmondi.org>\n\t<20200107165038.93041-3-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200107165038.93041-3-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 2/2] v4l2: camera_proxy: Break out\n\ttry_fmt","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 07 Jan 2020 17:07:20 -0000"}}]