From patchwork Tue Jul 4 15:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 18781 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 83C84BE175 for ; Tue, 4 Jul 2023 15:53:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4841661E38; Tue, 4 Jul 2023 17:53:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1688486020; bh=YF3cB3HCkOyspkdVqt96dhdY2lMeMLayMVavt5ox4O0=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=KjQKoQDG5yoY54XYMKOeYKKNWwE0jZnXmvsdNI04jKVgCx6HNlsIqiBwlTj2QeshP GUSiBaru4SRiSO+e7EwLTIFYz6cqyZQIPkxrv+KQNHh1CEvtwTLC54R29R95/W2AFb /pX3lL2JK1Ad/85+5P3rKO4+Fjo2ngRSkW0KRcelc3Fl+cFeTwrAWFbTQUj5j979Jh 3S53ajvedR0QGTd0yFky/xmiCeJKUczMTHn95OFstdsJIrUj0j7MdDVqL1vm5ocxMw 077P9opwm1Df1n0hUJrYUjSartW7Bbm0mzV5fmu4MDDsTTJhUwGwdHdtANpdlkUmSb FdkSg7cAZxc8w== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F33D860384 for ; Tue, 4 Jul 2023 17:53:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BAQ10/MC"; dkim-atps=neutral Received: from umang.jainideasonboard.com (85-160-42-71.reb.o2.cz [85.160.42.71]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 10951D4A; Tue, 4 Jul 2023 17:52:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1688485973; bh=YF3cB3HCkOyspkdVqt96dhdY2lMeMLayMVavt5ox4O0=; h=From:To:Cc:Subject:Date:From; b=BAQ10/MC+2xzwiww+/ilE2sF9jj+RWrYIR3wGX23N/qB9I6lLJv835wHgzB46T3Z8 g4IcdTAAiIBUb/IBApwq0677uDxLL0SsCpNuCI+O/iiNw/7Y1z576CCGRFvY7q9+l1 Wef4J4CFIHJLt4gNFCm/eMbT2xG3lVoHFic1nkII= To: libcamera-devel@lists.libcamera.org Date: Tue, 4 Jul 2023 17:53:29 +0200 Message-Id: <20230704155329.28734-1-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider 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: , X-Patchwork-Original-From: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Cc: nicolas.dufresne@collabora.com, vedantparanjape160201@gmail.com Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Test the enumeration of the cameras through GstDeviceProvider against the libcamera camera manager. Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- test/gstreamer/gstreamer_test.cpp | 52 +++++++++++++++++++++++++++++++ test/gstreamer/gstreamer_test.h | 1 + 2 files changed, 53 insertions(+) diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 6ad0c15c..f94f3fd9 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -27,6 +27,18 @@ const char *__asan_default_options() } } +static GstDeviceMonitor * +libcamerasrc_get_device_provider() +{ + GstDeviceMonitor *monitor = gst_device_monitor_new(); + + gst_device_monitor_add_filter(monitor, "Video/Source", NULL); + + gst_device_monitor_start(monitor); + + return monitor; +} + GstreamerTest::GstreamerTest(unsigned int numStreams) : pipeline_(nullptr), libcameraSrc_(nullptr) { @@ -78,6 +90,12 @@ GstreamerTest::GstreamerTest(unsigned int numStreams) return; } + if (!checkCameraEnumeration()) { + g_printerr("Failed to enumerate cameras on GstDeviceProvider\n"); + status_ = TestFail; + return; + } + status_ = TestPass; } @@ -102,6 +120,40 @@ bool GstreamerTest::checkMinCameraStreamsAndSetCameraName(unsigned int numStream return cameraFound; } +bool GstreamerTest::checkCameraEnumeration() +{ + GstDeviceMonitor *monitor; + GList *devices, *l; + std::vector cameraNames; + std::unique_ptr cm + = std::make_unique(); + + cm->start(); + for (auto &camera : cm->cameras()) + cameraNames.push_back(strdup(camera->id().c_str())); + cm->stop(); + cm.reset(); + + monitor = libcamerasrc_get_device_provider(); + devices = gst_device_monitor_get_devices(monitor); + + for (l = devices; l != NULL; l = g_list_next(l)) { + bool matched = false; + GstDevice *device = GST_DEVICE(l->data); + for (const gchar *name : cameraNames) { + if (strcmp(name, gst_device_get_display_name(device)) == 0) { + matched = true; + break; + } + } + + if (!matched) + return false; + } + + return true; +} + GstreamerTest::~GstreamerTest() { g_clear_object(&pipeline_); diff --git a/test/gstreamer/gstreamer_test.h b/test/gstreamer/gstreamer_test.h index aa2261e2..3479c7c4 100644 --- a/test/gstreamer/gstreamer_test.h +++ b/test/gstreamer/gstreamer_test.h @@ -31,4 +31,5 @@ protected: private: bool checkMinCameraStreamsAndSetCameraName(unsigned int numStreams); + bool checkCameraEnumeration(); };