Patch Detail
Show a patch.
GET /api/1.1/patches/3127/?format=api
{ "id": 3127, "url": "https://patchwork.libcamera.org/api/1.1/patches/3127/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3127/", "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": "<20200316214310.27665-11-laurent.pinchart@ideasonboard.com>", "date": "2020-03-16T21:43:10", "name": "[libcamera-devel,v2,10/10] libcamera: pipeline: simple: Integrate converter support", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "c16c41beefed45121c2c5a2c146fa0126589b218", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3127/mbox/", "series": [ { "id": 724, "url": "https://patchwork.libcamera.org/api/1.1/series/724/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=724", "date": "2020-03-16T21:43:00", "name": "Simple pipeline handler", "version": 2, "mbox": "https://patchwork.libcamera.org/series/724/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3127/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3127/checks/", "tags": {}, "headers": { "Return-Path": "<laurent.pinchart@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 72FF56297B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 22:43:30 +0100 (CET)", "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 C95841961;\n\tMon, 16 Mar 2020 22:43:29 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584395010;\n\tbh=EhPtWClmMeBryNcfmhlq56VHPc4NCWvum1YLv6gJZlc=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=FspJl5lRUahpoXVn4ckDj3x4/bleBQ1ZTi1BfhOmPmjEX0C3Sq7UMfVDgY8mSVe7j\n\tFRqzWjO162LR0gkNMarporRk5w96rLAv12iSgkHe6KozUzXY0Lm3af2Uq8ofVkC5kl\n\ta8mggofPEIypz350oYmtm9mLWzPvj2ao3GIGLjmQ=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Martijn Braam <martijn@brixit.nl>, Mickael GUENE <mickael.guene@st.com>, \n\tBenjamin GAIGNARD <benjamin.gaignard@st.com>,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>", "Date": "Mon, 16 Mar 2020 23:43:10 +0200", "Message-Id": "<20200316214310.27665-11-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200316214310.27665-1-laurent.pinchart@ideasonboard.com>", "References": "<20200316214310.27665-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 10/10] libcamera: pipeline: simple:\n\tIntegrate converter support", "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>", "X-List-Received-Date": "Mon, 16 Mar 2020 21:43:30 -0000" }, "content": "Add support for an optional format converter, supported by the\nSimpleConverter class. If a converter is available for the pipeline, it\nwill be used to expose additional pixel formats.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline/simple/simple.cpp | 192 ++++++++++++++++++++---\n 1 file changed, 174 insertions(+), 18 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 2126799c54eb..218b28e70eb2 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -11,6 +11,7 @@\n #include <list>\n #include <map>\n #include <memory>\n+#include <queue>\n #include <set>\n #include <string>\n #include <string.h>\n@@ -31,12 +32,19 @@\n #include \"v4l2_subdevice.h\"\n #include \"v4l2_videodevice.h\"\n \n+#include \"converter.h\"\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(SimplePipeline)\n \n class SimplePipelineHandler;\n \n+struct SimplePipelineInfo {\n+\tconst char *driver;\n+\tconst char *converter;\n+};\n+\n class SimpleCameraData : public CameraData\n {\n public:\n@@ -79,6 +87,8 @@ public:\n \n \tconst V4L2SubdeviceFormat &sensorFormat() { return sensorFormat_; }\n \n+\tbool needConversion() const { return needConversion_; }\n+\n private:\n \t/*\n \t * The SimpleCameraData instance is guaranteed to be valid as long as\n@@ -89,6 +99,7 @@ private:\n \tconst SimpleCameraData *data_;\n \n \tV4L2SubdeviceFormat sensorFormat_;\n+\tbool needConversion_;\n };\n \n class SimplePipelineHandler : public PipelineHandler\n@@ -111,6 +122,7 @@ public:\n \n \tV4L2VideoDevice *video() { return video_; }\n \tV4L2Subdevice *subdev(const MediaEntity *entity);\n+\tSimpleConverter *converter() { return converter_; }\n \n protected:\n \tint queueRequestDevice(Camera *camera, Request *request) override;\n@@ -127,11 +139,17 @@ private:\n \tint createCamera(MediaEntity *sensor);\n \n \tvoid bufferReady(FrameBuffer *buffer);\n+\tvoid converterDone(FrameBuffer *input, FrameBuffer *output);\n \n \tMediaDevice *media_;\n \tV4L2VideoDevice *video_;\n \tstd::map<const MediaEntity *, V4L2Subdevice> subdevs_;\n \n+\tSimpleConverter *converter_;\n+\tbool useConverter_;\n+\tstd::vector<std::unique_ptr<FrameBuffer>> converterBuffers_;\n+\tstd::queue<FrameBuffer *> converterQueue_;\n+\n \tCamera *activeCamera_;\n };\n \n@@ -209,6 +227,7 @@ int SimpleCameraData::init()\n {\n \tSimplePipelineHandler *pipe = static_cast<SimplePipelineHandler *>(pipe_);\n \tV4L2VideoDevice *video = pipe->video();\n+\tSimpleConverter *converter = pipe->converter();\n \tint ret;\n \n \t/*\n@@ -258,7 +277,13 @@ int SimpleCameraData::init()\n \t\t\tconfig.pixelFormat = pixelFormat;\n \t\t\tconfig.size = format.size;\n \n-\t\t\tformats_[pixelFormat] = config;\n+\t\t\tif (!converter) {\n+\t\t\t\tformats_[pixelFormat] = config;\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n+\t\t\tfor (PixelFormat format : converter->formats(pixelFormat))\n+\t\t\t\tformats_[format] = config;\n \t\t}\n \t}\n \n@@ -385,6 +410,8 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n \t\tstatus = Adjusted;\n \t}\n \n+\tneedConversion_ = cfg.pixelFormat != pipeConfig.pixelFormat;\n+\n \tif (cfg.size != pipeConfig.size) {\n \t\tLOG(SimplePipeline, Debug)\n \t\t\t<< \"Adjusting size from \" << cfg.size.toString()\n@@ -403,13 +430,14 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n */\n \n SimplePipelineHandler::SimplePipelineHandler(CameraManager *manager)\n-\t: PipelineHandler(manager), video_(nullptr)\n+\t: PipelineHandler(manager), video_(nullptr), converter_(nullptr)\n {\n }\n \n SimplePipelineHandler::~SimplePipelineHandler()\n {\n \tdelete video_;\n+\tdelete converter_;\n }\n \n CameraConfiguration *SimplePipelineHandler::generateConfiguration(Camera *camera,\n@@ -473,22 +501,37 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n \t\treturn ret;\n \n \t/* Configure the video node. */\n-\tuint32_t fourcc = video_->toV4L2Fourcc(cfg.pixelFormat);\n+\tuint32_t fourcc = video_->toV4L2Fourcc(pipeConfig.pixelFormat);\n \n-\tV4L2DeviceFormat outputFormat = {};\n-\toutputFormat.fourcc = fourcc;\n-\toutputFormat.size = cfg.size;\n+\tV4L2DeviceFormat captureFormat = {};\n+\tcaptureFormat.fourcc = fourcc;\n+\tcaptureFormat.size = cfg.size;\n \n-\tret = video_->setFormat(&outputFormat);\n+\tret = video_->setFormat(&captureFormat);\n \tif (ret)\n \t\treturn ret;\n \n-\tif (outputFormat.size != cfg.size || outputFormat.fourcc != fourcc) {\n+\tif (captureFormat.fourcc != fourcc || captureFormat.size != cfg.size) {\n \t\tLOG(SimplePipeline, Error)\n \t\t\t<< \"Unable to configure capture in \" << cfg.toString();\n \t\treturn -EINVAL;\n \t}\n \n+\t/* Configure the converter if required. */\n+\tuseConverter_ = config->needConversion();\n+\n+\tif (useConverter_) {\n+\t\tint ret = converter_->configure(pipeConfig.pixelFormat,\n+\t\t\t\t\t\tcfg.pixelFormat, cfg.size);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(SimplePipeline, Error)\n+\t\t\t\t<< \"Unable to configure converter\";\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\tLOG(SimplePipeline, Debug) << \"Using format converter\";\n+\t}\n+\n \tcfg.setStream(&data->stream_);\n \n \treturn 0;\n@@ -499,24 +542,47 @@ int SimplePipelineHandler::exportFrameBuffers(Camera *camera, Stream *stream,\n {\n \tunsigned int count = stream->configuration().bufferCount;\n \n-\treturn video_->exportBuffers(count, buffers);\n+\t/*\n+\t * Export buffers on the converter or capture video node, depending on\n+\t * whether the converter is used or not.\n+\t */\n+\tif (useConverter_)\n+\t\treturn converter_->exportBuffers(count, buffers);\n+\telse\n+\t\treturn video_->exportBuffers(count, buffers);\n }\n \n int SimplePipelineHandler::start(Camera *camera)\n {\n \tSimpleCameraData *data = cameraData(camera);\n \tunsigned int count = data->stream_.configuration().bufferCount;\n+\tint ret;\n \n-\tint ret = video_->importBuffers(count);\n+\tif (useConverter_)\n+\t\tret = video_->allocateBuffers(count, &converterBuffers_);\n+\telse\n+\t\tret = video_->importBuffers(count);\n \tif (ret < 0)\n \t\treturn ret;\n \n \tret = video_->streamOn();\n \tif (ret < 0) {\n-\t\tvideo_->releaseBuffers();\n+\t\tstop(camera);\n \t\treturn ret;\n \t}\n \n+\tif (useConverter_) {\n+\t\tret = converter_->start(count);\n+\t\tif (ret < 0) {\n+\t\t\tstop(camera);\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\t/* Queue all internal buffers for capture. */\n+\t\tfor (std::unique_ptr<FrameBuffer> &buffer : converterBuffers_)\n+\t\t\tvideo_->queueBuffer(buffer.get());\n+\t}\n+\n \tactiveCamera_ = camera;\n \n \treturn 0;\n@@ -524,8 +590,13 @@ int SimplePipelineHandler::start(Camera *camera)\n \n void SimplePipelineHandler::stop(Camera *camera)\n {\n+\tif (useConverter_)\n+\t\tconverter_->stop();\n+\n \tvideo_->streamOff();\n \tvideo_->releaseBuffers();\n+\n+\tconverterBuffers_.clear();\n \tactiveCamera_ = nullptr;\n }\n \n@@ -541,6 +612,15 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request)\n \t\treturn -ENOENT;\n \t}\n \n+\t/*\n+\t * If conversion is needed, push the buffer to the converter queue, it\n+\t * will be handed to the converter in the capture completion handler.\n+\t */\n+\tif (useConverter_) {\n+\t\tconverterQueue_.push(buffer);\n+\t\treturn 0;\n+\t}\n+\n \treturn video_->queueBuffer(buffer);\n }\n \n@@ -550,16 +630,21 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request)\n \n bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n {\n-\tstatic const char * const drivers[] = {\n-\t\t\"imx7-csi\",\n-\t\t\"sun6i-csi\",\n+\tstatic const SimplePipelineInfo infos[] = {\n+\t\t{ \"imx7-csi\", \"pxp\" },\n+\t\t{ \"sun6i-csi\", nullptr },\n \t};\n \n-\tfor (const char *driver : drivers) {\n-\t\tDeviceMatch dm(driver);\n+\tMediaDevice *converter;\n+\n+\tfor (const SimplePipelineInfo &info : infos) {\n+\t\tDeviceMatch dm(info.driver);\n \t\tmedia_ = acquireMediaDevice(enumerator, dm);\n-\t\tif (media_)\n+\t\tif (media_) {\n+\t\t\tDeviceMatch converterMatch(info.converter);\n+\t\t\tconverter = acquireMediaDevice(enumerator, converterMatch);\n \t\t\tbreak;\n+\t\t}\n \t}\n \n \tif (!media_)\n@@ -614,6 +699,19 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n \n \tvideo_->bufferReady.connect(this, &SimplePipelineHandler::bufferReady);\n \n+\t/* Open the converter, if any. */\n+\tif (converter) {\n+\t\tconverter_ = new SimpleConverter(converter);\n+\t\tif (converter_->open() < 0) {\n+\t\t\tLOG(SimplePipeline, Warning)\n+\t\t\t\t<< \"Failed to open converter, disabling format conversion\";\n+\t\t\tdelete converter_;\n+\t\t\tconverter_ = nullptr;\n+\t\t}\n+\n+\t\tconverter_->bufferReady.connect(this, &SimplePipelineHandler::converterDone);\n+\t}\n+\n \t/*\n \t * Create one camera data instance for each sensor and gather all\n \t * entities in all pipelines.\n@@ -688,12 +786,70 @@ V4L2Subdevice *SimplePipelineHandler::subdev(const MediaEntity *entity)\n \n void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\n {\n-\tASSERT(activeCamera_);\n+\t/*\n+\t * If an error occurred during capture, or if the buffer was cancelled,\n+\t * complete the request, even if the converter is in use as there's no\n+\t * point converting an erroneous buffer.\n+\t */\n+\tif (buffer->metadata().status != FrameMetadata::FrameSuccess) {\n+\t\tif (useConverter_) {\n+\t\t\t/* Requeue the buffer for capture. */\n+\t\t\tvideo_->queueBuffer(buffer);\n+\n+\t\t\t/*\n+\t\t\t * Get the next user-facing buffer to complete the\n+\t\t\t * request.\n+\t\t\t */\n+\t\t\tif (converterQueue_.empty())\n+\t\t\t\treturn;\n+\n+\t\t\tbuffer = converterQueue_.front();\n+\t\t\tconverterQueue_.pop();\n+\t\t}\n+\n+\t\tRequest *request = buffer->request();\n+\t\tcompleteBuffer(activeCamera_, request, buffer);\n+\t\tcompleteRequest(activeCamera_, request);\n+\t\treturn;\n+\t}\n+\n+\t/*\n+\t * Queue the captured and the request buffer to the converter if format\n+\t * conversion is needed. If there's no queued request, just requeue the\n+\t * captured buffer for capture.\n+\t */\n+\tif (useConverter_) {\n+\t\tif (converterQueue_.empty()) {\n+\t\t\tvideo_->queueBuffer(buffer);\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tFrameBuffer *output = converterQueue_.front();\n+\t\tconverterQueue_.pop();\n+\n+\t\tconverter_->queueBuffers(buffer, output);\n+\t\treturn;\n+\t}\n+\n+\t/* Otherwise simply complete the request. */\n \tRequest *request = buffer->request();\n \tcompleteBuffer(activeCamera_, request, buffer);\n \tcompleteRequest(activeCamera_, request);\n }\n \n+void SimplePipelineHandler::converterDone(FrameBuffer *input,\n+\t\t\t\t\t FrameBuffer *output)\n+{\n+\t/* Complete the request. */\n+\tASSERT(activeCamera_);\n+\tRequest *request = output->request();\n+\tcompleteBuffer(activeCamera_, request, output);\n+\tcompleteRequest(activeCamera_, request);\n+\n+\t/* Queue the input buffer back for capture. */\n+\tvideo_->queueBuffer(input);\n+}\n+\n REGISTER_PIPELINE_HANDLER(SimplePipelineHandler);\n \n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v2", "10/10" ] }