[{"id":1432,"web_url":"https://patchwork.libcamera.org/comment/1432/","msgid":"<20190417110014.GE4993@pendragon.ideasonboard.com>","date":"2019-04-17T11:00:14","subject":"Re: [libcamera-devel] [RFC 08/11] libcamera: media_device: Restrict\n\tacquire() and release()","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Sun, Apr 14, 2019 at 03:35:03AM +0200, Niklas Söderlund wrote:\n> The only valid call site for acquire() and release() are inside the\n> PipelineHandler base class. Make them private to with a specific friend\n> clause to block specific pipeline handler implementations from calling\n> them.\n\nThis looks OK to me, but I have a bit of trouble understanding the\nrationale behind this change. The locking introduced in the next patches\ndoesn't seem to interact with acquire() and release() of the media\ndevice at all.\n\n> Signed-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(-)\n> \n> diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h\n> index 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);\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 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\n> diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp\n> index 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();\n> diff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp\n> index 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>  }","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B9A4F60DBE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 17 Apr 2019 13:00:23 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2653133B;\n\tWed, 17 Apr 2019 13:00:23 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1555498823;\n\tbh=O7u41uya038VgPeyGZ3p3DVTBCARtt17bmjmxBAa8mA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=JrwlswOzC7dn2lAZenNESQfJ+PB8OChvA8cReY9MJTMxl0y3JLzXEt9iI7bEBVEAA\n\tSAuaWgOpBEGpuH1eLZ933NMy/ZqJFjKDXV/Zv79TyFP6AmXYQz5+btI98KOxEnAml4\n\tBcfv8suKoLijUAMPUls0FC8BsHwmMTr0qZxs59Ao=","Date":"Wed, 17 Apr 2019 14:00:14 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190417110014.GE4993@pendragon.ideasonboard.com>","References":"<20190414013506.10515-1-niklas.soderlund@ragnatech.se>\n\t<20190414013506.10515-9-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190414013506.10515-9-niklas.soderlund@ragnatech.se>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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":"Wed, 17 Apr 2019 11:00:24 -0000"}}]