Show a patch.

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

{
    "id": 3306,
    "url": "https://patchwork.libcamera.org/api/patches/3306/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/3306/",
    "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": "<20200324155145.3896183-8-niklas.soderlund@ragnatech.se>",
    "date": "2020-03-24T15:51:45",
    "name": "[libcamera-devel,7/7] libcamera: ipu3: Add support for a RAW still capture stream",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "9fb4302ea79b56a20f4f5c5807f2a7b828e6ebc7",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/3306/mbox/",
    "series": [
        {
            "id": 770,
            "url": "https://patchwork.libcamera.org/api/series/770/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=770",
            "date": "2020-03-24T15:51:39",
            "name": "libcamera: Add support for a RAW still capture",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/770/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/3306/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/3306/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<niklas.soderlund@ragnatech.se>",
        "Received": [
            "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E70AD62CE3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 24 Mar 2020 16:51:56 +0100 (CET)",
            "from bismarck.berto.se (p4fca2392.dip0.t-ipconnect.de\n\t[79.202.35.146]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 612be4ff-6de7-11ea-b7d8-005056917a89;\n\tTue, 24 Mar 2020 16:51:52 +0100 (CET)"
        ],
        "X-Halon-ID": "612be4ff-6de7-11ea-b7d8-005056917a89",
        "Authorized-sender": "niklas@soderlund.pp.se",
        "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 24 Mar 2020 16:51:45 +0100",
        "Message-Id": "<20200324155145.3896183-8-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "<20200324155145.3896183-1-niklas.soderlund@ragnatech.se>",
        "References": "<20200324155145.3896183-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 7/7] libcamera: ipu3: Add support for a\n\tRAW still capture stream",
        "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": "Tue, 24 Mar 2020 15:51:58 -0000"
    },
    "content": "Allow the RAW buffer cycling between CIO2 and IMGU to be memory copied\nto a new FrameBuffer in a new RAW stream. This allows users to capture\nthe raw Bayer format coming from the sensor.\n\nAs the RAW frame is memory copied queueing requests with the\nStillCaptureRaw stream might impact performance.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes from RFC\n- Add definition for IPU3_MAX_STREAMS.\n- Deal with all IPU3 Bayer patterns.\n- Rework size logic.\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 99 +++++++++++++++++++++++++---\n 1 file changed, 91 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex cc602834f24108a7..c1b143e58d0a536e 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -140,11 +140,12 @@ class IPU3Stream : public Stream\n {\n public:\n \tIPU3Stream()\n-\t\t: active_(false), device_(nullptr)\n+\t\t: active_(false), raw_(false), device_(nullptr)\n \t{\n \t}\n \n \tbool active_;\n+\tbool raw_;\n \tstd::string name_;\n \tImgUDevice::ImgUOutput *device_;\n };\n@@ -166,6 +167,7 @@ public:\n \n \tIPU3Stream outStream_;\n \tIPU3Stream vfStream_;\n+\tIPU3Stream rawStream_;\n };\n \n class IPU3CameraConfiguration : public CameraConfiguration\n@@ -180,6 +182,7 @@ public:\n \n private:\n \tstatic constexpr unsigned int IPU3_BUFFER_COUNT = 4;\n+\tstatic constexpr unsigned int IPU3_MAX_STREAMS = 3;\n \n \tvoid adjustStream(StreamConfiguration &cfg, bool scale);\n \n@@ -304,8 +307,8 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \t\treturn Invalid;\n \n \t/* Cap the number of entries to the available streams. */\n-\tif (config_.size() > 2) {\n-\t\tconfig_.resize(2);\n+\tif (config_.size() > IPU3_MAX_STREAMS) {\n+\t\tconfig_.resize(IPU3_MAX_STREAMS);\n \t\tstatus = Adjusted;\n \t}\n \n@@ -345,6 +348,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \tstd::set<const IPU3Stream *> availableStreams = {\n \t\t&data_->outStream_,\n \t\t&data_->vfStream_,\n+\t\t&data_->rawStream_,\n \t};\n \n \tstreams_.clear();\n@@ -356,7 +360,9 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \t\tconst Size size = cfg.size;\n \t\tconst IPU3Stream *stream;\n \n-\t\tif (cfg.size == sensorFormat_.size)\n+\t\tif (cfg.pixelFormat.modifiers().count(IPU3_FORMAT_MOD_PACKED))\n+\t\t\tstream = &data_->rawStream_;\n+\t\telse if (cfg.size == sensorFormat_.size)\n \t\t\tstream = &data_->outStream_;\n \t\telse\n \t\t\tstream = &data_->vfStream_;\n@@ -367,8 +373,32 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()\n \t\tLOG(IPU3, Debug)\n \t\t\t<< \"Assigned '\" << stream->name_ << \"' to stream \" << i;\n \n-\t\tbool scale = stream == &data_->vfStream_;\n-\t\tadjustStream(config_[i], scale);\n+\t\tif (stream->raw_) {\n+\t\t\tunsigned int drmfourcc;\n+\t\t\tswitch (sensorFormat_.mbus_code) {\n+\t\t\tcase MEDIA_BUS_FMT_SBGGR10_1X10:\n+\t\t\t\tdrmfourcc = DRM_FORMAT_SBGGR10;\n+\t\t\t\tbreak;\n+\t\t\tcase MEDIA_BUS_FMT_SGBRG10_1X10:\n+\t\t\t\tdrmfourcc = DRM_FORMAT_SGBRG10;\n+\t\t\t\tbreak;\n+\t\t\tcase MEDIA_BUS_FMT_SGRBG10_1X10:\n+\t\t\t\tdrmfourcc = DRM_FORMAT_SGRBG10;\n+\t\t\t\tbreak;\n+\t\t\tcase MEDIA_BUS_FMT_SRGGB10_1X10:\n+\t\t\t\tdrmfourcc = DRM_FORMAT_SRGGB10;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\treturn Invalid;\n+\t\t\t}\n+\t\t\tcfg.pixelFormat = PixelFormat(drmfourcc,\n+\t\t\t\t\t\t      { IPU3_FORMAT_MOD_PACKED });\n+\t\t\tcfg.size = sensorFormat_.size;\n+\t\t\tcfg.bufferCount = IPU3_BUFFER_COUNT;\n+\t\t} else {\n+\t\t\tbool scale = stream == &data_->vfStream_;\n+\t\t\tadjustStream(config_[i], scale);\n+\t\t}\n \n \t\tif (cfg.pixelFormat != pixelFormat || cfg.size != size) {\n \t\t\tLOG(IPU3, Debug)\n@@ -397,6 +427,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,\n \tstd::set<IPU3Stream *> streams = {\n \t\t&data->outStream_,\n \t\t&data->vfStream_,\n+\t\t&data->rawStream_,\n \t};\n \n \tconfig = new IPU3CameraConfiguration(camera, data);\n@@ -438,6 +469,21 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,\n \n \t\t\tbreak;\n \n+\t\tcase StreamRole::StillCaptureRaw: {\n+\t\t\tif (streams.find(&data->rawStream_) == streams.end()) {\n+\t\t\t\tLOG(IPU3, Error)\n+\t\t\t\t\t<< \"No stream available for requested role \"\n+\t\t\t\t\t<< role;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\n+\t\t\tstream = &data->rawStream_;\n+\n+\t\t\tcfg.pixelFormat = PixelFormat(DRM_FORMAT_SRGGB10, { IPU3_FORMAT_MOD_PACKED });\n+\t\t\tcfg.size = data->cio2_.sensor_->resolution();\n+\t\t\tbreak;\n+\t\t}\n+\n \t\tcase StreamRole::Viewfinder:\n \t\tcase StreamRole::VideoRecording: {\n \t\t\t/*\n@@ -571,6 +617,9 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n \t\tstream->active_ = true;\n \t\tcfg.setStream(stream);\n \n+\t\tif (stream->raw_)\n+\t\t\tcontinue;\n+\n \t\tret = imgu->configureOutput(stream->device_, cfg);\n \t\tif (ret)\n \t\t\treturn ret;\n@@ -621,9 +670,15 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c)\n int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream,\n \t\t\t\t\t    std::vector<std::unique_ptr<FrameBuffer>> *buffers)\n {\n+\tIPU3CameraData *data = cameraData(camera);\n \tIPU3Stream *ipu3stream = static_cast<IPU3Stream *>(stream);\n-\tV4L2VideoDevice *video = ipu3stream->device_->dev;\n \tunsigned int count = stream->configuration().bufferCount;\n+\tV4L2VideoDevice *video;\n+\n+\tif (ipu3stream->raw_)\n+\t\tvideo = data->cio2_.output_;\n+\telse\n+\t\tvideo = ipu3stream->device_->dev;\n \n \treturn video->exportBuffers(count, buffers);\n }\n@@ -737,6 +792,10 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n \t\tIPU3Stream *stream = static_cast<IPU3Stream *>(it.first);\n \t\tbuffer = it.second;\n \n+\t\t/* Skip raw streams, they are copied from the CIO2 buffer. */\n+\t\tif (stream->raw_)\n+\t\t\tcontinue;\n+\n \t\tint ret = stream->device_->dev->queueBuffer(buffer);\n \t\tif (ret < 0)\n \t\t\terror = ret;\n@@ -831,6 +890,7 @@ int PipelineHandlerIPU3::registerCameras()\n \t\tstd::set<Stream *> streams = {\n \t\t\t&data->outStream_,\n \t\t\t&data->vfStream_,\n+\t\t\t&data->rawStream_,\n \t\t};\n \t\tCIO2Device *cio2 = &data->cio2_;\n \n@@ -852,6 +912,8 @@ int PipelineHandlerIPU3::registerCameras()\n \t\tdata->outStream_.name_ = \"output\";\n \t\tdata->vfStream_.device_ = &data->imgu_->viewfinder_;\n \t\tdata->vfStream_.name_ = \"viewfinder\";\n+\t\tdata->rawStream_.raw_ = true;\n+\t\tdata->rawStream_.name_ = \"raw\";\n \n \t\t/*\n \t\t * Connect video devices' 'bufferReady' signals to their\n@@ -941,7 +1003,28 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n \tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n \t\treturn;\n \n-\timgu_->input_->queueBuffer(buffer);\n+\tRequest *request = buffer->request();\n+\tFrameBuffer *raw = request->findBuffer(&rawStream_);\n+\n+\tif (!raw) {\n+\t\t/* No RAW buffers present, just queue to IMGU. */\n+\t\timgu_->input_->queueBuffer(buffer);\n+\t\treturn;\n+\t}\n+\n+\t/* RAW buffers present, special care is needed. */\n+\tif (request->buffers().size() > 1)\n+\t\timgu_->input_->queueBuffer(buffer);\n+\n+\tif (raw->copyFrom(buffer))\n+\t\tLOG(IPU3, Debug) << \"Memcopy of FrameBuffer Failed\";\n+\n+\tpipe_->completeBuffer(camera_, request, raw);\n+\n+\tif (request->buffers().size() == 1) {\n+\t\tcio2_.putBuffer(buffer);\n+\t\tpipe_->completeRequest(camera_, request);\n+\t}\n }\n \n /* -----------------------------------------------------------------------------\n",
    "prefixes": [
        "libcamera-devel",
        "7/7"
    ]
}