libcamera: pipeline_handler: Decouple buffer import and export

Use the V4L2 buffer orphaning feature, exposed through
V4L2VideoDevice::exportBuffers(), to decouple buffer import and export.
The PipelineHandler::importFrameBuffers() function is now called for all
streams regardless of whether exportFrameBuffers() has been called or
not. This simplifies the Camera implementation slightly, and opens the
door to additional simplifications.

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 2020-03-14 16:14:27 +02:00
parent 7d8604128a
commit 9da27d5d84
8 changed files with 10 additions and 54 deletions

View file

@ -113,7 +113,6 @@ private:
friend class FrameBufferAllocator;
int exportFrameBuffers(Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
int freeFrameBuffers(Stream *stream);
/* \todo Remove allocator_ from the exposed API */
FrameBufferAllocator *allocator_;
};

View file

@ -554,18 +554,6 @@ int Camera::exportFrameBuffers(Stream *stream,
buffers);
}
int Camera::freeFrameBuffers(Stream *stream)
{
int ret = p_->isAccessAllowed(Private::CameraConfigured, true);
if (ret < 0)
return ret;
p_->pipe_->invokeMethod(&PipelineHandler::freeFrameBuffers,
ConnectionTypeBlocking, this, stream);
return 0;
}
/**
* \brief Acquire the camera device for exclusive access
*
@ -928,9 +916,6 @@ int Camera::start()
LOG(Camera, Debug) << "Starting capture";
for (Stream *stream : p_->activeStreams_) {
if (allocator_ && !allocator_->buffers(stream).empty())
continue;
ret = p_->pipe_->invokeMethod(&PipelineHandler::importFrameBuffers,
ConnectionTypeDirect, this, stream);
if (ret < 0)
@ -974,13 +959,9 @@ int Camera::stop()
p_->pipe_->invokeMethod(&PipelineHandler::stop, ConnectionTypeBlocking,
this);
for (Stream *stream : p_->activeStreams_) {
if (allocator_ && !allocator_->buffers(stream).empty())
continue;
for (Stream *stream : p_->activeStreams_)
p_->pipe_->invokeMethod(&PipelineHandler::freeFrameBuffers,
ConnectionTypeBlocking, this, stream);
}
return 0;
}

View file

@ -87,11 +87,6 @@ FrameBufferAllocator::FrameBufferAllocator(std::shared_ptr<Camera> camera)
FrameBufferAllocator::~FrameBufferAllocator()
{
for (auto &value : buffers_) {
Stream *stream = value.first;
camera_->freeFrameBuffers(stream);
}
buffers_.clear();
camera_->allocator_ = nullptr;
@ -148,10 +143,6 @@ int FrameBufferAllocator::free(Stream *stream)
if (iter == buffers_.end())
return -EINVAL;
int ret = camera_->freeFrameBuffers(stream);
if (ret < 0)
return ret;
std::vector<std::unique_ptr<FrameBuffer>> &buffers = iter->second;
buffers.clear();
buffers_.erase(iter);

View file

@ -621,7 +621,7 @@ int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream,
V4L2VideoDevice *video = ipu3stream->device_->dev;
unsigned int count = stream->configuration().bufferCount;
return video->allocateBuffers(count, buffers);
return video->exportBuffers(count, buffers);
}
int PipelineHandlerIPU3::importFrameBuffers(Camera *camera, Stream *stream)

View file

@ -664,7 +664,7 @@ int PipelineHandlerRkISP1::exportFrameBuffers(Camera *camera, Stream *stream,
std::vector<std::unique_ptr<FrameBuffer>> *buffers)
{
unsigned int count = stream->configuration().bufferCount;
return video_->allocateBuffers(count, buffers);
return video_->exportBuffers(count, buffers);
}
int PipelineHandlerRkISP1::importFrameBuffers(Camera *camera, Stream *stream)

View file

@ -211,7 +211,7 @@ int PipelineHandlerUVC::exportFrameBuffers(Camera *camera, Stream *stream,
UVCCameraData *data = cameraData(camera);
unsigned int count = stream->configuration().bufferCount;
return data->video_->allocateBuffers(count, buffers);
return data->video_->exportBuffers(count, buffers);
}
int PipelineHandlerUVC::importFrameBuffers(Camera *camera, Stream *stream)

View file

@ -264,7 +264,7 @@ int PipelineHandlerVimc::exportFrameBuffers(Camera *camera, Stream *stream,
VimcCameraData *data = cameraData(camera);
unsigned int count = stream->configuration().bufferCount;
return data->video_->allocateBuffers(count, buffers);
return data->video_->exportBuffers(count, buffers);
}
int PipelineHandlerVimc::importFrameBuffers(Camera *camera, Stream *stream)

View file

@ -337,16 +337,7 @@ const ControlList &PipelineHandler::properties(Camera *camera)
*
* The method may only be called after the Camera has been configured and before
* it gets started, or after it gets stopped. It shall be called only for
* streams that are part of the active camera configuration, and at most once
* per stream until buffers for the stream are freed with freeFrameBuffers().
*
* exportFrameBuffers() shall also allocate all other resources required by
* the pipeline handler for the stream to prepare for starting the Camera. This
* responsibility is shared with importFrameBuffers(), and one and only one of
* those two methods shall be called for each stream until the buffers are
* freed. The pipeline handler shall support all combinations of
* exportFrameBuffers() and importFrameBuffers() for the streams contained in
* any camera configuration.
* streams that are part of the active camera configuration.
*
* The only intended caller is Camera::exportFrameBuffers().
*
@ -371,12 +362,7 @@ const ControlList &PipelineHandler::properties(Camera *camera)
* per stream until buffers for the stream are freed with freeFrameBuffers().
*
* importFrameBuffers() shall also allocate all other resources required by the
* pipeline handler for the stream to prepare for starting the Camera. This
* responsibility is shared with exportFrameBuffers(), and one and only one of
* those two methods shall be called for each stream until the buffers are
* freed. The pipeline handler shall support all combinations of
* exportFrameBuffers() and importFrameBuffers() for the streams contained in
* any camera configuration.
* pipeline handler for the stream to prepare for starting the Camera.
*
* The only intended caller is Camera::start().
*
@ -391,10 +377,9 @@ const ControlList &PipelineHandler::properties(Camera *camera)
* \param[in] camera The camera
* \param[in] stream The stream to free buffers for
*
* This method shall free all buffers and all other resources allocated for the
* \a stream by exportFrameBuffers() or importFrameBuffers(). It shall be
* called only after a successful call to either of these two methods, and only
* once per stream.
* This method shall release all resources allocated for the \a stream by
* importFrameBuffers(). It shall be called only after a successful call that
* method, and only once per stream.
*
* The only intended callers are Camera::stop() and Camera::freeFrameBuffers().
*