From patchwork Thu Nov 23 04:48:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 19229 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 006E5C3220 for ; Thu, 23 Nov 2023 04:48:25 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9E187629C3; Thu, 23 Nov 2023 05:48:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1700714905; bh=oKNmoe5uIoMBAVhKJcFrgWVMNFo1cN2vM+RAbJZgy0U=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=f2Nb7r/raJNfmiA6AA44e0sZIe6V+kIu7XGuzRntYGqy5hWAamW0iQ7pjzT9Oy28F IloFk2OBXeejfLVPmt7rZMZVcP3OPFfTTbBiF4ZQXEk6H0KogvQnkT88g/ByNHjI3W KmUGls+HPxpfDxSb7vuC98CUrGTwo+J3XYBfWMRtDSXo5tHb3Z3htYCCdvomZbW89t 2E/LyrDITPHjcb7rZCvzLBfKGRbtghZ1ug2vfO8Yi9YN5HNUIKpXVjNqgn5ykr2zRO v+xqrYsHvZru6/lFq3RSyeP+FSvzgR+qmOOE6Je+hp2/+Pj1+vXmfLt6qgZhlFSwH/ o3IjOiOJMtVnA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A6B96629BB for ; Thu, 23 Nov 2023 05:48:23 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P6Xa/65+"; dkim-atps=neutral Received: from umang.jainideasonboard.com (unknown [103.251.226.72]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B0E4B749; Thu, 23 Nov 2023 05:47:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1700714872; bh=oKNmoe5uIoMBAVhKJcFrgWVMNFo1cN2vM+RAbJZgy0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P6Xa/65+JAL6bvVC5TuJihoe8DPbwy/3Glas4oBscMbyWWMDrDO/Hcmk6z1UwgNlZ uk87jzT0Zh5yQQVUBSHpId2fLVQQK+pLEyIIthj/fkqWpb04Rr9kT8t27KJuXsmdaW 5tGCbMvg4yjj+usaSSerQ8hxcUvZCLzlKomVR8xc= To: libcamera-devel@lists.libcamera.org Date: Thu, 23 Nov 2023 10:18:11 +0530 Message-Id: <20231123044811.70703-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231123044811.70703-1-umang.jain@ideasonboard.com> References: <20231123044811.70703-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/2] 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: Nicolas Dufresne Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Jaslo Ziska 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 receive EOS events, for example, from gst-launch-1.0 with the -e (--eos-on-shutdown) flag applied. 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 Signed-off-by: Umang Jain --- Changes in v4: - Fix clang build false-positive compile breakage Use gst_clear_event(&oldEvent) to free oldEvent. --- src/gstreamer/gstlibcamerasrc.cpp | 37 ++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 63d99571..fde1065d 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,28 @@ 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: { + GstEvent *oldEvent = self->pending_eos.exchange(event); + gst_clear_event(&oldEvent); + + ret = TRUE; + break; + } + default: + gst_event_unref(event); + break; + } + + return ret; +} + static void gst_libcamera_src_finalize(GObject *object) { @@ -779,6 +811,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 +878,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",