{"id":9039,"url":"https://patchwork.libcamera.org/api/1.1/patches/9039/?format=json","web_url":"https://patchwork.libcamera.org/patch/9039/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200728003058.2871461-6-niklas.soderlund@ragnatech.se>","date":"2020-07-28T00:30:57","name":"[libcamera-devel,v2,5/6] libcamera: pipeline: uvcvideo: Generate unique camera names","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"8f660fd25cd504aec62c030e305232acdb0946fe","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9039/mbox/","series":[{"id":1155,"url":"https://patchwork.libcamera.org/api/1.1/series/1155/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1155","date":"2020-07-28T00:30:52","name":"libcamera: Generate unique and stable camera names","version":2,"mbox":"https://patchwork.libcamera.org/series/1155/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9039/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9039/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8BE3BBD879\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Jul 2020 00:31:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 618E8617D0;\n\tTue, 28 Jul 2020 02:31:23 +0200 (CEST)","from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F3DE613C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Jul 2020 02:31:19 +0200 (CEST)","from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid a4dcba57-d069-11ea-933e-005056917a89;\n\tTue, 28 Jul 2020 02:31:14 +0200 (CEST)"],"X-Halon-ID":"a4dcba57-d069-11ea-933e-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","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:\n\tGenerate unique camera names","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Generate camera names that contains enough information to be unique\nwhile still being user friendly. In addition to the UVC model name add\ninformation about which USB bus and device it is and if available the\nserial number of the USB device.\n\nBefore this change example of camera names:\n\nVenus USB2.0 Camera: Venus USB2 (PipelineHandlerUVC)\nLogitech Webcam C930e (PipelineHandlerUVC)\n\nAfter this change the same cameras are:\n\nVenus USB2.0 Camera: Venus USB2 on bus 3:8 (PipelineHandlerUVC)\nLogitech Webcam C930e on bus 3:4 serial 9F8F445E (PipelineHandlerUVC)\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 41 +++++++++++++++++++-\n 1 file changed, 40 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 93e3dc17e3a7105e..b415678b13e28f5d 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -6,6 +6,7 @@\n  */\n \n #include <algorithm>\n+#include <fstream>\n #include <iomanip>\n #include <math.h>\n #include <tuple>\n@@ -81,6 +82,9 @@ public:\n \tbool match(DeviceEnumerator *enumerator) override;\n \n private:\n+\tstd::string generateName(const MediaDevice *media,\n+\t\t\t\t const std::string path);\n+\n \tint processControl(ControlList *controls, unsigned int id,\n \t\t\t   const ControlValue &value);\n \tint processControls(UVCCameraData *data, Request *request);\n@@ -379,6 +383,35 @@ int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request)\n \treturn 0;\n }\n \n+std::string PipelineHandlerUVC::generateName(const MediaDevice *media,\n+\t\t\t\t\t     const std::string path)\n+{\n+\tstd::string name, busnum, devnum;\n+\tstd::ifstream file;\n+\n+\tfile.open(path + \"/../busnum\");\n+\tif (!file.is_open())\n+\t\treturn \"\";\n+\tstd::getline(file, busnum);\n+\tfile.close();\n+\n+\tfile.open(path + \"/../devnum\");\n+\tif (!file.is_open())\n+\t\treturn \"\";\n+\tstd::getline(file, devnum);\n+\tfile.close();\n+\n+\tif (busnum.empty() || devnum.empty())\n+\t\treturn \"\";\n+\n+\tname = media->model() + \" on bus \" + busnum + \":\" + devnum;\n+\n+\tif (!media->serial().empty())\n+\t\tname += \" serial \" + media->serial();\n+\n+\treturn name;\n+}\n+\n bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n {\n \tMediaDevice *media;\n@@ -405,8 +438,14 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)\n \t\treturn false;\n \n \t/* Create and register the camera. */\n+\tstd::string name = generateName(media, data->video_->devicePath());\n+\tif (name.empty()) {\n+\t\tLOG(UVC, Error) << \"Failed to generate camera name\";\n+\t\treturn false;\n+\t}\n+\n \tstd::set<Stream *> streams{ &data->stream_ };\n-\tstd::shared_ptr<Camera> camera = Camera::create(this, media->model(), streams);\n+\tstd::shared_ptr<Camera> camera = Camera::create(this, name, streams);\n \tregisterCamera(std::move(camera), std::move(data));\n \n \t/* Enable hot-unplug notifications. */\n","prefixes":["libcamera-devel","v2","5/6"]}