From patchwork Tue Sep 14 06:34:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13842 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 E430EBDC71 for ; Tue, 14 Sep 2021 06:34:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 53D556916F; Tue, 14 Sep 2021 08:34:27 +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="nYJYyzdo"; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1876E6916F for ; Tue, 14 Sep 2021 08:34:26 +0200 (CEST) Received: by mail-pg1-x535.google.com with SMTP id t1so11805958pgv.3 for ; Mon, 13 Sep 2021 23:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rX3t3kqsPE5dxb6s9T51FplxW2wMBXEcQry411D9gBo=; b=nYJYyzdoS7YGr8d3CMY3+w7slib9+jfrRSi9a2KpP3SiB9ZPJG1TUQx0B95B30OdYc eD63KIiKfEYaBUjB5NM++6MTur7k2em6g7/MbpEMepsZz2064zgNW93mUjl6JMpHf0N+ yAkf6qq3c3VigsvMlUg6Q1owZm8DWJ6aCqhXKTnv1fkZbdNQhd4JPJ3dgeraImiDnxYg 9R0hMHT+ySjRpb8ybUhR3h4Ellg9p4wIIO87VwZb62xIyHZ7OI7iuX9ek5uZL8TJEdZD 33Q3J+prWA9+NazazEepe/jH3A4iAl386D3BQt628r9vn4B6/dHO14k9iNHCjqicL+Jy j54Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rX3t3kqsPE5dxb6s9T51FplxW2wMBXEcQry411D9gBo=; b=dc0QJ5koTurrrXG1B3faY6aaIW05yl3QE/jlQNIAxthBeCR8ii5+dJmPAUqjw1Arlb NDp+9gzj//qqllkFMBArOQfbHtHZt2J44hktVDeBBjKF/IMUTapI/ym0J3nG91k0ZL+P NmfkMVMx8wrtk+iYaCUfOniw/fFk9ZT6jhA7vegsEY6QE7C6yPrFTwxBmwpy/7nAMr+N 1e/14KYHyKKZ3g+o15L2AtH0SQpUHb/yPySbpvnmr3qUc5IOCe9tgKkowF+zGuDIfKJ2 Iwz43Fw4Om7jx3/3aHhnJ/2biwW1tsvC5AGqKT4fCJgayHvCyW7czxmu+dMNo8/6Rzqw +dwg== X-Gm-Message-State: AOAM531r2Qt0nFABmix2y4n3N6a6F6I/ptQqD6pulQrS4DhQGDdA7Tc4 PTc95yOITTlilUeiUBgEFgqR3K5CH+smNhrQ X-Google-Smtp-Source: ABdhPJxO39ZKk84ur8rfaJd20gE4fDzGLUQHM8WJ5AYOdWpaQpdJNWRm61cA6orKIYprtgKCfIkLug== X-Received: by 2002:a63:e506:: with SMTP id r6mr14179344pgh.85.1631601263920; Mon, 13 Sep 2021 23:34:23 -0700 (PDT) Received: from localhost.localdomain ([1.186.166.254]) by smtp.googlemail.com with ESMTPSA id l6sm9081176pff.74.2021.09.13.23.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 23:34:23 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Sep 2021 12:04:04 +0530 Message-Id: <20210914063404.53621-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] test: gstreamer: Add a test for gstreamer multi stream 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 a test to test if multi stream using libcamera's gstreamer element works. Signed-off-by: Vedant Paranjape Reviewed-by: Paul Elder Tested-by: Paul Elder --- .../gstreamer/gstreamer_multi_stream_test.cpp | 138 ++++++++++++++++++ test/gstreamer/meson.build | 1 + 2 files changed, 139 insertions(+) create mode 100644 test/gstreamer/gstreamer_multi_stream_test.cpp diff --git a/test/gstreamer/gstreamer_multi_stream_test.cpp b/test/gstreamer/gstreamer_multi_stream_test.cpp new file mode 100644 index 000000000000..aba86a3f8e27 --- /dev/null +++ b/test/gstreamer/gstreamer_multi_stream_test.cpp @@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2021, Vedant Paranjape + * + * gstreamer_multi_stream_test.cpp - GStreamer multi stream capture test + */ + +#include +#include + +#include + +#include + +#include "libcamera/internal/source_paths.h" + +#include + +#include "gstreamer_test.h" +#include "test.h" + +using namespace std; + +class GstreamerMultiStreamTest : public GstreamerTest, public Test +{ +public: + GstreamerMultiStreamTest() + : GstreamerTest() + { + } + +protected: + int init() override + { + if (status_ != TestPass) + return status_; + + /* Check if platform support multistream output */ + libcamera::CameraManager cm; + cm.start(); + bool cameraFound = false; + for (auto &camera : cm.cameras()) { + if (camera->streams().size() > 1) { + cameraName = camera->id(); + cameraFound = true; + cm.stop(); + break; + } + } + + if (!cameraFound) { + cm.stop(); + return TestSkip; + } + + g_autoptr(GstElement) convert0 = gst_element_factory_make("videoconvert", "convert0"); + g_autoptr(GstElement) convert1 = gst_element_factory_make("videoconvert", "convert1"); + g_autoptr(GstElement) sink0 = gst_element_factory_make("fakesink", "sink0"); + g_autoptr(GstElement) sink1 = gst_element_factory_make("fakesink", "sink1"); + g_autoptr(GstElement) queue0 = gst_element_factory_make("queue", "queue0"); + g_autoptr(GstElement) queue1 = gst_element_factory_make("queue", "queue1"); + g_object_ref_sink(convert0); + g_object_ref_sink(convert1); + g_object_ref_sink(sink0); + g_object_ref_sink(sink1); + g_object_ref_sink(queue0); + g_object_ref_sink(queue1); + + if (!convert0 || !convert1 || !sink0 || !sink1 || !queue0 || !queue1) { + g_printerr("Not all elements could be created. %p.%p.%p.%p.%p.%p\n", + convert0, convert1, sink0, sink1, queue0, queue1); + + return TestFail; + } + + convert0_ = reinterpret_cast(g_steal_pointer(&convert0)); + convert1_ = reinterpret_cast(g_steal_pointer(&convert1)); + sink0_ = reinterpret_cast(g_steal_pointer(&sink0)); + sink1_ = reinterpret_cast(g_steal_pointer(&sink1)); + queue0_ = reinterpret_cast(g_steal_pointer(&queue0)); + queue1_ = reinterpret_cast(g_steal_pointer(&queue1)); + + if (createPipeline() != TestPass) + return TestFail; + + return TestPass; + } + + int run() override + { + g_object_set(libcameraSrc_, "camera-name", cameraName.c_str(), NULL); + + /* Build the pipeline */ + gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, queue0_, queue1_, + convert0_, convert1_, sink0_, sink1_, NULL); + if (gst_element_link_many(queue0_, convert0_, sink0_, NULL) != TRUE || + gst_element_link_many(queue1_, convert1_, sink1_, NULL) != TRUE) { + g_printerr("Elements could not be linked.\n"); + return TestFail; + } + + g_autoptr(GstPad) src_pad = gst_element_get_static_pad(libcameraSrc_, "src"); + g_autoptr(GstPad) request_pad = gst_element_get_request_pad(libcameraSrc_, "src_%u"); + GstPad *queue0_sink_pad = gst_element_get_static_pad(queue0_, "sink"); + GstPad *queue1_sink_pad = gst_element_get_static_pad(queue1_, "sink"); + + if (gst_pad_link(src_pad, queue0_sink_pad) != GST_PAD_LINK_OK + || gst_pad_link(request_pad, queue1_sink_pad) != GST_PAD_LINK_OK) { + if (queue0_sink_pad) + gst_object_unref(queue0_sink_pad); + if (queue1_sink_pad) + gst_object_unref(queue1_sink_pad); + g_printerr("Pads could not be linked.\n"); + return TestFail; + } + gst_object_unref(queue0_sink_pad); + gst_object_unref(queue1_sink_pad); + + if (startPipeline() != TestPass) + return TestFail; + + if (processEvent() != TestPass) + return TestFail; + + return TestPass; + } + +private: + std::string cameraName; + GstElement *convert0_; + GstElement *convert1_; + GstElement *sink0_; + GstElement *sink1_; + GstElement *queue0_; + GstElement *queue1_; +}; + +TEST_REGISTER(GstreamerMultiStreamTest) diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build index aca53b920365..13652e87d05c 100644 --- a/test/gstreamer/meson.build +++ b/test/gstreamer/meson.build @@ -6,6 +6,7 @@ endif gstreamer_tests = [ ['single_stream_test', 'gstreamer_single_stream_test.cpp'], + ['multi_stream_test', 'gstreamer_multi_stream_test.cpp'], ] gstreamer_dep = dependency('gstreamer-1.0', required: true)