Patch Detail
Show a patch.
GET /api/patches/19953/?format=api
{ "id": 19953, "url": "https://patchwork.libcamera.org/api/patches/19953/?format=api", "web_url": "https://patchwork.libcamera.org/patch/19953/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20240425152010.313205-1-pobrn@protonmail.com>", "date": "2024-04-25T15:20:13", "name": "[v1] treewide: Query list of cameras just once", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b1a37072807fbcc355fef67a4670dd5182eba34d", "submitter": { "id": 133, "url": "https://patchwork.libcamera.org/api/people/133/?format=api", "name": "Pőcze Barnabás", "email": "pobrn@protonmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/19953/mbox/", "series": [ { "id": 4273, "url": "https://patchwork.libcamera.org/api/series/4273/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4273", "date": "2024-04-25T15:20:13", "name": "[v1] treewide: Query list of cameras just once", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4273/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/19953/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/19953/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 E464FC3220\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Apr 2024 15:20:23 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DFDD4633F4;\n\tThu, 25 Apr 2024 17:20:22 +0200 (CEST)", "from mail-4316.protonmail.ch (mail-4316.protonmail.ch\n\t[185.70.43.16])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4025661A9B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Apr 2024 17:20:21 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=protonmail.com header.i=@protonmail.com\n\theader.b=\"g2o14+ww\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;\n\ts=protonmail3; t=1714058420; x=1714317620;\n\tbh=Xlog3F9xxdLvkkP1wpAD1kbY33z7hKEgYRZ6uvwKWnA=;\n\th=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:\n\tSubject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;\n\tb=g2o14+wwsEgWKLs1i4SuqpuDD4x6K6dlxPh4An6Wzz1rUyX88W7N522Jv/MhSspJz\n\tFn5Rd//loaCmr1QGKdEg+t5W9g/45pHT1cK618bBuOZ2eGfmJBUQ2PLqLGLwVbtXiY\n\tYWr7K2PMi4DuEWYNDqxhzBds3eu3CQWeZrcscFDyys1x06oOUK9U46D3HDCzA71W58\n\t3iX08iPYh5q6YRf/Jjw2FFZNkjB0C4fGnOx7/F/32+BpSUt0odQOJEMZumb3NC7Qyb\n\tmya7GhXg3ntAgugilqtf54z60AbwjRK7Vwi9iu1AITgI7kWe3uF/qcC0NcUsgMnMwg\n\twKpGjkxYB2T1g==", "Date": "Thu, 25 Apr 2024 15:20:13 +0000", "To": "libcamera-devel@lists.libcamera.org", "From": "=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>", "Subject": "[PATCH v1] treewide: Query list of cameras just once", "Message-ID": "<20240425152010.313205-1-pobrn@protonmail.com>", "Feedback-ID": "20568564:user:proton", "X-Pm-Message-ID": "6daf2752af386938d94b193b76f2e28a588f9d1a", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=utf-8", "Content-Transfer-Encoding": "quoted-printable", "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>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "This is more efficient since only a single vector will be constructed,\nand furthermore, it prevents the TOCTOU issue that might arise when\nthe list of cameras changes between the two queries.\n---\n Documentation/guides/application-developer.rst | 8 ++++----\n src/apps/cam/camera_session.cpp | 6 ++++--\n src/gstreamer/gstlibcamerasrc.cpp | 5 +++--\n 3 files changed, 11 insertions(+), 8 deletions(-)\n\n\nbase-commit: fb74bb7df66b96dbe28702155cddfc96a1b30f78", "diff": "diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst\nindex 9a9905b1..dfbc268d 100644\n--- a/Documentation/guides/application-developer.rst\n+++ b/Documentation/guides/application-developer.rst\n@@ -115,20 +115,20 @@ by name from the Camera Manager, after making sure that at least one camera is\n available.\n \n .. code:: cpp\n-\n- if (cm->cameras().empty()) {\n+ auto cameras = cm->cameras();\n+ if (cameras.empty()) {\n std::cout << \"No cameras were identified on the system.\"\n << std::endl;\n cm->stop();\n return EXIT_FAILURE;\n }\n \n- std::string cameraId = cm->cameras()[0]->id();\n+ std::string cameraId = cameras[0]->id();\n camera = cm->get(cameraId);\n \n /*\n * Note that is equivalent to:\n- * camera = cm->cameras()[0];\n+ * camera = cameras[0];\n */\n \n Once a camera has been selected an application needs to acquire an exclusive\ndiff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp\nindex 8447f932..5afd087f 100644\n--- a/src/apps/cam/camera_session.cpp\n+++ b/src/apps/cam/camera_session.cpp\n@@ -39,8 +39,10 @@ CameraSession::CameraSession(CameraManager *cm,\n {\n \tchar *endptr;\n \tunsigned long index = strtoul(cameraId.c_str(), &endptr, 10);\n-\tif (*endptr == '\\0' && index > 0 && index <= cm->cameras().size())\n-\t\tcamera_ = cm->cameras()[index - 1];\n+\tauto cameras = cm->cameras();\n+\n+\tif (*endptr == '\\0' && index > 0 && index <= cameras.size())\n+\t\tcamera_ = std::move(cameras[index - 1]);\n \telse\n \t\tcamera_ = cm->get(cameraId);\n \ndiff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex f015c6d2..8613d66d 100644\n--- a/src/gstreamer/gstlibcamerasrc.cpp\n+++ b/src/gstreamer/gstlibcamerasrc.cpp\n@@ -385,13 +385,14 @@ gst_libcamera_src_open(GstLibcameraSrc *self)\n \t\t\treturn false;\n \t\t}\n \t} else {\n-\t\tif (cm->cameras().empty()) {\n+\t\tauto cameras = cm->cameras();\n+\t\tif (cameras.empty()) {\n \t\t\tGST_ELEMENT_ERROR(self, RESOURCE, NOT_FOUND,\n \t\t\t\t\t (\"Could not find any supported camera on this system.\"),\n \t\t\t\t\t (\"libcamera::CameraMananger::cameras() is empty\"));\n \t\t\treturn false;\n \t\t}\n-\t\tcam = cm->cameras()[0];\n+\t\tcam = std::move(cameras[0]);\n \t}\n \n \tGST_INFO_OBJECT(self, \"Using camera '%s'\", cam->id().c_str());\n", "prefixes": [ "v1" ] }