{"id":11176,"url":"https://patchwork.libcamera.org/api/patches/11176/?format=json","web_url":"https://patchwork.libcamera.org/patch/11176/","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":"<20210205131044.512128-3-helen.koike@collabora.com>","date":"2021-02-05T13:10:43","name":"[libcamera-devel,RFC,2/3] libcamera: Use VIDIOC_{S, G, TRY}_EXT_PIX_FMT API","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2a501268d1a42d23298376c2d814c2a105c257f4","submitter":{"id":20,"url":"https://patchwork.libcamera.org/api/people/20/?format=json","name":"Helen Koike","email":"helen.koike@collabora.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11176/mbox/","series":[{"id":1657,"url":"https://patchwork.libcamera.org/api/series/1657/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1657","date":"2021-02-05T13:10:41","name":"libcamera: Use extended fmt and buffer ioctls API","version":1,"mbox":"https://patchwork.libcamera.org/series/1657/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11176/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11176/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 43052BD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  5 Feb 2021 13:11:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1CDFE614B1;\n\tFri,  5 Feb 2021 14:11:04 +0100 (CET)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EE64614B0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  5 Feb 2021 14:11:03 +0100 (CET)","from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: koike) with ESMTPSA id 781101F466AB"],"From":"Helen Koike <helen.koike@collabora.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  5 Feb 2021 10:10:43 -0300","Message-Id":"<20210205131044.512128-3-helen.koike@collabora.com>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210205131044.512128-1-helen.koike@collabora.com>","References":"<20210205131044.512128-1-helen.koike@collabora.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH 2/3] libcamera: Use VIDIOC_{S, G,\n\tTRY}_EXT_PIX_FMT API","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>","Cc":"kieran.bingham+renesas@ideasonboard.com, frkoenig@chromium.org,\n\tkernel@collabora.com","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Use Ext API for format negotiation.\nUnify multi vs single planar handling, prepare to use modifiers.\n\nSigned-off-by: Helen Koike <helen.koike@collabora.com>\n---\n include/libcamera/internal/v4l2_videodevice.h |   8 +-\n src/libcamera/pipeline/ipu3/cio2.cpp          |   1 -\n src/libcamera/pipeline/ipu3/imgu.cpp          |   1 -\n .../pipeline/raspberrypi/raspberrypi.cpp      |   4 +\n src/libcamera/pipeline/rkisp1/rkisp1_path.cpp |   4 +-\n src/libcamera/pipeline/simple/converter.cpp   |   6 +-\n src/libcamera/pipeline/simple/simple.cpp      |   8 +-\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp  |   2 +\n src/libcamera/pipeline/vimc/vimc.cpp          |   2 +\n src/libcamera/v4l2_videodevice.cpp            | 183 ++++++------------\n 10 files changed, 75 insertions(+), 144 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex 626dfbcd..d2de44c0 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -163,7 +163,6 @@ public:\n \tSize size;\n \n \tstd::array<Plane, 3> planes;\n-\tunsigned int planesCount = 0;\n \n \tconst std::string toString() const;\n };\n@@ -222,11 +221,8 @@ private:\n \tint getFormatMeta(V4L2DeviceFormat *format);\n \tint trySetFormatMeta(V4L2DeviceFormat *format, bool set);\n \n-\tint getFormatMultiplane(V4L2DeviceFormat *format);\n-\tint trySetFormatMultiplane(V4L2DeviceFormat *format, bool set);\n-\n-\tint getFormatSingleplane(V4L2DeviceFormat *format);\n-\tint trySetFormatSingleplane(V4L2DeviceFormat *format, bool set);\n+\tint getFormatExt(V4L2DeviceFormat *format);\n+\tint trySetFormatExt(V4L2DeviceFormat *format, bool set);\n \n \tstd::vector<V4L2PixelFormat> enumPixelformats(uint32_t code);\n \tstd::vector<SizeRange> enumSizes(V4L2PixelFormat pixelFormat);\ndiff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\nindex 0ef3bc04..ea0c2b59 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.cpp\n+++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n@@ -184,7 +184,6 @@ int CIO2Device::configure(const Size &size, V4L2DeviceFormat *outputFormat)\n \n \toutputFormat->fourcc = info.v4l2Format;\n \toutputFormat->size = sensorFormat.size;\n-\toutputFormat->planesCount = 1;\n \n \tret = output_->setFormat(outputFormat);\n \tif (ret)\ndiff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\nindex d5cf05b0..7684b466 100644\n--- a/src/libcamera/pipeline/ipu3/imgu.cpp\n+++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n@@ -527,7 +527,6 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad,\n \t*outputFormat = {};\n \toutputFormat->fourcc = dev->toV4L2PixelFormat(formats::NV12);\n \toutputFormat->size = cfg.size;\n-\toutputFormat->planesCount = 2;\n \n \tret = dev->setFormat(outputFormat);\n \tif (ret)\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 0804a439..5f7a1488 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -373,6 +373,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \n \t\t\tcfg.stride = sensorFormat.planes[0].bpl;\n \t\t\tcfg.frameSize = sensorFormat.planes[0].size;\n+\t\t\tfor (unsigned int i = 1; i < sensorFormat.planes.size(); ++i)\n+\t\t\t\tcfg.frameSize += sensorFormat.planes[i].size;\n \n \t\t\trawCount++;\n \t\t} else {\n@@ -445,6 +447,8 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \n \t\tcfg.stride = format.planes[0].bpl;\n \t\tcfg.frameSize = format.planes[0].size;\n+\t\tfor (unsigned int j = 1; j < format.planes.size(); ++j)\n+\t\t\tcfg.frameSize += format.planes[j].size;\n \n \t}\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\nindex 25f482eb..adea5590 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n@@ -89,6 +89,8 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg)\n \n \tcfg->stride = format.planes[0].bpl;\n \tcfg->frameSize = format.planes[0].size;\n+\tfor (unsigned int i = 1; i < format.planes.size(); ++i)\n+\t\tcfg->frameSize += format.planes[i].size;\n \n \tif (cfg->pixelFormat != reqCfg.pixelFormat || cfg->size != reqCfg.size) {\n \t\tLOG(RkISP1, Debug)\n@@ -144,11 +146,9 @@ int RkISP1Path::configure(const StreamConfiguration &config,\n \t\t<< \"Configured \" << name_ << \" resizer output pad with \"\n \t\t<< ispFormat.toString();\n \n-\tconst PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat);\n \tV4L2DeviceFormat outputFormat;\n \toutputFormat.fourcc = video_->toV4L2PixelFormat(config.pixelFormat);\n \toutputFormat.size = config.size;\n-\toutputFormat.planesCount = info.numPlanes();\n \n \tret = video_->setFormat(&outputFormat);\n \tif (ret)\ndiff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp\nindex a6a8e139..ccdd30cf 100644\n--- a/src/libcamera/pipeline/simple/converter.cpp\n+++ b/src/libcamera/pipeline/simple/converter.cpp\n@@ -263,12 +263,16 @@ SimpleConverter::strideAndFrameSize(const Size &size,\n \tV4L2DeviceFormat format;\n \tformat.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat);\n \tformat.size = size;\n+\tuint32_t frameSize = 0;\n \n \tint ret = m2m_->capture()->tryFormat(&format);\n \tif (ret < 0)\n \t\treturn std::make_tuple(0, 0);\n \n-\treturn std::make_tuple(format.planes[0].bpl, format.planes[0].size);\n+\tfor (unsigned int i = 0; i < format.planes.size(); ++i)\n+\t\tframeSize += format.planes[i].size;\n+\n+\treturn std::make_tuple(format.planes[0].bpl, frameSize);\n }\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 23320d26..97111d30 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -487,6 +487,8 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n \n \t\tcfg.stride = format.planes[0].bpl;\n \t\tcfg.frameSize = format.planes[0].size;\n+\t\tfor (unsigned int i = 1; i < format.planes.size(); ++i)\n+\t\t\tcfg.frameSize += format.planes[i].size;\n \n \t\treturn status;\n \t}\n@@ -590,12 +592,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n \tif (ret)\n \t\treturn ret;\n \n-\tif (captureFormat.planesCount != 1) {\n-\t\tLOG(SimplePipeline, Error)\n-\t\t\t<< \"Planar formats using non-contiguous memory not supported\";\n-\t\treturn -EINVAL;\n-\t}\n-\n \tif (captureFormat.fourcc != videoFormat ||\n \t    captureFormat.size != pipeConfig.captureSize) {\n \t\tLOG(SimplePipeline, Error)\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 08a59417..136399b6 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -160,6 +160,8 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()\n \n \tcfg.stride = format.planes[0].bpl;\n \tcfg.frameSize = format.planes[0].size;\n+\tfor (unsigned int i = 1; i < format.planes.size(); ++i)\n+\t\tcfg.frameSize += format.planes[i].size;\n \n \treturn status;\n }\ndiff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex 36325ffb..d42c9ec0 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -171,6 +171,8 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()\n \n \tcfg.stride = format.planes[0].bpl;\n \tcfg.frameSize = format.planes[0].size;\n+\tfor (unsigned int i = 1; i < format.planes.size(); ++i)\n+\t\tcfg.frameSize += format.planes[i].size;\n \n \treturn status;\n }\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex c77e1aff..fab3ba4c 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -337,27 +337,24 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n  * stride length and size, but only a global stride length which is applied to\n  * all planes.\n  *\n- * The V4L2DeviceFormat class describes both packed and planar image formats,\n- * regardless of the API type (single or multi plane) implemented by the video\n- * device the format has to be applied to. The total size and bytes per line\n- * of images represented with packed formats are configured using the first\n- * entry of the V4L2DeviceFormat::planes array, while the per-plane size and\n- * per-plane stride length of images represented with planar image formats are\n- * configured using the opportune number of entries of the\n- * V4L2DeviceFormat::planes array, as prescribed by the image format\n- * definition (semi-planar formats use 2 entries, while planar formats use the\n- * whole 3 entries). The number of valid entries of the\n- * V4L2DeviceFormat::planes array is defined by the\n- * V4L2DeviceFormat::planesCount value.\n+ * The V4L2DeviceFormat class describes formats per color component and not\n+ * memory planes. Even if a single memory buffer is used, color planes are still\n+ * described separately.\n+ * The size and bytes per line of each color component is defined separately\n+ * with the V4L2DeviceFormat:::planes array.\n+ * Except for metadata, this class uses the Ext API that unifies the\n+ * multiplanar and single planar API.\n+ * The number of valid entries of the V4L2DeviceFormat::planes array is defined\n+ * by the number of non-zero bytesperline field, up to 3 planes.\n  */\n \n /**\n  * \\struct V4L2DeviceFormat::Plane\n- * \\brief Per-plane memory size information\n+ * \\brief Per color plane size information\n  * \\var V4L2DeviceFormat::Plane::size\n- * \\brief The plane total memory size (in bytes)\n+ * \\brief The color plane total memory size (in bytes)\n  * \\var V4L2DeviceFormat::Plane::bpl\n- * \\brief The plane line stride (in bytes)\n+ * \\brief The color plane line stride (in bytes)\n  */\n \n /**\n@@ -375,17 +372,11 @@ bool V4L2BufferCache::Entry::operator==(const FrameBuffer &buffer) const\n \n /**\n  * \\var V4L2DeviceFormat::planes\n- * \\brief The per-plane memory size information\n+ * \\brief The per color plane memory size information\n  *\n  * Images are stored in memory in one or more data planes. Each data plane has a\n  * specific line stride and memory size, which could differ from the image\n  * visible sizes to accommodate padding at the end of lines and end of planes.\n- * Only the first \\ref planesCount entries are considered valid.\n- */\n-\n-/**\n- * \\var V4L2DeviceFormat::planesCount\n- * \\brief The number of valid data planes\n  */\n \n /**\n@@ -723,10 +714,8 @@ int V4L2VideoDevice::getFormat(V4L2DeviceFormat *format)\n {\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+\t\treturn getFormatExt(format);\n }\n \n /**\n@@ -743,10 +732,8 @@ int V4L2VideoDevice::tryFormat(V4L2DeviceFormat *format)\n {\n \tif (caps_.isMeta())\n \t\treturn trySetFormatMeta(format, false);\n-\telse if (caps_.isMultiplanar())\n-\t\treturn trySetFormatMultiplane(format, false);\n \telse\n-\t\treturn trySetFormatSingleplane(format, false);\n+\t\treturn trySetFormatExt(format, false);\n }\n \n /**\n@@ -762,10 +749,8 @@ int V4L2VideoDevice::setFormat(V4L2DeviceFormat *format)\n {\n \tif (caps_.isMeta())\n \t\treturn trySetFormatMeta(format, true);\n-\telse if (caps_.isMultiplanar())\n-\t\treturn trySetFormatMultiplane(format, true);\n \telse\n-\t\treturn trySetFormatSingleplane(format, true);\n+\t\treturn trySetFormatExt(format, true);\n }\n \n int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n@@ -784,9 +769,12 @@ int V4L2VideoDevice::getFormatMeta(V4L2DeviceFormat *format)\n \tformat->size.width = 0;\n \tformat->size.height = 0;\n \tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n-\tformat->planesCount = 1;\n \tformat->planes[0].bpl = pix->buffersize;\n \tformat->planes[0].size = pix->buffersize;\n+\tfor (unsigned int i = 1; i < format->planes.size(); ++i) {\n+\t\tformat->planes[i].bpl = 0;\n+\t\tformat->planes[i].size = 0;\n+\t}\n \n \treturn 0;\n }\n@@ -800,6 +788,8 @@ int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n \tv4l2Format.type = bufferType_;\n \tpix->dataformat = format->fourcc;\n \tpix->buffersize = format->planes[0].size;\n+\tfor (unsigned int i = 1; i < format->planes.size(); ++i)\n+\t\tpix->buffersize += format->planes[i].size;\n \tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n@@ -815,122 +805,60 @@ int V4L2VideoDevice::trySetFormatMeta(V4L2DeviceFormat *format, bool set)\n \tformat->size.width = 0;\n \tformat->size.height = 0;\n \tformat->fourcc = V4L2PixelFormat(pix->dataformat);\n-\tformat->planesCount = 1;\n \tformat->planes[0].bpl = pix->buffersize;\n \tformat->planes[0].size = pix->buffersize;\n+\tfor (unsigned int i = 1; i < format->planes.size(); ++i) {\n+\t\tformat->planes[i].bpl = 0;\n+\t\tformat->planes[i].size = 0;\n+\t}\n \n \treturn 0;\n }\n \n-int V4L2VideoDevice::getFormatMultiplane(V4L2DeviceFormat *format)\n+int V4L2VideoDevice::getFormatExt(V4L2DeviceFormat *format)\n {\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n+\tstruct v4l2_ext_pix_format v4l2FormatExt = {};\n \tint ret;\n \n-\tv4l2Format.type = bufferType_;\n-\tret = ioctl(VIDIOC_G_FMT, &v4l2Format);\n+\tv4l2FormatExt.type = bufferType_;\n+\tret = ioctl(VIDIOC_G_EXT_PIX_FMT, &v4l2FormatExt);\n \tif (ret) {\n-\t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n+\t\tLOG(V4L2, Error) << \"Unable to get format ext: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n \n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = V4L2PixelFormat(pix->pixelformat);\n-\tformat->planesCount = pix->num_planes;\n+\tformat->size.width = v4l2FormatExt.width;\n+\tformat->size.height = v4l2FormatExt.height;\n+\tformat->fourcc = V4L2PixelFormat(v4l2FormatExt.pixelformat);\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+\tfor (unsigned int i = 0; i < format->planes.size(); ++i) {\n+\t\tformat->planes[i].bpl = v4l2FormatExt.plane_fmt[i].bytesperline;\n+\t\tformat->planes[i].size = v4l2FormatExt.plane_fmt[i].sizeimage;\n \t}\n \n \treturn 0;\n }\n \n-int V4L2VideoDevice::trySetFormatMultiplane(V4L2DeviceFormat *format, bool set)\n+int V4L2VideoDevice::trySetFormatExt(V4L2DeviceFormat *format, bool set)\n {\n-\tstruct v4l2_format v4l2Format = {};\n-\tstruct v4l2_pix_format_mplane *pix = &v4l2Format.fmt.pix_mp;\n+\tstruct v4l2_ext_pix_format v4l2FormatExt = {};\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->num_planes = format->planesCount;\n-\tpix->field = V4L2_FIELD_NONE;\n-\n-\tASSERT(pix->num_planes <= std::size(pix->plane_fmt));\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-\t}\n-\n-\tret = ioctl(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n-\tif (ret) {\n-\t\tLOG(V4L2, Error)\n-\t\t\t<< \"Unable to \" << (set ? \"set\" : \"try\")\n-\t\t\t<< \" format: \" << strerror(-ret);\n-\t\treturn ret;\n-\t}\n-\n-\t/*\n-\t * Return to caller the format actually applied on the video 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 = V4L2PixelFormat(pix->pixelformat);\n-\tformat->planesCount = pix->num_planes;\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-\t}\n-\n-\treturn 0;\n-}\n+\tv4l2FormatExt.type = bufferType_;\n+\tv4l2FormatExt.width = format->size.width;\n+\tv4l2FormatExt.height = format->size.height;\n+\tv4l2FormatExt.pixelformat = format->fourcc;\n+\tv4l2FormatExt.field = V4L2_FIELD_NONE;\n \n-int V4L2VideoDevice::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(VIDIOC_G_FMT, &v4l2Format);\n-\tif (ret) {\n-\t\tLOG(V4L2, Error) << \"Unable to get format: \" << strerror(-ret);\n-\t\treturn ret;\n+\tfor (unsigned int i = 0; i < format->planes.size(); ++i) {\n+\t\tv4l2FormatExt.plane_fmt[i].bytesperline = format->planes[i].bpl;\n+\t\tv4l2FormatExt.plane_fmt[i].sizeimage = format->planes[i].size;\n \t}\n \n-\tformat->size.width = pix->width;\n-\tformat->size.height = pix->height;\n-\tformat->fourcc = V4L2PixelFormat(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 V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\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(set ? VIDIOC_S_FMT : VIDIOC_TRY_FMT, &v4l2Format);\n+\tret = ioctl(set ? VIDIOC_S_EXT_PIX_FMT : VIDIOC_TRY_EXT_PIX_FMT, &v4l2FormatExt);\n \tif (ret) {\n \t\tLOG(V4L2, Error)\n-\t\t\t<< \"Unable to \" << (set ? \"set\" : \"try\")\n+\t\t\t<< \"Unable to \" << (set ? \"set ext pix\" : \"try ext pi\")\n \t\t\t<< \" format: \" << strerror(-ret);\n \t\treturn ret;\n \t}\n@@ -939,12 +867,13 @@ int V4L2VideoDevice::trySetFormatSingleplane(V4L2DeviceFormat *format, bool set)\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 = V4L2PixelFormat(pix->pixelformat);\n-\tformat->planesCount = 1;\n-\tformat->planes[0].bpl = pix->bytesperline;\n-\tformat->planes[0].size = pix->sizeimage;\n+\tformat->size.width = v4l2FormatExt.width;\n+\tformat->size.height = v4l2FormatExt.height;\n+\tformat->fourcc = V4L2PixelFormat(v4l2FormatExt.pixelformat);\n+\tfor (unsigned int i = 0; i < format->planes.size(); ++i) {\n+\t\tformat->planes[i].bpl = v4l2FormatExt.plane_fmt[i].bytesperline;\n+\t\tformat->planes[i].size = v4l2FormatExt.plane_fmt[i].sizeimage;\n+\t}\n \n \treturn 0;\n }\n","prefixes":["libcamera-devel","RFC","2/3"]}