Patch Detail
Show a patch.
GET /api/1.1/patches/2070/?format=api
{ "id": 2070, "url": "https://patchwork.libcamera.org/api/1.1/patches/2070/?format=api", "web_url": "https://patchwork.libcamera.org/patch/2070/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190930053520.2711-2-paul.elder@ideasonboard.com>", "date": "2019-09-30T05:35:19", "name": "[libcamera-devel,RFC,2/3] libcamera: device_enumerator: Check that expected cameras are available", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "858aaf38976c612ece43e1536a8923c10f5c7401", "submitter": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api", "name": "Paul Elder", "email": "paul.elder@ideasonboard.com" }, "delegate": { "id": 17, "url": "https://patchwork.libcamera.org/api/1.1/users/17/?format=api", "username": "epaul", "first_name": "Paul", "last_name": "Elder", "email": "paul.elder@ideasonboard.com" }, "mbox": "https://patchwork.libcamera.org/patch/2070/mbox/", "series": [ { "id": 513, "url": "https://patchwork.libcamera.org/api/1.1/series/513/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=513", "date": "2019-09-30T05:35:18", "name": "[libcamera-devel,RFC,1/3] libcamera: pipeline: Add device IDs", "version": 1, "mbox": "https://patchwork.libcamera.org/series/513/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/2070/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/2070/checks/", "tags": {}, "headers": { "Return-Path": "<paul.elder@ideasonboard.com>", "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FDFA6101D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 30 Sep 2019 07:35:38 +0200 (CEST)", "from neptunite.amanokami.net (unknown [96.44.9.94])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C5415311;\n\tMon, 30 Sep 2019 07:35:37 +0200 (CEST)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1569821738;\n\tbh=Spx0K1o4ot3i00+ww3EvoCG0uSp+P1+EzVEIWstK66M=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=B6nYfWfj3i/gRrlErZMJl/sYQ2ukMRymB22EAiszpJ+qpU/m+zCYjg3AwueBB7ZnS\n\t/qg3HatZ0RH9TnPo1tQPn5x/iLjevU7u0JrjCbm7bCThbx6rvHlimi96sonhQYIkdx\n\tvuCbwjbUvpUlednSob7vBIj2vtlKjNrBNqrWbeqA=", "From": "Paul Elder <paul.elder@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 30 Sep 2019 01:35:19 -0400", "Message-Id": "<20190930053520.2711-2-paul.elder@ideasonboard.com>", "X-Mailer": "git-send-email 2.23.0", "In-Reply-To": "<20190930053520.2711-1-paul.elder@ideasonboard.com>", "References": "<20190930053520.2711-1-paul.elder@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC PATCH 2/3] libcamera: device_enumerator:\n\tCheck that expected cameras are available", "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>", "X-List-Received-Date": "Mon, 30 Sep 2019 05:35:38 -0000" }, "content": "Add a static method to DeviceEnumerator to check if the expected number\nof cameras have been enumerated. The expected cameras are the supported\ncameras declared by the pipeline handlers that the system has.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n src/libcamera/device_enumerator.cpp | 69 +++++++++++++++++++++++\n src/libcamera/include/device_enumerator.h | 4 ++\n 2 files changed, 73 insertions(+)", "diff": "diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex 0b596bce..7d28f9b8 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -9,10 +9,15 @@\n #include \"device_enumerator_sysfs.h\"\n #include \"device_enumerator_udev.h\"\n \n+#include <algorithm>\n+#include <dirent.h>\n+#include <fstream>\n #include <string.h>\n+#include <sys/types.h>\n \n #include \"log.h\"\n #include \"media_device.h\"\n+#include \"pipeline_handler.h\"\n #include \"utils.h\"\n \n /**\n@@ -306,4 +311,68 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::search(const DeviceMatch &dm)\n \treturn nullptr;\n }\n \n+int extractNumberFromFile(std::string &path)\n+{\n+\tstd::ifstream file;\n+\tstd::string line;\n+\n+\tfile.open(path);\n+\tif (!file)\n+\t\treturn -1;\n+\n+\tfile >> line;\n+\tint i = std::stoi(line, 0, 16);\n+\tfile.close();\n+\n+\treturn i;\n+}\n+\n+bool DeviceEnumerator::haveExpectedCameras(CameraManager *cm)\n+{\n+\tstd::vector<std::reference_wrapper<DeviceID>> &supportedDevices =\n+\t\tPipelineHandlerFactory::getDeviceIDs();\n+\tstd::vector<DeviceID> availableDevices;\n+\tstd::vector<DeviceID> intersection;\n+\tstruct dirent *ent;\n+\tDIR *dir;\n+\tconst char *pciDir = \"/sys/bus/pci/devices\";\n+\n+\tdir = opendir(pciDir);\n+\tif (!dir) {\n+\t\tLOG(DeviceEnumerator, Error)\n+\t\t\t<< \"Failed to open sysfs PCI directory\";\n+\t\t/* We can't expect any cameras, so we vacuously have them all. */\n+\t\treturn true;\n+\t}\n+\n+\twhile ((ent = readdir(dir)) != nullptr) {\n+\t\tstd::string path = pciDir + std::string(\"/\") + ent->d_name + \"/vendor\";\n+\t\tint vendor = extractNumberFromFile(path);\n+\t\tif (vendor < 0)\n+\t\t\tcontinue;\n+\n+\t\tpath = pciDir + std::string(\"/\") + ent->d_name + \"/device\";\n+\t\tint device = extractNumberFromFile(path);\n+\t\tif (device < 0)\n+\t\t\tcontinue;\n+\n+\t\tavailableDevices.push_back(PCIDeviceID(vendor, device));\n+\t}\n+\n+\tclosedir(dir);\n+\n+\tstd::set_intersection(supportedDevices.begin(), supportedDevices.end(),\n+\t\t\t availableDevices.begin(), availableDevices.end(),\n+\t\t\t back_inserter(intersection),\n+\t\t\t compareDevices<PCIDeviceID>);\n+\n+\tif (cm->cameras().size() < intersection.size()) {\n+\t\tLOG(DeviceEnumerator, Warning) << \"Not enough cameras!\";\n+\t\treturn false;\n+\t}\n+\n+\tLOG(DeviceEnumerator, Debug) << \"All cameras correctly initialized\";\n+\treturn true;\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h\nindex 770f4277..11c4cdfb 100644\n--- a/src/libcamera/include/device_enumerator.h\n+++ b/src/libcamera/include/device_enumerator.h\n@@ -13,6 +13,8 @@\n \n #include <linux/media.h>\n \n+#include <libcamera/camera_manager.h>\n+\n namespace libcamera {\n \n class MediaDevice;\n@@ -43,6 +45,8 @@ public:\n \n \tstd::shared_ptr<MediaDevice> search(const DeviceMatch &dm);\n \n+\tstatic bool haveExpectedCameras(CameraManager *cm);\n+\n protected:\n \tstd::shared_ptr<MediaDevice> createDevice(const std::string &deviceNode);\n \tvoid addDevice(const std::shared_ptr<MediaDevice> &media);\n", "prefixes": [ "libcamera-devel", "RFC", "2/3" ] }