[libcamera-devel,v4,3/6] libcamera: pipeline: virtual: Create a Camera
diff mbox series

Message ID 20230315102300.2265491-4-chenghaoyang@google.com
State Superseded
Headers show
Series
  • Virtual pipeline handler
Related show

Commit Message

Harvey Yang March 15, 2023, 10:22 a.m. UTC
Create a VirtualCameraData inheriting from the CameraData to handle camera
specific data, and use it to create and register the camera with the
CameraManager.

This can now be tested to see that the camera becomes available to
applications:

"""
build/src/apps/cam/cam -l
[550:47:04.505850647] [1969734]  INFO IPAManager ipa_manager.cpp:143
libcamera is not installed. Adding ... to the IPA search path
[550:47:04.509307667] [1969734]  INFO Camera camera_manager.cpp:293
libcamera v0.0.1+54-55fecb4d-dirty (2022-12-01T05:47:11+00:00)
Available cameras:
1: (Virtual0)
"""

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
---
 src/libcamera/pipeline/virtual/virtual.cpp | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index 09583b4e..1d66a60e 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -9,12 +9,26 @@ 
 
 #include <libcamera/camera.h>
 
+#include "libcamera/internal/camera.h"
 #include "libcamera/internal/pipeline_handler.h"
 
 namespace libcamera {
 
 LOG_DEFINE_CATEGORY(VIRTUAL)
 
+class VirtualCameraData : public Camera::Private
+{
+public:
+	VirtualCameraData(PipelineHandler *pipe)
+		: Camera::Private(pipe)
+	{
+	}
+
+	~VirtualCameraData() = default;
+
+	Stream stream_;
+};
+
 class VirtualCameraConfiguration : public CameraConfiguration
 {
 public:
@@ -104,7 +118,15 @@  int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request)
 bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator)
 {
 	(void)enumerator;
-	return false;
+
+	std::unique_ptr<VirtualCameraData> data = std::make_unique<VirtualCameraData>(this);
+	/* Create and register the camera. */
+	std::set<Stream *> streams{ &data->stream_ };
+	const std::string id = "Virtual0";
+	std::shared_ptr<Camera> camera = Camera::create(std::move(data), id, streams);
+	registerCamera(std::move(camera));
+
+	return false; // Prevent infinite loops for now
 }
 
 REGISTER_PIPELINE_HANDLER(PipelineHandlerVirtual)