From patchwork Tue Nov 14 12:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaslo Ziska X-Patchwork-Id: 19213 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6833DC3213 for ; Tue, 14 Nov 2023 12:29:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AFB65629BC; Tue, 14 Nov 2023 13:29:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1699964959; bh=37kERtv048rb2gEwBd/vbzTSMW6IfaZv6J7FWmc+cX4=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uzOdLAlTdweX9KGXEkz6PMUHtD0lSIQpBqICjAYXGDhQEQDLSnJg24GKmbXt9CFvD oISyEhmYMu2/OchLREf7HxJhihvmmQ350VKVjbwt2ycGTGiByp8VzNL+0hyTRsHxSG 8ghxNVlRViJ06TPai6pG0xosYmLKg1cZQneEY8Hh+tJYfpO5EFHFc7BBTB50QmLOsc TZDuUGEpiotNzN0nB3sm5C1yxjisZgDc5UQRDrMbCGpJZiwrnS+WVcsLqzH4HI+cVI Bzr+Zzhqe/qR3JHPpKJW1h2DcM3aacGzSC3hTAFBVldLmK0zbNd5WcYbscKruP8LZo DHFbO5Yy7fpNg== Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.220]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 52DE56299E for ; Tue, 14 Nov 2023 13:29:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=ziska.de header.i=@ziska.de header.b="Fq3pFej2"; dkim=permerror (0-bit key) header.d=ziska.de header.i=@ziska.de header.b="NK0KJuCF"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; t=1699964956; cv=none; d=strato.com; s=strato-dkim-0002; b=fs8eisYuPMlY0uLic695Q3FKsBGRyiKBVUici0SOKLKUQNlpe+CRythe6pB7YqG1Lv Gj2xjeXT+3j0An9Rok+H5jTzVjia9XNvhnvj8X1e4O+9xLGwjAz6z0w/KEZk4WoaKFyX vHZf2JZ2/7zKFGE096nCYBZsQ21J5Xr0nddTICdS+YLQGR5ll277TSLMMMp0pnVMvOvF ZC6JS/3KuBbumgD+/ROE5ldhehGmPPSR+Y3u9WSKKYPLEDnyQ0NWvbmPQHBlHpd269pV vGSDq9hHCjIMnq6Iz4IFjSkjCi0KotRQQXAhTRW1NkdIoaPG0m20YoXIx8W/qNaRPpdQ qZ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1699964956; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=pxDXlX0pFgep9WKfoOsj0HSKbBG9gmNbPQrgEOZ5nSA=; b=h1g/OlPaXzAPz+CXcCIQDuHIYvwwsAAKkQbsDC9pJW3Y5+bR7/AAkIi/UGoBWAudM3 b5936UPSlP2JJog1lvt+6Y6VRrCzoGizv26SgbjEJF2i+D/TW150kfiH0vnZLQhAOPHv WFM7ffAMv9xGMDgLUeULN2ki5+eDq20NYAAufd5gsfwYdzh9AvMtNgShtPitxYihkNET TMykQloPgr/QFy0GS+Nvj1Dd41biNpd5Drz6XALduIptNtN1M6P+wxLn0Mpq3HSalYAV TYPXwONXZtgBFdkzQPg+mv9zQcY6bT9Y/e8WunppdSiLqWM6tWemQEBNrV+RFCcs3Hb4 aTWg== ARC-Authentication-Results: i=1; strato.com; arc=none; dkim=none X-RZG-CLASS-ID: mo00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1699964956; s=strato-dkim-0002; d=ziska.de; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=pxDXlX0pFgep9WKfoOsj0HSKbBG9gmNbPQrgEOZ5nSA=; b=Fq3pFej2C9qZwx1Iz3lf7DelgEdbfWPSN+TkMiC1rQUu5DodTtBpTX0xu8Y07ESPDH zbHZJy1PXVd5M2FNtCxKfCGw9k1cxrALg9sxZPER2YI6jnzA29yipdTBMXmL9TxoQUaQ x64kbPubcF2V8GifpFOHzlhax4rcuXbCVaVjnWMjd1gmkR9ZSBu3VR2s51LI04Hr+plH Y1wlr02Ig4xkiOrb1SkZfHgsJBWu9f+RXYG8hw5EiQ4GbaI0vKgIpsYMBHEHeEU3qkLW s/gN+ofjWRgda4wK0h4Bjc+shj/107GLnIhoPnkNhYhcYn2udEBr86FqxjHN0M5OJ9ed HIZA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1699964956; s=strato-dkim-0003; d=ziska.de; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=pxDXlX0pFgep9WKfoOsj0HSKbBG9gmNbPQrgEOZ5nSA=; b=NK0KJuCFyrCM4AhnYhuUHEvWbwAWg1VnQctLhwOs7HAr78NcTkCBvDK/OYxqYSICBL lV+geDnfyT/RaWlBwNDA== X-RZG-AUTH: ":Jm0XeU+IYfb0x77LHmrjN5Wlb7TBwusDqIM6Hizy8VdfzvKi4yoFC9cCgorrBfJa1Ew82pWz/tz8/A+0LafdQ1JRlSvq" Received: from archlinux.fritz.box by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id j3f4eezAECTG5AV (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Tue, 14 Nov 2023 13:29:16 +0100 (CET) To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Nov 2023 13:18:57 +0100 Message-ID: <20231114122800.10007-1-jaslo@ziska.de> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] gstreamer: Implement element EOS handling X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jaslo Ziska via libcamera-devel From: Jaslo Ziska Reply-To: Jaslo Ziska Cc: Jaslo Ziska , Nicolas Dufresne Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This commit implements EOS handling for events sent to the libcamerasrc element by the send_event method (which can happen when pressing Ctrl-C while running gst-launch-1.0 -e, see below). EOS events from downstream elements returning GST_FLOW_EOS are not considered here. To archive this add a function for the send_event method which handles the GST_EVENT_EOS event. This function will set an atomic to the received event and push this EOS event to all source pads in the running task. Also set the GST_ELEMENT_FLAG_SOURCE flag to identify libcamerasrc as a source element which enables it to receive EOS events sent to the (pipeline) bin containing it. This in turn enables libcamerasrc to for example receive EOS events from gst-launch-1.0 when using the -e flag. Bug: https://bugs.libcamera.org/show_bug.cgi?id=91 Signed-off-by: Jaslo Ziska Acked-by: Nicolas Dufresne Reviewed-by: Nicolas Dufresne Reviewed-by: Umang Jain --- Thanks for all the advise on v2 everyone! In this revision I explain which EOS events are handled in the commit message a little bit more and link to the bug report. As recommended, g_autoptr is now used. I decided to declare g_autoptr(event) outside of the if-statement for now, I was not sure what the consensus on this is at the moment. Regards, Jaslo src/gstreamer/gstlibcamerasrc.cpp | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) -- 2.42.1 diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 63d99571..767017db 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -9,7 +9,6 @@ /** * \todo The following is a list of items that needs implementation in the GStreamer plugin * - Implement GstElement::send_event - * + Allowing application to send EOS * + Allowing application to use FLUSH/FLUSH_STOP * + Prevent the main thread from accessing streaming thread * - Implement renegotiation (even if slow) @@ -29,6 +28,7 @@ #include "gstlibcamerasrc.h" +#include #include #include @@ -144,6 +144,8 @@ struct _GstLibcameraSrc { gchar *camera_name; controls::AfModeEnum auto_focus_mode = controls::AfModeManual; + std::atomic pending_eos; + GstLibcameraSrcState *state; GstLibcameraAllocator *allocator; GstFlowCombiner *flow_combiner; @@ -397,6 +399,14 @@ gst_libcamera_src_task_run(gpointer user_data) bool doResume = false; + g_autoptr(GstEvent) event = self->pending_eos.exchange(nullptr); + if (event) { + for (GstPad *srcpad : state->srcpads_) + gst_pad_push_event(srcpad, gst_event_ref(event)); + + return; + } + /* * Create and queue one request. If no buffers are available the * function returns -ENOBUFS, which we ignore here as that's not a @@ -747,6 +757,27 @@ gst_libcamera_src_change_state(GstElement *element, GstStateChange transition) return ret; } +static gboolean +gst_libcamera_src_send_event(GstElement *element, GstEvent *event) +{ + GstLibcameraSrc *self = GST_LIBCAMERA_SRC(element); + gboolean ret = FALSE; + + switch (GST_EVENT_TYPE(event)) { + case GST_EVENT_EOS: { + g_autoptr(GstEvent) oldEvent = self->pending_eos.exchange(event); + + ret = TRUE; + break; + } + default: + gst_event_unref(event); + break; + } + + return ret; +} + static void gst_libcamera_src_finalize(GObject *object) { @@ -779,6 +810,8 @@ gst_libcamera_src_init(GstLibcameraSrc *self) state->srcpads_.push_back(gst_pad_new_from_template(templ, "src")); gst_element_add_pad(GST_ELEMENT(self), state->srcpads_.back()); + GST_OBJECT_FLAG_SET(self, GST_ELEMENT_FLAG_SOURCE); + /* C-style friend. */ state->src_ = self; self->state = state; @@ -844,6 +877,7 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) element_class->request_new_pad = gst_libcamera_src_request_new_pad; element_class->release_pad = gst_libcamera_src_release_pad; element_class->change_state = gst_libcamera_src_change_state; + element_class->send_event = gst_libcamera_src_send_event; gst_element_class_set_metadata(element_class, "libcamera Source", "Source/Video",