{"id":8491,"url":"https://patchwork.libcamera.org/api/patches/8491/?format=json","web_url":"https://patchwork.libcamera.org/patch/8491/","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":"<20200628231934.29025-8-laurent.pinchart@ideasonboard.com>","date":"2020-06-28T23:19:32","name":"[libcamera-devel,v1,7/9] ipa: raspberrypi: Pass sensor config back from configure()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f5ffaab9a41236651eceb85b9075c0dd85ff4984","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8491/mbox/","series":[{"id":1054,"url":"https://patchwork.libcamera.org/api/series/1054/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1054","date":"2020-06-28T23:19:25","name":"Support passing custom data to IPA configure()","version":1,"mbox":"https://patchwork.libcamera.org/series/1054/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8491/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8491/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 C1795C2E66\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 28 Jun 2020 23:19:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8F4E260B07;\n\tMon, 29 Jun 2020 01:19:52 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C1DD60AF7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Jun 2020 01:19:44 +0200 (CEST)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 887AF734;\n\tMon, 29 Jun 2020 01:19:43 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ZG1fxYi/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593386383;\n\tbh=NgGKREy6lYlJjjhepbY3Yi1cgHIIqnWbSsjsdhpoEGg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=ZG1fxYi/QyoSdR/jeKgVGgjGGqjHlgsuP1JISN4I7s8vBNx1/fJaS1C0+w8huCiDK\n\trjcz8+miGU2kSrPOt9Bzso879ggLS5zhq1Hf2XPx0v7tP9arhdptnhzR4y8RzTPHJ+\n\tMD6uHUv7gd+vc8qXBOvviGdXUIh2wbTJWB2/gr2w=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 29 Jun 2020 02:19:32 +0300","Message-Id":"<20200628231934.29025-8-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200628231934.29025-1-laurent.pinchart@ideasonboard.com>","References":"<20200628231934.29025-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v1 7/9] ipa: raspberrypi: Pass sensor\n\tconfig back from configure()","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>","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":"The Raspberry Pi IPA uses a custom frame action,\nRPI_IPA_ACTION_SET_SENSOR_CONFIG, to send initial sensor configuration\nto the pipeline handler when the IPA is configured. Replace this ad-hoc\nmechanism by passing the corresponding data back from the IPA to the\npipeline handler through the configure() response. This allows\nsynchronous handling of the response on the pipeline handler side.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/ipa/raspberrypi.h           |  3 +-\n src/ipa/raspberrypi/raspberrypi.cpp           | 44 ++++++++------\n .../pipeline/raspberrypi/raspberrypi.cpp      | 60 +++++++++++--------\n 3 files changed, 61 insertions(+), 46 deletions(-)","diff":"diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h\nindex c335d0259549..77a7e6d40a2f 100644\n--- a/include/libcamera/ipa/raspberrypi.h\n+++ b/include/libcamera/ipa/raspberrypi.h\n@@ -12,6 +12,8 @@\n \n enum RPiConfigParameters {\n \tRPI_IPA_CONFIG_LSTABLE = (1 << 0),\n+\tRPI_IPA_CONFIG_STAGGERED_WRITE = (1 << 1),\n+\tRPI_IPA_CONFIG_SENSOR = (1 << 2),\n };\n \n enum RPiOperations {\n@@ -20,7 +22,6 @@ enum RPiOperations {\n \tRPI_IPA_ACTION_STATS_METADATA_COMPLETE,\n \tRPI_IPA_ACTION_RUN_ISP,\n \tRPI_IPA_ACTION_RUN_ISP_AND_DROP_FRAME,\n-\tRPI_IPA_ACTION_SET_SENSOR_CONFIG,\n \tRPI_IPA_ACTION_EMBEDDED_COMPLETE,\n \tRPI_IPA_EVENT_SIGNAL_STAT_READY,\n \tRPI_IPA_EVENT_SIGNAL_ISP_PREPARE,\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex c9f7dea375a5..7da2ffdf84a1 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -93,7 +93,7 @@ private:\n \tvoid reportMetadata();\n \tbool parseEmbeddedData(unsigned int bufferId, struct DeviceStatus &deviceStatus);\n \tvoid processStats(unsigned int bufferId);\n-\tvoid applyAGC(const struct AgcStatus *agcStatus);\n+\tvoid applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls);\n \tvoid applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls);\n \tvoid applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls);\n \tvoid applyCCM(const struct CcmStatus *ccmStatus, ControlList &ctrls);\n@@ -195,6 +195,8 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n \tif (entityControls.empty())\n \t\treturn;\n \n+\tresult->operation = 0;\n+\n \tunicam_ctrls_ = entityControls.at(0);\n \tisp_ctrls_ = entityControls.at(1);\n \t/* Setup a metadata ControlList to output metadata. */\n@@ -217,18 +219,16 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n \t\tsensorMetadata = helper_->SensorEmbeddedDataPresent();\n \t\tRPi::CamTransform orientation = helper_->GetOrientation();\n \n-\t\tIPAOperationData op;\n-\t\top.operation = RPI_IPA_ACTION_SET_SENSOR_CONFIG;\n-\t\top.data.push_back(gainDelay);\n-\t\top.data.push_back(exposureDelay);\n-\t\top.data.push_back(sensorMetadata);\n+\t\tresult->data.push_back(gainDelay);\n+\t\tresult->data.push_back(exposureDelay);\n+\t\tresult->data.push_back(sensorMetadata);\n \n \t\tControlList ctrls(unicam_ctrls_);\n \t\tctrls.set(V4L2_CID_HFLIP, (int32_t) !!(orientation & RPi::CamTransform_HFLIP));\n \t\tctrls.set(V4L2_CID_VFLIP, (int32_t) !!(orientation & RPi::CamTransform_VFLIP));\n-\t\top.controls.push_back(ctrls);\n+\t\tresult->controls.push_back(ctrls);\n \n-\t\tqueueFrameAction.emit(0, op);\n+\t\tresult->operation |= RPI_IPA_CONFIG_STAGGERED_WRITE;\n \t}\n \n \t/* Re-assemble camera mode using the sensor info. */\n@@ -273,8 +273,13 @@ void IPARPi::configure(const CameraSensorInfo &sensorInfo,\n \n \t/* SwitchMode may supply updated exposure/gain values to use. */\n \tmetadata.Get(\"agc.status\", agcStatus);\n-\tif (agcStatus.shutter_time != 0.0 && agcStatus.analogue_gain != 0.0)\n-\t\tapplyAGC(&agcStatus);\n+\tif (agcStatus.shutter_time != 0.0 && agcStatus.analogue_gain != 0.0) {\n+\t\tControlList ctrls(unicam_ctrls_);\n+\t\tapplyAGC(&agcStatus, ctrls);\n+\t\tresult->controls.push_back(ctrls);\n+\n+\t\tresult->operation |= RPI_IPA_CONFIG_SENSOR;\n+\t}\n \n \tlastMode_ = mode_;\n \n@@ -781,8 +786,15 @@ void IPARPi::processStats(unsigned int bufferId)\n \tcontroller_.Process(statistics, &rpiMetadata_);\n \n \tstruct AgcStatus agcStatus;\n-\tif (rpiMetadata_.Get(\"agc.status\", agcStatus) == 0)\n-\t\tapplyAGC(&agcStatus);\n+\tif (rpiMetadata_.Get(\"agc.status\", agcStatus) == 0) {\n+\t\tControlList ctrls(unicam_ctrls_);\n+\t\tapplyAGC(&agcStatus, ctrls);\n+\n+\t\tIPAOperationData op;\n+\t\top.operation = RPI_IPA_ACTION_V4L2_SET_STAGGERED;\n+\t\top.controls.push_back(ctrls);\n+\t\tqueueFrameAction.emit(0, op);\n+\t}\n }\n \n void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n@@ -808,11 +820,8 @@ void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)\n \t\t  static_cast<int32_t>(awbStatus->gain_b * 1000));\n }\n \n-void IPARPi::applyAGC(const struct AgcStatus *agcStatus)\n+void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n {\n-\tIPAOperationData op;\n-\top.operation = RPI_IPA_ACTION_V4L2_SET_STAGGERED;\n-\n \tint32_t gain_code = helper_->GainCode(agcStatus->analogue_gain);\n \tint32_t exposure_lines = helper_->ExposureLines(agcStatus->shutter_time);\n \n@@ -831,11 +840,8 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus)\n \t\t\t   << agcStatus->analogue_gain << \" (Gain Code: \"\n \t\t\t   << gain_code << \")\";\n \n-\tControlList ctrls(unicam_ctrls_);\n \tctrls.set(V4L2_CID_ANALOGUE_GAIN, gain_code);\n \tctrls.set(V4L2_CID_EXPOSURE, exposure_lines);\n-\top.controls.push_back(ctrls);\n-\tqueueFrameAction.emit(0, op);\n }\n \n void IPARPi::applyDG(const struct AgcStatus *dgStatus, ControlList &ctrls)\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 903796790f44..60b01484b329 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -806,7 +806,7 @@ int PipelineHandlerRPi::start(Camera *camera)\n \t/*\n \t * Write the last set of gain and exposure values to the camera before\n \t * starting. First check that the staggered ctrl has been initialised\n-\t * by the IPA action.\n+\t * by configure().\n \t */\n \tASSERT(data->staggeredCtrl_);\n \tdata->staggeredCtrl_.reset();\n@@ -1152,44 +1152,45 @@ int RPiCameraData::configureIPA()\n \t}\n \n \t/* Ready the IPA - it must know about the sensor resolution. */\n+\tIPAOperationData result;\n+\n \tipa_->configure(sensorInfo, streamConfig, entityControls, ipaConfig,\n-\t\t\tnullptr);\n+\t\t\t&result);\n \n-\treturn 0;\n-}\n-\n-void RPiCameraData::queueFrameAction(unsigned int frame, const IPAOperationData &action)\n-{\n-\t/*\n-\t * The following actions can be handled when the pipeline handler is in\n-\t * a stopped state.\n-\t */\n-\tswitch (action.operation) {\n-\tcase RPI_IPA_ACTION_V4L2_SET_STAGGERED: {\n-\t\tControlList controls = action.controls[0];\n-\t\tif (!staggeredCtrl_.set(controls))\n-\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n-\t\tgoto done;\n-\t}\n-\n-\tcase RPI_IPA_ACTION_SET_SENSOR_CONFIG: {\n+\tif (result.operation & RPI_IPA_CONFIG_STAGGERED_WRITE) {\n \t\t/*\n \t\t * Setup our staggered control writer with the sensor default\n \t\t * gain and exposure delays.\n \t\t */\n \t\tif (!staggeredCtrl_) {\n \t\t\tstaggeredCtrl_.init(unicam_[Unicam::Image].dev(),\n-\t\t\t\t\t    { { V4L2_CID_ANALOGUE_GAIN, action.data[0] },\n-\t\t\t\t\t      { V4L2_CID_EXPOSURE, action.data[1] } });\n-\t\t\tsensorMetadata_ = action.data[2];\n+\t\t\t\t\t    { { V4L2_CID_ANALOGUE_GAIN, result.data[0] },\n+\t\t\t\t\t      { V4L2_CID_EXPOSURE, result.data[1] } });\n+\t\t\tsensorMetadata_ = result.data[2];\n \t\t}\n \n \t\t/* Set the sensor orientation here as well. */\n-\t\tControlList controls = action.controls[0];\n-\t\tunicam_[Unicam::Image].dev()->setControls(&controls);\n-\t\tgoto done;\n+\t\tunicam_[Unicam::Image].dev()->setControls(&result.controls[0]);\n \t}\n \n+\tif (result.operation & RPI_IPA_CONFIG_SENSOR) {\n+\t\tunsigned int idx = result.operation & RPI_IPA_CONFIG_STAGGERED_WRITE\n+\t\t\t\t ? 1 : 0;\n+\t\tconst ControlList &ctrls = result.controls[idx];\n+\t\tif (!staggeredCtrl_.set(ctrls))\n+\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n+\t}\n+\n+\treturn 0;\n+}\n+\n+void RPiCameraData::queueFrameAction(unsigned int frame, const IPAOperationData &action)\n+{\n+\t/*\n+\t * The following actions can be handled when the pipeline handler is in\n+\t * a stopped state.\n+\t */\n+\tswitch (action.operation) {\n \tcase RPI_IPA_ACTION_V4L2_SET_ISP: {\n \t\tControlList controls = action.controls[0];\n \t\tisp_[Isp::Input].dev()->setControls(&controls);\n@@ -1205,6 +1206,13 @@ void RPiCameraData::queueFrameAction(unsigned int frame, const IPAOperationData\n \t * is in a stopped state.\n \t */\n \tswitch (action.operation) {\n+\tcase RPI_IPA_ACTION_V4L2_SET_STAGGERED: {\n+\t\tconst ControlList &controls = action.controls[0];\n+\t\tif (!staggeredCtrl_.set(controls))\n+\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n+\t\tbreak;\n+\t}\n+\n \tcase RPI_IPA_ACTION_STATS_METADATA_COMPLETE: {\n \t\tunsigned int bufferId = action.data[0];\n \t\tFrameBuffer *buffer = isp_[Isp::Stats].getBuffers()->at(bufferId).get();\n","prefixes":["libcamera-devel","v1","7/9"]}