Patch Detail
Show a patch.
GET /api/1.1/patches/974/?format=api
{ "id": 974, "url": "https://patchwork.libcamera.org/api/1.1/patches/974/?format=api", "web_url": "https://patchwork.libcamera.org/patch/974/", "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": "<20190414013506.10515-5-niklas.soderlund@ragnatech.se>", "date": "2019-04-14T01:34:59", "name": "[libcamera-devel,RFC,04/11] libcamera: media_device: Handle media device fd in acquire() and release()", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "d00926b1a166aee0909f5aefe39e5eb59880f474", "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/974/mbox/", "series": [ { "id": 249, "url": "https://patchwork.libcamera.org/api/1.1/series/249/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=249", "date": "2019-04-14T01:34:55", "name": "libcamerea: Add support for exclusive access to cameras between processes", "version": 1, "mbox": "https://patchwork.libcamera.org/series/249/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/974/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/974/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 10DCE60DBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Apr 2019 03:35:18 +0200 (CEST)", "from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 8e0c302b-5e55-11e9-8e2c-005056917f90;\n\tSun, 14 Apr 2019 03:35:16 +0200 (CEST)" ], "X-Halon-ID": "8e0c302b-5e55-11e9-8e2c-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": "Sun, 14 Apr 2019 03:34:59 +0200", "Message-Id": "<20190414013506.10515-5-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190414013506.10515-1-niklas.soderlund@ragnatech.se>", "References": "<20190414013506.10515-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC 04/11] libcamera: media_device: Handle media\n\tdevice fd in acquire() and release()", "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": "Sun, 14 Apr 2019 01:35:18 -0000" }, "content": "To gain better control of when a file descriptor is open to the media\ndevice and reduce the work needed in pipeline handler implementations,\nhandle the file descriptor in acquire() and release().\n\nThis changes the current behavior where a file descriptor is only open\nwhen requested by the pipeline handler to that one is always open as\nlong a media device is acquired. This new behavior is desired to allow\nimplementing exclusive access to a pipeline handler between processes.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/media_device.h | 2 +-\n src/libcamera/media_device.cpp | 33 ++++++++++----------\n src/libcamera/pipeline/ipu3/ipu3.cpp | 25 +--------------\n test/media_device/media_device_link_test.cpp | 7 -----\n test/v4l2_subdevice/v4l2_subdevice_test.cpp | 10 +-----\n 5 files changed, 19 insertions(+), 58 deletions(-)", "diff": "diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex 9f038093b2b22fc7..883985055eb419dd 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -27,7 +27,7 @@ public:\n \t~MediaDevice();\n \n \tbool acquire();\n-\tvoid release() { acquired_ = false; }\n+\tvoid release();\n \tbool busy() const { return acquired_; }\n \n \tint open();\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 54706bb73a7591d5..644c6143fb15e1fa 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -39,10 +39,9 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n * instance.\n *\n * The instance is created with an empty media graph. Before performing any\n- * other operation, it must be opened with the open() function and the media\n- * graph populated by calling populate(). Instances of MediaEntity, MediaPad and\n- * MediaLink are created to model the media graph, and stored in a map indexed\n- * by object id.\n+ * other operation, it must be populate by calling populate(). Instances of\n+ * MediaEntity, MediaPad and MediaLink are created to model the media graph,\n+ * and stored in a map indexed by object id.\n *\n * The graph is valid once successfully populated, as reported by the valid()\n * function. It can be queried to list all entities(), or entities can be\n@@ -50,12 +49,6 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n * entity to entity through pads and links as exposed by the corresponding\n * classes.\n *\n- * An open media device will keep an open file handle for the underlying media\n- * controller device node. It can be closed at any time with a call to close().\n- * This will not invalidate the media graph and all cached media objects remain\n- * valid and can be accessed normally. The device can then be later reopened if\n- * needed to perform other operations that interact with the device node.\n- *\n * Media device can be claimed for exclusive use with acquire(), released with\n * release() and tested with busy(). This mechanism is aimed at pipeline\n * managers to claim media devices they support during enumeration.\n@@ -65,8 +58,8 @@ LOG_DEFINE_CATEGORY(MediaDevice)\n * \\brief Construct a MediaDevice\n * \\param deviceNode The media device node path\n *\n- * Once constructed the media device is invalid, and must be opened and\n- * populated with open() and populate() before the media graph can be queried.\n+ * Once constructed the media device is invalid, and must be populated with\n+ * populate() before the media graph can be queried.\n */\n MediaDevice::MediaDevice(const std::string &deviceNode)\n \t: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false)\n@@ -106,15 +99,22 @@ bool MediaDevice::acquire()\n \tif (acquired_)\n \t\treturn false;\n \n+\tif (open())\n+\t\treturn false;\n+\n \tacquired_ = true;\n \treturn true;\n }\n \n /**\n- * \\fn MediaDevice::release()\n * \\brief Release a device previously claimed for exclusive use\n * \\sa acquire(), busy()\n */\n+void MediaDevice::release()\n+{\n+\tclose();\n+\tacquired_ = false;\n+}\n \n /**\n * \\fn MediaDevice::busy()\n@@ -127,10 +127,6 @@ bool MediaDevice::acquire()\n /**\n * \\brief Open a media device and retrieve device information\n *\n- * Before populating the media graph or performing any operation that interact\n- * with the device node associated with the media device, the device node must\n- * be opened.\n- *\n * If the device is already open the function returns -EBUSY.\n *\n * \\return 0 on success or a negative error code otherwise\n@@ -201,6 +197,9 @@ int MediaDevice::populate()\n \t__u64 version = -1;\n \tint ret;\n \n+\tif (fd_ != -1)\n+\t\treturn -EBUSY;\n+\n \tclear();\n \n \tret = open();\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex d8de6b3c36314fc0..a87eff8dfec6d143 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -468,23 +468,10 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n \t/*\n \t * Disable all links that are enabled by default on CIO2, as camera\n \t * creation enables all valid links it finds.\n-\t *\n-\t * Close the CIO2 media device after, as links are enabled and should\n-\t * not need to be changed after.\n \t */\n-\tif (cio2MediaDev_->open())\n+\tif (cio2MediaDev_->disableLinks())\n \t\treturn false;\n \n-\tif (cio2MediaDev_->disableLinks()) {\n-\t\tcio2MediaDev_->close();\n-\t\treturn false;\n-\t}\n-\n-\tif (imguMediaDev_->open()) {\n-\t\tcio2MediaDev_->close();\n-\t\treturn false;\n-\t}\n-\n \t/*\n \t * FIXME: enabled links in one ImgU instance interfere with capture\n \t * operations on the other one. This can be easily triggered by\n@@ -516,9 +503,6 @@ bool PipelineHandlerIPU3::match(DeviceEnumerator *enumerator)\n \tret = registerCameras();\n \n error:\n-\tcio2MediaDev_->close();\n-\timguMediaDev_->close();\n-\n \treturn ret == 0;\n }\n \n@@ -961,11 +945,6 @@ int ImgUDevice::enableLinks(bool enable)\n \tstd::string inputName = name_ + \" input\";\n \tint ret;\n \n-\t/* \\todo Establish rules to handle media devices open/close. */\n-\tret = media_->open();\n-\tif (ret)\n-\t\treturn ret;\n-\n \tret = linkSetup(inputName, 0, name_, PAD_INPUT, enable);\n \tif (ret)\n \t\tgoto done;\n@@ -981,8 +960,6 @@ int ImgUDevice::enableLinks(bool enable)\n \tret = linkSetup(name_, PAD_STAT, statName, 0, enable);\n \n done:\n-\tmedia_->close();\n-\n \treturn ret;\n }\n \ndiff --git a/test/media_device/media_device_link_test.cpp b/test/media_device/media_device_link_test.cpp\nindex 4b8de3bee722e912..3989da43ca9ec30f 100644\n--- a/test/media_device/media_device_link_test.cpp\n+++ b/test/media_device/media_device_link_test.cpp\n@@ -57,12 +57,6 @@ class MediaDeviceLinkTest : public Test\n \t\t\treturn TestSkip;\n \t\t}\n \n-\t\tif (dev_->open()) {\n-\t\t\tcerr << \"Failed to open media device at \"\n-\t\t\t << dev_->deviceNode() << endl;\n-\t\t\treturn TestFail;\n-\t\t}\n-\n \t\treturn 0;\n \t}\n \n@@ -238,7 +232,6 @@ class MediaDeviceLinkTest : public Test\n \n \tvoid cleanup()\n \t{\n-\t\tdev_->close();\n \t\tdev_->release();\n \t}\n \ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\nindex 21335efbad4d5668..31f3465a7ba3a5b1 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n+++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n@@ -51,14 +51,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\tmedia_->release();\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@@ -67,7 +59,7 @@ int V4L2SubdeviceTest::init()\n \t}\n \n \tscaler_ = new V4L2Subdevice(videoEntity);\n-\tret = scaler_->open();\n+\tint ret = scaler_->open();\n \tif (ret) {\n \t\tcerr << \"Unable to open video subdevice \"\n \t\t << scaler_->deviceNode() << endl;\n", "prefixes": [ "libcamera-devel", "RFC", "04/11" ] }