[libcamera-devel,v3,8/9] libcamera: pipeline: virtual: Queue requests
diff mbox series

Message ID 20230105043726.679968-9-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
[todo Use UDMA to allocate buffers in the exportFrameBuffers API]

[todo Read frames from the virtual video if any]

Currently we only use external buffers and complete them immediately
with green frames.

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

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/virtual/virtual.cpp b/src/libcamera/pipeline/virtual/virtual.cpp
index ef2901e7..db6fe14c 100644
--- a/src/libcamera/pipeline/virtual/virtual.cpp
+++ b/src/libcamera/pipeline/virtual/virtual.cpp
@@ -8,6 +8,8 @@ 
 #include <libcamera/base/log.h>
 
 #include <libcamera/camera.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
 #include <libcamera/formats.h>
 
 #include "libcamera/internal/camera.h"
@@ -18,6 +20,17 @@  namespace libcamera {
 
 LOG_DEFINE_CATEGORY(VIRTUAL)
 
+uint64_t CurrentTimestamp()
+{
+	struct timespec ts;
+	if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) {
+		LOG(VIRTUAL, Error) << "Get clock time fails";
+		return 0;
+	}
+
+	return ts.tv_sec * 1'000'000'000LL + ts.tv_nsec;
+}
+
 class VirtualCameraData : public Camera::Private
 {
 public:
@@ -214,6 +227,7 @@  int PipelineHandlerVirtual::exportFrameBuffers(Camera *camera, Stream *stream,
 	(void)camera;
 	(void)stream;
 	(void)buffers;
+	// TODO: Use UDMA to allocate buffers.
 	return -1;
 }
 
@@ -221,19 +235,28 @@  int PipelineHandlerVirtual::start(Camera *camera, const ControlList *controls)
 {
 	(void)camera;
 	(void)controls;
-	return -1;
+	// TODO: Start reading the virtual video if any.
+	return 0;
 }
 
 void PipelineHandlerVirtual::stopDevice(Camera *camera)
 {
 	(void)camera;
+	// TODO: Reset the virtual video if any.
 }
 
 int PipelineHandlerVirtual::queueRequestDevice(Camera *camera, Request *request)
 {
 	(void)camera;
-	(void)request;
-	return -1;
+
+	// TODO: Read from the virtual video if any.
+	for (auto it : request->buffers())
+		completeBuffer(request, it.second);
+
+	request->metadata().set(controls::SensorTimestamp, CurrentTimestamp());
+	completeRequest(request);
+
+	return 0;
 }
 
 bool PipelineHandlerVirtual::match(DeviceEnumerator *enumerator)