From patchwork Mon Jun 7 17:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 12502 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 676B4C3206 for ; Mon, 7 Jun 2021 17:01:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D082268926; Mon, 7 Jun 2021 19:01:20 +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="pV9c3lKG"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A4F3602A7 for ; Mon, 7 Jun 2021 19:01:19 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id u126so9570514pfu.13 for ; Mon, 07 Jun 2021 10:01:19 -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=VW5sARprOQoK3MFFk125r2N4vbB4Ve9yU9uVFS7oaEc=; b=pV9c3lKG3f3fhflqJNAjvbf+lm/muBw0NeL1WvL3VaSkdshWYuFP0ONeDtaX6Mzwus FYwxIzoQieRNG3TH9dVX2hrSndpKHGCAt5IC6H7GribvnleDqJdTgFf+fMgwcuedfQP0 n/Iz1PUbOYCKJcmoPL1s/pwym48VGCX5/n4OEQOU05D1fdGNIvCu0DTDYu83YjhFtn2P zzqZncrgVT4bK8KGbBvFjgAwsw+KkdWwEBzMmuzLMvyvR/a3jNija28eakFfAJkZTADe yRn/KAA8USYwinXbWotajrEZegQ1BAycronfVTStKs5+cZ4XnPNoSPH0TvM/phFfqILy ZASw== 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=VW5sARprOQoK3MFFk125r2N4vbB4Ve9yU9uVFS7oaEc=; b=HPV7oDGdaEIrlK+5U2nAsSzNVzyjDgHfp7HwW2r7dIIoCx7iByYL5ULOLuROOIuMpt bIQ2aBWJ37bnvSjS8Tw+mOfF4kugVBMQeILZJImUpA8NlRW26VdYOEX+IOH8pklmyXdQ QWY8DXzhBWzSruxV7k8Qnyul/UurdJv2pnADseI4OPR3VRe9pY2/oHNf5HFK4k+AHQPl 2tpK+UQgUx7Vqxrs4tZ7u+leD7eZcw9zGbWCCxYmwg2Eh7DbrqAWfoZD5lRhmd1firjn eGMf+E79kbMppRZ8lsWWOL2b1m4JXbD8FVkmVZf6OE1Mm+ZgC70U+s/gTXwNjKRmk4Hs 4q0Q== X-Gm-Message-State: AOAM533WxF6ajW3qaTjSQH79ISiGEzLUNQMiX5XLlcp909f5GWpJQlZb hvK3gSn2cuYTEY6gCwWTD+rFhQkDT5nCwg== X-Google-Smtp-Source: ABdhPJyC4MJ5sdbBc5bKuHkHrzkpYBHWy4vdWNad8ybcUa5Vw7gPmvH1WTLkG8167MFNrGG54pzTMA== X-Received: by 2002:a62:8491:0:b029:2e9:c618:fa32 with SMTP id k139-20020a6284910000b02902e9c618fa32mr17923475pfd.15.1623085277205; Mon, 07 Jun 2021 10:01:17 -0700 (PDT) Received: from localhost.localdomain ([1.186.76.76]) by smtp.googlemail.com with ESMTPSA id g8sm8961506pgo.10.2021.06.07.10.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 10:01:16 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Jun 2021 22:31:00 +0530 Message-Id: <20210607170100.797671-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1] 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. It defines the functions gst_libcamera_src_request_new_pad() and gst_libcamera_src_release_pad() which handle, creating and releasing request pads. It also assigned these functions to their callback handlers in GstLibcameraSrcClass. 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 --- src/gstreamer/gstlibcamerasrc.cpp | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index ccc61590..f0a4fbf0 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -640,6 +640,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; + + pad = gst_pad_new_from_template(templ, name); + if (G_IS_INITIALLY_UNOWNED (pad)) + { + g_object_ref_sink(pad); + } + + { + GLibLocker lock(GST_OBJECT(self->state)); + self->state->srcpads_.push_back((GstPad*)g_object_ref(&pad)); + } + + if (!gst_element_add_pad(element, pad)) + { + GST_ELEMENT_ERROR (element, STREAM, FAILED, + ("Internal data stream error."), ("Could not add pad to element")); + { + GLibLocker lock(GST_OBJECT(self->state)); + self->state->srcpads_.pop_back(); + } + return NULL; + } + + return (GstPad*)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->state)); + auto iterator = std::find(self->state->srcpads_.begin(), self->state->srcpads_.end(), pad); + if (iterator != self->state->srcpads_.end()) + { + g_object_unref(self->state->srcpads_[std::distance(self->state->srcpads_.begin(), iterator)]); + self->state->srcpads_.erase(iterator); + } + } + gst_element_remove_pad(element, pad); +} + static void gst_libcamera_src_class_init(GstLibcameraSrcClass *klass) { @@ -650,6 +701,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,