Show a patch.

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

{
    "id": 13958,
    "url": "https://patchwork.libcamera.org/api/patches/13958/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13958/",
    "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": "<20210927213700.25365-3-jacopo@jmondi.org>",
    "date": "2021-09-27T21:37:00",
    "name": "[libcamera-devel,v2,2/2] android: Wait on fences in CameraStream::process()",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ff313ba706dbef77af6bc721b6fd21f5d1325b3e",
    "submitter": {
        "id": 3,
        "url": "https://patchwork.libcamera.org/api/people/3/?format=api",
        "name": "Jacopo Mondi",
        "email": "jacopo@jmondi.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/13958/mbox/",
    "series": [
        {
            "id": 2577,
            "url": "https://patchwork.libcamera.org/api/series/2577/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2577",
            "date": "2021-09-27T21:36:58",
            "name": "android: Wait on acquisition fences in CameraStream",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2577/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13958/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13958/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 C38A8BDC71\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Sep 2021 21:36:21 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A050E6918E;\n\tMon, 27 Sep 2021 23:36:21 +0200 (CEST)",
            "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E4C9A69189\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 Sep 2021 23:36:17 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 7B8DBC0005;\n\tMon, 27 Sep 2021 21:36:17 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 27 Sep 2021 23:37:00 +0200",
        "Message-Id": "<20210927213700.25365-3-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210927213700.25365-1-jacopo@jmondi.org>",
        "References": "<20210927213700.25365-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 2/2] android: Wait on fences in\n\tCameraStream::process()",
        "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>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Acquisition fences for streams of type Mapped generated by\npost-processing, are not correctly handled and are currently\nignored by the camera HAL.\n\nFix this by adding CameraStream::waitFence(), executed before\nstarting the post-processing in CameraStream::process().\n\nThe change applies to all streams generated by post-processing (Mapped\nand Internal) but currently acquire fences of Internal streams are\nhandled by the camera worker. Post-pone that to post-processing time by\npassing -1 to the worker for Internal streams.\n\nThe CameraStream::waitFence() implementation is copied from the\nCameraWorker::Worker::waitFence() one, and both should be replaced by a\nlibcamera core mechanism.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/android/camera_device.cpp |  6 +++--\n src/android/camera_stream.cpp | 48 +++++++++++++++++++++++++++++++++--\n src/android/camera_stream.h   |  4 ++-\n 3 files changed, 53 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 3c9609d74402..8b0caf2bda7d 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -973,6 +973,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\tconst camera3_stream_buffer_t &camera3Buffer = descriptor.buffers_[i];\n \t\tcamera3_stream *camera3Stream = camera3Buffer.stream;\n \t\tCameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv);\n+\t\tint acquireFence = -1;\n \n \t\tstd::stringstream ss;\n \t\tss << i << \" - (\" << camera3Stream->width << \"x\"\n@@ -1008,6 +1009,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t\t\t\t\t  cameraStream->configuration().size));\n \n \t\t\tbuffer = descriptor.frameBuffers_.back().get();\n+\t\t\tacquireFence = camera3Buffer.acquire_fence;\n \t\t\tLOG(HAL, Debug) << ss.str() << \" (direct)\";\n \t\t\tbreak;\n \n@@ -1030,7 +1032,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques\n \t\t}\n \n \t\tdescriptor.request_->addBuffer(cameraStream->stream(), buffer,\n-\t\t\t\t\t\tcamera3Buffer.acquire_fence);\n+\t\t\t\t\t       acquireFence);\n \t}\n \n \t/*\n@@ -1186,7 +1188,7 @@ void CameraDevice::requestComplete(Request *request)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tint ret = cameraStream->process(*src, *buffer.buffer,\n+\t\tint ret = cameraStream->process(*src, buffer,\n \t\t\t\t\t\tdescriptor.settings_,\n \t\t\t\t\t\tresultMetadata.get());\n \t\t/*\ndiff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp\nindex e30c7ee4fcb3..40dcb361749f 100644\n--- a/src/android/camera_stream.cpp\n+++ b/src/android/camera_stream.cpp\n@@ -7,7 +7,10 @@\n \n #include \"camera_stream.h\"\n \n+#include <errno.h>\n #include <sys/mman.h>\n+#include <sys/poll.h>\n+#include <unistd.h>\n \n #include <libcamera/formats.h>\n \n@@ -109,11 +112,52 @@ int CameraStream::configure()\n \treturn 0;\n }\n \n+int CameraStream::waitFence(int fence)\n+{\n+\t/*\n+\t * \\todo The implementation here is copied from camera_worker.cpp\n+\t * and both should be removed once libcamera is instrumented to handle\n+\t * fences waiting in the core.\n+\t *\n+\t * \\todo Better characterize the timeout. Currently equal to the one\n+\t * used by the Rockchip Camera HAL on ChromeOS.\n+\t */\n+\tconstexpr unsigned int timeoutMs = 300;\n+\tstruct pollfd fds = { fence, POLLIN, 0 };\n+\n+\tdo {\n+\t\tint ret = poll(&fds, 1, timeoutMs);\n+\t\tif (ret == 0)\n+\t\t\treturn -ETIME;\n+\n+\t\tif (ret > 0) {\n+\t\t\tif (fds.revents & (POLLERR | POLLNVAL))\n+\t\t\t\treturn -EINVAL;\n+\n+\t\t\treturn 0;\n+\t\t}\n+\t} while (errno == EINTR || errno == EAGAIN);\n+\n+\treturn -errno;\n+}\n+\n int CameraStream::process(const FrameBuffer &source,\n-\t\t\t  buffer_handle_t camera3Dest,\n+\t\t\t  camera3_stream_buffer_t &camera3Buffer,\n \t\t\t  const CameraMetadata &requestMetadata,\n \t\t\t  CameraMetadata *resultMetadata)\n {\n+\t/* Handle waiting on fences on the destination buffer. */\n+\tint fence = camera3Buffer.acquire_fence;\n+\tif (fence != -1) {\n+\t\tint ret = waitFence(fence);\n+\t\t::close(fence);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(HAL, Error) << \"Failed waiting for fence: \"\n+\t\t\t\t\t<< fence << \": \" << strerror(-ret);\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n \tif (!postProcessor_)\n \t\treturn 0;\n \n@@ -122,7 +166,7 @@ int CameraStream::process(const FrameBuffer &source,\n \t * separate thread.\n \t */\n \tconst StreamConfiguration &output = configuration();\n-\tCameraBuffer dest(camera3Dest, formats::MJPEG, output.size,\n+\tCameraBuffer dest(*camera3Buffer.buffer, formats::MJPEG, output.size,\n \t\t\t  PROT_READ | PROT_WRITE);\n \tif (!dest.isValid()) {\n \t\tLOG(HAL, Error) << \"Failed to map android blob buffer\";\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex 2dab6c3a37d1..454a33dcdaaa 100644\n--- a/src/android/camera_stream.h\n+++ b/src/android/camera_stream.h\n@@ -119,7 +119,7 @@ public:\n \n \tint configure();\n \tint process(const libcamera::FrameBuffer &source,\n-\t\t    buffer_handle_t camera3Dest,\n+\t\t    camera3_stream_buffer_t &camera3Buffer,\n \t\t    const CameraMetadata &requestMetadata,\n \t\t    CameraMetadata *resultMetadata);\n \tlibcamera::FrameBuffer *getBuffer();\n@@ -140,6 +140,8 @@ private:\n \t */\n \tstd::unique_ptr<std::mutex> mutex_;\n \tstd::unique_ptr<PostProcessor> postProcessor_;\n+\n+\tint waitFence(int fence);\n };\n \n #endif /* __ANDROID_CAMERA_STREAM__ */\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "2/2"
    ]
}