@@ -24,6 +24,7 @@ namespace libcamera {
class Camera;
class CameraConfiguration;
+class CameraDescriptor;
class DeviceEnumerator;
class DeviceMatch;
class FrameBuffer;
@@ -40,8 +41,12 @@ public:
virtual ~PipelineHandler();
virtual bool match(DeviceEnumerator *enumerator) = 0;
+ virtual int survey(const DeviceEnumerator *enumerator,
+ std::vector<std::shared_ptr<CameraDescriptor>> *descriptors);
+ virtual int createCamera(const CameraDescriptor *descriptor);
std::shared_ptr<MediaDevice> acquireMediaDevice(DeviceEnumerator *enumerator,
const DeviceMatch &dm);
+ bool usesMediaDevice(const MediaDevice *media) const;
bool acquire(Camera *camera);
void release(Camera *camera);
@@ -115,6 +115,62 @@ PipelineHandler::~PipelineHandler()
* created, or false otherwise
*/
+/**
+ * \brief Survey the media devices for cameras this pipeline handler supports
+ * \param[in] enumerator The enumerator providing all media devices found in the
+ * system
+ * \param[out] descriptors The vector to which the descriptors of the cameras
+ * found are appended
+ *
+ * This function inspects the media devices provided by the \a enumerator and
+ * produces a camera descriptor for every camera that this pipeline handler
+ * supports. It shall not acquire any media device, open any device node, or
+ * alter any hardware state.
+ *
+ * Unlike match(), a single call shall report the cameras of all matching
+ * pipeline instances in the system, in the same order as repeated match() calls
+ * would register them.
+ *
+ * Pipeline handlers that do not implement this function do not support camera
+ * enumeration through CameraManager::enumerate(), and their cameras are only
+ * created through match().
+ *
+ * A pipeline handler that supports surveying shall return 0 and append a
+ * descriptor to \a descriptors for every camera it finds. Pipeline handlers
+ * that don't support surveying return -ENOTSUP from the default implementation.
+ *
+ * \context This function is called from the CameraManager thread.
+ *
+ * \return 0 on success or a negative error code otherwise
+ * \retval -ENOTSUP The pipeline handler does not support surveying
+ */
+int PipelineHandler::survey([[maybe_unused]] const DeviceEnumerator *enumerator,
+ [[maybe_unused]] std::vector<std::shared_ptr<CameraDescriptor>> *descriptors)
+{
+ return -ENOTSUP;
+}
+
+/**
+ * \brief Create and register the camera described by a descriptor
+ * \param[in] descriptor The descriptor of the camera to create
+ *
+ * This function performs the initialisation of a single camera previously
+ * reported by survey(). It shall acquire the media devices for the camera,
+ * unless this pipeline handler instance has already acquired them for a
+ * previously created camera, perform the same per-camera initialisation as
+ * match(), and register the camera with the camera manager.
+ *
+ * \context This function is called from the CameraManager thread.
+ *
+ * \return 0 on success or a negative error code otherwise
+ * \retval -ENOTSUP The pipeline handler does not support camera creation from
+ * a descriptor
+ */
+int PipelineHandler::createCamera([[maybe_unused]] const CameraDescriptor *descriptor)
+{
+ return -ENOTSUP;
+}
+
/**
* \brief Search and acquire a MediaDevice matching a device pattern
* \param[in] enumerator Enumerator containing all media devices in the system
@@ -148,6 +204,25 @@ PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,
return media;
}
+/**
+ * \brief Check if this pipeline handler instance uses a media device
+ * \param[in] media The media device to check for
+ *
+ * \context This function shall be called from the CameraManager thread.
+ *
+ * \return True if \a media has been acquired by this pipeline handler
+ * instance, otherwise false
+ */
+bool PipelineHandler::usesMediaDevice(const MediaDevice *media) const
+{
+ for (const std::shared_ptr<MediaDevice> &m : mediaDevices_) {
+ if (m.get() == media)
+ return true;
+ }
+
+ return false;
+}
+
/**
* \brief Acquire exclusive access to the pipeline handler for the process
*
Add two virtual functions splitting the match() contract into a cheap enumeration half and a heavy per-camera initialisation half. survey() reports descriptors for the cameras a pipeline handler supports without acquiring media devices or altering hardware state. createCamera() initialises and registers a single camera from one of those descriptors. The base implementations report no descriptors and -ENOTSUP respectively, so pipeline handlers may keep using match() unchanged. Also add a usesMediaDevice() helper that the camera manager will use to route descriptors to pipeline handlers in a future commit. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> --- include/libcamera/internal/pipeline_handler.h | 5 ++ src/libcamera/pipeline_handler.cpp | 75 +++++++++++++++++++ 2 files changed, 80 insertions(+)