libcamera: Handle request completion explicitly in pipeline handlers

Request complete by themselves when all the buffers they contain have
completed, connecting the buffer's completed signal to be notified of
buffer completion. While this works for now, it prevents pipelines from
delaying request completion until all metadata is available, and makes
it impossible to ensure that requests complete in the order they are
queued.

To fix this, make request completion handling explicit in pipeline
handlers. The base PipelineHandler class is extended with
implementations of the queueRequest() and stop() methods and gets new
completeBuffer() and completeRequest() methods to help pipeline handlers
tracking requests and buffers.

The three existing pipeline handlers connect the bufferReady signal of
their capture video node to a slot of their respective camera data
instance, where they use the PipelineHandler helpers to notify buffer
and request completion. Request completion is handled synchronously with
buffer completion as the pipeline handlers don't need to support more
advanced use cases, but this paves the road for future work.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Laurent Pinchart 2019-02-28 17:59:10 +02:00
parent 1accc258cc
commit b2c06cf409
12 changed files with 194 additions and 38 deletions

View file

@ -56,6 +56,8 @@ private:
delete video_;
}
void bufferReady(Buffer *buffer);
V4L2Device *video_;
Stream stream_;
};
@ -153,6 +155,7 @@ void PipelineHandlerVimc::stop(Camera *camera)
{
VimcCameraData *data = cameraData(camera);
data->video_->streamOff();
PipelineHandler::stop(camera);
}
int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)
@ -166,7 +169,11 @@ int PipelineHandlerVimc::queueRequest(Camera *camera, Request *request)
return -ENOENT;
}
data->video_->queueBuffer(buffer);
int ret = data->video_->queueBuffer(buffer);
if (ret < 0)
return ret;
PipelineHandler::queueRequest(camera, request);
return 0;
}
@ -198,6 +205,8 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
if (data->video_->open())
return false;
data->video_->bufferReady.connect(data.get(), &VimcCameraData::bufferReady);
/* Create and register the camera. */
std::set<Stream *> streams{ &data->stream_ };
std::shared_ptr<Camera> camera = Camera::create(this, "VIMC Sensor B",
@ -207,6 +216,14 @@ bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
return true;
}
void PipelineHandlerVimc::VimcCameraData::bufferReady(Buffer *buffer)
{
Request *request = queuedRequests_.front();
pipe_->completeBuffer(camera_, request, buffer);
pipe_->completeRequest(camera_, request);
}
REGISTER_PIPELINE_HANDLER(PipelineHandlerVimc);
} /* namespace libcamera */