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

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

Commit Message

Harvey Yang Jan. 5, 2023, 4:37 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 | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index 6221196c..ba77d757 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -9,6 +9,7 @@ 
 
 #include <libcamera/camera.h>
 
+#include "libcamera/internal/camera.h"
 #include "libcamera/internal/media_device_virtual.h"
 #include "libcamera/internal/pipeline_handler.h"
 
@@ -16,6 +17,19 @@  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:
@@ -109,6 +123,14 @@  bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator)
 {
 	(void)enumerator;
 	mediaDevices_.push_back(mediaDeviceVirtual_);
+
+	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
 }