From patchwork Fri Sep 10 18:11:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13813 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 63AF7BDB1D for ; Fri, 10 Sep 2021 18:12:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A55069170; Fri, 10 Sep 2021 20:12:02 +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="GarYdL1D"; dkim-atps=neutral Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B23669169 for ; Fri, 10 Sep 2021 20:12:01 +0200 (CEST) Received: by mail-pj1-x102e.google.com with SMTP id m21-20020a17090a859500b00197688449c4so2037932pjn.0 for ; Fri, 10 Sep 2021 11:12:01 -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=zJ89xjz7qF10EGdij96cvdRRIEc5qE/mO1UTQBIMZrc=; b=GarYdL1DHdzL1PbyCh0UkbrjHmR/pTXMzD/8btaEJqwkqh00I9MRSq4cJauFmZQIH7 RjZfTS0sn4Zkbz9ciL/Se0wLn2Z3CZ3a+MV6HkfCoTBiMe9Y9wnevb5vSN33gXEQTMpB i9c6Ti3MjDhJRG1ljl/9pN/2LbF9qy6AW8BFHC/sZHpIOCnfWIz7i6Gdm1ONlsUGfZMv sR6Gfn1eD6kdyX+CnKNEjOEUlENCX8FnArqbMFrhiLAxjENwzIjIn2p6/aWY+8B2vb1x +262TwK/wJdUwvm1hE7FmI1AKKDeqdoZFAtK/PhWdpU85m3d+Cj2jKxfs1mtIlQvjvna Nbrg== 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=zJ89xjz7qF10EGdij96cvdRRIEc5qE/mO1UTQBIMZrc=; b=XEGCNmp3v/vcBkkNiXSxnpYDwI8NIcPaAwROggrrlNiSWLwnl5KkVBtHtbwpYpr4C1 cvON4Kn9dQWVgrskNS4PoYp8tptiAQBsqdH7rCpF7b0ivdyo6wmcUQt7NPV3zeuwUdQA DQYZTNFZuAVHQnrH8nBFYEFQUTjeX4ULFr6XdcWgSmOzRedAXXnXGApKmlCx1WREpQKz kEQ9qtqp6kBdlQa49ba6cDsDsPKk5k+kgXvu6nRXoAsh0vGkHNntgu9LrGn33c1iSHEZ fE3zxrTeaUuFIiajyJBsGQMtFmg3iotZMvdiUs+g8p+MFlLKRQi358o2Xiyus06zbV/r PVrQ== X-Gm-Message-State: AOAM5325s8Ol+L2BevgmfDPzZGkpotPwe4KV/GxMxesKROlR3OzLY97M rQPvEeUeFfKlt2rN7yRe4Pmtldn+iSaiXg== X-Google-Smtp-Source: ABdhPJz/7XBccsmZtwlVsszzdR7GN3t3fqnyvQ+OtX+f68avp0Cx9claKJdH8BqYAobga3Ath1PPLg== X-Received: by 2002:a17:902:e550:b0:13b:63c3:46b4 with SMTP id n16-20020a170902e55000b0013b63c346b4mr4009582plf.78.1631297519697; Fri, 10 Sep 2021 11:11:59 -0700 (PDT) Received: from localhost.localdomain ([1.186.165.88]) by smtp.googlemail.com with ESMTPSA id h8sm5570378pfr.219.2021.09.10.11.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Sep 2021 11:11:59 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Fri, 10 Sep 2021 23:41:52 +0530 Message-Id: <20210910181152.878132-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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..e5c909c85da2 --- /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 &i : cm.cameras()) { + if (i->streams().size() > 1) { + cameraName = i->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)