[libcamera-devel] [RFC PATCH 1/5] libcamera: pipeline: uvcvideo: Add UVC metadata node

Gabby George gabbymg94 at gmail.com
Mon Aug 14 13:28:45 CEST 2023


Identify and open the UVC metadata's video node. This will give us
access to metadata associated with the video stream of the uvc camera.
The user will not have access to this video node and will not need to
manage its data in any way.

Signed-off-by: Gabby George <gabbymg94 at gmail.com>
---
 src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 36 +++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 38f48a5d..4470d8a2 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -49,10 +49,13 @@ public:
 	const std::string &id() const { return id_; }
 
 	std::unique_ptr<V4L2VideoDevice> video_;
+	std::unique_ptr<V4L2VideoDevice> metadata_;
 	Stream stream_;
 	std::map<PixelFormat, std::vector<SizeRange>> formats_;
 
 private:
+	int initMetadata(MediaDevice *media);
+
 	bool generateId();
 
 	std::string id_;
@@ -411,6 +414,37 @@ bool PipelineHandlerUVC::match(DeviceEnumerator *enumerator)
 	return true;
 }
 
+int UVCCameraData::initMetadata(MediaDevice *media)
+{
+	int ret;
+
+	const std::vector<MediaEntity *> &entities = media->entities();
+	std::string dev_node_name = video_->deviceNode();
+	auto metadata = std::find_if(entities.begin(), entities.end(),
+				     [&dev_node_name](MediaEntity *e) {
+					     return e->type() == MediaEntity::Type::V4L2VideoDevice && !(e->flags() & MEDIA_ENT_FL_DEFAULT);
+				     });
+
+	if (metadata == entities.end()) {
+		LOG(UVC, Error) << "Could not find a metadata video device.";
+		return -ENODEV;
+	}
+
+	/* configure the metadata node */
+	metadata_ = std::make_unique<V4L2VideoDevice>(*metadata);
+	ret = metadata_->open();
+	if (ret)
+		return ret;
+
+	if (!(metadata_->caps().isMeta())) {
+		/* if the caps do not have the metadata attribute
+		 * (shouldn't happen) */
+		metadata_ = NULL;
+		return -EINVAL;
+	}
+	return 0;
+}
+
 int UVCCameraData::init(MediaDevice *media)
 {
 	int ret;
@@ -512,7 +546,7 @@ int UVCCameraData::init(MediaDevice *media)
 
 	controlInfo_ = ControlInfoMap(std::move(ctrls), controls::controls);
 
-	return 0;
+	return initMetadata(media);
 }
 
 bool UVCCameraData::generateId()
-- 
2.34.1



More information about the libcamera-devel mailing list