[{"id":2548,"web_url":"https://patchwork.libcamera.org/comment/2548/","msgid":"<c96ec863-9c43-c98a-1d6d-314dddb6f24c@ideasonboard.com>","date":"2019-08-29T15:16:06","subject":"Re: [libcamera-devel] [PATCH 12/13] libcamera: ipa: rkisp1: Add\n\tbasic control of auto exposure","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Niklas,\n\nOn 28/08/2019 02:17, Niklas Söderlund wrote:\n> Add an IPA which controls the exposure time and analog gain for a sensor\n> connected to the rkisp1 pipeline. The IPA supports turning AE on and off\n> but lacks the support to inform the camera of the status of the AE\n> control loop.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  src/ipa/ipa_rkisp1.cpp | 165 +++++++++++++++++++++++++++++++++++++++++\n>  src/ipa/meson.build    |   1 +\n>  2 files changed, 166 insertions(+)\n>  create mode 100644 src/ipa/ipa_rkisp1.cpp\n> \n> diff --git a/src/ipa/ipa_rkisp1.cpp b/src/ipa/ipa_rkisp1.cpp\n> new file mode 100644\n> index 0000000000000000..950efb244cfe7879\n> --- /dev/null\n> +++ b/src/ipa/ipa_rkisp1.cpp\n> @@ -0,0 +1,165 @@\n> +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * ipa_rkisp1.cpp - RkISP1 Image Processing Algorithms\n> + */\n> +\n> +#include <algorithm>\n> +#include <string.h>\n> +\n> +#include <linux/rkisp1-config.h>\n> +\n> +#include <libcamera/buffer.h>\n> +#include <libcamera/ipa/ipa_interface.h>\n> +#include <libcamera/ipa/ipa_module_info.h>\n> +#include <libcamera/request.h>\n> +\n> +#include \"log.h\"\n> +#include \"utils.h\"\n> +\n> +namespace libcamera {\n> +\n> +LOG_DEFINE_CATEGORY(IPARkISP1)\n> +\n> +class IPARkISP1 : public IPAInterface\n> +{\n> +public:\n> +\tint initSensor(const V4L2ControlInfoMap &controls) override;\n> +\tvoid processRequest(const void *cookie, const ControlList &controls,\n> +\t\t\t    Buffer &parameters) override;\n> +\tvoid updateStatistics(const void *cookie, Buffer &statistics) override;\n> +\n> +private:\n> +\tvoid setControls();\n> +\n> +\tuint64_t statFrame_;\n> +\n> +\t/* Camera sensor controls. */\n> +\tbool autoExposure_;\n> +\tuint64_t exposure_;\n> +\tuint64_t minExposure_;\n> +\tuint64_t maxExposure_;\n> +\tuint64_t gain_;\n> +\tuint64_t minGain_;\n> +\tuint64_t maxGain_;\n\nI don't think you need to store the min/max value of each. You should\ninstead store a reference to the relevant ControlInfo for the control,\nwhich will be populated with the min/max.\n\nAnd perhaps all of those would be stored in a single ControlList ...\n\n\n> +};\n> +\n> +int IPARkISP1::initSensor(const V4L2ControlInfoMap &controls)\n> +{\n> +\tstatFrame_ = 0;\n> +\n> +\tconst auto itExp = controls.find(V4L2_CID_EXPOSURE);\n> +\tif (itExp == controls.end())\n> +\t\treturn -ENODEV;\n> +\n> +\tconst auto itGain = controls.find(V4L2_CID_ANALOGUE_GAIN);\n> +\tif (itGain == controls.end())\n> +\t\treturn -ENODEV;\n> +\n> +\tautoExposure_ = true;\n> +\n> +\tminExposure_ = std::max<uint64_t>(itExp->second.min(), 1);\n> +\tmaxExposure_ = itExp->second.max();\n> +\texposure_ = minExposure_;\n> +\n> +\tminGain_ = std::max<uint64_t>(itGain->second.min(), 1);\n> +\tmaxGain_ = itGain->second.max();\n> +\tgain_ = minGain_;\n> +\n> +\tLOG(IPARkISP1, Info)\n> +\t\t<< \"Exposure: \" << minExposure_ << \"-\" << maxExposure_\n> +\t\t<< \" Gain: \" << minGain_ << \"-\" << maxGain_;\n> +\n> +\tsetControls();\n> +\n> +\treturn 0;\n> +}\n> +\n> +void IPARkISP1::setControls()\n> +{\n> +\tV4L2ControlList ctrls;\n> +\tctrls.add(V4L2_CID_EXPOSURE);\n> +\tctrls.add(V4L2_CID_ANALOGUE_GAIN);\n> +\tctrls[V4L2_CID_EXPOSURE]->setValue(exposure_);\n> +\tctrls[V4L2_CID_ANALOGUE_GAIN]->setValue(gain_);\n> +\n> +\tupdateSensor.emit(ctrls);\n> +}\n> +\n> +void IPARkISP1::processRequest(const void *cookie, const ControlList &controls,\n> +\t\t\t       Buffer &parameters)\n\nAre you preventing the Request being passed in directly here to stop\ndirect access to the Request object? If so - why not pass it in as a const?\n\nAre you perhaps trying to optimise this for serialisation already?\n\n> +{\n> +\trkisp1_isp_params_cfg *params =\n> +\t\tstatic_cast<rkisp1_isp_params_cfg *>(parameters.mem()->planes()[0].mem());\n> +\n> +\tmemset(params, 0, sizeof(*params));\n> +\n> +\t/* Auto Exposure on/off*/\n\ns#off*/#off. */#\n\n> +\tif (controls.contains(AeEnable)) {\n> +\t\tautoExposure_ = controls[AeEnable].getBool();\n> +\t\tif (autoExposure_)\n> +\t\t\tparams->module_ens = CIFISP_MODULE_AEC;\n> +\n> +\t\tparams->module_en_update = CIFISP_MODULE_AEC;\n> +\t}\n> +\n> +\tqueueRequest.emit(cookie);\n> +}\n> +\n> +void IPARkISP1::updateStatistics(const void *cookie, Buffer &statistics)\n> +{\n> +\tconst rkisp1_stat_buffer *stats =\n> +\t\tstatic_cast<rkisp1_stat_buffer *>(statistics.mem()->planes()[0].mem());\n> +\tconst cifisp_stat *params = &stats->params;\n> +\n> +\tif ((stats->meas_type & CIFISP_STAT_AUTOEXP) && (statFrame_ % 2 == 0)) {\n> +\t\tconst cifisp_ae_stat *ae = &params->ae;\n> +\n> +\t\tconst unsigned int target = 60;\n> +\n> +\t\tunsigned int value = 0;\n> +\t\tunsigned int num = 0;\n> +\t\tfor (int i = 0; i < CIFISP_AE_MEAN_MAX; i++) {\n> +\t\t\tif (ae->exp_mean[i] > 15) {\n> +\t\t\t\tvalue += ae->exp_mean[i];\n> +\t\t\t\tnum++;\n> +\t\t\t}\n> +\t\t}\n> +\t\tvalue /= num;\n> +\n> +\t\tdouble factor = (double)target / value;\n> +\t\tdouble tmp;\n> +\n> +\t\ttmp = factor * exposure_ * gain_ / minGain_;\n> +\t\texposure_ = utils::clamp<uint64_t>((uint64_t)tmp, minExposure_, maxExposure_);\n> +\n> +\t\ttmp = tmp / exposure_ * minGain_;\n> +\t\tgain_ = utils::clamp<uint64_t>((uint64_t)tmp, minGain_, maxGain_);\n> +\n> +\t\tsetControls();\n> +\t}\n> +\n> +\tstatFrame_++;\n> +}\n\nI think this would update the local ControlList, which would at the end\nbe submitted, and reused.\n\nI'll ignore all the calculations for now, and assume they do 'something'\nuseful :D\n\n\n> +\n> +/*\n> + * External IPA module interface\n> + */\n> +\n> +extern \"C\" {\n> +const struct IPAModuleInfo ipaModuleInfo = {\n> +\tIPA_MODULE_API_VERSION,\n> +\t1,\n> +\t\"PipelineHandlerRkISP1\",\n> +\t\"RkISP1 IPA\",\n> +\t\"LGPL-2.1-or-later\",\n> +};\n> +\n> +IPAInterface *ipaCreate()\n> +{\n> +\treturn new IPARkISP1();\n> +}\n> +};\n> +\n> +}; /* namespace libcamera */\n> diff --git a/src/ipa/meson.build b/src/ipa/meson.build\n> index dca7a9461385b68d..16592a71e03990ce 100644\n> --- a/src/ipa/meson.build\n> +++ b/src/ipa/meson.build\n> @@ -1,6 +1,7 @@\n>  ipa_dummy_sources = [\n>      ['ipa_dummy', 'ipa_dummy.cpp'],\n>      ['ipa_dummy_isolate', 'ipa_dummy_isolate.cpp'],\n> +    ['ipa_rkisp1', 'ipa_rkisp1.cpp'],\n\nAs mentioned in an earlier patch, I don't think this is an\n'ipa_dummy_source' file, but I do think this list can be re-used.\n\nIt just needs renaming first.\n\n\n>  ]\n>  \n>  ipa_install_dir = join_paths(get_option('libdir'), 'libcamera')\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CF6960BB0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Aug 2019 17:16:10 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DF23F741;\n\tThu, 29 Aug 2019 17:16:09 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1567091770;\n\tbh=bHwMwOYt3psOwBSnL7b1lI0Xam9gwRVaa1D5uyFaS6k=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=KgbX8z3sHzJSME46gqYocALFRnyXuSd0kuEv0JGziMhWeRJuaqO9R9pPGxjZTF3rL\n\tr9v9TCEro8APZryPEiVQlWe4NP86mCGt7J9zcEvlr39/+34WsY8IvLHiv5WF7syhAJ\n\tIHFfBzx2XCOI/fXAgJf9BFVtjP71dcgVgx82NmHg=","Reply-To":"kieran.bingham@ideasonboard.com","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20190828011710.32128-1-niklas.soderlund@ragnatech.se>\n\t<20190828011710.32128-13-niklas.soderlund@ragnatech.se>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffA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7D2g6nZeOp+F2zY8CEUW+sd\n\tCDVd9BH9QX9KN5SZo6YtJzMzSzpcx45VwTvtQW0n/6Eujg9EUqblfU9xqvqDmbjEapr5d/OL\n\t21GTALb0owKhA5qDUGEcKGCphpQffKhTNo/BP99jvmJUj7IPSKH97qPypi8/ym8bAxB+uY31\n\tgHTMHf1jMJJ1pRo2tYYPeIIHGDqXBI4sp5GHHF+JcIhgR/e/A6w/dgzHYmQPl2ix5eZYEZbV\n\tTRP+gkX4NV8oHqa/lR+xPOlWElGB57viOSOoWriqxQbFy8XbG1GR8cWlkNtGBGVWaJaSoORP\n\tiowD7irXL91bCyFIqL+7BVk3Jy4uzP744PzE80KwxOp5SQAp9sPzFbgsJrLev90PZySjFHG0\n\twP144DK7nBjOj/J0g9OHVASP1JjK+nw7SDoKnETDIdRC0XmiHXk7TXzPdkvO0UkpHdEPjZUp\n\tWyuc0MqehjR/hTTPt4m/Y14XzEcy6JREIjOrFfUZVho2QpOdv9CNryGdieRTNjUtz463CIaZ\n\tdPBiw9mOMBoNffkn9FIoCjLnAaj9gUAnEHWBZOEviQ5NuyqpeP0YtzI4iaRbSUkYZHej99X3\n\tVmHrdLlMqd/ZgYYbPGSL4AN3FVACb5CxuxEHwo029VcE5U3CSjzqtCoX12tm7A==","Organization":"Ideas on Board","Message-ID":"<c96ec863-9c43-c98a-1d6d-314dddb6f24c@ideasonboard.com>","Date":"Thu, 29 Aug 2019 16:16:06 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.8.0","MIME-Version":"1.0","In-Reply-To":"<20190828011710.32128-13-niklas.soderlund@ragnatech.se>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 12/13] libcamera: ipa: rkisp1: Add\n\tbasic control of auto exposure","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":"Thu, 29 Aug 2019 15:16:10 -0000"}},{"id":2560,"web_url":"https://patchwork.libcamera.org/comment/2560/","msgid":"<20190829222529.GH8479@bigcity.dyn.berto.se>","date":"2019-08-29T22:25:29","subject":"Re: [libcamera-devel] [PATCH 12/13] libcamera: ipa: rkisp1: Add\n\tbasic control of auto exposure","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nThanks for your feedback.\n\nOn 2019-08-29 16:16:06 +0100, Kieran Bingham wrote:\n> Hi Niklas,\n> \n> On 28/08/2019 02:17, Niklas Söderlund wrote:\n> > Add an IPA which controls the exposure time and analog gain for a sensor\n> > connected to the rkisp1 pipeline. The IPA supports turning AE on and off\n> > but lacks the support to inform the camera of the status of the AE\n> > control loop.\n> > \n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  src/ipa/ipa_rkisp1.cpp | 165 +++++++++++++++++++++++++++++++++++++++++\n> >  src/ipa/meson.build    |   1 +\n> >  2 files changed, 166 insertions(+)\n> >  create mode 100644 src/ipa/ipa_rkisp1.cpp\n> > \n> > diff --git a/src/ipa/ipa_rkisp1.cpp b/src/ipa/ipa_rkisp1.cpp\n> > new file mode 100644\n> > index 0000000000000000..950efb244cfe7879\n> > --- /dev/null\n> > +++ b/src/ipa/ipa_rkisp1.cpp\n> > @@ -0,0 +1,165 @@\n> > +/* SPDX-License-Identifier: LGPL-2.1-or-later */\n> > +/*\n> > + * Copyright (C) 2019, Google Inc.\n> > + *\n> > + * ipa_rkisp1.cpp - RkISP1 Image Processing Algorithms\n> > + */\n> > +\n> > +#include <algorithm>\n> > +#include <string.h>\n> > +\n> > +#include <linux/rkisp1-config.h>\n> > +\n> > +#include <libcamera/buffer.h>\n> > +#include <libcamera/ipa/ipa_interface.h>\n> > +#include <libcamera/ipa/ipa_module_info.h>\n> > +#include <libcamera/request.h>\n> > +\n> > +#include \"log.h\"\n> > +#include \"utils.h\"\n> > +\n> > +namespace libcamera {\n> > +\n> > +LOG_DEFINE_CATEGORY(IPARkISP1)\n> > +\n> > +class IPARkISP1 : public IPAInterface\n> > +{\n> > +public:\n> > +\tint initSensor(const V4L2ControlInfoMap &controls) override;\n> > +\tvoid processRequest(const void *cookie, const ControlList &controls,\n> > +\t\t\t    Buffer &parameters) override;\n> > +\tvoid updateStatistics(const void *cookie, Buffer &statistics) override;\n> > +\n> > +private:\n> > +\tvoid setControls();\n> > +\n> > +\tuint64_t statFrame_;\n> > +\n> > +\t/* Camera sensor controls. */\n> > +\tbool autoExposure_;\n> > +\tuint64_t exposure_;\n> > +\tuint64_t minExposure_;\n> > +\tuint64_t maxExposure_;\n> > +\tuint64_t gain_;\n> > +\tuint64_t minGain_;\n> > +\tuint64_t maxGain_;\n> \n> I don't think you need to store the min/max value of each. You should\n> instead store a reference to the relevant ControlInfo for the control,\n> which will be populated with the min/max.\n> \n> And perhaps all of those would be stored in a single ControlList ...\n\nThe IPA will be isolated so we can't store references. We could have a \nlocal ControlList, but why have all that extra code in a hot path?\n\n> \n> \n> > +};\n> > +\n> > +int IPARkISP1::initSensor(const V4L2ControlInfoMap &controls)\n> > +{\n> > +\tstatFrame_ = 0;\n> > +\n> > +\tconst auto itExp = controls.find(V4L2_CID_EXPOSURE);\n> > +\tif (itExp == controls.end())\n> > +\t\treturn -ENODEV;\n> > +\n> > +\tconst auto itGain = controls.find(V4L2_CID_ANALOGUE_GAIN);\n> > +\tif (itGain == controls.end())\n> > +\t\treturn -ENODEV;\n> > +\n> > +\tautoExposure_ = true;\n> > +\n> > +\tminExposure_ = std::max<uint64_t>(itExp->second.min(), 1);\n> > +\tmaxExposure_ = itExp->second.max();\n> > +\texposure_ = minExposure_;\n> > +\n> > +\tminGain_ = std::max<uint64_t>(itGain->second.min(), 1);\n> > +\tmaxGain_ = itGain->second.max();\n> > +\tgain_ = minGain_;\n> > +\n> > +\tLOG(IPARkISP1, Info)\n> > +\t\t<< \"Exposure: \" << minExposure_ << \"-\" << maxExposure_\n> > +\t\t<< \" Gain: \" << minGain_ << \"-\" << maxGain_;\n> > +\n> > +\tsetControls();\n> > +\n> > +\treturn 0;\n> > +}\n> > +\n> > +void IPARkISP1::setControls()\n> > +{\n> > +\tV4L2ControlList ctrls;\n> > +\tctrls.add(V4L2_CID_EXPOSURE);\n> > +\tctrls.add(V4L2_CID_ANALOGUE_GAIN);\n> > +\tctrls[V4L2_CID_EXPOSURE]->setValue(exposure_);\n> > +\tctrls[V4L2_CID_ANALOGUE_GAIN]->setValue(gain_);\n> > +\n> > +\tupdateSensor.emit(ctrls);\n> > +}\n> > +\n> > +void IPARkISP1::processRequest(const void *cookie, const ControlList &controls,\n> > +\t\t\t       Buffer &parameters)\n> \n> Are you preventing the Request being passed in directly here to stop\n> direct access to the Request object? If so - why not pass it in as a const?\n> \n> Are you perhaps trying to optimise this for serialisation already?\n\nYes, this is a step to reduce the information passed between pipeline \nand IPA to visualize what is really needed and make it easier to \nserialize.\n\n> \n> > +{\n> > +\trkisp1_isp_params_cfg *params =\n> > +\t\tstatic_cast<rkisp1_isp_params_cfg *>(parameters.mem()->planes()[0].mem());\n> > +\n> > +\tmemset(params, 0, sizeof(*params));\n> > +\n> > +\t/* Auto Exposure on/off*/\n> \n> s#off*/#off. */#\n> \n> > +\tif (controls.contains(AeEnable)) {\n> > +\t\tautoExposure_ = controls[AeEnable].getBool();\n> > +\t\tif (autoExposure_)\n> > +\t\t\tparams->module_ens = CIFISP_MODULE_AEC;\n> > +\n> > +\t\tparams->module_en_update = CIFISP_MODULE_AEC;\n> > +\t}\n> > +\n> > +\tqueueRequest.emit(cookie);\n> > +}\n> > +\n> > +void IPARkISP1::updateStatistics(const void *cookie, Buffer &statistics)\n> > +{\n> > +\tconst rkisp1_stat_buffer *stats =\n> > +\t\tstatic_cast<rkisp1_stat_buffer *>(statistics.mem()->planes()[0].mem());\n> > +\tconst cifisp_stat *params = &stats->params;\n> > +\n> > +\tif ((stats->meas_type & CIFISP_STAT_AUTOEXP) && (statFrame_ % 2 == 0)) {\n> > +\t\tconst cifisp_ae_stat *ae = &params->ae;\n> > +\n> > +\t\tconst unsigned int target = 60;\n> > +\n> > +\t\tunsigned int value = 0;\n> > +\t\tunsigned int num = 0;\n> > +\t\tfor (int i = 0; i < CIFISP_AE_MEAN_MAX; i++) {\n> > +\t\t\tif (ae->exp_mean[i] > 15) {\n> > +\t\t\t\tvalue += ae->exp_mean[i];\n> > +\t\t\t\tnum++;\n> > +\t\t\t}\n> > +\t\t}\n> > +\t\tvalue /= num;\n> > +\n> > +\t\tdouble factor = (double)target / value;\n> > +\t\tdouble tmp;\n> > +\n> > +\t\ttmp = factor * exposure_ * gain_ / minGain_;\n> > +\t\texposure_ = utils::clamp<uint64_t>((uint64_t)tmp, minExposure_, maxExposure_);\n> > +\n> > +\t\ttmp = tmp / exposure_ * minGain_;\n> > +\t\tgain_ = utils::clamp<uint64_t>((uint64_t)tmp, minGain_, maxGain_);\n> > +\n> > +\t\tsetControls();\n> > +\t}\n> > +\n> > +\tstatFrame_++;\n> > +}\n> \n> I think this would update the local ControlList, which would at the end\n> be submitted, and reused.\n> \n> I'll ignore all the calculations for now, and assume they do 'something'\n> useful :D\n\n:-)\n\n> \n> \n> > +\n> > +/*\n> > + * External IPA module interface\n> > + */\n> > +\n> > +extern \"C\" {\n> > +const struct IPAModuleInfo ipaModuleInfo = {\n> > +\tIPA_MODULE_API_VERSION,\n> > +\t1,\n> > +\t\"PipelineHandlerRkISP1\",\n> > +\t\"RkISP1 IPA\",\n> > +\t\"LGPL-2.1-or-later\",\n> > +};\n> > +\n> > +IPAInterface *ipaCreate()\n> > +{\n> > +\treturn new IPARkISP1();\n> > +}\n> > +};\n> > +\n> > +}; /* namespace libcamera */\n> > diff --git a/src/ipa/meson.build b/src/ipa/meson.build\n> > index dca7a9461385b68d..16592a71e03990ce 100644\n> > --- a/src/ipa/meson.build\n> > +++ b/src/ipa/meson.build\n> > @@ -1,6 +1,7 @@\n> >  ipa_dummy_sources = [\n> >      ['ipa_dummy', 'ipa_dummy.cpp'],\n> >      ['ipa_dummy_isolate', 'ipa_dummy_isolate.cpp'],\n> > +    ['ipa_rkisp1', 'ipa_rkisp1.cpp'],\n> \n> As mentioned in an earlier patch, I don't think this is an\n> 'ipa_dummy_source' file, but I do think this list can be re-used.\n> \n> It just needs renaming first.\n> \n> \n> >  ]\n> >  \n> >  ipa_install_dir = join_paths(get_option('libdir'), 'libcamera')\n> > \n> \n> -- \n> Regards\n> --\n> Kieran","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x244.google.com (mail-lj1-x244.google.com\n\t[IPv6:2a00:1450:4864:20::244])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DF30360BE5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 30 Aug 2019 00:25:32 +0200 (CEST)","by mail-lj1-x244.google.com with SMTP id t14so4602193lji.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 29 Aug 2019 15:25:31 -0700 (PDT)","from localhost (h-177-236.A463.priv.bahnhof.se. [217.31.177.236])\n\tby smtp.gmail.com with ESMTPSA id\n\tb205sm661916lfg.72.2019.08.29.15.25.29\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 29 Aug 2019 15:25:30 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=jDUznK9ZnVDQmBbCITi5gecRQy+PYTdRxv3yH1KbNvA=;\n\tb=0H0OVr1rO7WkQgQczkuT1sMaainp1wyC4WWC9oRt0rJNXZ7dmu0T3Kskw6X+OajOvj\n\tPWJ9ftvpVFayKw83WkD+yuyjCS9c/YkzQTTJH65+ZIKWsmXNpHSYcW5K5fcVS7q1KoA8\n\tes0bTJHq4koUxg2i01vq38MaXWTBovWPIBHJQSmzCXEtE5j5EVXQQB6mLNuXJfskjtIJ\n\tGgeeFG+Dmpgr/1Sqoiqn2HVfZb3s6pqWSsu/xMuODF4iFCtCjavL0fM8VtQTl1DJ5NWz\n\tcv59vKdBr3UgMcAb2ZTRc9PLdVMechA6TUH2zByCNiLww0gRY6tpdHX5fyhrodS9Badp\n\tTd3g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=jDUznK9ZnVDQmBbCITi5gecRQy+PYTdRxv3yH1KbNvA=;\n\tb=DM6lHfpMpVufp+40zfIaA2nMXVt3q7FVk5twdv6r8LawZfQm3fYp3A399IPboLGHBA\n\tn4LWpLUiGbfTOaPteaVc+l/sDxxQpJAg1Hfv0O9Y37sUdzQwyT4gInEFi5s/ol64aTrq\n\twfmYy4hOmj6CdchyrP7fNDrC2Vj+TtoSgcENUUI31EczGs1XQTQAMR5ov/Zp9+QINRFr\n\tLxwW0sJD+TUaSKT8XLf4wNWkKsQZ7/IJvieNPma731l15m5lyB9M9eskFknwUygMODHq\n\td4MBxUJTU5VaJBsHLU5k52zLkMI8aGn6hua9E0JYuP/PWDXW6viTMq8+brBJZsjuth7G\n\tKreQ==","X-Gm-Message-State":"APjAAAWw1bdG0iHC8uwpdoEgqJV5biSGfq9lxG7fb3AvZp11M8HoJJYn\n\t2WpugtY8LTshPitFDP9mRmnMwqy65Kg=","X-Google-Smtp-Source":"APXvYqweC//vktc6J6abphyFylrZUssj6/mkzW1t2moS0l67Vja7SSP0308B7gAYJASAI7DVBm3nDQ==","X-Received":"by 2002:a2e:5050:: with SMTP id v16mr6952798ljd.29.1567117531246;\n\tThu, 29 Aug 2019 15:25:31 -0700 (PDT)","Date":"Fri, 30 Aug 2019 00:25:29 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190829222529.GH8479@bigcity.dyn.berto.se>","References":"<20190828011710.32128-1-niklas.soderlund@ragnatech.se>\n\t<20190828011710.32128-13-niklas.soderlund@ragnatech.se>\n\t<c96ec863-9c43-c98a-1d6d-314dddb6f24c@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<c96ec863-9c43-c98a-1d6d-314dddb6f24c@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH 12/13] libcamera: ipa: rkisp1: Add\n\tbasic control of auto exposure","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":"Thu, 29 Aug 2019 22:25:33 -0000"}}]