Show a patch.

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

{
    "id": 13929,
    "url": "https://patchwork.libcamera.org/api/patches/13929/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13929/",
    "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": "<20210924170234.152783-2-jacopo@jmondi.org>",
    "date": "2021-09-24T17:02:33",
    "name": "[libcamera-devel,1/2] android: wait on fences in CameraStream::process()",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "ebcc7e25af99cc9c109d0bd67edbd4243e5b930d",
    "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/13929/mbox/",
    "series": [
        {
            "id": 2566,
            "url": "https://patchwork.libcamera.org/api/series/2566/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2566",
            "date": "2021-09-24T17:02:32",
            "name": "android: Wait on acquisition fences in CameraStream",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2566/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13929/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13929/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 998C9BF01C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Sep 2021 17:01:58 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4C8FA69194;\n\tFri, 24 Sep 2021 19:01:55 +0200 (CEST)",
            "from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C763687DD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Sep 2021 19:01:51 +0200 (CEST)",
            "(Authenticated sender: jacopo@jmondi.org)\n\tby relay1-d.mail.gandi.net (Postfix) with ESMTPSA id B402C240006;\n\tFri, 24 Sep 2021 17:01:50 +0000 (UTC)"
        ],
        "From": "Jacopo Mondi <jacopo@jmondi.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri, 24 Sep 2021 19:02:33 +0200",
        "Message-Id": "<20210924170234.152783-2-jacopo@jmondi.org>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210924170234.152783-1-jacopo@jmondi.org>",
        "References": "<20210924170234.152783-1-jacopo@jmondi.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 1/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 generated by post-processing are not\ncorrectly handled and are currently ignored by the camera HAL.\n\nAdd a waitFence() function to the CameraStream class to be executed before\nstarting the post-processing in CameraStream::process().\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 |  2 +-\n src/android/camera_stream.cpp | 47 ++++++++++++++++++++++++++++++++++-\n src/android/camera_stream.h   |  4 ++-\n 3 files changed, 50 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\nindex 21844e5114a9..db35947afc2f 100644\n--- a/src/android/camera_device.cpp\n+++ b/src/android/camera_device.cpp\n@@ -1179,7 +1179,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..c723da2c6407 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,6 +166,7 @@ int CameraStream::process(const FrameBuffer &source,\n \t * separate thread.\n \t */\n \tconst StreamConfiguration &output = configuration();\n+\tbuffer_handle_t &camera3Dest = *camera3Buffer.buffer;\n \tCameraBuffer dest(camera3Dest, formats::MJPEG, output.size,\n \t\t\t  PROT_READ | PROT_WRITE);\n \tif (!dest.isValid()) {\ndiff --git a/src/android/camera_stream.h b/src/android/camera_stream.h\nindex 2dab6c3a37d1..1566e5e4009c 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@@ -132,6 +132,8 @@ private:\n \tcamera3_stream_t *camera3Stream_;\n \tconst unsigned int index_;\n \n+\tint waitFence(int fence);\n+\n \tstd::unique_ptr<libcamera::FrameBufferAllocator> allocator_;\n \tstd::vector<libcamera::FrameBuffer *> buffers_;\n \t/*\n",
    "prefixes": [
        "libcamera-devel",
        "1/2"
    ]
}