Patch Detail
Show a patch.
GET /api/1.1/patches/13587/?format=api
{ "id": 13587, "url": "https://patchwork.libcamera.org/api/1.1/patches/13587/?format=api", "web_url": "https://patchwork.libcamera.org/patch/13587/", "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": "<20210831223705.1928000-2-nfraprado@collabora.com>", "date": "2021-08-31T22:37:01", "name": "[libcamera-devel,v2,1/5] libcamera: pipeline: vimc: Add internal request queue", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "3b5394e641b53bcaf6003502976a4597b4175f8c", "submitter": { "id": 84, "url": "https://patchwork.libcamera.org/api/1.1/people/84/?format=api", "name": "Nícolas F. R. A. Prado", "email": "nfraprado@collabora.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/13587/mbox/", "series": [], "comments": "https://patchwork.libcamera.org/api/patches/13587/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/13587/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 B5B23C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 31 Aug 2021 22:37:45 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 512FA6917B;\n\tWed, 1 Sep 2021 00:37:45 +0200 (CEST)", "from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DCF560258\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Sep 2021 00:37:31 +0200 (CEST)", "from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:b693:c9:5cb6:b688])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nfraprado)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id 7E4101F43851;\n\tTue, 31 Aug 2021 23:37:29 +0100 (BST)" ], "From": "=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 31 Aug 2021 19:37:01 -0300", "Message-Id": "<20210831223705.1928000-2-nfraprado@collabora.com>", "X-Mailer": "git-send-email 2.33.0", "In-Reply-To": "<20210831223705.1928000-1-nfraprado@collabora.com>", "References": "<20210831223705.1928000-1-nfraprado@collabora.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 1/5] libcamera: pipeline: vimc: Add\n\tinternal request queue", "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": "kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?=\n\t<andrealmeid@collabora.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Add an internal queue that stores requests until there are V4L2 buffer\nslots available. This avoids the need to cancel requests when there is a\nshortage of said buffers.\n\nSigned-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n\n---\n\nChanges in v2:\n- Moved processControls() from PipelineHandlerVimc to VimcCameraData\n- Moved cancellation of pending requests to after video devices stop\n- Added a counter to keep track of the number of available buffer slots\n- Added error log on failure to process controls\n\n src/libcamera/pipeline/vimc/vimc.cpp | 167 +++++++++++++++++++--------\n 1 file changed, 116 insertions(+), 51 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp\nindex ad71bfc67228..d8f88000d9d7 100644\n--- a/src/libcamera/pipeline/vimc/vimc.cpp\n+++ b/src/libcamera/pipeline/vimc/vimc.cpp\n@@ -9,6 +9,7 @@\n #include <iomanip>\n #include <map>\n #include <math.h>\n+#include <queue>\n #include <tuple>\n \n #include <linux/media-bus-format.h>\n@@ -56,6 +57,11 @@ public:\n \tvoid bufferReady(FrameBuffer *buffer);\n \tvoid paramsFilled(unsigned int id);\n \n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n+\n+\tvoid setAvailableBufferSlotCount(unsigned int count) { availableBufferSlotCount_ = count; }\n+\n \tMediaDevice *media_;\n \tstd::unique_ptr<CameraSensor> sensor_;\n \tstd::unique_ptr<V4L2Subdevice> debayer_;\n@@ -66,6 +72,13 @@ public:\n \n \tstd::unique_ptr<ipa::vimc::IPAProxyVimc> ipa_;\n \tstd::vector<std::unique_ptr<FrameBuffer>> mockIPABufs_;\n+\n+\tstd::queue<Request *> pendingRequests_;\n+\n+private:\n+\tint processControls(Request *request);\n+\n+\tunsigned int availableBufferSlotCount_;\n };\n \n class VimcCameraConfiguration : public CameraConfiguration\n@@ -99,8 +112,6 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n-\tint processControls(VimcCameraData *data, Request *request);\n-\n \tVimcCameraData *cameraData(Camera *camera)\n \t{\n \t\treturn static_cast<VimcCameraData *>(camera->_d());\n@@ -335,6 +346,8 @@ int PipelineHandlerVimc::start(Camera *camera, [[maybe_unused]] const ControlLis\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tdata->setAvailableBufferSlotCount(kVimcBufferSlotCount);\n+\n \t/* Map the mock IPA buffers to VIMC IPA to exercise IPC code paths. */\n \tstd::vector<IPABuffer> ipaBuffers;\n \tfor (auto [i, buffer] : utils::enumerate(data->mockIPABufs_)) {\n@@ -370,67 +383,24 @@ void PipelineHandlerVimc::stop(Camera *camera)\n \tdata->ipa_->unmapBuffers(ids);\n \tdata->ipa_->stop();\n \n-\tdata->video_->releaseBuffers();\n-}\n-\n-int PipelineHandlerVimc::processControls(VimcCameraData *data, Request *request)\n-{\n-\tControlList controls(data->sensor_->controls());\n-\n-\tfor (auto it : request->controls()) {\n-\t\tunsigned int id = it.first;\n-\t\tunsigned int offset;\n-\t\tuint32_t cid;\n+\tdata->cancelPendingRequests();\n \n-\t\tif (id == controls::Brightness) {\n-\t\t\tcid = V4L2_CID_BRIGHTNESS;\n-\t\t\toffset = 128;\n-\t\t} else if (id == controls::Contrast) {\n-\t\t\tcid = V4L2_CID_CONTRAST;\n-\t\t\toffset = 0;\n-\t\t} else if (id == controls::Saturation) {\n-\t\t\tcid = V4L2_CID_SATURATION;\n-\t\t\toffset = 0;\n-\t\t} else {\n-\t\t\tcontinue;\n-\t\t}\n-\n-\t\tint32_t value = lroundf(it.second.get<float>() * 128 + offset);\n-\t\tcontrols.set(cid, std::clamp(value, 0, 255));\n-\t}\n-\n-\tfor (const auto &ctrl : controls)\n-\t\tLOG(VIMC, Debug)\n-\t\t\t<< \"Setting control \" << utils::hex(ctrl.first)\n-\t\t\t<< \" to \" << ctrl.second.toString();\n-\n-\tint ret = data->sensor_->setControls(&controls);\n-\tif (ret) {\n-\t\tLOG(VIMC, Error) << \"Failed to set controls: \" << ret;\n-\t\treturn ret < 0 ? ret : -EINVAL;\n-\t}\n-\n-\treturn ret;\n+\tdata->video_->releaseBuffers();\n }\n \n int PipelineHandlerVimc::queueRequestDevice(Camera *camera, Request *request)\n {\n \tVimcCameraData *data = cameraData(camera);\n-\tFrameBuffer *buffer = request->findBuffer(&data->stream_);\n-\tif (!buffer) {\n+\n+\tif (!request->findBuffer(&data->stream_)) {\n \t\tLOG(VIMC, Error)\n \t\t\t<< \"Attempt to queue request with invalid stream\";\n \n \t\treturn -ENOENT;\n \t}\n \n-\tint ret = processControls(data, request);\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tret = data->video_->queueBuffer(buffer);\n-\tif (ret < 0)\n-\t\treturn ret;\n+\tdata->pendingRequests_.push(request);\n+\tdata->queuePendingRequests();\n \n \tdata->ipa_->processControls(request->sequence(), request->controls());\n \n@@ -565,6 +535,46 @@ int VimcCameraData::init()\n \treturn 0;\n }\n \n+int VimcCameraData::processControls(Request *request)\n+{\n+\tControlList controls(sensor_->controls());\n+\n+\tfor (auto it : request->controls()) {\n+\t\tunsigned int id = it.first;\n+\t\tunsigned int offset;\n+\t\tuint32_t cid;\n+\n+\t\tif (id == controls::Brightness) {\n+\t\t\tcid = V4L2_CID_BRIGHTNESS;\n+\t\t\toffset = 128;\n+\t\t} else if (id == controls::Contrast) {\n+\t\t\tcid = V4L2_CID_CONTRAST;\n+\t\t\toffset = 0;\n+\t\t} else if (id == controls::Saturation) {\n+\t\t\tcid = V4L2_CID_SATURATION;\n+\t\t\toffset = 0;\n+\t\t} else {\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tint32_t value = lroundf(it.second.get<float>() * 128 + offset);\n+\t\tcontrols.set(cid, std::clamp(value, 0, 255));\n+\t}\n+\n+\tfor (const auto &ctrl : controls)\n+\t\tLOG(VIMC, Debug)\n+\t\t\t<< \"Setting control \" << utils::hex(ctrl.first)\n+\t\t\t<< \" to \" << ctrl.second.toString();\n+\n+\tint ret = sensor_->setControls(&controls);\n+\tif (ret) {\n+\t\tLOG(VIMC, Error) << \"Failed to set controls: \" << ret;\n+\t\treturn ret < 0 ? ret : -EINVAL;\n+\t}\n+\n+\treturn ret;\n+}\n+\n void VimcCameraData::bufferReady(FrameBuffer *buffer)\n {\n \tPipelineHandlerVimc *pipe =\n@@ -591,6 +601,10 @@ void VimcCameraData::bufferReady(FrameBuffer *buffer)\n \tpipe->completeRequest(request);\n \n \tipa_->fillParams(request->sequence(), mockIPABufs_[0]->cookie());\n+\n+\tavailableBufferSlotCount_++;\n+\n+\tqueuePendingRequests();\n }\n \n int VimcCameraData::allocateMockIPABuffers()\n@@ -612,6 +626,57 @@ void VimcCameraData::paramsFilled([[maybe_unused]] unsigned int id)\n {\n }\n \n+void VimcCameraData::queuePendingRequests()\n+{\n+\twhile (!pendingRequests_.empty() && availableBufferSlotCount_) {\n+\t\tRequest *request = pendingRequests_.front();\n+\t\tFrameBuffer *buffer = request->findBuffer(&stream_);\n+\n+\t\tint ret = processControls(request);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(VIMC, Error) << \"Failed to process controls with\"\n+\t\t\t\t\t << \" error \" << ret << \". Cancelling\"\n+\t\t\t\t\t << \" buffer.\";\n+\t\t\tbuffer->cancel();\n+\t\t\tpipe()->completeBuffer(request, buffer);\n+\t\t\tpipe()->completeRequest(request);\n+\t\t\tpendingRequests_.pop();\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tret = video_->queueBuffer(buffer);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(VIMC, Error) << \"Failed to queue buffer with error \"\n+\t\t\t\t\t << ret << \". Cancelling buffer.\";\n+\t\t\tbuffer->cancel();\n+\t\t\tpipe()->completeBuffer(request, buffer);\n+\t\t\tpipe()->completeRequest(request);\n+\t\t\tpendingRequests_.pop();\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tavailableBufferSlotCount_--;\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n+void VimcCameraData::cancelPendingRequests()\n+{\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n+\t\tFrameBuffer *buffer = request->findBuffer(&stream_);\n+\n+\t\tbuffer->cancel();\n+\t\tpipe()->completeBuffer(request, buffer);\n+\t\tpipe()->completeRequest(request);\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n REGISTER_PIPELINE_HANDLER(PipelineHandlerVimc)\n \n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v2", "1/5" ] }