@@ -8,7 +8,10 @@
#include <libcamera/base/log.h>
#include <libcamera/camera.h>
+#include <libcamera/control_ids.h>
+#include <libcamera/controls.h>
#include <libcamera/formats.h>
+#include <libcamera/heap_allocator.h>
#include "libcamera/internal/camera.h"
#include "libcamera/internal/pipeline_handler.h"
@@ -17,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:
@@ -74,6 +88,8 @@ private:
{
return static_cast<VirtualCameraData *>(camera->_d());
}
+
+ HeapAllocator heapAllocator_;
};
VirtualCameraConfiguration::VirtualCameraConfiguration(VirtualCameraData *data)
@@ -208,29 +224,38 @@ int PipelineHandlerVirtual::configure(Camera *camera, CameraConfiguration *confi
int PipelineHandlerVirtual::exportFrameBuffers(Camera *camera, Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers)
{
- (void)camera;
- (void)stream;
- (void)buffers;
- return -1;
+ if (!heapAllocator_.isValid())
+ return -ENOBUFS;
+
+ return heapAllocator_.exportFrameBuffers(camera, stream, buffers);
}
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)
[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 | 39 ++++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-)