From patchwork Tue Jul 28 00:30:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9035 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 C648ABD86F for ; Tue, 28 Jul 2020 00:31:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B49C617D6; Tue, 28 Jul 2020 02:31:20 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C2C960939 for ; Tue, 28 Jul 2020 02:31:17 +0200 (CEST) X-Halon-ID: a36d82e2-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a36d82e2-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:53 +0200 Message-Id: <20200728003058.2871461-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/6] libcamera: camera: Append pipeline name to camera name 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Append the pipeline handler name to each camera name. This is done to create a separate namespace for each pipeline to generate unique camera names in. This change modifies the name of all cameras. Before this change example of camera names: Venus USB2.0 Camera: Venus USB2 Logitech Webcam C930e VIMC Sensor B After this change the same cameras are: Venus USB2.0 Camera: Venus USB2 (PipelineHandlerUVC) Logitech Webcam C930e (PipelineHandlerUVC) VIMC Sensor B (PipelineHandlerVimc) Signed-off-by: Niklas Söderlund --- src/libcamera/camera.cpp | 4 +++- test/camera/buffer_import.cpp | 2 +- test/camera/capture.cpp | 2 +- test/camera/configuration_default.cpp | 2 +- test/camera/configuration_set.cpp | 2 +- test/camera/statemachine.cpp | 2 +- test/controls/control_info_map.cpp | 2 +- test/controls/control_list.cpp | 2 +- test/serialization/serialization_test.h | 2 +- 9 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 69a1b4428e3f4eca..81d5816ef6a653b3 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -468,7 +468,9 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, } }; - Camera *camera = new Camera(pipe, name, streams); + std::string fullName = name + " (" + pipe->name() + ")"; + + Camera *camera = new Camera(pipe, fullName, streams); return std::shared_ptr(camera, Deleter()); } diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp index ad680a83f9187213..ab406c35fe9e07e7 100644 --- a/test/camera/buffer_import.cpp +++ b/test/camera/buffer_import.cpp @@ -28,7 +28,7 @@ class BufferImportTest : public CameraTest, public Test { public: BufferImportTest() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index f6b2f348bda52752..1d57201ef83de1aa 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -18,7 +18,7 @@ class Capture : public CameraTest, public Test { public: Capture() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/camera/configuration_default.cpp b/test/camera/configuration_default.cpp index 31c908d2449eafe7..a1159c18d78c8493 100644 --- a/test/camera/configuration_default.cpp +++ b/test/camera/configuration_default.cpp @@ -18,7 +18,7 @@ class ConfigurationDefault : public CameraTest, public Test { public: ConfigurationDefault() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/camera/configuration_set.cpp b/test/camera/configuration_set.cpp index b4b5968115e81f59..63331c0a2c7df799 100644 --- a/test/camera/configuration_set.cpp +++ b/test/camera/configuration_set.cpp @@ -18,7 +18,7 @@ class ConfigurationSet : public CameraTest, public Test { public: ConfigurationSet() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp index 325b4674bcc958d8..77d021823774a674 100644 --- a/test/camera/statemachine.cpp +++ b/test/camera/statemachine.cpp @@ -18,7 +18,7 @@ class Statemachine : public CameraTest, public Test { public: Statemachine() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/controls/control_info_map.cpp b/test/controls/control_info_map.cpp index e4305f132db7952f..1d601a827e10e995 100644 --- a/test/controls/control_info_map.cpp +++ b/test/controls/control_info_map.cpp @@ -24,7 +24,7 @@ class ControlInfoMapTest : public CameraTest, public Test { public: ControlInfoMapTest() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp index 5c8485b5dcc31499..5dad297501d009a5 100644 --- a/test/controls/control_list.cpp +++ b/test/controls/control_list.cpp @@ -24,7 +24,7 @@ class ControlListTest : public CameraTest, public Test { public: ControlListTest() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } diff --git a/test/serialization/serialization_test.h b/test/serialization/serialization_test.h index fe77221ef5d07478..621c6d6279525300 100644 --- a/test/serialization/serialization_test.h +++ b/test/serialization/serialization_test.h @@ -20,7 +20,7 @@ class SerializationTest : public CameraTest, public Test { public: SerializationTest() - : CameraTest("VIMC Sensor B") + : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") { } From patchwork Tue Jul 28 00:30:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9036 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 18710BD86F for ; Tue, 28 Jul 2020 00:31:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E23596196D; Tue, 28 Jul 2020 02:31:21 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC4AC60939 for ; Tue, 28 Jul 2020 02:31:17 +0200 (CEST) X-Halon-ID: a3cf7bbb-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a3cf7bbb-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:54 +0200 Message-Id: <20200728003058.2871461-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/6] libcamera: camera: Generate camera name from a CameraSensor 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a create() that generates a camera name from information in a CameraSensor. The intention is to keep the style of camera names more standardised and to ease adding more parameters to the name as they become available. The goal is to generate a unique name that describes where the camera is located in the system without using bus information, as enumerated bus information is not guaranteed to be static between resets of the system. More parameters should be added to the name as CameraSensor is extended. In this first change the name is made up of the mandatory CameraSensor controls model, location and rotation if it is not 0. As many platforms hardware description (devicetree or ACPI) do not yet describe these properties the default location front is used for some cameras which is not true. All pipelines that implements a CameraSensor (all but UVC) are updated to make use of this new function. All names of cameras created by the updated pipelines are modified. Before this change example of camera names: ov5695 7-0036 (PipelineHandlerRkISP1) ov2685 7-003c (PipelineHandlerRkISP1) After this change the same cameras are: ov5695 location front (PipelineHandlerRkISP1) ov2685 location front (PipelineHandlerRkISP1) Signed-off-by: Niklas Söderlund --- include/libcamera/camera.h | 5 +++ src/libcamera/camera.cpp | 38 +++++++++++++++++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 12 +++--- .../pipeline/raspberrypi/raspberrypi.cpp | 3 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 2 +- src/libcamera/pipeline/simple/simple.cpp | 2 +- src/libcamera/pipeline/vimc/vimc.cpp | 4 +- test/camera/buffer_import.cpp | 2 +- test/camera/capture.cpp | 2 +- test/camera/configuration_default.cpp | 2 +- test/camera/configuration_set.cpp | 2 +- test/camera/statemachine.cpp | 2 +- test/controls/control_info_map.cpp | 2 +- test/controls/control_list.cpp | 2 +- test/serialization/serialization_test.h | 2 +- 15 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 4d1a4a9f52ec0fac..784510c9a79d44b9 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -19,6 +19,7 @@ namespace libcamera { +class CameraSensor; class FrameBuffer; class FrameBufferAllocator; class PipelineHandler; @@ -73,6 +74,10 @@ public: const std::string &name, const std::set &streams); + static std::shared_ptr create(PipelineHandler *pipe, + const CameraSensor *sensor, + const std::set &streams); + Camera(const Camera &) = delete; Camera &operator=(const Camera &) = delete; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 81d5816ef6a653b3..c5413341fefa1124 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -11,9 +11,11 @@ #include #include +#include #include #include +#include "libcamera/internal/camera_sensor.h" #include "libcamera/internal/log.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/utils.h" @@ -475,6 +477,42 @@ std::shared_ptr Camera::create(PipelineHandler *pipe, return std::shared_ptr(camera, Deleter()); } +/** + * \brief Create a camera instance + * \param[in] pipe The pipeline handler responsible for the camera device + * \param[in] sensor The sensor of the camera device + * \param[in] streams Array of streams the camera provides + * + * Create a camera with name generated from \a sensor. + * + * \return A shared pointer to the newly created camera object + */ +std::shared_ptr Camera::create(PipelineHandler *pipe, + const CameraSensor *sensor, + const std::set &streams) +{ + std::string name = sensor->model(); + + name += " location "; + switch (sensor->properties().get(properties::Location)) { + case properties::CameraLocationFront: + name += "front"; + break; + case properties::CameraLocationBack: + name += "back"; + break; + case properties::CameraLocationExternal: + name += "external"; + break; + } + + unsigned int rotation = sensor->properties().get(properties::Location); + if (rotation) + name += " rotated " + std::to_string(rotation) + " degrees"; + + return Camera::create(pipe, name, streams); +} + /** * \brief Retrieve the name of the camera * \context This function is \threadsafe. diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index eb00eecfd10a89e4..72da6ed62a7f0de5 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -813,18 +813,16 @@ int PipelineHandlerIPU3::registerCameras() &IPU3CameraData::imguOutputBufferReady); /* Create and register the Camera instance. */ - std::string cameraName = cio2->sensor()->entity()->name(); - std::shared_ptr camera = Camera::create(this, - cameraName, - streams); - - registerCamera(std::move(camera), std::move(data)); + std::shared_ptr camera = + Camera::create(this, cio2->sensor(), streams); LOG(IPU3, Info) << "Registered Camera[" << numCameras << "] \"" - << cameraName << "\"" + << camera->name() << "\"" << " connected to CSI-2 receiver " << id; + registerCamera(std::move(camera), std::move(data)); + numCameras++; } diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp index 82a0a4dfd6824fce..a62dd24b1ab76b87 100644 --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp @@ -972,7 +972,8 @@ bool PipelineHandlerRPi::match(DeviceEnumerator *enumerator) streams.insert(&data->isp_[Isp::Stats]); /* Create and register the camera. */ - std::shared_ptr camera = Camera::create(this, data->sensor_->model(), streams); + std::shared_ptr camera = + Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data)); return true; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 52a0d862417cc4ec..663e45b109aae9eb 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -971,7 +971,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) std::set streams{ &data->stream_ }; std::shared_ptr camera = - Camera::create(this, sensor->name(), streams); + Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data)); return 0; diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 5221ff3384923f56..fcbf0723b69f87d4 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -800,7 +800,7 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) continue; std::shared_ptr camera = - Camera::create(this, data->sensor_->entity()->name(), + Camera::create(this, data->sensor_.get(), data->streams()); registerCamera(std::move(camera), std::move(data)); } diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp index 4f461b928514022d..74243de13346d4a8 100644 --- a/src/libcamera/pipeline/vimc/vimc.cpp +++ b/src/libcamera/pipeline/vimc/vimc.cpp @@ -432,9 +432,9 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator) return false; /* Create and register the camera. */ - std::string name{ "VIMC " + data->sensor_->model() }; std::set streams{ &data->stream_ }; - std::shared_ptr camera = Camera::create(this, name, streams); + std::shared_ptr camera = + Camera::create(this, data->sensor_, streams); registerCamera(std::move(camera), std::move(data)); return true; diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp index ab406c35fe9e07e7..838b3e867b220adc 100644 --- a/test/camera/buffer_import.cpp +++ b/test/camera/buffer_import.cpp @@ -28,7 +28,7 @@ class BufferImportTest : public CameraTest, public Test { public: BufferImportTest() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/camera/capture.cpp b/test/camera/capture.cpp index 1d57201ef83de1aa..a0d7c5cba8b16c56 100644 --- a/test/camera/capture.cpp +++ b/test/camera/capture.cpp @@ -18,7 +18,7 @@ class Capture : public CameraTest, public Test { public: Capture() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/camera/configuration_default.cpp b/test/camera/configuration_default.cpp index a1159c18d78c8493..7e87c2f84add463d 100644 --- a/test/camera/configuration_default.cpp +++ b/test/camera/configuration_default.cpp @@ -18,7 +18,7 @@ class ConfigurationDefault : public CameraTest, public Test { public: ConfigurationDefault() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/camera/configuration_set.cpp b/test/camera/configuration_set.cpp index 63331c0a2c7df799..80a78f63d59b8d7c 100644 --- a/test/camera/configuration_set.cpp +++ b/test/camera/configuration_set.cpp @@ -18,7 +18,7 @@ class ConfigurationSet : public CameraTest, public Test { public: ConfigurationSet() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/camera/statemachine.cpp b/test/camera/statemachine.cpp index 77d021823774a674..1fa63a243405613c 100644 --- a/test/camera/statemachine.cpp +++ b/test/camera/statemachine.cpp @@ -18,7 +18,7 @@ class Statemachine : public CameraTest, public Test { public: Statemachine() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/controls/control_info_map.cpp b/test/controls/control_info_map.cpp index 1d601a827e10e995..c2bf583eaeeb3d04 100644 --- a/test/controls/control_info_map.cpp +++ b/test/controls/control_info_map.cpp @@ -24,7 +24,7 @@ class ControlInfoMapTest : public CameraTest, public Test { public: ControlInfoMapTest() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp index 5dad297501d009a5..b33e44f5014bbb98 100644 --- a/test/controls/control_list.cpp +++ b/test/controls/control_list.cpp @@ -24,7 +24,7 @@ class ControlListTest : public CameraTest, public Test { public: ControlListTest() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B location front (PipelineHandlerVimc)") { } diff --git a/test/serialization/serialization_test.h b/test/serialization/serialization_test.h index 621c6d6279525300..3f326e8f9c90ff34 100644 --- a/test/serialization/serialization_test.h +++ b/test/serialization/serialization_test.h @@ -20,7 +20,7 @@ class SerializationTest : public CameraTest, public Test { public: SerializationTest() - : CameraTest("VIMC Sensor B (PipelineHandlerVimc)") + : CameraTest("Sensor B facing forward (PipelineHandlerVimc)") { } From patchwork Tue Jul 28 00:30:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9037 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 AAEFEBD879 for ; Tue, 28 Jul 2020 00:31:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3BAA261976; Tue, 28 Jul 2020 02:31:22 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5C31D617AF for ; Tue, 28 Jul 2020 02:31:18 +0200 (CEST) X-Halon-ID: a4553b0d-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a4553b0d-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:13 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:55 +0200 Message-Id: <20200728003058.2871461-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/6] libcamera: v4l2_device: Add method to lookup device path 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a method to lookup a V4L2 devices path in sysfs. Signed-off-by: Niklas Söderlund --- include/libcamera/internal/v4l2_device.h | 1 + src/libcamera/v4l2_device.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index bf643f2ec966bb33..3b605aab343b3b94 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -30,6 +30,7 @@ public: int setControls(ControlList *ctrls); const std::string &deviceNode() const { return deviceNode_; } + std::string devicePath() const; protected: V4L2Device(const std::string &deviceNode); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 56ea1ddda2c1425f..c186f246dbfaff66 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -350,6 +351,29 @@ int V4L2Device::setControls(ControlList *ctrls) return ret; } +/** + * \brief Retrieve the device path + * + * The device path describes the device backing the V4L2 device. + * + * \todo When switching to C++17 use std::filesystem:: in the implementation. + * \todo Query udev for this information as the path created for vdev here + * migh not be correct. + * + * \return The device path + */ +std::string V4L2Device::devicePath() const +{ + std::string vdev = basename(deviceNode_.c_str()); + std::string sysfs = "/sys/class/video4linux/" + vdev + "/device"; + + char path[PATH_MAX]; + if (!realpath(sysfs.c_str(), path)) + LOG(V4L2, Fatal) << "Can not resolve path for " << deviceNode_; + + return path; +} + /** * \brief Perform an IOCTL system call on the device node * \param[in] request The IOCTL request code From patchwork Tue Jul 28 00:30:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9038 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 353BABD86F for ; Tue, 28 Jul 2020 00:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C189F6197D; Tue, 28 Jul 2020 02:31:22 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C993C616AD for ; Tue, 28 Jul 2020 02:31:18 +0200 (CEST) X-Halon-ID: a49b0115-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a49b0115-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:14 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:56 +0200 Message-Id: <20200728003058.2871461-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 4/6] libcamera: media_device: Expose media device serial number 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a MediaDevice::serial() function to expose the media device serial number. This can be useful to support driver changes in pipeline handlers. Signed-off-by: Niklas Söderlund --- include/libcamera/internal/media_device.h | 2 ++ src/libcamera/media_device.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index d0459cdefd3ece2a..1d23bdd2e9ba5270 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -40,6 +40,7 @@ public: const std::string driver() const { return driver_; } const std::string deviceNode() const { return deviceNode_; } const std::string model() const { return model_; } + const std::string serial() const { return serial_; } unsigned int version() const { return version_; } const std::vector &entities() const { return entities_; } @@ -78,6 +79,7 @@ private: std::string driver_; std::string deviceNode_; std::string model_; + std::string serial_; unsigned int version_; int fd_; diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index de18d572f4799931..f22a937d14cd8554 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -230,6 +230,7 @@ int MediaDevice::populate() driver_ = info.driver; model_ = info.model; + serial_ = info.serial; version_ = info.media_version; /* @@ -314,6 +315,12 @@ done: * \return The MediaDevice model name */ +/** + * \fn MediaDevice::serial() + * \brief Retrieve the media device serial number + * \return The MediaDevice serial number + */ + /** * \fn MediaDevice::version() * \brief Retrieve the media device API version From patchwork Tue Jul 28 00:30:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9039 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 8BE3BBD879 for ; Tue, 28 Jul 2020 00:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 618E8617D0; Tue, 28 Jul 2020 02:31:23 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F3DE613C6 for ; Tue, 28 Jul 2020 02:31:19 +0200 (CEST) X-Halon-ID: a4dcba57-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a4dcba57-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:14 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:57 +0200 Message-Id: <20200728003058.2871461-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/6] libcamera: pipeline: uvcvideo: Generate unique camera names 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Generate camera names that contains enough information to be unique while still being user friendly. In addition to the UVC model name add information about which USB bus and device it is and if available the serial number of the USB device. Before this change example of camera names: Venus USB2.0 Camera: Venus USB2 (PipelineHandlerUVC) Logitech Webcam C930e (PipelineHandlerUVC) After this change the same cameras are: Venus USB2.0 Camera: Venus USB2 on bus 3:8 (PipelineHandlerUVC) Logitech Webcam C930e on bus 3:4 serial 9F8F445E (PipelineHandlerUVC) Signed-off-by: Niklas Söderlund --- src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp index 93e3dc17e3a7105e..b415678b13e28f5d 100644 --- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp +++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -81,6 +82,9 @@ public: bool match(DeviceEnumerator *enumerator) override; private: + std::string generateName(const MediaDevice *media, + const std::string path); + int processControl(ControlList *controls, unsigned int id, const ControlValue &value); int processControls(UVCCameraData *data, Request *request); @@ -379,6 +383,35 @@ int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request) return 0; } +std::string PipelineHandlerUVC::generateName(const MediaDevice *media, + const std::string path) +{ + std::string name, busnum, devnum; + std::ifstream file; + + file.open(path + "/../busnum"); + if (!file.is_open()) + return ""; + std::getline(file, busnum); + file.close(); + + file.open(path + "/../devnum"); + if (!file.is_open()) + return ""; + std::getline(file, devnum); + file.close(); + + if (busnum.empty() || devnum.empty()) + return ""; + + name = media->model() + " on bus " + busnum + ":" + devnum; + + if (!media->serial().empty()) + name += " serial " + media->serial(); + + return name; +} + bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) { MediaDevice *media; @@ -405,8 +438,14 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator) return false; /* Create and register the camera. */ + std::string name = generateName(media, data->video_->devicePath()); + if (name.empty()) { + LOG(UVC, Error) << "Failed to generate camera name"; + return false; + } + std::set streams{ &data->stream_ }; - std::shared_ptr camera = Camera::create(this, media->model(), streams); + std::shared_ptr camera = Camera::create(this, name, streams); registerCamera(std::move(camera), std::move(data)); /* Enable hot-unplug notifications. */ From patchwork Tue Jul 28 00:30:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 9040 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 D1062BD86F for ; Tue, 28 Jul 2020 00:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 988E661981; Tue, 28 Jul 2020 02:31:23 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B057D6053C for ; Tue, 28 Jul 2020 02:31:19 +0200 (CEST) X-Halon-ID: a52fb5a2-d069-11ea-933e-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id a52fb5a2-d069-11ea-933e-005056917a89; Tue, 28 Jul 2020 02:31:15 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 28 Jul 2020 02:30:58 +0200 Message-Id: <20200728003058.2871461-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> References: <20200728003058.2871461-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 6/6] libcamera: camera_manager: Enforce unique camera names 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The camera name have always been documented that it should be unique but it has never been enforced. Change this by refuse to add cameras to the CameraManager that would create two cameras with the exact same name. Signed-off-by: Niklas Söderlund --- src/libcamera/camera_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index f60491d2c1a7500f..7d83263f1fabf5da 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -178,10 +178,10 @@ void CameraManager::Private::addCamera(std::shared_ptr camera, for (std::shared_ptr c : cameras_) { if (c->name() == camera->name()) { - LOG(Camera, Warning) - << "Registering camera with duplicate name '" + LOG(Camera, Error) + << "Skip registering camera with duplicated name '" << camera->name() << "'"; - break; + return; } }