From patchwork Fri Jun 18 18:32:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 12652 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 44E5EBD78E for ; Fri, 18 Jun 2021 18:33:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF61460298; Fri, 18 Jun 2021 20:33:40 +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="hDyZDHD6"; dkim-atps=neutral Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F6A460298 for ; Fri, 18 Jun 2021 20:33:39 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id u18so2948235pfk.11 for ; Fri, 18 Jun 2021 11:33:39 -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=3xjAz4DnDkQQMb1D9Gn5VxprtdKfZZMeuFqkSHtIKF0=; b=hDyZDHD6HPUwjDl6hu4FinP6VqPvpFCtgImqTEc9pgD2v68Zqp63oNmBrXUJ1IcR2L 91K1hIuK60B963JTKLGb1BgXBE4Uqb09LvrLQ7mDc8i1mu1wj2vt6m3VdVxdvulubKay MRByactl+/yLm+pjMc7z4lLxYWHe53lQDw6oRXWLvSuuv4QqKNyJM22pkc0go0G9K1ca x376YEe3/TcSt/UNf/NAkrsZTp32Zmp0xsKQ8ks62D5amXN4GhhRkTGqxT7K8ni099V+ OXS9Zh7fKbR4MzGuv/P3T/863rdEYkUEln3H/bca9O6El+G+dOkxEHzb6D6sPEnEcHXp hGkQ== 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=3xjAz4DnDkQQMb1D9Gn5VxprtdKfZZMeuFqkSHtIKF0=; b=V86cd1h9FDQlJJ8kEwjCBV06s87afmS+671yBCMtb3ihWRIzNqw5+cL6peTEmjDFJv E91JTUp1H87xabUdor+QUiRwIYwP4h1WBqTiZgyyFag4SfFSxCNt8gPk9c++ODqT3aAO HzYwbW64hUsY68vVd/pujWngQ78+mSXVMpghfRXwlyaYnXDPDja57YSDTIokoDjp7xwE OAKZsl3l42tAz9Xa0PzxjpozUzyOKjVamM0FuH/bcBz+ehgRERvDneTXXp87X3JISo1n YLPcn4K8qTdDbH85yUsD42GT5oE32mEFmWCzIoxsIFdvIAi/TB/JOajqEuCEIeO+y7S9 /c9g== X-Gm-Message-State: AOAM531fZtR/We+WLdvZYZMFgUyFJ+ujgh3eukALcIh+fCUwI+MBwsiP 2Qbw4WkA15LX2yOS+bWBawBMFeUvBdR71w== X-Google-Smtp-Source: ABdhPJz0UD0rioaVtlE4UW97rWB9ujoDfg7+eJWwmUqZ8pAr1Kb2oEaDNHtjYIiup4pbnEqeZGydbQ== X-Received: by 2002:aa7:838b:0:b029:2ea:3332:dd8a with SMTP id u11-20020aa7838b0000b02902ea3332dd8amr6582216pfm.74.1624041217315; Fri, 18 Jun 2021 11:33:37 -0700 (PDT) Received: from localhost.localdomain ([1.186.76.76]) by smtp.googlemail.com with ESMTPSA id x20sm8557835pfh.112.2021.06.18.11.33.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 11:33:36 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Sat, 19 Jun 2021 00:02:18 +0530 Message-Id: <20210618183218.449146-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6] 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" This patch adds support for using request pads in libcamerasrc Gst Element. It allows a user to request multiple streams if the platform supports multistream output using libcamera. This was tested on Raspberry Pi 4B+ with a camera connected to CSI port. It can be tested by running the following command gst-launch-1.0 libcamerasrc camera-name="" name=src src.src ! queue ! videoconvert ! autovideosink src.src_0 ! queue ! videoconvert ! autovideosink Signed-off-by: Vedant Paranjape Reviewed-by: Nicolas Dufresne Reviewed-by: Paul Elder --- src/gstreamer/gstlibcamerasrc.cpp | 53 ++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index ccc61590..ea53c2b5 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,53 @@ 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 +699,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,