Show a patch.

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

{
    "id": 15064,
    "url": "https://patchwork.libcamera.org/api/patches/15064/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/15064/",
    "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": "<20211206233948.1351206-9-kieran.bingham@ideasonboard.com>",
    "date": "2021-12-06T23:39:48",
    "name": "[libcamera-devel,8/8] gstreamer: Use Sensor sequence numbers and detect frame drop",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "5c50b4e9444cc566a665a193a0524bafe48b23f5",
    "submitter": {
        "id": 4,
        "url": "https://patchwork.libcamera.org/api/people/4/?format=api",
        "name": "Kieran Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "delegate": {
        "id": 11,
        "url": "https://patchwork.libcamera.org/api/users/11/?format=api",
        "username": "kbingham",
        "first_name": "Kieran",
        "last_name": "Bingham",
        "email": "kieran.bingham@ideasonboard.com"
    },
    "mbox": "https://patchwork.libcamera.org/patch/15064/mbox/",
    "series": [
        {
            "id": 2822,
            "url": "https://patchwork.libcamera.org/api/series/2822/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2822",
            "date": "2021-12-06T23:39:40",
            "name": "Request metadata: SensorSequence",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2822/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/15064/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/15064/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 E8871C325B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  6 Dec 2021 23:40:02 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 55483608A0;\n\tTue,  7 Dec 2021 00:40:02 +0100 (CET)",
            "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 7A6EF60897\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 Dec 2021 00:39:56 +0100 (CET)",
            "from Monstersaurus.local\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1CFF15B0;\n\tTue,  7 Dec 2021 00:39:56 +0100 (CET)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"W2m6sX1M\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1638833996;\n\tbh=ccv875roBOef5VHCE9Pk42QtScQxh7XLZAFWnEY5n8Q=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=W2m6sX1M4RvTCuzP56/9PhNOk/a8n+gqLG9Vw8xNt6jYfoZeXZnPMxNRJPclI+Ori\n\t61spHn/WAjzIGvnf+TvoKrycFu5Om1nZNzqjksTpitMgd1RK4Lu3mfnAMWYpDDWVnL\n\tLRmCd/YNBD7CS35zZarSyKd4OyMwTTCo42IgoIBM=",
        "From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "To": "libcamera devel <libcamera-devel@lists.libcamera.org>",
        "Date": "Mon,  6 Dec 2021 23:39:48 +0000",
        "Message-Id": "<20211206233948.1351206-9-kieran.bingham@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20211206233948.1351206-1-kieran.bingham@ideasonboard.com>",
        "References": "<20211206233948.1351206-1-kieran.bingham@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 8/8] gstreamer: Use Sensor sequence\n\tnumbers and detect frame drop",
        "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": "The stream buffer sequence numbers might produce sequential\nmonotonic sequence numbers from an ISP producing a frame for every\ninput.\n\nThis however, doesn't capture pipeline stalls that cause us to miss or\ndrop frames from the sensor.\n\nUse the SensorSequence metadata to report sequence information, and\nreport to the application if a frame drop is detected.\n\nSigned-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n---\nRFC: This one likely needs better plumbing into gstreamer events.\nIs there anything we should specifically signal to gst ?\n\nIs there a better way to report the errors?\n---\n src/gstreamer/gstlibcamerasrc.cpp | 42 ++++++++++++++++++++++++++-----\n 1 file changed, 36 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex c7292f66b17b..8653127f0d85 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -33,6 +33,7 @@\n #include <vector>\n \n #include <libcamera/camera.h>\n+#include <libcamera/control_ids.h>\n #include <libcamera/camera_manager.h>\n \n #include <gst/base/base.h>\n@@ -111,6 +112,8 @@ struct GstLibcameraSrcState {\n \tstd::queue<std::unique_ptr<RequestWrap>> requests_;\n \tguint group_id_;\n \n+\tguint64 sequence_;\n+\n \tvoid requestCompleted(Request *request);\n };\n \n@@ -165,13 +168,40 @@ GstLibcameraSrcState::requestCompleted(Request *request)\n \t\treturn;\n \t}\n \n+\t/* Extract request metadata */\n+\tuint64_t sequence = 0;\n+\tuint64_t timestamp = 0;\n+\n+\tfor (const auto &ctrl : request->metadata()) {\n+\t\tconst int id = ctrl.first;\n+\t\tconst ControlValue &value = ctrl.second;\n+\n+\t\tif (id == controls::SensorSequence) {\n+\t\t\t/* Handle basic frame drop detection and reporting. */\n+\t\t\tsequence = value.get<int64_t>();\n+\t\t\tif (sequence_ == 0)\n+\t\t\t\tsequence_ = sequence - 1;\n+\t\t\tunsigned int drops = sequence - sequence_ - 1;\n+\t\t\tif (drops)\n+\t\t\t\tGST_ELEMENT_WARNING(src_, RESOURCE, BUSY,\n+\t\t\t\t\t\t    (\"Camera '%s' dropped %u frames.\", cam_->id().c_str(), drops),\n+\t\t\t\t\t\t    (\"libcamera::Request.metadata() reports %u dropped frames at sequence %lu\", drops, sequence));\n+\n+\t\t\tsequence_ = sequence;\n+\t\t}\n+\n+\t\tif (id == controls::SensorTimestamp) {\n+\t\t\ttimestamp = value.get<int64_t>();\n+\t\t}\n+\n+\t\t/* \\todo Handle all/other metadata types here. */\n+\t}\n+\n \tGstBuffer *buffer;\n \tfor (GstPad *srcpad : srcpads_) {\n \t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n \t\tbuffer = wrap->detachBuffer(stream);\n \n-\t\tFrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer);\n-\n \t\tif (GST_ELEMENT_CLOCK(src_)) {\n \t\t\tGstClockTime gst_base_time = GST_ELEMENT(src_)->base_time;\n \t\t\tGstClockTime gst_now = gst_clock_get_time(GST_ELEMENT_CLOCK(src_));\n@@ -180,14 +210,14 @@ GstLibcameraSrcState::requestCompleted(Request *request)\n \n \t\t\t/* Deduced from: sys_now - sys_base_time == gst_now - gst_base_time */\n \t\t\tGstClockTime sys_base_time = sys_now - (gst_now - gst_base_time);\n-\t\t\tGST_BUFFER_PTS(buffer) = fb->metadata().timestamp - sys_base_time;\n-\t\t\tgst_libcamera_pad_set_latency(srcpad, sys_now - fb->metadata().timestamp);\n+\t\t\tGST_BUFFER_PTS(buffer) = timestamp - sys_base_time;\n+\t\t\tgst_libcamera_pad_set_latency(srcpad, sys_now - timestamp);\n \t\t} else {\n \t\t\tGST_BUFFER_PTS(buffer) = 0;\n \t\t}\n \n-\t\tGST_BUFFER_OFFSET(buffer) = fb->metadata().sequence;\n-\t\tGST_BUFFER_OFFSET_END(buffer) = fb->metadata().sequence;\n+\t\tGST_BUFFER_OFFSET(buffer) = sequence;\n+\t\tGST_BUFFER_OFFSET_END(buffer) = sequence;\n \n \t\tgst_libcamera_pad_queue_buffer(srcpad, buffer);\n \t}\n",
    "prefixes": [
        "libcamera-devel",
        "8/8"
    ]
}