From patchwork Sun Apr 14 01:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 977 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9017D60DCA for ; Sun, 14 Apr 2019 03:35:19 +0200 (CEST) X-Halon-ID: 8f958efd-5e55-11e9-8e2c-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 8f958efd-5e55-11e9-8e2c-005056917f90; Sun, 14 Apr 2019 03:35:18 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= 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 Subject: [libcamera-devel] [RFC 08/11] libcamera: media_device: Restrict acquire() and release() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Apr 2019 01:35:20 -0000 The only valid call site for acquire() and release() are inside the PipelineHandler base class. Make them private to with a specific friend clause to block specific pipeline handler implementations from calling them. Signed-off-by: Niklas Söderlund --- src/libcamera/include/media_device.h | 6 +- src/libcamera/media_device.cpp | 85 +++++++++++---------- test/v4l2_device/v4l2_device_test.cpp | 5 -- test/v4l2_subdevice/v4l2_subdevice_test.cpp | 10 --- 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/src/libcamera/include/media_device.h b/src/libcamera/include/media_device.h index e513a2fee1b91a1b..5d28a7bb8214ef4a 100644 --- a/src/libcamera/include/media_device.h +++ b/src/libcamera/include/media_device.h @@ -26,8 +26,6 @@ public: MediaDevice(const std::string &deviceNode); ~MediaDevice(); - bool acquire(); - void release(); bool busy() const { return acquired_; } int populate(); @@ -62,6 +60,10 @@ private: int open(); void close(); + friend class PipelineHandler; + bool acquire(); + void release(); + std::map objects_; MediaObject *object(unsigned int id); bool addObject(MediaObject *object); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 0138be526f886c90..46931f52688f6c82 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -73,48 +73,6 @@ MediaDevice::~MediaDevice() clear(); } -/** - * \brief Claim a device for exclusive use - * - * The device claiming mechanism offers simple media device access arbitration - * between multiple users. When the media device is created, it is available to - * all users. Users can query the media graph to determine whether they can - * support the device and, if they do, claim the device for exclusive use. Other - * users are then expected to skip over media devices in use as reported by the - * busy() function. - * - * Once claimed the device shall be released by its user when not needed anymore - * by calling the release() function. - * - * Exclusive access is only guaranteed if all users of the media device abide by - * the device claiming mechanism, as it isn't enforced by the media device - * itself. - * - * \return true if the device was successfully claimed, or false if it was - * already in use - * \sa release(), busy() - */ -bool MediaDevice::acquire() -{ - if (acquired_) - return false; - - if (open()) - return false; - - acquired_ = true; - return true; -} - -/** - * \brief Release a device previously claimed for exclusive use - * \sa acquire(), busy() - */ -void MediaDevice::release() -{ - close(); - acquired_ = false; -} /** * \fn MediaDevice::busy() @@ -420,6 +378,49 @@ void MediaDevice::close() fd_ = -1; } +/** + * \brief Claim a device for exclusive use + * + * The device claiming mechanism offers simple media device access arbitration + * between multiple users. When the media device is created, it is available to + * all users. Users can query the media graph to determine whether they can + * support the device and, if they do, claim the device for exclusive use. Other + * users are then expected to skip over media devices in use as reported by the + * busy() function. + * + * Once claimed the device shall be released by its user when not needed anymore + * by calling the release() function. + * + * Exclusive access is only guaranteed if all users of the media device abide by + * the device claiming mechanism, as it isn't enforced by the media device + * itself. + * + * \return true if the device was successfully claimed, or false if it was + * already in use + * \sa release(), busy() + */ +bool MediaDevice::acquire() +{ + if (acquired_) + return false; + + if (open()) + return false; + + acquired_ = true; + return true; +} + +/** + * \brief Release a device previously claimed for exclusive use + * \sa acquire(), busy() + */ +void MediaDevice::release() +{ + close(); + acquired_ = false; +} + /** * \var MediaDevice::objects_ * \brief Global map of media objects (entities, pads, links) keyed by their diff --git a/test/v4l2_device/v4l2_device_test.cpp b/test/v4l2_device/v4l2_device_test.cpp index 90e5f7a3ee0c0f2f..833038d56ea4631d 100644 --- a/test/v4l2_device/v4l2_device_test.cpp +++ b/test/v4l2_device/v4l2_device_test.cpp @@ -46,9 +46,6 @@ int V4L2DeviceTest::init() if (!media_) return TestSkip; - if (!media_->acquire()) - return TestSkip; - MediaEntity *entity = media_->getEntityByName("vivid-000-vid-cap"); if (!entity) return TestSkip; @@ -62,8 +59,6 @@ int V4L2DeviceTest::init() void V4L2DeviceTest::cleanup() { - media_->release(); - capture_->streamOff(); capture_->releaseBuffers(); capture_->close(); diff --git a/test/v4l2_subdevice/v4l2_subdevice_test.cpp b/test/v4l2_subdevice/v4l2_subdevice_test.cpp index 31f3465a7ba3a5b1..0180698840cc2751 100644 --- a/test/v4l2_subdevice/v4l2_subdevice_test.cpp +++ b/test/v4l2_subdevice/v4l2_subdevice_test.cpp @@ -45,16 +45,9 @@ int V4L2SubdeviceTest::init() return TestSkip; } - if (!media_->acquire()) { - cerr << "Unable to acquire media device: " - << media_->deviceNode() << endl; - return TestSkip; - } - MediaEntity *videoEntity = media_->getEntityByName("Scaler"); if (!videoEntity) { cerr << "Unable to find media entity 'Scaler'" << endl; - media_->release(); return TestFail; } @@ -63,7 +56,6 @@ int V4L2SubdeviceTest::init() if (ret) { cerr << "Unable to open video subdevice " << scaler_->deviceNode() << endl; - media_->release(); return TestSkip; } @@ -72,7 +64,5 @@ int V4L2SubdeviceTest::init() void V4L2SubdeviceTest::cleanup() { - media_->release(); - delete scaler_; }