Show a patch.

GET /api/1.1/patches/1317/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1317,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1317/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1317/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/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": "<20190527090559.26549-7-jacopo@jmondi.org>",
    "date": "2019-05-27T09:05:59",
    "name": "[libcamera-devel,v2,6/6] POC: Don't merge: Access params and stat on IPU3",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "d37d8ceb55812d76f7ea07f2cce70d7fb86dae67",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": {
        "id": 15,
        "url": "https://patchwork.libcamera.org/api/1.1/users/15/?format=api",
        "username": "jmondi",
        "first_name": "Jacopo",
        "last_name": "Mondi",
        "email": "jacopo@jmondi.org"
    },
    "mbox": "https://patchwork.libcamera.org/patch/1317/mbox/",
    "series": [
        {
            "id": 329,
            "url": "https://patchwork.libcamera.org/api/1.1/series/329/?format=api",
            "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/1317/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1317/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 9BFDC61908\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 11:05:07 +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 C21AA6000C;\n\tMon, 27 May 2019 09:05:06 +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:59 +0200",
        "Message-Id": "<20190527090559.26549-7-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 6/6] POC: Don't merge: Access params\n\tand stat on IPU3",
        "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:07 -0000"
    },
    "content": "Proof of concept patch to demonstrate the ability to access the statistic\ngenerated by the ImgU and configure the ISP parameters.\n\nNot intended for merge.\n\nNot-Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 208 ++++++++++++++++++++++++++-\n 1 file changed, 202 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 05005c42106b..4c90c2081fbb 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -6,10 +6,12 @@\n  */\n \n #include <algorithm>\n+#include <cstdio>\n #include <iomanip>\n #include <memory>\n #include <vector>\n \n+#include <linux/intel-ipu3.h>\n #include <linux/media-bus-format.h>\n \n #include <libcamera/camera.h>\n@@ -33,6 +35,7 @@ class ImgUDevice\n {\n public:\n \tstatic constexpr unsigned int PAD_INPUT = 0;\n+\tstatic constexpr unsigned int PAD_PARAMS = 1;\n \tstatic constexpr unsigned int PAD_OUTPUT = 2;\n \tstatic constexpr unsigned int PAD_VF = 3;\n \tstatic constexpr unsigned int PAD_STAT = 4;\n@@ -89,11 +92,15 @@ public:\n \tImgUOutput output_;\n \tImgUOutput viewfinder_;\n \tImgUOutput stat_;\n-\t/* \\todo Add param video device for 3A tuning */\n+\tV4L2Device *params_;\n \n \tBufferPool vfPool_;\n \tBufferPool statPool_;\n+\tBufferPool paramsPool_;\n \tBufferPool outPool_;\n+\n+\tstd::vector<Buffer *> statBuffers;\n+\tstd::vector<Buffer *> paramsBuffers;\n };\n \n class CIO2Device\n@@ -154,6 +161,8 @@ public:\n \t}\n \n \tvoid imguOutputBufferReady(Buffer *buffer);\n+\tvoid statBufferReady(Buffer *buffer);\n+\tvoid paramsBufferReady(Buffer *buffer);\n \tvoid imguInputBufferReady(Buffer *buffer);\n \tvoid cio2BufferReady(Buffer *buffer);\n \n@@ -549,16 +558,49 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \t}\n \n \t/*\n-\t * Apply the largest available format to the stat node.\n-\t * \\todo Revise this when we'll actually use the stat node.\n+\t * Configure the statistics and parameter devices and subdevices.\n+\t *\n+\t * \\todo: This is the datasize calculation using pagesize() implemented\n+\t * in the Intel IPU3 Camera HAL.\n+\t *\n+\t * unsigned int page_size = getpagesize();\n+\t * unsigned int datasize = sizeof(struct ipu3_uapi_stats_3a) + page_size\n+\t *\t\t         - (sizeof(struct ipu3_uapi_stats_3a) % page_size);\n+\t *\n+\t * Find out why they do so, as v4l2_format.fmt.meta.datasize is\n+\t * said to be set by the driver by V4L2 specification\n \t */\n-\tStreamConfiguration statCfg = {};\n-\tstatCfg.size = cio2Format.size;\n \n-\tret = imgu->configureOutput(&imgu->stat_, statCfg);\n+\tV4L2SubdeviceFormat metaSubdevFormat = {};\n+\tV4L2DeviceFormat metaDeviceFormat = {};\n+\n+\tmetaSubdevFormat.mbus_code = V4L2_META_FMT_IPU3_STAT_3A;\n+\tret = imgu->imgu_->setFormat(ImgUDevice::PAD_STAT, &metaSubdevFormat);\n \tif (ret)\n \t\treturn ret;\n \n+\tmetaDeviceFormat.fourcc = V4L2_META_FMT_IPU3_STAT_3A;\n+\tret = imgu->stat_.dev->setFormat(&metaDeviceFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"ImgU stat format\" << metaDeviceFormat.toString();\n+\n+\tmetaSubdevFormat = {};\n+\tmetaDeviceFormat = {};\n+\n+\tmetaSubdevFormat.mbus_code = V4L2_META_FMT_IPU3_PARAMS;\n+\tret = imgu->imgu_->setFormat(ImgUDevice::PAD_PARAMS, &metaSubdevFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tmetaDeviceFormat.fourcc = V4L2_META_FMT_IPU3_PARAMS;\n+\tret = imgu->stat_.dev->setFormat(&metaDeviceFormat);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tLOG(IPU3, Debug) << \"ImgU  param format\" << metaDeviceFormat.toString();\n+\n \treturn 0;\n }\n \n@@ -601,6 +643,21 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,\n \tif (ret)\n \t\tgoto error;\n \n+\t/* Reserve the same number of buffers in the params node. */\n+\timgu->paramsPool_.createBuffers(bufferCount);\n+\tret = imgu->params_->exportBuffers(&imgu->paramsPool_);\n+\tif (ret)\n+\t\tgoto error;\n+\n+\t/*\n+\t * Store the available stat and param buffers in a vector and\n+\t * queue them at the opportune time.\n+\t */\n+\tfor (Buffer &b : imgu->stat_.pool->buffers())\n+\t\timgu->statBuffers.push_back(&b);\n+\tfor (Buffer &b : imgu->paramsPool_.buffers())\n+\t\timgu->paramsBuffers.push_back(&b);\n+\n \t/* Allocate buffers for each active stream. */\n \tfor (Stream *s : streams) {\n \t\tIPU3Stream *stream = static_cast<IPU3Stream *>(s);\n@@ -858,6 +915,10 @@ int PipelineHandlerIPU3::registerCameras()\n \t\t\t\t\t&IPU3CameraData::imguOutputBufferReady);\n \t\tdata->imgu_->viewfinder_.dev->bufferReady.connect(data.get(),\n \t\t\t\t\t&IPU3CameraData::imguOutputBufferReady);\n+\t\tdata->imgu_->stat_.dev->bufferReady.connect(data.get(),\n+\t\t\t\t\t&IPU3CameraData::statBufferReady);\n+\t\tdata->imgu_->params_->bufferReady.connect(data.get(),\n+\t\t\t\t\t&IPU3CameraData::paramsBufferReady);\n \n \t\t/* Create and register the Camera instance. */\n \t\tstd::string cameraName = cio2->sensor_->entity()->name() + \" \"\n@@ -919,15 +980,124 @@ void IPU3CameraData::imguOutputBufferReady(Buffer *buffer)\n \t}\n }\n \n+/**\n+ * \\brief Handle buffers completion at the ImgU statistics output\n+ * \\param[in] buffer The completed buffer\n+ *\n+ * HACK: this is just a proof of concept.\n+ * Inspect the statistics by printing a few of them out.\n+ */\n+void IPU3CameraData::statBufferReady(Buffer *buffer)\n+{\n+\tstruct ipu3_uapi_stats_3a *stats_3a =\n+\t\tstatic_cast<struct ipu3_uapi_stats_3a *>(buffer->planes()[0].mem());\n+\tstruct ipu3_uapi_awb_raw_buffer *raw_awb = &stats_3a->awb_raw_buffer;\n+\tuint8_t *awb_meta = raw_awb->meta_data;\n+\n+\t/*\n+\t * 'Inspect' stats and return the buffer to the vector of\n+\t * available ones. Print them out for visual inspection!\n+\t */\n+\tprintf(\"\\n\");\n+\tfor (unsigned int i = 0; i < IPU3_UAPI_AWB_MAX_BUFFER_SIZE; i++) {\n+\t\tif (!*awb_meta)\n+\t\t\tbreak;\n+\n+\t\tprintf(\"%u \", *awb_meta++);\n+\t}\n+\tprintf(\"\\n\");\n+\n+\timgu_->stat_.dev->queueBuffer(buffer);\n+}\n+\n+/**\n+ * \\brief Handle buffers completion at the ImgU parameters input\n+ * \\param[in] buffer The completed buffer\n+ *\n+ * The completed parameters buffer has been processed and can be returned\n+ * to the vector of available buffers.\n+ */\n+void IPU3CameraData::paramsBufferReady(Buffer *buffer)\n+{\n+\timgu_->paramsBuffers.push_back(buffer);\n+}\n+\n /**\n  * \\brief Handle buffers completion at the CIO2 output\n  * \\param[in] buffer The completed buffer\n  *\n  * Buffers completed from the CIO2 are immediately queued to the ImgU unit\n  * for further processing.\n+ *\n+ * HACK: apply a few parameters to the ImgU before queuing the image frame\n+ * for processing. This is just a proof of concept.\n  */\n void IPU3CameraData::cio2BufferReady(Buffer *buffer)\n {\n+\t/*\n+\t * If no buffer is available for parameter configuration, just\n+\t * queue the new image buffer to the ImgU.\n+\t *\n+\t * Otherwise prepare the parameter configuration buffer and provide\n+\t * it to the ImgU parameters node -before- the new image frame gets\n+\t * queued.\n+\t */\n+\tif (imgu_->paramsBuffers.empty()) {\n+\t\timgu_->input_->queueBuffer(buffer);\n+\t\treturn;\n+\t}\n+\n+\tauto b = imgu_->paramsBuffers.begin();\n+\tstruct ipu3_uapi_params *params = static_cast<struct ipu3_uapi_params *>\n+\t\t\t\t\t  ((*b)->planes()[0].mem());\n+\tstruct ipu3_uapi_acc_param *acc_param = &params->acc_param;\n+\tstruct ipu3_uapi_csc_mat_config *csc_mat = &acc_param->csc;\n+\n+\t/* Default CSC matrix values. Here just for reference. */\n+\tcsc_mat->coeff_c11 = 4898;\n+\tcsc_mat->coeff_c12 = 9617;\n+\tcsc_mat->coeff_c13 = 1867;\n+\tcsc_mat->coeff_b1 = 0;\n+\tcsc_mat->coeff_c21 = -2410;\n+\tcsc_mat->coeff_c22 = -4732;\n+\tcsc_mat->coeff_c23 = 7143;\n+\tcsc_mat->coeff_b2 = 0;\n+\tcsc_mat->coeff_c31 = 10076;\n+\tcsc_mat->coeff_c32 = -8437;\n+\tcsc_mat->coeff_c33 = -1638;\n+\tcsc_mat->coeff_b3 = 0;\n+\n+\t/*\n+\t * Halve the default CSC matrix coefficient and bias.\n+\t * The resulting image will have mangled colors (it's actually just\n+\t * 'darker' from local testings).\n+\t */\n+\tcsc_mat->coeff_c11 = 2449;\n+\tcsc_mat->coeff_c12 = 4809;\n+\tcsc_mat->coeff_c13 = 932;\n+\tcsc_mat->coeff_b1 = 0;\n+\tcsc_mat->coeff_c21 = -1205;\n+\tcsc_mat->coeff_c22 = -2312;\n+\tcsc_mat->coeff_c23 = 3571;\n+\tcsc_mat->coeff_b2 = 0;\n+\tcsc_mat->coeff_c31 = 5038;\n+\tcsc_mat->coeff_c32 = -4219;\n+\tcsc_mat->coeff_c33 = -819;\n+\tcsc_mat->coeff_b3 = 0;\n+\n+\tparams->use.acc_csc = 1;\n+\n+\timgu_->paramsBuffers.erase(b);\n+\tint ret = imgu_->params_->queueBuffer(*b);\n+\tif (ret) {\n+\t\tLOG(IPU3, Error) << \"Failed to queue parameters\";\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Once parameters have been applied, it's safe to provide the ImgU\n+\t * a new frame to process.\n+\t */\n \timgu_->input_->queueBuffer(buffer);\n }\n \n@@ -999,6 +1169,11 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index)\n \tstat_.name = \"stat\";\n \tstat_.pool = &statPool_;\n \n+\tparams_ = V4L2Device::fromEntityName(media, name_ + \" parameters\");\n+\tret = params_->open();\n+\tif (ret)\n+\t\treturn ret;\n+\n \treturn 0;\n }\n \n@@ -1154,6 +1329,10 @@ void ImgUDevice::freeBuffers()\n \tif (ret)\n \t\tLOG(IPU3, Error) << \"Failed to release ImgU viewfinder buffers\";\n \n+\tret = params_->releaseBuffers();\n+\tif (ret)\n+\t\tLOG(IPU3, Error) << \"Failed to release ImgU params buffers\";\n+\n \tret = input_->releaseBuffers();\n \tif (ret)\n \t\tLOG(IPU3, Error) << \"Failed to release ImgU input buffers\";\n@@ -1176,12 +1355,23 @@ int ImgUDevice::start()\n \t\treturn ret;\n \t}\n \n+\tfor (Buffer &b : stat_.pool->buffers()) {\n+\t\tint ret = stat_.dev->queueBuffer(&b);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t}\n \tret = stat_.dev->streamOn();\n \tif (ret) {\n \t\tLOG(IPU3, Error) << \"Failed to start ImgU stat\";\n \t\treturn ret;\n \t}\n \n+\tret = params_->streamOn();\n+\tif (ret) {\n+\t\tLOG(IPU3, Error) << \"Failed to start ImgU params\";\n+\t\treturn ret;\n+\t}\n+\n \tret = input_->streamOn();\n \tif (ret) {\n \t\tLOG(IPU3, Error) << \"Failed to start ImgU input\";\n@@ -1198,6 +1388,7 @@ int ImgUDevice::stop()\n \tret = output_.dev->streamOff();\n \tret |= viewfinder_.dev->streamOff();\n \tret |= stat_.dev->streamOff();\n+\tret |= params_->streamOff();\n \tret |= input_->streamOff();\n \n \treturn ret;\n@@ -1238,6 +1429,7 @@ int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad,\n int ImgUDevice::enableLinks(bool enable)\n {\n \tstd::string viewfinderName = name_ + \" viewfinder\";\n+\tstd::string paramsName = name_ + \" parameters\";\n \tstd::string outputName = name_ + \" output\";\n \tstd::string statName = name_ + \" 3a stat\";\n \tstd::string inputName = name_ + \" input\";\n@@ -1247,6 +1439,10 @@ int ImgUDevice::enableLinks(bool enable)\n \tif (ret)\n \t\treturn ret;\n \n+\tret = linkSetup(paramsName, 0, name_, PAD_PARAMS, enable);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tret = linkSetup(name_, PAD_OUTPUT, outputName, 0, enable);\n \tif (ret)\n \t\treturn ret;\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "6/6"
    ]
}