From 33fedea818e2b6a9ed68ac86acf194b1a2da8828 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 14 Mar 2020 16:14:27 +0200 Subject: libcamera: pipeline_handler: Fold buffer management with start/stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's no need anymore to have the Camera object control how and when pipeline handlers allocate and free the buffers for the application-facing video devices. Fold those operations, currently performed by importFrameBuffers() and freeFrameBuffers(), into the start() and stop() functions. This simplifies the pipeline handler API, its implementation, and the implementation of the Camera class. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/pipeline/ipu3/ipu3.cpp | 146 +++++++++++++++++------------------ 1 file changed, 69 insertions(+), 77 deletions(-) (limited to 'src/libcamera/pipeline/ipu3') diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 2edca02e..55ce8fa1 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -71,6 +71,7 @@ public: int configureOutput(ImgUOutput *output, const StreamConfiguration &cfg); + int allocateBuffers(IPU3CameraData *data, unsigned int bufferCount); void freeBuffers(IPU3CameraData *data); int start(); @@ -207,8 +208,6 @@ public: int exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) override; - int importFrameBuffers(Camera *camera, Stream *stream) override; - void freeFrameBuffers(Camera *camera, Stream *stream) override; int start(Camera *camera) override; void stop(Camera *camera) override; @@ -624,23 +623,6 @@ int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream, return video->exportBuffers(count, buffers); } -int PipelineHandlerIPU3::importFrameBuffers(Camera *camera, Stream *stream) -{ - IPU3Stream *ipu3stream = static_cast(stream); - V4L2VideoDevice *video = ipu3stream->device_->dev; - unsigned int count = stream->configuration().bufferCount; - - return video->importBuffers(count); -} - -void PipelineHandlerIPU3::freeFrameBuffers(Camera *camera, Stream *stream) -{ - IPU3Stream *ipu3stream = static_cast(stream); - V4L2VideoDevice *video = ipu3stream->device_->dev; - - video->releaseBuffers(); -} - /** * \todo Clarify if 'viewfinder' and 'stat' nodes have to be set up and * started even if not in use. As of now, if not properly configured and @@ -652,69 +634,24 @@ void PipelineHandlerIPU3::freeFrameBuffers(Camera *camera, Stream *stream) int PipelineHandlerIPU3::allocateBuffers(Camera *camera) { IPU3CameraData *data = cameraData(camera); - IPU3Stream *outStream = &data->outStream_; - IPU3Stream *vfStream = &data->vfStream_; CIO2Device *cio2 = &data->cio2_; ImgUDevice *imgu = data->imgu_; unsigned int bufferCount; int ret; - /* Share buffers between CIO2 output and ImgU input. */ ret = cio2->allocateBuffers(); if (ret < 0) return ret; bufferCount = ret; - ret = imgu->input_->importBuffers(bufferCount); - if (ret) { - LOG(IPU3, Error) << "Failed to import ImgU input buffers"; - goto error; - } - - /* - * Use for the stat's internal pool the same number of buffers as for - * the input pool. - * \todo To be revised when we'll actually use the stat node. - */ - ret = imgu->stat_.dev->allocateBuffers(bufferCount, &imgu->stat_.buffers); + ret = imgu->allocateBuffers(data, bufferCount); if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; - goto error; - } - - /* - * Allocate buffers also on non-active outputs; use the same number - * of buffers as the active ones. - */ - if (!outStream->active_) { - ImgUDevice::ImgUOutput *output = outStream->device_; - - ret = output->dev->allocateBuffers(bufferCount, &output->buffers); - if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU " - << output->name << " buffers"; - goto error; - } - } - - if (!vfStream->active_) { - ImgUDevice::ImgUOutput *output = vfStream->device_; - - ret = output->dev->allocateBuffers(bufferCount, &output->buffers); - if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU " - << output->name << " buffers"; - goto error; - } + cio2->freeBuffers(); + return ret; } return 0; - -error: - freeBuffers(camera); - - return ret; } int PipelineHandlerIPU3::freeBuffers(Camera *camera) @@ -1155,6 +1092,65 @@ int ImgUDevice::configureOutput(ImgUOutput *output, return 0; } +/** + * \brief Allocate buffers for all the ImgU video devices + */ +int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) +{ + IPU3Stream *outStream = &data->outStream_; + IPU3Stream *vfStream = &data->vfStream_; + + /* Share buffers between CIO2 output and ImgU input. */ + int ret = input_->importBuffers(bufferCount); + if (ret) { + LOG(IPU3, Error) << "Failed to import ImgU input buffers"; + return ret; + } + + /* + * Use for the stat's internal pool the same number of buffers as for + * the input pool. + * \todo To be revised when we'll actually use the stat node. + */ + ret = stat_.dev->allocateBuffers(bufferCount, &stat_.buffers); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; + goto error; + } + + /* + * Allocate buffers for both outputs. If an output is active, prepare + * for buffer import, otherwise allocate internal buffers. Use the same + * number of buffers in either case. + */ + if (outStream->active_) + ret = output_.dev->importBuffers(bufferCount); + else + ret = output_.dev->allocateBuffers(bufferCount, + &output_.buffers); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to allocate ImgU output buffers"; + goto error; + } + + if (vfStream->active_) + ret = viewfinder_.dev->importBuffers(bufferCount); + else + ret = viewfinder_.dev->allocateBuffers(bufferCount, + &viewfinder_.buffers); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to allocate ImgU viewfinder buffers"; + goto error; + } + + return 0; + +error: + freeBuffers(data); + + return ret; +} + /** * \brief Release buffers for all the ImgU video devices */ @@ -1162,21 +1158,17 @@ void ImgUDevice::freeBuffers(IPU3CameraData *data) { int ret; - if (!data->outStream_.active_) { - ret = output_.dev->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU output buffers"; - } + ret = output_.dev->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU output buffers"; ret = stat_.dev->releaseBuffers(); if (ret) LOG(IPU3, Error) << "Failed to release ImgU stat buffers"; - if (!data->vfStream_.active_) { - ret = viewfinder_.dev->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU viewfinder buffers"; - } + ret = viewfinder_.dev->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU viewfinder buffers"; ret = input_->releaseBuffers(); if (ret) -- cgit v1.2.1