From patchwork Mon Nov 6 16:52: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: 19191 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 3A24CBDE6B for ; Mon, 6 Nov 2023 19:31:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 88792629A2; Mon, 6 Nov 2023 20:31:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1699299086; bh=joazzP8pAi8f+f+035xJHb92zrQ/zFLWfbOy5G6jkxY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=D9mrCfKiWKxSb5IVhhCLx1TR3VSbTLx+DAF/Iw88JMngxsiREj3k0nUhivSwSnrxo V6CACpedc4sjtaLW91QcYABmYJfqucApkJQv3TpgJzvtT17EauCSRH9XUm9bz4LcDP GxyI9F/BInm6K4sc4vl9Cz/GJ106ETt1TrUuUpzzzxrR7caIF6APsaFRipddTdO5Nr wT6+Y8satKHhP96FDrBM5AVueO5xxZd6ysJ3CpY/w2/ceFkUFdtaMiVV9gcjm5sZtV K/HR6mtsE77HsLvDo2w5Ri+soXAdM8JH0pZRryqrO2T0pFZsM2V2fOmO7MnqPXui/p u0cEDMfzSO+nw== Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.218]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F63261DBA for ; Mon, 6 Nov 2023 17:57:01 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=ziska.de header.i=@ziska.de header.b="Dy9RraW+"; dkim=permerror (0-bit key) header.d=ziska.de header.i=@ziska.de header.b="jABrY6s6"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; t=1699289821; cv=none; d=strato.com; s=strato-dkim-0002; b=jUYm4zLfFRbWJILfp1JelDrUeYO2770nIcZ4OB4YWbKGJL3c0ddA14abTJSsWcZu23 L3QJ6fzg2XeqpZUVhk2HGAumdNhwLdMQxko1JxydMuIk5Zyjt/vdeiqdFnH4KEbkQ4Pc QTgKbTIF6BgS6tiOyZhXI9BXcB1+yfcMwVK3uXbvtNAYGMwCb8CyeDTbheDp8ULjpMzK pTrIjgEhyKqUkn7eR3HxWlgRl0T32sziqbUY9TWRVg+daV4h4tzClLgzAy/XSeziPNU8 n+uy2JreOOINi7bSb5bIo/FA08i5UpqKv91+fpqtLwQLvFJyE8f7G36xM7lTB2O3mJ9a 2GzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1699289821; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=owrJwswb0NiuH1dPo0kJ4a70ARu+u32XGFubs2kyL5Y=; b=S+VyWF6jJwUBo1o6GIYAqkuNSdtEnyTa15e+SiI9D536dZjwaw8rkzFMF7wuIhkwjf DVzEWnFxLN1HwLOblnqXMbVPlwZ/58rBY5GoA6OJNmlM4rcOR6rD/74d0toHHOxyiAC4 t/9pIMZULNyFiJqdK2zqEcSG7TP+gv9kf/37Ea19I52O4D5aAlaPR5B71rOVMFXzmvH7 J8hqCjR8OxXMsrHstOKGqNObqiVNULvy7M+K0YC5M1vz6y2+7NPk0LHY/jYZFJ1Jf/MO 4uDXplYPwEerhjpvNnozOQ5W+wX9FlF2mCReVHTmmyuKww5gb2uSUe+ah7L/wnDGf6gJ RCAQ== 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=1699289821; s=strato-dkim-0002; d=ziska.de; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=owrJwswb0NiuH1dPo0kJ4a70ARu+u32XGFubs2kyL5Y=; b=Dy9RraW+o34G7Bswtp0cpOagixUbVvk5L6zNsqvnGrCIKGpxqapFdgQRGjNGIFDkgT GBWp0/SZ+iAYG5Zoa6B98caFFNN0o17RfU4/5K39OwvAO837Wc1aKvVhC/nqDGI0+MpW k/v1zOAtOwImm4Xllvd70AXJQE4zspAuASAClWuUl/f631nKbk0Mmv44bU7tiKMdddJy fxAjNHbP8vSbDtY5bh1LpxDVM2VAZTkRaz5i61oltAba864g8Tij5BzmPcGJziPJOyCG ct7vQeZIfy/HLI9N4e1Pgi2lHSWShNQiJowcc+GWGzfM9tqubph2pcg+SkSU/zCAAbqe Cq2g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; t=1699289821; s=strato-dkim-0003; d=ziska.de; h=Message-ID:Date:Subject:Cc:To:From:Cc:Date:From:Subject:Sender; bh=owrJwswb0NiuH1dPo0kJ4a70ARu+u32XGFubs2kyL5Y=; b=jABrY6s6dzYkIZ3fYt1yXXL0qihbSAbfblEboDOnqj+nzmsMQ393MvEHnwzL64l1eM XsWH7WYNGESQXjs/oPAQ== X-RZG-AUTH: ":Jm0XeU+IYfb0x77LHmrjN5Wlb7TBwusDqIM6Hizy8VdfzvKi4yoFC9cE0Yq7VvJaIN88vdzOogHquPEQYsYDeV75nip6" Received: from archlinux.fritz.box by smtp.strato.de (RZmta 49.9.1 AUTH) with ESMTPSA id 6bb150zA6Gv1mxn (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Mon, 6 Nov 2023 17:57:01 +0100 (CET) To: libcamera-devel@lists.libcamera.org Date: Mon, 6 Nov 2023 17:52:57 +0100 Message-ID: <20231106165545.47116-1-jaslo@ziska.de> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 06 Nov 2023 20:31:24 +0100 Subject: [libcamera-devel] [PATCH] gstreamer: Implement 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" --- Hi, I recently implemented basic EOS handling for the libcamerasrc gstreamer element. I basically looked at how GstBaseSrc does it and tried to do it similarly. I have no idea whether the locking is correct or if this is thread safe but so far it worked without any issues for my purposes. You can also now run the following command and receive a working video file: gst-launch-1.0 -e libcamerasrc ! videoconvert ! x264enc ! h264parse ! mp4mux ! filesink location=test.mp4 Looking forward for feedback! Cheers, Jaslo src/gstreamer/gstlibcamerasrc.cpp | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) Acked-by: Nicolas Dufresne --- 2.42.1 diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 63d99571..a4681e1e 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -144,6 +144,9 @@ struct _GstLibcameraSrc { gchar *camera_name; controls::AfModeEnum auto_focus_mode = controls::AfModeManual; + GstEvent *pending_eos; + int has_pending_eos; + GstLibcameraSrcState *state; GstLibcameraAllocator *allocator; GstFlowCombiner *flow_combiner; @@ -397,6 +400,21 @@ gst_libcamera_src_task_run(gpointer user_data) bool doResume = false; + if (g_atomic_int_get(&self->has_pending_eos)) { + g_atomic_int_set(&self->has_pending_eos, FALSE); + + GST_OBJECT_LOCK(self); + GstEvent *event = self->pending_eos; + self->pending_eos = NULL; + GST_OBJECT_UNLOCK(self); + + for (GstPad *srcpad : state->srcpads_) + gst_pad_push_event(srcpad, gst_event_ref(event)); + gst_event_unref(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 +765,32 @@ 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: { + GST_OBJECT_LOCK(self); + g_atomic_int_set(&self->has_pending_eos, TRUE); + if (self->pending_eos) + gst_event_unref(self->pending_eos); + self->pending_eos = event; + GST_OBJECT_UNLOCK(self); + + ret = TRUE; + break; + } + default: + gst_event_unref(event); + break; + } + + return ret; +} + static void gst_libcamera_src_finalize(GObject *object) { @@ -779,6 +823,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 +890,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",