summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2020-07-13 10:46:26 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-09-09 14:00:23 +0100
commite0884453a9a112dc8742e6df0b8e45e8b559c536 (patch)
tree65300c8b584c3b2133f16572a11b7fa605790eab
parent08c0a1e6421e0763c36df3ee59682b73e1bf3db4 (diff)
libcamera: pipeline: vivid: Buffer handling and stream control
We can now add buffer management, and connect up our bufferReady signal to a callback. Note that we provide the ability to export buffers from our capture device (data->video_) using the exportBuffers() functionality from the V4L2VideoDevice which allows a FrameBufferAllocater to obtain buffers from this device. When buffers are obtained through the exportFrameBuffers API, they are orphaned and left unassociated with the device, and must be reimported at start() time anyway. This allows the same interface to be used whether internal buffers, or external buffers are used for the stream. When a buffer completes, we call the buffer completion handler on the pipeline handler, and because we have only a single stream, we can also immediately complete the request. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/pipeline/vivid/vivid.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/libcamera/pipeline/vivid/vivid.cpp b/src/libcamera/pipeline/vivid/vivid.cpp
index e89234ce..7498b349 100644
--- a/src/libcamera/pipeline/vivid/vivid.cpp
+++ b/src/libcamera/pipeline/vivid/vivid.cpp
@@ -47,6 +47,7 @@ public:
}
int init();
+ void bufferReady(FrameBuffer *buffer);
MediaDevice *media_;
V4L2VideoDevice *video_;
@@ -189,16 +190,35 @@ int PipelineHandlerVivid::configure(Camera *camera, CameraConfiguration *config)
int PipelineHandlerVivid::exportFrameBuffers(Camera *camera, Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers)
{
- return -1;
+ VividCameraData *data = cameraData(camera);
+ unsigned int count = stream->configuration().bufferCount;
+
+ return data->video_->exportBuffers(count, buffers);
}
int PipelineHandlerVivid::start(Camera *camera, const ControlList *controls)
{
- return -1;
+ VividCameraData *data = cameraData(camera);
+ unsigned int count = data->stream_.configuration().bufferCount;
+
+ int ret = data->video_->importBuffers(count);
+ if (ret < 0)
+ return ret;
+
+ ret = data->video_->streamOn();
+ if (ret < 0) {
+ data->video_->releaseBuffers();
+ return ret;
+ }
+
+ return 0;
}
void PipelineHandlerVivid::stop(Camera *camera)
{
+ VividCameraData *data = cameraData(camera);
+ data->video_->streamOff();
+ data->video_->releaseBuffers();
}
int PipelineHandlerVivid::queueRequestDevice(Camera *camera, Request *request)
@@ -236,9 +256,19 @@ int VividCameraData::init()
if (video_->open())
return -ENODEV;
+ video_->bufferReady.connect(this, &VividCameraData::bufferReady);
+
return 0;
}
+void VividCameraData::bufferReady(FrameBuffer *buffer)
+{
+ Request *request = buffer->request();
+
+ pipe()->completeBuffer(request, buffer);
+ pipe()->completeRequest(request);
+}
+
REGISTER_PIPELINE_HANDLER(PipelineHandlerVivid)
} /* namespace libcamera */