Show a patch.

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

{
    "id": 3388,
    "url": "https://patchwork.libcamera.org/api/patches/3388/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3388/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20200404004438.17992-12-laurent.pinchart@ideasonboard.com>",
    "date": "2020-04-04T00:44:38",
    "name": "[libcamera-devel,v4,11/11] libcamera: pipeline: simple: Integrate converter support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "e42a9328df1778f4543fbe24f2b704b59761e05f",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/3388/mbox/",
    "series": [
        {
            "id": 796,
            "url": "https://patchwork.libcamera.org/api/series/796/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=796",
            "date": "2020-04-04T00:44:27",
            "name": "Simple pipeline handler",
            "version": 4,
            "mbox": "https://patchwork.libcamera.org/series/796/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3388/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3388/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@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 A928962DD9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 Apr 2020 02:44:57 +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 14A9355B;\n\tSat,  4 Apr 2020 02:44:57 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"KYgfmCXI\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1585961097;\n\tbh=nLXEyMuDusyDeNafX+6TY854JqAIGEbPhDPCXj5zQXs=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=KYgfmCXIMXryHPtxkQIbniUYu4tQfyyWGkTrR+IpiZbh6n08I626zFBs2fwgXE9TT\n\tFmr35bc3/f17bmB3vBBLqrCcDklEnjGEs7mqwFFRBo/p9qhnS/4XuZKENhPbIU2zsf\n\ttJUh2hw5dO1ViwYNATLooVO76MZa/z6iz53WfIg0=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Martijn Braam <martijn@brixit.nl>,\n\tBenjamin GAIGNARD <benjamin.gaignard@st.com>,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>",
        "Date": "Sat,  4 Apr 2020 03:44:38 +0300",
        "Message-Id": "<20200404004438.17992-12-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200404004438.17992-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20200404004438.17992-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v4 11/11] 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": "Sat, 04 Apr 2020 00:44:58 -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---\nChanges since v2:\n\n- Rebase on top of V4L2PixelFormat\n- Don't crash if the device has no converter\n---\n src/libcamera/pipeline/simple/simple.cpp | 196 ++++++++++++++++++++---\n 1 file changed, 178 insertions(+), 18 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex e4f33f6ff531..8e7dd091b4ab 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,17 +32,24 @@\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 namespace {\n \n-static const char * const drivers[] = {\n-\t\"imx7-csi\",\n-\t\"sun6i-csi\",\n+static const SimplePipelineInfo supportedDevices[] = {\n+\t{ \"imx7-csi\", \"pxp\" },\n+\t{ \"sun6i-csi\", nullptr },\n };\n \n } /* namespace */\n@@ -88,6 +96,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@@ -98,6 +108,7 @@ private:\n \tconst SimpleCameraData *data_;\n \n \tV4L2SubdeviceFormat sensorFormat_;\n+\tbool needConversion_;\n };\n \n class SimplePipelineHandler : public PipelineHandler\n@@ -120,6 +131,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@@ -136,11 +148,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@@ -219,6 +237,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@@ -275,7 +294,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@@ -414,6 +439,8 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()\n \t\tstatus = Adjusted;\n \t}\n \n+\tneedConversion_ = cfg.pixelFormat != pipeConfig.pixelFormat;\n+\n \tcfg.bufferCount = 3;\n \n \treturn status;\n@@ -424,13 +451,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@@ -496,22 +524,37 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)\n \t\treturn ret;\n \n \t/* Configure the video node. */\n-\tV4L2PixelFormat videoFormat = video_->toV4L2PixelFormat(cfg.pixelFormat);\n+\tV4L2PixelFormat videoFormat = video_->toV4L2PixelFormat(pipeConfig.pixelFormat);\n \n-\tV4L2DeviceFormat outputFormat = {};\n-\toutputFormat.fourcc = videoFormat;\n-\toutputFormat.size = cfg.size;\n+\tV4L2DeviceFormat captureFormat = {};\n+\tcaptureFormat.fourcc = videoFormat;\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 != videoFormat) {\n+\tif (captureFormat.fourcc != videoFormat || 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@@ -522,24 +565,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@@ -547,8 +613,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@@ -564,6 +635,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@@ -573,11 +653,20 @@ int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request)\n \n bool SimplePipelineHandler::match(DeviceEnumerator *enumerator)\n {\n-\tfor (const char *driver : drivers) {\n-\t\tDeviceMatch dm(driver);\n+\tMediaDevice *converter = nullptr;\n+\n+\tfor (const SimplePipelineInfo &info : supportedDevices) {\n+\t\tDeviceMatch dm(info.driver);\n \t\tmedia_ = acquireMediaDevice(enumerator, dm);\n-\t\tif (media_)\n+\t\tif (!media_)\n+\t\t\tcontinue;\n+\n+\t\tif (!info.converter)\n \t\t\tbreak;\n+\n+\t\tDeviceMatch converterMatch(info.converter);\n+\t\tconverter = acquireMediaDevice(enumerator, converterMatch);\n+\t\tbreak;\n \t}\n \n \tif (!media_)\n@@ -632,6 +721,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@@ -706,12 +808,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",
        "v4",
        "11/11"
    ]
}