{"id":1314,"url":"https://patchwork.libcamera.org/api/patches/1314/?format=json","web_url":"https://patchwork.libcamera.org/patch/1314/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190527090559.26549-4-jacopo@jmondi.org>","date":"2019-05-27T09:05:56","name":"[libcamera-devel,v2,3/6] libcamera: v4l2_device: Add META support in g/s_fmt","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e5e9ff71ca547c9e3b4b50c5d06502258e907518","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1314/mbox/","series":[{"id":329,"url":"https://patchwork.libcamera.org/api/series/329/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=329","date":"2019-05-27T09:05:53","name":"META_OUTPUT support + IPU3 parameters tuning","version":2,"mbox":"https://patchwork.libcamera.org/series/329/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1314/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1314/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net\n\t[217.70.183.195])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 756FA61900\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 11:05:03 +0200 (CEST)","from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay3-d.mail.gandi.net (Postfix) with ESMTPSA id DEF9E60017;\n\tMon, 27 May 2019 09:05:02 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 27 May 2019 11:05:56 +0200","Message-Id":"<20190527090559.26549-4-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190527090559.26549-1-jacopo@jmondi.org>","References":"<20190527090559.26549-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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":"Mon, 27 May 2019 09:05:04 -0000"},"content":"Add two operations to set and get format on devices implementing the\nV4L2 Metadata Interface, identified by the META_OUTPUT or META_CAPTURE\ncapabilities.\n\nWhile at it, sort get/setFormat operations alphabetically and unify\ntheir style (eg. no empty line before ioctl).\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_device.h |   7 +-\n src/libcamera/v4l2_device.cpp       | 108 +++++++++++++++++++++-------\n 2 files changed, 89 insertions(+), 26 deletions(-)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 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);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex e42f6ef0c340..c9251da465af 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+\telse if (caps_.isMultiplanar())\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+\telse if (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 = 0;\n+\tformat->size.height = 0;\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 = 0;\n+\tformat->size.height = 0;\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@@ -573,6 +576,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 = {};\n","prefixes":["libcamera-devel","v2","3/6"]}