Patch Detail
Show a patch.
GET /api/patches/19012/?format=api
{ "id": 19012, "url": "https://patchwork.libcamera.org/api/patches/19012/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19012/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230915-libyuv-convert-v1-6-1e5bcf68adac@baylibre.com>", "date": "2023-09-15T07:57:30", "name": "[libcamera-devel,RFC,6/7] android: yuv: add YUYV -> NV12 conversion", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "ee4d5562232d44c8574c9bd0923e761f24843523", "submitter": { "id": 153, "url": "https://patchwork.libcamera.org/api/people/153/?format=api", "name": "Mattijs Korpershoek", "email": "mkorpershoek@baylibre.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19012/mbox/", "series": [ { "id": 4023, "url": "https://patchwork.libcamera.org/api/series/4023/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4023", "date": "2023-09-15T07:57:24", "name": "android: add YUYV->NV12 conversion via libyuv", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4023/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19012/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19012/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 199D9C32B1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Sep 2023 07:57:37 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C643562922;\n\tFri, 15 Sep 2023 09:57:36 +0200 (CEST)", "from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com\n\t[IPv6:2a00:1450:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E29616291E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 09:57:31 +0200 (CEST)", "by mail-wr1-x42a.google.com with SMTP id\n\tffacd0b85a97d-31dd10c2b8bso1649808f8f.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Sep 2023 00:57:31 -0700 (PDT)", "from [192.168.1.20] ([2a01:cb19:8704:be00:4f55:bd9d:611a:6c8e])\n\tby smtp.gmail.com with ESMTPSA id\n\tm2-20020a056000174200b0031fe9a47a87sm2506942wrf.112.2023.09.15.00.57.30\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 15 Sep 2023 00:57:31 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1694764656;\n\tbh=IBL60Z2Vz20HmwGlky/i1f7Jcbli+IO2LFw0N0ieF8k=;\n\th=Date:References:In-Reply-To:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=tGEMjS5divFR3Adetvs4JyvQAnEvP8lmDxjdaY55gGNYybSlJSEGC9tCryAjqgRDw\n\twH48RuCMX2MW3UYxUbig19jodA5c+yyXjShkSbmpLX+cqXm35JEu5XDyuj5EWljYsr\n\tGs/AG9nN3ywhPFotZAH+afFL3+KBfRQUsy643lDry2QMpgzHbmn+mGzV7QV5Z7FR1d\n\t/QOdluB7GfbjjJ35Ywhqb9A4J9K1aqv9rX6tRSJcVv/SRNvyhaSzXpkLbmOkA0+cnV\n\txXsh10zLp23jDyqLVjptpfJVi8/+dtMWQAXgygmNhBLToQuP8buKSgSu6Ud96pZIcC\n\tWuNhkBBnldlZA==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1694764651;\n\tx=1695369451; darn=lists.libcamera.org; \n\th=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n\t:mime-version:subject:date:from:from:to:cc:subject:date:message-id\n\t:reply-to; bh=xovdNtMrWbtfBJY3joA+lnakbzSinm4xINrzUSJhrX8=;\n\tb=lkKojsLjb5hyBeopBpzA6oqAyb/3h6ES6TUUxsaGZ8Aac+NXSWr5xP0Geu4dC1GBb2\n\tKyDMuEgI4RX1yu5nhcvMojLGl4lbSUaZicjnbuzCtdl4iStdWyWMjcq9xb6+0zev1df6\n\tZAPgb94bgH4iGhGCwIWhhzbxMRn9UgAfu4VcIpF3B0XSQOGQAPd2reLtSjTQT8dPOSeF\n\tKvSgxuiJCOERGhHeoQmNyxtqmcrODTyaaKa7LRfYPE2EAcD7Sgp6+gGwAeALAhbQ+bEr\n\tyQUO/aKk4dym4aBf+S/d4d4i3ZIFUscjam1+t5O9oswO4TKPlgB3IRgVI6KKuMiCtnFu\n\t4rPg==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20230601.gappssmtp.com\n\theader.i=@baylibre-com.20230601.gappssmtp.com header.b=\"lkKojsLj\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1694764651; x=1695369451;\n\th=cc:to:in-reply-to:references:message-id:content-transfer-encoding\n\t:mime-version:subject:date:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=xovdNtMrWbtfBJY3joA+lnakbzSinm4xINrzUSJhrX8=;\n\tb=aPOcGSePnJps5ECJVMv2FH/kI7SGJMM/vjeJ4Matw/sbivVMoYNZtFr5HyYztg7UWf\n\t+L32YoQjPxzDPoIk12vLD3Eodv/eJsPsS3C8Q6XWwZZQG52wxldvH4P7Uk6lj+tThVxC\n\tqJNihZuOEg2M5+Hp7aBM/FvfXEp6YmlpFl8WyryAYFTxh2HhYXJFtvTD7JQGIAWdOfKv\n\tILfY1dAXKzilYMXYTrZsKvy6mRZ7CRA/xIK63II7GziAh/s+KH1Oq0ub2bOSrxfXCvWZ\n\tWUfi307NLdA+AZZAicDnRBdP4mvTnjEdUoRqnqP1vRJgqQ7/zhbCm3LoqA8HBecJbpLS\n\tlWPA==", "X-Gm-Message-State": "AOJu0YwFGtg4jL/80bFZbH/BE14scfIRkC5hMFVwqQjKuK851MplT6JT\n\tId/gOLskM92r/tPx35SCOHl+o/3oEj97f77/4fw=", "X-Google-Smtp-Source": "AGHT+IE7DLoHjaO1Dpz99bNJFqTaqJW3nSxT40SOP8pdS7dcLdsr+utje8ItLsiajfLsuRrD4mEzvg==", "X-Received": "by 2002:adf:fc8c:0:b0:319:7fdc:d15f with SMTP id\n\tg12-20020adffc8c000000b003197fdcd15fmr800723wrr.26.1694764651355; \n\tFri, 15 Sep 2023 00:57:31 -0700 (PDT)", "Date": "Fri, 15 Sep 2023 09:57:30 +0200", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20230915-libyuv-convert-v1-6-1e5bcf68adac@baylibre.com>", "References": "<20230915-libyuv-convert-v1-0-1e5bcf68adac@baylibre.com>", "In-Reply-To": "<20230915-libyuv-convert-v1-0-1e5bcf68adac@baylibre.com>", "To": "libcamera-devel@lists.libcamera.org", "X-Mailer": "b4 0.12.4-dev-6aa5d", "Subject": "[libcamera-devel] [PATCH RFC 6/7] android: yuv: add YUYV -> NV12\n\tconversion", "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>", "From": "Mattijs Korpershoek via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Mattijs Korpershoek <mkorpershoek@baylibre.com>", "Cc": "Guillaume La Roque <glaroque@baylibre.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "On am62x platforms, the receiver driver (j721e-csi2rx) only\nsupports packed YUV422 formats such as YUYV, YVYU, UYVY and VYUY.\n\nThe receiver and the sensor (ov5640) hardware are both capable of\nYUV420, however:\n\n* we are not aware of OV5640 being tested with YUV420 formats on any\n vendor tree.\n* NV12 has different line lines (even lines are twice as long as odd\n lines) Different line-sized DMA transfers have not been tested on\n the TI CSI-RX SHIM IP.\n\nOn the other hand, the graphics allocator (gralloc) cannot allocate\nYUV422 buffers directly. It mainly allocated NV12 buffers when\nuserspace requests HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.\n\nBecause of the above, we need a pixel conversion from YUYV to NV12,\nwhich is handled in the yuv processor via libyuv.\n\nSigned-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n---\n src/android/yuv/post_processor_yuv.cpp | 91 +++++++++++++++++++++++++---------\n 1 file changed, 68 insertions(+), 23 deletions(-)", "diff": "diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp\nindex 734bb85b7351..b680b833dafb 100644\n--- a/src/android/yuv/post_processor_yuv.cpp\n+++ b/src/android/yuv/post_processor_yuv.cpp\n@@ -7,6 +7,9 @@\n \n #include \"post_processor_yuv.h\"\n \n+#include <utility>\n+\n+#include <libyuv/convert.h>\n #include <libyuv/scale.h>\n \n #include <libcamera/base/log.h>\n@@ -22,14 +25,42 @@ using namespace libcamera;\n \n LOG_DEFINE_CATEGORY(YUV)\n \n+namespace {\n+\n+/**\n+ * \\var supportedConversions\n+ * \\brief list of supported output pixel formats for an input pixel format\n+ */\n+const std::map<PixelFormat, const std::vector<PixelFormat>> supportedConversions = {\n+\t{ formats::YUYV, { formats::NV12 } },\n+};\n+\n+} /* namespace */\n+\n int PostProcessorYuv::configure(const StreamConfiguration &inCfg,\n \t\t\t\tconst StreamConfiguration &outCfg)\n {\n \tif (inCfg.pixelFormat != outCfg.pixelFormat) {\n-\t\tLOG(YUV, Error) << \"Pixel format conversion is not supported\"\n-\t\t\t\t<< \" (from \" << inCfg.pixelFormat\n-\t\t\t\t<< \" to \" << outCfg.pixelFormat << \")\";\n-\t\treturn -EINVAL;\n+\t\tconst auto it = supportedConversions.find(inCfg.pixelFormat);\n+\t\tif (it == supportedConversions.end()) {\n+\t\t\tLOG(YUV, Error) << \"Unsupported source format \" << inCfg.pixelFormat;\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tstd::vector<PixelFormat> outFormats = it->second;\n+\t\tconst auto &match = std::find(outFormats.begin(), outFormats.end(), outCfg.pixelFormat);\n+\t\tif (match == outFormats.end()) {\n+\t\t\tLOG(YUV, Error) << \"Requested pixel format conversion is not supported\"\n+\t\t\t\t\t<< \" (from \" << inCfg.pixelFormat\n+\t\t\t\t\t<< \" to \" << outCfg.pixelFormat << \")\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t} else {\n+\t\tif (inCfg.pixelFormat != formats::NV12) {\n+\t\t\tLOG(YUV, Error) << \"Unsupported format \" << inCfg.pixelFormat\n+\t\t\t\t\t<< \" (only NV12 is supported for scaling)\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n \t}\n \n \tif (inCfg.size < outCfg.size) {\n@@ -39,12 +70,6 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,\n \t\treturn -EINVAL;\n \t}\n \n-\tif (inCfg.pixelFormat != formats::NV12) {\n-\t\tLOG(YUV, Error) << \"Unsupported format \" << inCfg.pixelFormat\n-\t\t\t\t<< \" (only NV12 is supported)\";\n-\t\treturn -EINVAL;\n-\t}\n-\n \tcalculateLengths(inCfg, outCfg);\n \treturn 0;\n }\n@@ -66,20 +91,40 @@ void PostProcessorYuv::process(Camera3RequestDescriptor::StreamBuffer *streamBuf\n \t\treturn;\n \t}\n \n-\tint ret = libyuv::NV12Scale(sourceMapped.planes()[0].data(),\n-\t\t\t\t sourceStride_[0],\n-\t\t\t\t sourceMapped.planes()[1].data(),\n-\t\t\t\t sourceStride_[1],\n-\t\t\t\t sourceSize_.width, sourceSize_.height,\n-\t\t\t\t destination->plane(0).data(),\n-\t\t\t\t destinationStride_[0],\n-\t\t\t\t destination->plane(1).data(),\n-\t\t\t\t destinationStride_[1],\n-\t\t\t\t destinationSize_.width,\n-\t\t\t\t destinationSize_.height,\n-\t\t\t\t libyuv::FilterMode::kFilterBilinear);\n+\tint ret = 0;\n+\tswitch (sourceFormat_) {\n+\tcase formats::NV12:\n+\t\tret = libyuv::NV12Scale(sourceMapped.planes()[0].data(),\n+\t\t\t\t\tsourceStride_[0],\n+\t\t\t\t\tsourceMapped.planes()[1].data(),\n+\t\t\t\t\tsourceStride_[1],\n+\t\t\t\t\tsourceSize_.width, sourceSize_.height,\n+\t\t\t\t\tdestination->plane(0).data(),\n+\t\t\t\t\tdestinationStride_[0],\n+\t\t\t\t\tdestination->plane(1).data(),\n+\t\t\t\t\tdestinationStride_[1],\n+\t\t\t\t\tdestinationSize_.width,\n+\t\t\t\t\tdestinationSize_.height,\n+\t\t\t\t\tlibyuv::FilterMode::kFilterBilinear);\n+\t\tbreak;\n+\tcase formats::YUYV:\n+\t\tret = libyuv::YUY2ToNV12(sourceMapped.planes()[0].data(),\n+\t\t\t\t\t sourceStride_[0],\n+\t\t\t\t\t destination->plane(0).data(),\n+\t\t\t\t\t destinationStride_[0],\n+\t\t\t\t\t destination->plane(1).data(),\n+\t\t\t\t\t destinationStride_[1],\n+\t\t\t\t\t destinationSize_.width,\n+\t\t\t\t\t destinationSize_.height);\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(YUV, Error) << \"Unsupported source format \" << sourceFormat_;\n+\t\tprocessComplete.emit(streamBuffer, PostProcessor::Status::Error);\n+\t\tbreak;\n+\t}\n+\n \tif (ret) {\n-\t\tLOG(YUV, Error) << \"Failed NV12 scaling: \" << ret;\n+\t\tLOG(YUV, Error) << \"Libyuv operation failure: \" << ret;\n \t\tprocessComplete.emit(streamBuffer, PostProcessor::Status::Error);\n \t\treturn;\n \t}\n", "prefixes": [ "libcamera-devel", "RFC", "6/7" ] }