[libcamera-devel,v3,5/9] libcamera: pipeline: virtual: Add MediaDeviceVirtual
diff mbox series

Message ID 20230105043726.679968-6-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
Add a dummy MediaDeviceVirtual in PipelineHandlerVirtual::match, to
avoid having no MediaDevice in the pipeline handler.

Signed-off-by: Harvey Yang <chenghaoyang@chromium.org>
---
 include/libcamera/internal/device_enumerator.h | 2 +-
 include/libcamera/internal/pipeline_handler.h  | 2 +-
 src/libcamera/pipeline/virtual/virtual.cpp     | 9 +++++++--
 3 files changed, 9 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h
index 87a2b5ce..e5eb3e94 100644
--- a/include/libcamera/internal/device_enumerator.h
+++ b/include/libcamera/internal/device_enumerator.h
@@ -41,13 +41,13 @@  public:
 	virtual int init() = 0;
 	virtual int enumerate() = 0;
 
+	void addDevice(std::unique_ptr<MediaDeviceBase> media);
 	std::shared_ptr<MediaDeviceBase> search(const DeviceMatch &dm);
 
 	Signal<> devicesAdded;
 
 protected:
 	std::unique_ptr<MediaDeviceBase> createDevice(const std::string &deviceNode);
-	void addDevice(std::unique_ptr<MediaDeviceBase> media);
 	void removeDevice(const std::string &deviceNode);
 
 private:
diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h
index 1223b1cb..09004365 100644
--- a/include/libcamera/internal/pipeline_handler.h
+++ b/include/libcamera/internal/pipeline_handler.h
@@ -77,6 +77,7 @@  protected:
 	virtual void releaseDevice(Camera *camera);
 
 	CameraManager *manager_;
+	std::vector<std::shared_ptr<MediaDeviceBase>> mediaDevices_;
 
 private:
 	void unlockMediaDevices();
@@ -87,7 +88,6 @@  private:
 	void doQueueRequest(Request *request);
 	void doQueueRequests();
 
-	std::vector<std::shared_ptr<MediaDeviceBase>> mediaDevices_;
 	std::vector<std::weak_ptr<Camera>> cameras_;
 
 	std::queue<Request *> waitingRequests_;
diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index 09583b4e..6221196c 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/media_device_virtual.h"
 #include "libcamera/internal/pipeline_handler.h"
 
 namespace libcamera {
@@ -41,6 +42,9 @@  public:
 	int queueRequestDevice(Camera *camera, Request *request) override;
 
 	bool match(DeviceEnumerator *enumerator) override;
+
+private:
+	std::shared_ptr<MediaDeviceVirtual> mediaDeviceVirtual_;
 };
 
 VirtualCameraConfiguration::VirtualCameraConfiguration()
@@ -54,7 +58,7 @@  CameraConfiguration::Status VirtualCameraConfiguration::validate()
 }
 
 PipelineHandlerVirtual::PipelineHandlerVirtual(CameraManager *manager)
-	: PipelineHandler(manager)
+	: PipelineHandler(manager), mediaDeviceVirtual_(new MediaDeviceVirtual("virtual"))
 {
 }
 
@@ -104,7 +108,8 @@  int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request)
 bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator)
 {
 	(void)enumerator;
-	return false;
+	mediaDevices_.push_back(mediaDeviceVirtual_);
+	return false; // Prevent infinite loops for now
 }
 
 REGISTER_PIPELINE_HANDLER(PipelineHandlerVirtual)