{"id":977,"url":"https://patchwork.libcamera.org/api/patches/977/?format=json","web_url":"https://patchwork.libcamera.org/patch/977/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190414013506.10515-9-niklas.soderlund@ragnatech.se>","date":"2019-04-14T01:35:03","name":"[libcamera-devel,RFC,08/11] libcamera: media_device: Restrict acquire() and release()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"e30f9d697fafe46516042924bb2169928b432063","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/977/mbox/","series":[{"id":249,"url":"https://patchwork.libcamera.org/api/series/249/?format=json","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/977/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/977/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 9017D60DCA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 14 Apr 2019 03:35:19 +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 8f958efd-5e55-11e9-8e2c-005056917f90;\n\tSun, 14 Apr 2019 03:35:18 +0200 (CEST)"],"X-Halon-ID":"8f958efd-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:35:03 +0200","Message-Id":"<20190414013506.10515-9-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 08/11] libcamera: media_device: Restrict\n\tacquire() 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:20 -0000"},"content":"The only valid call site for acquire() and release() are inside the\nPipelineHandler base class. Make them private to with a specific friend\nclause to block specific pipeline handler implementations from calling\nthem.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/media_device.h        |  6 +-\n src/libcamera/media_device.cpp              | 85 +++++++++++----------\n test/v4l2_device/v4l2_device_test.cpp       |  5 --\n test/v4l2_subdevice/v4l2_subdevice_test.cpp | 10 ---\n 4 files changed, 47 insertions(+), 59 deletions(-)","diff":"diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\nindex e513a2fee1b91a1b..5d28a7bb8214ef4a 100644\n--- a/src/libcamera/include/media_device.h\n+++ b/src/libcamera/include/media_device.h\n@@ -26,8 +26,6 @@ public:\n \tMediaDevice(const std::string &deviceNode);\n \t~MediaDevice();\n \n-\tbool acquire();\n-\tvoid release();\n \tbool busy() const { return acquired_; }\n \n \tint populate();\n@@ -62,6 +60,10 @@ private:\n \tint open();\n \tvoid close();\n \n+\tfriend class PipelineHandler;\n+\tbool acquire();\n+\tvoid release();\n+\n \tstd::map<unsigned int, MediaObject *> objects_;\n \tMediaObject *object(unsigned int id);\n \tbool addObject(MediaObject *object);\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 0138be526f886c90..46931f52688f6c82 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -73,48 +73,6 @@ MediaDevice::~MediaDevice()\n \tclear();\n }\n \n-/**\n- * \\brief Claim a device for exclusive use\n- *\n- * The device claiming mechanism offers simple media device access arbitration\n- * between multiple users. When the media device is created, it is available to\n- * all users. Users can query the media graph to determine whether they can\n- * support the device and, if they do, claim the device for exclusive use. Other\n- * users are then expected to skip over media devices in use as reported by the\n- * busy() function.\n- *\n- * Once claimed the device shall be released by its user when not needed anymore\n- * by calling the release() function.\n- *\n- * Exclusive access is only guaranteed if all users of the media device abide by\n- * the device claiming mechanism, as it isn't enforced by the media device\n- * itself.\n- *\n- * \\return true if the device was successfully claimed, or false if it was\n- * already in use\n- * \\sa release(), busy()\n- */\n-bool MediaDevice::acquire()\n-{\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- * \\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@@ -420,6 +378,49 @@ void MediaDevice::close()\n \tfd_ = -1;\n }\n \n+/**\n+ * \\brief Claim a device for exclusive use\n+ *\n+ * The device claiming mechanism offers simple media device access arbitration\n+ * between multiple users. When the media device is created, it is available to\n+ * all users. Users can query the media graph to determine whether they can\n+ * support the device and, if they do, claim the device for exclusive use. Other\n+ * users are then expected to skip over media devices in use as reported by the\n+ * busy() function.\n+ *\n+ * Once claimed the device shall be released by its user when not needed anymore\n+ * by calling the release() function.\n+ *\n+ * Exclusive access is only guaranteed if all users of the media device abide by\n+ * the device claiming mechanism, as it isn't enforced by the media device\n+ * itself.\n+ *\n+ * \\return true if the device was successfully claimed, or false if it was\n+ * already in use\n+ * \\sa release(), busy()\n+ */\n+bool MediaDevice::acquire()\n+{\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+ * \\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  * \\var MediaDevice::objects_\n  * \\brief Global map of media objects (entities, pads, links) keyed by their\ndiff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\nindex 90e5f7a3ee0c0f2f..833038d56ea4631d 100644\n--- a/test/v4l2_device/v4l2_device_test.cpp\n+++ b/test/v4l2_device/v4l2_device_test.cpp\n@@ -46,9 +46,6 @@ int V4L2DeviceTest::init()\n \tif (!media_)\n \t\treturn TestSkip;\n \n-\tif (!media_->acquire())\n-\t\treturn TestSkip;\n-\n \tMediaEntity *entity = media_->getEntityByName(\"vivid-000-vid-cap\");\n \tif (!entity)\n \t\treturn TestSkip;\n@@ -62,8 +59,6 @@ int V4L2DeviceTest::init()\n \n void V4L2DeviceTest::cleanup()\n {\n-\tmedia_->release();\n-\n \tcapture_->streamOff();\n \tcapture_->releaseBuffers();\n \tcapture_->close();\ndiff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\nindex 31f3465a7ba3a5b1..0180698840cc2751 100644\n--- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n+++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n@@ -45,16 +45,9 @@ int V4L2SubdeviceTest::init()\n \t\treturn TestSkip;\n \t}\n \n-\tif (!media_->acquire()) {\n-\t\tcerr << \"Unable to acquire media device: \"\n-\t\t     << media_->deviceNode() << 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-\t\tmedia_->release();\n \t\treturn TestFail;\n \t}\n \n@@ -63,7 +56,6 @@ int V4L2SubdeviceTest::init()\n \tif (ret) {\n \t\tcerr << \"Unable to open video subdevice \"\n \t\t     << scaler_->deviceNode() << endl;\n-\t\tmedia_->release();\n \t\treturn TestSkip;\n \t}\n \n@@ -72,7 +64,5 @@ int V4L2SubdeviceTest::init()\n \n void V4L2SubdeviceTest::cleanup()\n {\n-\tmedia_->release();\n-\n \tdelete scaler_;\n }\n","prefixes":["libcamera-devel","RFC","08/11"]}