From patchwork Tue Aug 10 07:34:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13270 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 B9083C3240 for ; Tue, 10 Aug 2021 07:35:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 83820687FA; Tue, 10 Aug 2021 09:35:23 +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="Mpnct7lF"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 276A2687DE for ; Tue, 10 Aug 2021 09:35:22 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so3103674pjr.1 for ; Tue, 10 Aug 2021 00:35:22 -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=EU+nH2IQ6yt3lCTsE23t4o2bpLB6ImUTB4GDIeKqKP8=; b=Mpnct7lFIv8RRT1Yv1TxRoqkONuQgA5JWiKNX9gRzR+hmyGOQc2en1KEoSGMRrslaO CdayFt9z6jtiNBlP2lkkapattkiP0FNF+rLiktTXHKBlnHQA4Akb6FwiWtelYKlYkxrm Z+zRNxAa2hXWJ8cNkZ7+uIAm91glIgh0j1trSwJhQuy05yNfuhC5a2OCjlBm0XvGWFnE +v+DblkQ+mUt9s123IgaacL1bN06fEVqwKM4NGlcZ1o0ZSbjJNNrSDPy2NAWv9+i6IXF 67FYjdYeCuzqELjIJfa30e1KQxEOOs1bI5IAdH9fjVnJQQ+VCiEpI8H5hB6rkyafokkx UGZA== 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=EU+nH2IQ6yt3lCTsE23t4o2bpLB6ImUTB4GDIeKqKP8=; b=Ww9nNeYJ7BvdI7Pzd5hFMCv8C8jDYpiGwKIpfoSMKIjGHqu5YM8hRq7haszlbDUM0W /yJ/CjazoUsDqT/G7BsVtTEMOJo83xt9qE5wIzaBquMU1SBsnILRb3aBl8pdr2Khqcfl aYvs2Fvmduu1G+09ze+lb1fWmfH19c3Hymx6kpJliRzkkmji4P2uq0IEBFuVzVk/Rgmw 310+uYj6aiUpBHrCn704bOVHf4Cd+T8ofFm0Uxm/eiD6nDK0MbxkKi0CRt4MLRv2j5bm QRr9s5+L8hBa8j7r/iNLY0Tp1L/giMqIv2sZrs0nUamEX0p0AVbyhrulyUbhdWvC6s1e M70Q== X-Gm-Message-State: AOAM532oMHp/tgGrJBBEJ+8+BwPyiy4obgtd3IJfhlWy9zBRSqcvqi0s dnv0ZTL32mBg6604RE0ktUtzrzuwM9eVtw== X-Google-Smtp-Source: ABdhPJx5s4aYn+pkMTa+JU9OP1JcKO9BmLtUhZRcvoSohFxwqdSgYiGsEROAIqVHCBFl0QXojITUhw== X-Received: by 2002:a62:32c7:0:b029:3cd:fba0:3218 with SMTP id y190-20020a6232c70000b02903cdfba03218mr575323pfy.52.1628580920023; Tue, 10 Aug 2021 00:35:20 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.156]) by smtp.googlemail.com with ESMTPSA id r13sm25907298pgi.78.2021.08.10.00.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 00:35:19 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 10 Aug 2021 13:04:44 +0530 Message-Id: <20210810073444.1739476-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1] gstreamer: Add unit test to test single stream output 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 unit tests to check single stream output using libcamera's gstreamer element. Signed-off-by: Vedant Paranjape --- .../gstreamer_single_stream_test.cpp | 103 ++++++++++++++++++ test/gstreamer/meson.build | 15 +++ test/meson.build | 1 + 3 files changed, 119 insertions(+) create mode 100644 test/gstreamer/gstreamer_single_stream_test.cpp create mode 100644 test/gstreamer/meson.build diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp new file mode 100644 index 00000000..cdd5cd9c --- /dev/null +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -0,0 +1,103 @@ +#include +#include + +#include "test.h" + +using namespace std; + +class GstreamerSingleStreamTest: public Test +{ +protected: + int GstreamerPrintError(GstMessage *msg) + { + int TestResult = TestPass; + + if (msg != NULL) { + GError *err; + gchar *debug_info; + + switch (GST_MESSAGE_TYPE(msg)) { + case GST_MESSAGE_ERROR: + gst_message_parse_error(msg, &err, &debug_info); + g_printerr("Error received from element %s: %s\n", GST_OBJECT_NAME(msg->src), err->message); + g_printerr("Debugging information: %s\n", debug_info ? debug_info : "none"); + g_clear_error(&err); + g_free(debug_info); + TestResult = TestFail; + break; + case GST_MESSAGE_EOS: + g_printerr("End-Of-Stream reached.\n"); + TestResult = TestFail; + break; + default: + /* We should not reach here because we only asked for ERRORs and EOS */ + g_printerr("Unexpected message received.\n"); + TestResult = TestFail; + break; + } + } + + return TestResult; + } + + int run() override + { + GstElement *pipeline, *libcamera_src, *convert0, *sink0; + GstBus *bus; + GstMessage *msg; + GstStateChangeReturn ret; + + /* Initialize GStreamer */ + gst_init(nullptr, nullptr); + + /* Create the elements */ + libcamera_src = gst_element_factory_make("libcamerasrc", "libcamera"); + convert0 = gst_element_factory_make("videoconvert", "convert0"); + sink0 = gst_element_factory_make("autovideosink", "sink0"); + + /* Create the empty pipeline */ + pipeline = gst_pipeline_new("test-pipeline"); + + if (!pipeline || !convert0 || !sink0 || !libcamera_src) { + g_printerr("Not all elements could be created.\n"); + return TestFail; + } + + /* Build the pipeline */ + gst_bin_add_many(GST_BIN(pipeline), libcamera_src, convert0, sink0, NULL); + if (gst_element_link_many(libcamera_src, convert0, sink0, NULL) != TRUE) { + g_printerr("Elements could not be linked (1).\n"); + gst_object_unref(pipeline); + return TestFail; + } + + /* Start playing */ + ret = gst_element_set_state(pipeline, GST_STATE_PLAYING); + if (ret == GST_STATE_CHANGE_FAILURE) { + g_printerr("Unable to set the pipeline to the playing state.\n"); + gst_object_unref(pipeline); + return TestFail; + } + + /* Wait until error or EOS */ + GstClockTime timeout = 1000000000; + bus = gst_element_get_bus(pipeline); + msg = gst_bus_timed_pop_filtered(bus, timeout, + GstMessageType((uint)GST_MESSAGE_ERROR | (uint)GST_MESSAGE_EOS)); + + /* Parse error message */ + if (GstreamerPrintError(msg) == TestFail) { + return TestFail; + } + gst_message_unref(msg); + + /* Free resources */ + gst_object_unref(bus); + gst_element_set_state(pipeline, GST_STATE_NULL); + gst_object_unref(pipeline); + + return TestPass; + } +}; + +TEST_REGISTER(GstreamerSingleStreamTest) diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build new file mode 100644 index 00000000..36643d4a --- /dev/null +++ b/test/gstreamer/meson.build @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: CC0-1.0 + +gstreamer_tests = [ + ['single_stream_test', 'gstreamer_single_stream_test.cpp'], +] +gstreamer_dep = dependency('gstreamer-1.0', required: true) + +foreach t : gstreamer_tests + exe = executable(t[0], t[1], + dependencies : [libcamera_private, gstreamer_dep], + link_with : test_libraries, + include_directories : test_includes_internal) + + test(t[0], exe, suite : 'gstreamer', is_parallel : false) +endforeach diff --git a/test/meson.build b/test/meson.build index 3bceb5df..d0466f17 100644 --- a/test/meson.build +++ b/test/meson.build @@ -11,6 +11,7 @@ subdir('libtest') subdir('camera') subdir('controls') +subdir('gstreamer') subdir('ipa') subdir('ipc') subdir('log')