[{"id":1698,"web_url":"https://patchwork.libcamera.org/comment/1698/","msgid":"<20190524193408.GE1702@pendragon.ideasonboard.com>","date":"2019-05-24T19:34:08","subject":"Re: [libcamera-devel] [PATCH 3/6] libcamera: v4l2_device: Add META\n\tsupport in g/s_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 Fri, May 24, 2019 at 06:21:36PM +0200, Jacopo Mondi wrote:\n> Add two operations to set and get format on devices implementing the\n> V4L2 Metadata Interface, identified by the META_OUTPUT or META_CAPTURE\n> capabilities.\n> \n> While at it, sort get/setFormat operations alphabetically and unify\n> their style (eg. no empty line before ioctl).\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/include/v4l2_device.h |   7 +-\n>  src/libcamera/v4l2_device.cpp       | 110 +++++++++++++++++++++-------\n>  2 files changed, 89 insertions(+), 28 deletions(-)\n> \n> diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\n> index cecafa151caa..bdecc087fe5a 100644\n> --- a/src/libcamera/include/v4l2_device.h\n> +++ b/src/libcamera/include/v4l2_device.h\n> @@ -150,12 +150,15 @@ protected:\n>  \tstd::string logPrefix() const;\n>  \n>  private:\n> -\tint getFormatSingleplane(V4L2DeviceFormat *format);\n> -\tint setFormatSingleplane(V4L2DeviceFormat *format);\n> +\tint getFormatMeta(V4L2DeviceFormat *format);\n> +\tint setFormatMeta(V4L2DeviceFormat *format);\n>  \n>  \tint getFormatMultiplane(V4L2DeviceFormat *format);\n>  \tint setFormatMultiplane(V4L2DeviceFormat *format);\n>  \n> +\tint getFormatSingleplane(V4L2DeviceFormat *format);\n> +\tint setFormatSingleplane(V4L2DeviceFormat *format);\n> +\n>  \tint requestBuffers(unsigned int count);\n>  \tint createPlane(Buffer *buffer, unsigned int plane,\n>  \t\t\tunsigned int length);\n> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\n> index e42f6ef0c340..789f76b0f69f 100644\n> --- a/src/libcamera/v4l2_device.cpp\n> +++ b/src/libcamera/v4l2_device.cpp\n> @@ -428,8 +428,12 @@ std::string V4L2Device::logPrefix() const\n>   */\n>  int V4L2Device::getFormat(V4L2DeviceFormat *format)\n>  {\n> -\treturn caps_.isMultiplanar() ? getFormatMultiplane(format) :\n> -\t\t\t\t       getFormatSingleplane(format);\n> +\tif (caps_.isMeta())\n> +\t\treturn getFormatMeta(format);\n> +\tif (caps_.isMultiplanar())\n\nI would either use an else if here, or remove the else below. Same for\nthe next function.\n\n> +\t\treturn getFormatMultiplane(format);\n> +\telse\n> +\t\treturn getFormatSingleplane(format);\n>  }\n>  \n>  /**\n> @@ -443,14 +447,18 @@ int V4L2Device::getFormat(V4L2DeviceFormat *format)\n>   */\n>  int V4L2Device::setFormat(V4L2DeviceFormat *format)\n>  {\n> -\treturn caps_.isMultiplanar() ? setFormatMultiplane(format) :\n> -\t\t\t\t       setFormatSingleplane(format);\n> +\tif (caps_.isMeta())\n> +\t\treturn setFormatMeta(format);\n> +\tif (caps_.isMultiplanar())\n> +\t\treturn setFormatMultiplane(format);\n> +\telse\n> +\t\treturn setFormatSingleplane(format);\n>  }\n>  \n> -int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)\n> +int V4L2Device::getFormatMeta(V4L2DeviceFormat *format)\n>  {\n>  \tstruct v4l2_format v4l2Format = {};\n> -\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n> +\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n>  \tint ret;\n>  \n>  \tv4l2Format.type = bufferType_;\n> @@ -461,29 +469,24 @@ int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)\n>  \t\treturn ret;\n>  \t}\n>  \n> -\tformat->size.width = pix->width;\n> -\tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->size.width = pix->buffersize;\n> +\tformat->size.height = 1;\n\nI would set those two fields to 0, the buffer size is already reported\nthrough format->planes[0].bpl. Same for the other locations below.\n\n> +\tformat->fourcc = pix->dataformat;\n>  \tformat->planesCount = 1;\n> -\tformat->planes[0].bpl = pix->bytesperline;\n> -\tformat->planes[0].size = pix->sizeimage;\n> +\tformat->planes[0].bpl = pix->buffersize;\n> +\tformat->planes[0].size = pix->buffersize;\n>  \n>  \treturn 0;\n>  }\n>  \n> -int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)\n> +int V4L2Device::setFormatMeta(V4L2DeviceFormat *format)\n>  {\n>  \tstruct v4l2_format v4l2Format = {};\n> -\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n> +\tstruct v4l2_meta_format *pix = &v4l2Format.fmt.meta;\n>  \tint ret;\n>  \n>  \tv4l2Format.type = bufferType_;\n> -\tpix->width = format->size.width;\n> -\tpix->height = format->size.height;\n> -\tpix->pixelformat = format->fourcc;\n> -\tpix->bytesperline = format->planes[0].bpl;\n> -\tpix->field = V4L2_FIELD_NONE;\n> -\n> +\tpix->dataformat = format->fourcc;\n>  \tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n>  \tif (ret) {\n>  \t\tret = -errno;\n> @@ -495,12 +498,12 @@ int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)\n>  \t * Return to caller the format actually applied on the device,\n>  \t * which might differ from the requested one.\n>  \t */\n> -\tformat->size.width = pix->width;\n> -\tformat->size.height = pix->height;\n> -\tformat->fourcc = pix->pixelformat;\n> +\tformat->size.width = pix->buffersize;\n> +\tformat->size.height = 1;\n> +\tformat->fourcc = format->fourcc;\n>  \tformat->planesCount = 1;\n> -\tformat->planes[0].bpl = pix->bytesperline;\n> -\tformat->planes[0].size = pix->sizeimage;\n> +\tformat->planes[0].bpl = pix->buffersize;\n> +\tformat->planes[0].size = pix->buffersize;\n>  \n>  \treturn 0;\n>  }\n> @@ -523,7 +526,6 @@ int V4L2Device::getFormatMultiplane(V4L2DeviceFormat *format)\n>  \tformat->size.height = pix->height;\n>  \tformat->fourcc = pix->pixelformat;\n>  \tformat->planesCount = pix->num_planes;\n> -\n\nI would keep this, I think it makes the code more readable.\n\n>  \tfor (unsigned int i = 0; i < format->planesCount; ++i) {\n>  \t\tformat->planes[i].bpl = pix->plane_fmt[i].bytesperline;\n>  \t\tformat->planes[i].size = pix->plane_fmt[i].sizeimage;\n> @@ -544,7 +546,6 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format)\n>  \tpix->pixelformat = format->fourcc;\n>  \tpix->num_planes = format->planesCount;\n>  \tpix->field = V4L2_FIELD_NONE;\n> -\n>  \tfor (unsigned int i = 0; i < pix->num_planes; ++i) {\n>  \t\tpix->plane_fmt[i].bytesperline = format->planes[i].bpl;\n>  \t\tpix->plane_fmt[i].sizeimage = format->planes[i].size;\n> @@ -573,6 +574,63 @@ int V4L2Device::setFormatMultiplane(V4L2DeviceFormat *format)\n>  \treturn 0;\n>  }\n>  \n> +int V4L2Device::getFormatSingleplane(V4L2DeviceFormat *format)\n> +{\n> +\tstruct v4l2_format v4l2Format = {};\n> +\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n> +\tint ret;\n> +\n> +\tv4l2Format.type = bufferType_;\n> +\tret = ioctl(fd_, VIDIOC_G_FMT, &v4l2Format);\n> +\tif (ret) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\tformat->size.width = pix->width;\n> +\tformat->size.height = pix->height;\n> +\tformat->fourcc = pix->pixelformat;\n> +\tformat->planesCount = 1;\n> +\tformat->planes[0].bpl = pix->bytesperline;\n> +\tformat->planes[0].size = pix->sizeimage;\n> +\n> +\treturn 0;\n> +}\n> +\n> +int V4L2Device::setFormatSingleplane(V4L2DeviceFormat *format)\n> +{\n> +\tstruct v4l2_format v4l2Format = {};\n> +\tstruct v4l2_pix_format *pix = &v4l2Format.fmt.pix;\n> +\tint ret;\n> +\n> +\tv4l2Format.type = bufferType_;\n> +\tpix->width = format->size.width;\n> +\tpix->height = format->size.height;\n> +\tpix->pixelformat = format->fourcc;\n> +\tpix->bytesperline = format->planes[0].bpl;\n> +\tpix->field = V4L2_FIELD_NONE;\n> +\tret = ioctl(fd_, VIDIOC_S_FMT, &v4l2Format);\n> +\tif (ret) {\n> +\t\tret = -errno;\n> +\t\tLOG(V4L2, Error) << \"Unable to set format: \" << strerror(-ret);\n> +\t\treturn ret;\n> +\t}\n> +\n> +\t/*\n> +\t * Return to caller the format actually applied on the device,\n> +\t * which might differ from the requested one.\n> +\t */\n> +\tformat->size.width = pix->width;\n> +\tformat->size.height = pix->height;\n> +\tformat->fourcc = pix->pixelformat;\n> +\tformat->planesCount = 1;\n> +\tformat->planes[0].bpl = pix->bytesperline;\n> +\tformat->planes[0].size = pix->sizeimage;\n> +\n> +\treturn 0;\n> +}\n> +\n>  int V4L2Device::requestBuffers(unsigned int count)\n>  {\n>  \tstruct v4l2_requestbuffers rb = {};","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A573260E4C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 May 2019 21:34:26 +0200 (CEST)","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 101C2510;\n\tFri, 24 May 2019 21:34:25 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1558726466;\n\tbh=CwoSVKyljtwxXXqDcA4eqwhFq2FppfBxDLsVqg1dETo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=WHgxbvgQfiSFzU4OM8SMMoA2+2RMq7Md+3Rj1xr5XAUrxoqQVt+KqHUiKraRwA9jU\n\tbEmP41Xx3s4BlnuPbDNMGVbdRZfHyZkJnxuANSHyaKivKh3Ng/ZSreKz4La9zKp0mM\n\t8n5kdzTcW2u8T4XlrUV4omSbD3I5NlX7cPe//Is4=","Date":"Fri, 24 May 2019 22:34:08 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190524193408.GE1702@pendragon.ideasonboard.com>","References":"<20190524162139.4446-1-jacopo@jmondi.org>\n\t<20190524162139.4446-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190524162139.4446-4-jacopo@jmondi.org>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 3/6] libcamera: v4l2_device: Add META\n\tsupport in g/s_fmt","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Fri, 24 May 2019 19:34:27 -0000"}}]