Patch Detail
Show a patch.
GET /api/1.1/patches/1187/?format=api
{ "id": 1187, "url": "https://patchwork.libcamera.org/api/1.1/patches/1187/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1187/", "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": "<20190511091907.10050-3-niklas.soderlund@ragnatech.se>", "date": "2019-05-11T09:18:58", "name": "[libcamera-devel,v3,02/11] libcamera: media_device: Open and close media device inside populate()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "0883b6d9f8593018c616d0625c26d136621765c9", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1187/mbox/", "series": [ { "id": 303, "url": "https://patchwork.libcamera.org/api/1.1/series/303/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=303", "date": "2019-05-11T09:18:56", "name": "libcamerea: Add support for exclusive access to cameras between processes", "version": 3, "mbox": "https://patchwork.libcamera.org/series/303/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1187/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1187/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 91CE360E6E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 May 2019 11:19:45 +0200 (CEST)", "from localhost.localdomain (unknown [185.224.57.161])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid e912fc8c-73cd-11e9-8e2f-005056917f90;\n\tSat, 11 May 2019 11:19:43 +0200 (CEST)" ], "X-Halon-ID": "e912fc8c-73cd-11e9-8e2f-005056917f90", "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": "Sat, 11 May 2019 11:18:58 +0200", "Message-Id": "<20190511091907.10050-3-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190511091907.10050-1-niklas.soderlund@ragnatech.se>", "References": "<20190511091907.10050-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 02/11] libcamera: media_device: Open\n\tand close media device inside populate()", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.23", "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": "Sat, 11 May 2019 09:19:45 -0000" }, "content": "Remove the need for the caller to open and close the media device when\npopulating the MediaDevice. This is done as an effort to make the usage\nof the MediaDevice less error prone and the interface stricter.\n\nThe rework also revealed and fixes a potential memory leak in\nMediaDevice::populate() where resources would not be deleted if the\nsecond MEDIA_IOC_G_TOPOLOGY would fail.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/libcamera/device_enumerator.cpp | 8 +-------\n src/libcamera/media_device.cpp | 12 ++++++++++--\n test/media_device/media_device_print_test.cpp | 6 ------\n test/pipeline/ipu3/ipu3_pipeline_test.cpp | 5 -----\n test/v4l2_subdevice/v4l2_subdevice_test.cpp | 10 +---------\n 5 files changed, 12 insertions(+), 29 deletions(-)", "diff": "diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex 259eec41776e2ec4..6fcbae76b64e3774 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -207,11 +207,7 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)\n {\n \tstd::shared_ptr<MediaDevice> media = std::make_shared<MediaDevice>(deviceNode);\n \n-\tint ret = media->open();\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tret = media->populate();\n+\tint ret = media->populate();\n \tif (ret < 0) {\n \t\tLOG(DeviceEnumerator, Info)\n \t\t\t<< \"Unable to populate media device \" << deviceNode\n@@ -238,8 +234,6 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)\n \t\t\treturn ret;\n \t}\n \n-\tmedia->close();\n-\n \tLOG(DeviceEnumerator, Debug)\n \t\t<< \"Added device \" << deviceNode << \": \" << media->driver();\n \ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 449571fb4b78fb94..c39775164fab7487 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -221,6 +221,10 @@ int MediaDevice::populate()\n \n \tclear();\n \n+\tret = open();\n+\tif (ret)\n+\t\treturn ret;\n+\n \t/*\n \t * Keep calling G_TOPOLOGY until the version number stays stable.\n \t */\n@@ -237,7 +241,7 @@ int MediaDevice::populate()\n \t\t\tLOG(MediaDevice, Error)\n \t\t\t\t<< \"Failed to enumerate topology: \"\n \t\t\t\t<< strerror(-ret);\n-\t\t\treturn ret;\n+\t\t\tgoto done;\n \t\t}\n \n \t\tif (version == topology.topology_version)\n@@ -262,6 +266,10 @@ int MediaDevice::populate()\n \t populateLinks(topology))\n \t\tvalid_ = true;\n \n+\tret = 0;\n+done:\n+\tclose();\n+\n \tdelete[] ents;\n \tdelete[] interfaces;\n \tdelete[] pads;\n@@ -272,7 +280,7 @@ int MediaDevice::populate()\n \t\treturn -EINVAL;\n \t}\n \n-\treturn 0;\n+\treturn ret;\n }\n \n /**\ndiff --git a/test/media_device/media_device_print_test.cpp b/test/media_device/media_device_print_test.cpp\nindex 3eef973939201b27..ceffd538e13fca73 100644\n--- a/test/media_device/media_device_print_test.cpp\n+++ b/test/media_device/media_device_print_test.cpp\n@@ -124,10 +124,6 @@ int MediaDevicePrintTest::testMediaDevice(const string deviceNode)\n \n \tdev.close();\n \n-\tret = dev.open();\n-\tif (ret)\n-\t\treturn ret;\n-\n \tret = dev.populate();\n \tif (ret)\n \t\treturn ret;\n@@ -135,8 +131,6 @@ int MediaDevicePrintTest::testMediaDevice(const string deviceNode)\n \t/* Print out the media graph. */\n \tprintMediaGraph(dev, cerr);\n \n-\tdev.close();\n-\n \treturn 0;\n }\n \ndiff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\nindex 953f0233cde485cb..1d4cc4d4950b8391 100644\n--- a/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n+++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n@@ -71,11 +71,6 @@ int IPU3PipelineTest::init()\n \t\treturn TestSkip;\n \t}\n \n-\tif (cio2->open()) {\n-\t\tcerr << \"Failed to open media device \" << cio2->deviceNode() << endl;\n-\t\treturn TestFail;\n-\t}\n-\n \t/*\n \t * Camera sensor are connected to the CIO2 unit.\n \t * Count how many sensors are connected in the system\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\nindex 5810ef3c962fab8e..562a638cb28ebfb2 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n+++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n@@ -45,13 +45,6 @@ int V4L2SubdeviceTest::init()\n \t\treturn TestSkip;\n \t}\n \n-\tint ret = media_->open();\n-\tif (ret) {\n-\t\tcerr << \"Unable to open media device: \" << media_->deviceNode()\n-\t\t << \": \" << strerror(ret) << endl;\n-\t\treturn TestSkip;\n-\t}\n-\n \tMediaEntity *videoEntity = media_->getEntityByName(\"Scaler\");\n \tif (!videoEntity) {\n \t\tcerr << \"Unable to find media entity 'Scaler'\" << endl;\n@@ -59,8 +52,7 @@ int V4L2SubdeviceTest::init()\n \t}\n \n \tscaler_ = new V4L2Subdevice(videoEntity);\n-\tret = scaler_->open();\n-\tif (ret) {\n+\tif (scaler_->open()) {\n \t\tcerr << \"Unable to open video subdevice \"\n \t\t << scaler_->entity()->deviceNode() << endl;\n \t\treturn TestSkip;\n", "prefixes": [ "libcamera-devel", "v3", "02/11" ] }