summaryrefslogtreecommitdiff
path: root/src/libcamera/media_device.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-14 00:43:29 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-05-17 01:33:57 +0200
commit1a813a5c3ab71a91e327d538d0df5d945e50561e (patch)
tree2ac615e5dacbb8d36a6408d59994eb7e448a45a9 /src/libcamera/media_device.cpp
parentef30be09eb0faba6739b4efee450d0c9751c121b (diff)
libcamera: media_device: Handle media device fd in acquire() and release()
To gain better control of when a file descriptor is open to the media device and reduce the work needed in pipeline handler implementations, handle the file descriptor in acquire() and release(). This changes the current behavior where a file descriptor is only open when requested by the pipeline handler to that one is always open as long a media device is acquired. This new behavior is desired to allow implementing exclusive access to a pipeline handler between processes. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/libcamera/media_device.cpp')
-rw-r--r--src/libcamera/media_device.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp
index eef348e3..b1cc37e8 100644
--- a/src/libcamera/media_device.cpp
+++ b/src/libcamera/media_device.cpp
@@ -40,10 +40,9 @@ LOG_DEFINE_CATEGORY(MediaDevice)
* instance.
*
* The instance is created with an empty media graph. Before performing any
- * other operation, it must be opened with the open() function and the media
- * graph populated by calling populate(). Instances of MediaEntity, MediaPad and
- * MediaLink are created to model the media graph, and stored in a map indexed
- * by object id.
+ * other operation, it must be populate by calling populate(). Instances of
+ * MediaEntity, MediaPad and MediaLink are created to model the media graph,
+ * and stored in a map indexed by object id.
*
* The graph is valid once successfully populated, as reported by the valid()
* function. It can be queried to list all entities(), or entities can be
@@ -51,12 +50,6 @@ LOG_DEFINE_CATEGORY(MediaDevice)
* entity to entity through pads and links as exposed by the corresponding
* classes.
*
- * An open media device will keep an open file handle for the underlying media
- * controller device node. It can be closed at any time with a call to close().
- * This will not invalidate the media graph and all cached media objects remain
- * valid and can be accessed normally. The device can then be later reopened if
- * needed to perform other operations that interact with the device node.
- *
* Media device can be claimed for exclusive use with acquire(), released with
* release() and tested with busy(). This mechanism is aimed at pipeline
* managers to claim media devices they support during enumeration.
@@ -66,8 +59,8 @@ LOG_DEFINE_CATEGORY(MediaDevice)
* \brief Construct a MediaDevice
* \param[in] deviceNode The media device node path
*
- * Once constructed the media device is invalid, and must be opened and
- * populated with open() and populate() before the media graph can be queried.
+ * Once constructed the media device is invalid, and must be populated with
+ * populate() before the media graph can be queried.
*/
MediaDevice::MediaDevice(const std::string &deviceNode)
: deviceNode_(deviceNode), fd_(-1), valid_(false), acquired_(false)
@@ -92,7 +85,8 @@ MediaDevice::~MediaDevice()
* busy() function.
*
* Once claimed the device shall be released by its user when not needed anymore
- * by calling the release() function.
+ * by calling the release() function. Acquiring the media device opens a file
+ * descriptor to the device which is kept open until release() is called.
*
* 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
@@ -107,15 +101,22 @@ bool MediaDevice::acquire()
if (acquired_)
return false;
+ if (open())
+ return false;
+
acquired_ = true;
return true;
}
/**
- * \fn MediaDevice::release()
* \brief Release a device previously claimed for exclusive use
* \sa acquire(), busy()
*/
+void MediaDevice::release()
+{
+ close();
+ acquired_ = false;
+}
/**
* \fn MediaDevice::busy()