From patchwork Sat Jun 12 08:22:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 12578 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 C7392BD78E for ; Sat, 12 Jun 2021 08:23:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F31406892C; Sat, 12 Jun 2021 10:23:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KrqIIU7z"; dkim-atps=neutral Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 247E86892B for ; Sat, 12 Jun 2021 10:22:59 +0200 (CEST) Received: by mail-pj1-x102a.google.com with SMTP id md2-20020a17090b23c2b029016de4440381so7297374pjb.1 for ; Sat, 12 Jun 2021 01:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7vIyUPozvMp2Qzdx8e6CI9H5VaPUebr+Ls+3gA2zzSo=; b=KrqIIU7zPVq3UUo15+JbMJHEkS37LYnZIe0rw2C6PaJWlDvOy3duf/KVaoihAp+5wo etL/QwZppNbz/VIWfbUMw7Fmj3w3G1K+tPQZr+Rl0MS1NtVLmOwV+uyziFzrjeEmyAPW 2Eh9LIerI7FQ/DqCLxdQ/dVbF8IkfGVXHHE3qhcHaqBaqfugo0AjY0VE+KukeZ8fLOOy wrmTPstpHGdRlpAjPVo4E5A2fkE5OanhCp5VvET9ajRaCPuUxDoPUMQhfdnt835ahOFb E0cDIeZsErhaHnWsCCSE+kPM6CN0TGe+FevEd1XxMF/igyGrqSJUO/+mGrndAdsCypxt FiUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7vIyUPozvMp2Qzdx8e6CI9H5VaPUebr+Ls+3gA2zzSo=; b=UVyWSxohrY+6fj+DiDKUYeHjC4NMyjxENVy7bgx6OvU91kwpW6iui/ZbKKfVBHoipo 7baksUJdCaX6EmTpPBWF8kzn9vABr5T4/alPPEetzOihn3HK8fM/DG09JvALaif7Lzx2 fawlu4yXpnoQj6p8mk7foA/o03bToBbTMc9FisHue3Yp2zpYUTK0zOxThJ4lB6FKdB/e bFKapcX2of4g9UtR01Yime1MfAZjL3c9/S+F5JCPGRYNpW6Ha+jXgVaxCPzt2+qnmQ+t JSPdWb99GUSKhX+BIIeDEWYAGB3b1HlPBi6qvIpKMbbaNfTxZNlJOGHKyuF45p9Djl4v 3VfA== X-Gm-Message-State: AOAM532Sc/6AREldYkEToLNvSra/+0jggK7greQJBXykLvBr2sWRWX2p Gp8LoKBG7Arrsedm0g0hE5KnpTLcHnwaXA== X-Google-Smtp-Source: ABdhPJw7xDh7CrGu9aB6staigAyD+QFR+NoviQhbxKh1HpZXw9mtojvmFd3yEJ++sc6ezy/l9zBPrg== X-Received: by 2002:a17:902:7401:b029:102:34f7:48f5 with SMTP id g1-20020a1709027401b029010234f748f5mr7581855pll.47.1623486176951; Sat, 12 Jun 2021 01:22:56 -0700 (PDT) Received: from localhost.localdomain ([1.186.76.76]) by smtp.googlemail.com with ESMTPSA id c15sm7735359pgt.68.2021.06.12.01.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Jun 2021 01:22:56 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Sat, 12 Jun 2021 13:52:31 +0530 Message-Id: <20210612082231.111138-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v5] gstreamer: Added virtual functions needed to support request pads 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: , Cc: Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Using request pads needs virtual functions to create new request pads and release the allocated pads. Added way to generate unique stream_id in gst_libcamera_src_task_enter(). It failed to execute when more than one pad was added. This patch defines the functions gst_libcamera_src_request_new_pad() and gst_libcamera_src_release_pad() which handle, creating and releasing request pads. Also assigns these functions to their callback handlers in GstLibcameraSrcClass. gst_pad_create_stream_id() failed as this gstreamer element has more than 2 source pads, and a nullptr was passed to it's stream_id argument. This function fails to auto generate a stream id for scenario of more than one source pad present. Used a gint which increments everytime new stream_id is requested and group_id to generate an unique stream_id by appending them togther as %i%i. This doesn't enable request pad support in gstreamer element. This is one of the series of changes needed to make it work. Signed-off-by: Vedant Paranjape --- In _request_new_pad and _release_pad, a GLibLock is taken on self->state. But since self->state is a C++ object, GST_OBJECT(self->state) fails and returns null, so GLibLocker throws a warning "invalid cast from '(null)' to 'GstObject'. This means that it actually fails to get lock the resource that needs to be protected, i.e., the srcpads_ vector. The following changes were tested using the following test code: https://pastebin.com/gNDF1cyG src/gstreamer/gstlibcamerasrc.cpp | 57 ++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index ccc61590..1614971d 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -361,10 +361,12 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread, GST_DEBUG_OBJECT(self, "Streaming thread has started"); guint group_id = gst_util_group_id_next(); + gint stream_id_num = 0; StreamRoles roles; for (GstPad *srcpad : state->srcpads_) { /* Create stream-id and push stream-start. */ - g_autofree gchar *stream_id = gst_pad_create_stream_id(srcpad, GST_ELEMENT(self), nullptr); + g_autofree gchar *stream_id_intermediate = g_strdup_printf("%i%i", group_id, stream_id_num++); + g_autofree gchar *stream_id = gst_pad_create_stream_id(srcpad, GST_ELEMENT(self), stream_id_intermediate); GstEvent *event = gst_event_new_stream_start(stream_id); gst_event_set_group_id(event, group_id); gst_pad_push_event(srcpad, event); @@ -640,6 +642,57 @@ gst_libcamera_src_init(GstLibcameraSrc *self) self->state = state; } +static GstPad* +gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ, + const gchar *name, [[maybe_unused]] const GstCaps *caps) +{ + GstLibcameraSrc *self = GST_LIBCAMERA_SRC(element); + g_autoptr(GstPad) pad = NULL; + + GST_DEBUG_OBJECT(self, "new request pad created"); + + pad = gst_pad_new_from_template(templ, name); + g_object_ref_sink(pad); + + if (gst_element_add_pad(element, pad)) + { + GLibLocker lock(GST_OBJECT(self)); + self->state->srcpads_.push_back(reinterpret_cast(g_object_ref(pad))); + } + else + { + GST_ELEMENT_ERROR (element, STREAM, FAILED, + ("Internal data stream error."), + ("Could not add pad to element")); + return NULL; + } + + return reinterpret_cast(g_steal_pointer(&pad)); +} + +static void +gst_libcamera_src_release_pad(GstElement *element, GstPad *pad) +{ + GstLibcameraSrc *self = GST_LIBCAMERA_SRC(element); + + GST_DEBUG_OBJECT (self, "Pad %" GST_PTR_FORMAT " being released", pad); + + { + GLibLocker lock(GST_OBJECT(self)); + std::vector &pads = self->state->srcpads_; + auto begin_iterator = pads.begin(); + auto end_iterator = pads.end(); + auto pad_iterator = std::find(begin_iterator, end_iterator, pad); + + if (pad_iterator != end_iterator) + { + g_object_unref(*pad_iterator); + pads.erase(pad_iterator); + } + } + gst_element_remove_pad(element, pad); +} + static void gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) { @@ -650,6 +703,8 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) object_class->get_property = gst_libcamera_src_get_property; object_class->finalize = gst_libcamera_src_finalize; + 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; gst_element_class_set_metadata(element_class,