libcamera: pipeline: Support importing buffers

Add support for importing external buffers in all pipeline handlers.

Use the stream memory type in the pipeline handlers during buffer
allocation to import buffers to or export buffers from the video device.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
Jacopo Mondi 2019-07-04 11:30:52 +02:00 committed by Laurent Pinchart
parent 9ed9d9b3c1
commit b5010e4cee
4 changed files with 51 additions and 14 deletions

View file

@ -69,8 +69,9 @@ public:
int configureOutput(ImgUOutput *output, int configureOutput(ImgUOutput *output,
const StreamConfiguration &cfg); const StreamConfiguration &cfg);
int importBuffers(BufferPool *pool); int importInputBuffers(BufferPool *pool);
int exportBuffers(ImgUOutput *output, BufferPool *pool); int importOutputBuffers(ImgUOutput *output, BufferPool *pool);
int exportOutputBuffers(ImgUOutput *output, BufferPool *pool);
void freeBuffers(); void freeBuffers();
int start(); int start();
@ -605,7 +606,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,
if (!pool) if (!pool)
return -ENOMEM; return -ENOMEM;
ret = imgu->importBuffers(pool); ret = imgu->importInputBuffers(pool);
if (ret) if (ret)
goto error; goto error;
@ -616,7 +617,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,
*/ */
bufferCount = pool->count(); bufferCount = pool->count();
imgu->stat_.pool->createBuffers(bufferCount); imgu->stat_.pool->createBuffers(bufferCount);
ret = imgu->exportBuffers(&imgu->stat_, imgu->stat_.pool); ret = imgu->exportOutputBuffers(&imgu->stat_, imgu->stat_.pool);
if (ret) if (ret)
goto error; goto error;
@ -625,7 +626,10 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,
IPU3Stream *stream = static_cast<IPU3Stream *>(s); IPU3Stream *stream = static_cast<IPU3Stream *>(s);
ImgUDevice::ImgUOutput *dev = stream->device_; ImgUDevice::ImgUOutput *dev = stream->device_;
ret = imgu->exportBuffers(dev, &stream->bufferPool()); if (stream->memoryType() == InternalMemory)
ret = imgu->exportOutputBuffers(dev, &stream->bufferPool());
else
ret = imgu->importOutputBuffers(dev, &stream->bufferPool());
if (ret) if (ret)
goto error; goto error;
} }
@ -637,8 +641,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,
if (!outStream->active_) { if (!outStream->active_) {
bufferCount = vfStream->configuration().bufferCount; bufferCount = vfStream->configuration().bufferCount;
outStream->device_->pool->createBuffers(bufferCount); outStream->device_->pool->createBuffers(bufferCount);
ret = imgu->exportBuffers(outStream->device_, ret = imgu->exportOutputBuffers(outStream->device_,
outStream->device_->pool); outStream->device_->pool);
if (ret) if (ret)
goto error; goto error;
} }
@ -646,8 +650,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera,
if (!vfStream->active_) { if (!vfStream->active_) {
bufferCount = outStream->configuration().bufferCount; bufferCount = outStream->configuration().bufferCount;
vfStream->device_->pool->createBuffers(bufferCount); vfStream->device_->pool->createBuffers(bufferCount);
ret = imgu->exportBuffers(vfStream->device_, ret = imgu->exportOutputBuffers(vfStream->device_,
vfStream->device_->pool); vfStream->device_->pool);
if (ret) if (ret)
goto error; goto error;
} }
@ -1113,7 +1117,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output,
* \param[in] pool The buffer pool to import * \param[in] pool The buffer pool to import
* \return 0 on success or a negative error code otherwise * \return 0 on success or a negative error code otherwise
*/ */
int ImgUDevice::importBuffers(BufferPool *pool) int ImgUDevice::importInputBuffers(BufferPool *pool)
{ {
int ret = input_->importBuffers(pool); int ret = input_->importBuffers(pool);
if (ret) { if (ret) {
@ -1134,7 +1138,7 @@ int ImgUDevice::importBuffers(BufferPool *pool)
* *
* \return 0 on success or a negative error code otherwise * \return 0 on success or a negative error code otherwise
*/ */
int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool) int ImgUDevice::exportOutputBuffers(ImgUOutput *output, BufferPool *pool)
{ {
int ret = output->dev->exportBuffers(pool); int ret = output->dev->exportBuffers(pool);
if (ret) { if (ret) {
@ -1146,6 +1150,29 @@ int ImgUDevice::exportBuffers(ImgUOutput *output, BufferPool *pool)
return 0; return 0;
} }
/**
* \brief Reserve buffers in \a output from the provided \a pool
* \param[in] output The ImgU output device
* \param[in] pool The buffer pool used to reserve buffers in \a output
*
* Reserve a number of buffers equal to the number of buffers in \a pool
* in the \a output device.
*
* \return 0 on success or a negative error code otherwise
*/
int ImgUDevice::importOutputBuffers(ImgUOutput *output, BufferPool *pool)
{
int ret = output->dev->importBuffers(pool);
if (ret) {
LOG(IPU3, Error)
<< "Failed to import buffer in " << output->name
<< " ImgU device";
return ret;
}
return 0;
}
/** /**
* \brief Release buffers for all the ImgU video devices * \brief Release buffers for all the ImgU video devices
*/ */

View file

@ -319,7 +319,11 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera,
const std::set<Stream *> &streams) const std::set<Stream *> &streams)
{ {
Stream *stream = *streams.begin(); Stream *stream = *streams.begin();
return video_->exportBuffers(&stream->bufferPool());
if (stream->memoryType() == InternalMemory)
return video_->exportBuffers(&stream->bufferPool());
else
return video_->importBuffers(&stream->bufferPool());
} }
int PipelineHandlerRkISP1::freeBuffers(Camera *camera, int PipelineHandlerRkISP1::freeBuffers(Camera *camera,

View file

@ -200,7 +200,10 @@ int PipelineHandlerUVC::allocateBuffers(Camera *camera,
LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; LOG(UVC, Debug) << "Requesting " << cfg.bufferCount << " buffers";
return data->video_->exportBuffers(&stream->bufferPool()); if (stream->memoryType() == InternalMemory)
return data->video_->exportBuffers(&stream->bufferPool());
else
return data->video_->importBuffers(&stream->bufferPool());
} }
int PipelineHandlerUVC::freeBuffers(Camera *camera, int PipelineHandlerUVC::freeBuffers(Camera *camera,

View file

@ -202,7 +202,10 @@ int PipelineHandlerVimc::allocateBuffers(Camera *camera,
LOG(VIMC, Debug) << "Requesting " << cfg.bufferCount << " buffers"; LOG(VIMC, Debug) << "Requesting " << cfg.bufferCount << " buffers";
return data->video_->exportBuffers(&stream->bufferPool()); if (stream->memoryType() == InternalMemory)
return data->video_->exportBuffers(&stream->bufferPool());
else
return data->video_->importBuffers(&stream->bufferPool());
} }
int PipelineHandlerVimc::freeBuffers(Camera *camera, int PipelineHandlerVimc::freeBuffers(Camera *camera,