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. */