[libcamera-devel] [PATCH v4 6/6] libcamera: stream: Remove bufferCount
Nícolas F. R. A. Prado
nfraprado at collabora.com
Thu May 6 20:02:49 CEST 2021
Now that the number of buffers allocated by the FrameBufferAllocator
helper is passed through FrameBufferAllocator::allocate() and the
pipelines no longer use bufferCount for internal buffer or V4L2 buffer
slots allocation, we no longer need to have bufferCount in the
StreamConfiguration, so remove it.
Signed-off-by: Nícolas F. R. A. Prado <nfraprado at collabora.com>
---
include/libcamera/stream.h | 2 --
src/android/camera_stream.cpp | 2 +-
src/libcamera/pipeline/ipu3/cio2.cpp | 1 -
src/libcamera/pipeline/ipu3/ipu3.cpp | 7 -------
src/libcamera/pipeline/raspberrypi/raspberrypi.cpp | 6 ------
src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 2 --
src/libcamera/pipeline/simple/converter.cpp | 3 ---
src/libcamera/pipeline/simple/converter.h | 3 ---
src/libcamera/pipeline/simple/simple.cpp | 5 +----
src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 3 ---
src/libcamera/pipeline/vimc/vimc.cpp | 3 ---
src/libcamera/stream.cpp | 9 ++-------
src/v4l2/v4l2_camera.cpp | 14 ++++++++++----
src/v4l2/v4l2_camera.h | 5 +++--
src/v4l2/v4l2_camera_proxy.cpp | 8 +++-----
test/camera/buffer_import.cpp | 10 +++++++---
test/libtest/buffer_source.cpp | 4 ++--
test/libtest/buffer_source.h | 2 +-
test/v4l2_videodevice/buffer_cache.cpp | 4 ++--
19 files changed, 32 insertions(+), 61 deletions(-)
diff --git a/include/libcamera/stream.h b/include/libcamera/stream.h
index bb47c390f8a1..f36aeffd9540 100644
--- a/include/libcamera/stream.h
+++ b/include/libcamera/stream.h
@@ -45,8 +45,6 @@ struct StreamConfiguration {
unsigned int stride;
unsigned int frameSize;
- unsigned int bufferCount;
-
Stream *stream() const { return stream_; }
void setStream(Stream *stream) { stream_ = stream; }
const StreamFormats &formats() const { return formats_; }
diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
index 859c8807e585..3498ecb0bc0e 100644
--- a/src/android/camera_stream.cpp
+++ b/src/android/camera_stream.cpp
@@ -94,7 +94,7 @@ int CameraStream::configure()
buffers_.push_back(frameBuffer.get());
}
- camera3Stream_->max_buffers = configuration().bufferCount;
+ camera3Stream_->max_buffers = bufferCount;
return 0;
}
diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp
index 3cd777d1b742..1e110fe0c189 100644
--- a/src/libcamera/pipeline/ipu3/cio2.cpp
+++ b/src/libcamera/pipeline/ipu3/cio2.cpp
@@ -213,7 +213,6 @@ StreamConfiguration CIO2Device::generateConfiguration(Size size) const
cfg.size = sensorFormat.size;
cfg.pixelFormat = mbusCodesToPixelFormat.at(sensorFormat.mbus_code);
- cfg.bufferCount = CIO2_BUFFER_COUNT;
return cfg;
}
diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 857cafcbbb72..b1bc421fc7aa 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -291,7 +291,6 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
/* Initialize the RAW stream with the CIO2 configuration. */
cfg->size = cio2Configuration_.size;
cfg->pixelFormat = cio2Configuration_.pixelFormat;
- cfg->bufferCount = cio2Configuration_.bufferCount;
cfg->stride = info.stride(cfg->size.width, 0, 64);
cfg->frameSize = info.frameSize(cfg->size, 64);
cfg->setStream(const_cast<Stream *>(&data_->rawStream_));
@@ -335,7 +334,6 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate()
IMGU_OUTPUT_HEIGHT_ALIGN);
cfg->pixelFormat = formats::NV12;
- cfg->bufferCount = IPU3_BUFFER_COUNT;
cfg->stride = info.stride(cfg->size.width, 0, 1);
cfg->frameSize = info.frameSize(cfg->size, 1);
@@ -403,7 +401,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
Size sensorResolution = data->cio2_.sensor()->resolution();
for (const StreamRole role : roles) {
std::map<PixelFormat, std::vector<SizeRange>> streamFormats;
- unsigned int bufferCount;
PixelFormat pixelFormat;
Size size;
@@ -424,7 +421,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
size.height = utils::alignDown(size.height - 1,
IMGU_OUTPUT_HEIGHT_MARGIN);
pixelFormat = formats::NV12;
- bufferCount = IPU3_BUFFER_COUNT;
streamFormats[pixelFormat] = { { IMGU_OUTPUT_MIN_SIZE, size } };
break;
@@ -434,7 +430,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
data->cio2_.generateConfiguration(sensorResolution);
pixelFormat = cio2Config.pixelFormat;
size = cio2Config.size;
- bufferCount = cio2Config.bufferCount;
for (const PixelFormat &format : data->cio2_.formats())
streamFormats[format] = data->cio2_.sizes();
@@ -453,7 +448,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
.alignedDownTo(IMGU_OUTPUT_WIDTH_ALIGN,
IMGU_OUTPUT_HEIGHT_ALIGN);
pixelFormat = formats::NV12;
- bufferCount = IPU3_BUFFER_COUNT;
streamFormats[pixelFormat] = { { IMGU_OUTPUT_MIN_SIZE, size } };
break;
@@ -470,7 +464,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
StreamConfiguration cfg(formats);
cfg.size = size;
cfg.pixelFormat = pixelFormat;
- cfg.bufferCount = bufferCount;
config->addConfiguration(cfg);
}
diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
index ca31e437a431..bf5fa8c158a3 100644
--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp
@@ -471,7 +471,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
RPiCameraData *data = cameraData(camera);
CameraConfiguration *config = new RPiCameraConfiguration(data);
V4L2DeviceFormat sensorFormat;
- unsigned int bufferCount;
PixelFormat pixelFormat;
V4L2VideoDevice::Formats fmts;
Size size;
@@ -489,7 +488,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
sensorFormat = findBestMode(fmts, size);
pixelFormat = sensorFormat.fourcc.toPixelFormat();
ASSERT(pixelFormat.isValid());
- bufferCount = 2;
rawCount++;
break;
@@ -498,7 +496,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
pixelFormat = formats::NV12;
/* Return the largest sensor resolution. */
size = data->sensor_->resolution();
- bufferCount = 1;
outCount++;
break;
@@ -514,7 +511,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
fmts = data->isp_[Isp::Output0].dev()->formats();
pixelFormat = formats::YUV420;
size = { 1920, 1080 };
- bufferCount = 4;
outCount++;
break;
@@ -522,7 +518,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
fmts = data->isp_[Isp::Output0].dev()->formats();
pixelFormat = formats::ARGB8888;
size = { 800, 600 };
- bufferCount = 4;
outCount++;
break;
@@ -552,7 +547,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
StreamConfiguration cfg(formats);
cfg.size = size;
cfg.pixelFormat = pixelFormat;
- cfg.bufferCount = bufferCount;
config->addConfiguration(cfg);
}
diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
index ec281fef316b..42cdb0ff7be6 100644
--- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
+++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp
@@ -61,7 +61,6 @@ StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution)
StreamConfiguration cfg(formats);
cfg.pixelFormat = formats::NV12;
cfg.size = maxResolution;
- cfg.bufferCount = RKISP1_BUFFER_COUNT;
return cfg;
}
@@ -77,7 +76,6 @@ CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg)
cfg->size.boundTo(maxResolution_);
cfg->size.expandTo(minResolution_);
- cfg->bufferCount = RKISP1_BUFFER_COUNT;
V4L2DeviceFormat format;
format.fourcc = video_->toV4L2PixelFormat(cfg->pixelFormat);
diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/pipeline/simple/converter.cpp
index bf491cf661eb..09d5ecb14084 100644
--- a/src/libcamera/pipeline/simple/converter.cpp
+++ b/src/libcamera/pipeline/simple/converter.cpp
@@ -86,9 +86,6 @@ int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg,
return -EINVAL;
}
- inputBufferCount_ = inputCfg.bufferCount;
- outputBufferCount_ = outputCfg.bufferCount;
-
return 0;
}
diff --git a/src/libcamera/pipeline/simple/converter.h b/src/libcamera/pipeline/simple/converter.h
index 6a7031b78ebf..1288b4717ff9 100644
--- a/src/libcamera/pipeline/simple/converter.h
+++ b/src/libcamera/pipeline/simple/converter.h
@@ -87,9 +87,6 @@ private:
SimpleConverter *converter_;
unsigned int index_;
std::unique_ptr<V4L2M2MDevice> m2m_;
-
- unsigned int inputBufferCount_;
- unsigned int outputBufferCount_;
};
std::string deviceNode_;
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index a6e432272364..6be9587062e8 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -617,7 +617,7 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
cfg.size != pipeConfig_->captureSize)
needConversion_ = true;
- /* Set the stride, frameSize and bufferCount. */
+ /* Set the stride and frameSize. */
if (needConversion_) {
std::tie(cfg.stride, cfg.frameSize) =
converter->strideAndFrameSize(cfg.pixelFormat, cfg.size);
@@ -635,8 +635,6 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
cfg.stride = format.planes[0].bpl;
cfg.frameSize = format.planes[0].size;
}
-
- cfg.bufferCount = 3;
}
return status;
@@ -759,7 +757,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
inputCfg.pixelFormat = pipeConfig->captureFormat;
inputCfg.size = pipeConfig->captureSize;
inputCfg.stride = captureFormat.planes[0].bpl;
- inputCfg.bufferCount = kNumInternalBuffers;
return converter_->configure(inputCfg, outputCfgs);
}
diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
index 1052b6f2fe5f..eaeb94887c93 100644
--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp
@@ -150,8 +150,6 @@ CameraConfiguration::Status UVCCameraConfiguration::validate()
status = Adjusted;
}
- cfg.bufferCount = 4;
-
V4L2DeviceFormat format;
format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);
format.size = cfg.size;
@@ -193,7 +191,6 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,
cfg.pixelFormat = formats.pixelformats().front();
cfg.size = formats.sizes(cfg.pixelFormat).back();
- cfg.bufferCount = 4;
config->addConfiguration(cfg);
diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
index 161d8ba6368d..569f07c694b5 100644
--- a/src/libcamera/pipeline/vimc/vimc.cpp
+++ b/src/libcamera/pipeline/vimc/vimc.cpp
@@ -167,8 +167,6 @@ CameraConfiguration::Status VimcCameraConfiguration::validate()
status = Adjusted;
}
- cfg.bufferCount = 4;
-
V4L2DeviceFormat format;
format.fourcc = data_->video_->toV4L2PixelFormat(cfg.pixelFormat);
format.size = cfg.size;
@@ -224,7 +222,6 @@ CameraConfiguration *PipelineHandlerVimc::generateConfiguration(Camera *camera,
cfg.pixelFormat = formats::BGR888;
cfg.size = { 1920, 1080 };
- cfg.bufferCount = 4;
config->addConfiguration(cfg);
diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp
index f7bafcf8fc97..be57abce4eb3 100644
--- a/src/libcamera/stream.cpp
+++ b/src/libcamera/stream.cpp
@@ -279,7 +279,7 @@ SizeRange StreamFormats::range(const PixelFormat &pixelformat) const
* handlers provide StreamFormats.
*/
StreamConfiguration::StreamConfiguration()
- : pixelFormat(0), stride(0), frameSize(0), bufferCount(0),
+ : pixelFormat(0), stride(0), frameSize(0),
stream_(nullptr)
{
}
@@ -288,7 +288,7 @@ StreamConfiguration::StreamConfiguration()
* \brief Construct a configuration with stream formats
*/
StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
- : pixelFormat(0), stride(0), frameSize(0), bufferCount(0),
+ : pixelFormat(0), stride(0), frameSize(0),
stream_(nullptr), formats_(formats)
{
}
@@ -323,11 +323,6 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
* validating the configuration with a call to CameraConfiguration::validate().
*/
-/**
- * \var StreamConfiguration::bufferCount
- * \brief Requested number of buffers to allocate for the stream
- */
-
/**
* \fn StreamConfiguration::stream()
* \brief Retrieve the stream associated with the configuration
diff --git a/src/v4l2/v4l2_camera.cpp b/src/v4l2/v4l2_camera.cpp
index 53d97f3e6b86..52f28960b3c2 100644
--- a/src/v4l2/v4l2_camera.cpp
+++ b/src/v4l2/v4l2_camera.cpp
@@ -10,6 +10,8 @@
#include <errno.h>
#include <unistd.h>
+#include <libcamera/property_ids.h>
+
#include "libcamera/internal/log.h"
using namespace libcamera;
@@ -107,14 +109,12 @@ void V4L2Camera::requestComplete(Request *request)
}
int V4L2Camera::configure(StreamConfiguration *streamConfigOut,
- const Size &size, const PixelFormat &pixelformat,
- unsigned int bufferCount)
+ const Size &size, const PixelFormat &pixelformat)
{
StreamConfiguration &streamConfig = config_->at(0);
streamConfig.size.width = size.width;
streamConfig.size.height = size.height;
streamConfig.pixelFormat = pixelformat;
- streamConfig.bufferCount = bufferCount;
/* \todo memoryType (interval vs external) */
CameraConfiguration::Status validation = config_->validate();
@@ -146,7 +146,6 @@ int V4L2Camera::validateConfiguration(const PixelFormat &pixelFormat,
StreamConfiguration &cfg = config->at(0);
cfg.size = size;
cfg.pixelFormat = pixelFormat;
- cfg.bufferCount = 1;
CameraConfiguration::Status validation = config->validate();
if (validation == CameraConfiguration::Invalid)
@@ -299,3 +298,10 @@ bool V4L2Camera::isRunning()
{
return isRunning_;
}
+
+unsigned int V4L2Camera::minNumRequests(unsigned int count)
+{
+ unsigned int min = camera_->properties().get(properties::MinNumRequests);
+
+ return std::max(count, min);
+}
diff --git a/src/v4l2/v4l2_camera.h b/src/v4l2/v4l2_camera.h
index d238046250e3..a5ad7dd35351 100644
--- a/src/v4l2/v4l2_camera.h
+++ b/src/v4l2/v4l2_camera.h
@@ -45,8 +45,7 @@ public:
std::vector<Buffer> completedBuffers();
int configure(StreamConfiguration *streamConfigOut,
- const Size &size, const PixelFormat &pixelformat,
- unsigned int bufferCount);
+ const Size &size, const PixelFormat &pixelformat);
int validateConfiguration(const PixelFormat &pixelformat,
const Size &size,
StreamConfiguration *streamConfigOut);
@@ -65,6 +64,8 @@ public:
bool isRunning();
+ unsigned int minNumRequests(unsigned int count);
+
private:
void requestComplete(Request *request);
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index f8bfe595e90e..48955f85b991 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -348,8 +348,7 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg)
Size size(arg->fmt.pix.width, arg->fmt.pix.height);
V4L2PixelFormat v4l2Format = V4L2PixelFormat(arg->fmt.pix.pixelformat);
ret = vcam_->configure(&streamConfig_, size,
- PixelFormatInfo::info(v4l2Format).format,
- bufferCount_);
+ PixelFormatInfo::info(v4l2Format).format);
if (ret < 0)
return -EINVAL;
@@ -490,14 +489,13 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf
Size size(v4l2PixFormat_.width, v4l2PixFormat_.height);
V4L2PixelFormat v4l2Format = V4L2PixelFormat(v4l2PixFormat_.pixelformat);
int ret = vcam_->configure(&streamConfig_, size,
- PixelFormatInfo::info(v4l2Format).format,
- arg->count);
+ PixelFormatInfo::info(v4l2Format).format);
if (ret < 0)
return -EINVAL;
setFmtFromConfig(streamConfig_);
- arg->count = streamConfig_.bufferCount;
+ arg->count = vcam_->minNumRequests(arg->count);
bufferCount_ = arg->count;
ret = vcam_->allocBuffers(arg->count);
diff --git a/test/camera/buffer_import.cpp b/test/camera/buffer_import.cpp
index 61f4eb92ae95..403829efcfd3 100644
--- a/test/camera/buffer_import.cpp
+++ b/test/camera/buffer_import.cpp
@@ -12,6 +12,8 @@
#include <numeric>
#include <vector>
+#include <libcamera/property_ids.h>
+
#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/event_dispatcher.h"
#include "libcamera/internal/media_device.h"
@@ -91,10 +93,12 @@ protected:
return TestFail;
}
+ unsigned int bufferCount = camera_->properties().get(properties::MinNumRequests);
+
Stream *stream = cfg.stream();
BufferSource source;
- int ret = source.allocate(cfg);
+ int ret = source.allocate(cfg, bufferCount);
if (ret != TestPass)
return ret;
@@ -138,10 +142,10 @@ protected:
while (timer.isRunning())
dispatcher->processEvents();
- if (completeRequestsCount_ < cfg.bufferCount * 2) {
+ if (completeRequestsCount_ < bufferCount * 2) {
std::cout << "Failed to capture enough frames (got "
<< completeRequestsCount_ << " expected at least "
- << cfg.bufferCount * 2 << ")" << std::endl;
+ << bufferCount * 2 << ")" << std::endl;
return TestFail;
}
diff --git a/test/libtest/buffer_source.cpp b/test/libtest/buffer_source.cpp
index 73563f2fc39d..c3d5286a2462 100644
--- a/test/libtest/buffer_source.cpp
+++ b/test/libtest/buffer_source.cpp
@@ -24,7 +24,7 @@ BufferSource::~BufferSource()
media_->release();
}
-int BufferSource::allocate(const StreamConfiguration &config)
+int BufferSource::allocate(const StreamConfiguration &config, unsigned int count)
{
/* Locate and open the video device. */
std::string videoDeviceName = "vivid-000-vid-out";
@@ -77,7 +77,7 @@ int BufferSource::allocate(const StreamConfiguration &config)
return TestFail;
}
- if (video->allocateBuffers(config.bufferCount, &buffers_) < 0) {
+ if (video->allocateBuffers(count, &buffers_) < 0) {
std::cout << "Failed to allocate buffers" << std::endl;
return TestFail;
}
diff --git a/test/libtest/buffer_source.h b/test/libtest/buffer_source.h
index 14b4770e8d8a..6a18e269a575 100644
--- a/test/libtest/buffer_source.h
+++ b/test/libtest/buffer_source.h
@@ -20,7 +20,7 @@ public:
BufferSource();
~BufferSource();
- int allocate(const StreamConfiguration &config);
+ int allocate(const StreamConfiguration &config, unsigned int count);
const std::vector<std::unique_ptr<FrameBuffer>> &buffers();
private:
diff --git a/test/v4l2_videodevice/buffer_cache.cpp b/test/v4l2_videodevice/buffer_cache.cpp
index b3f2bec11783..07fddfd2617c 100644
--- a/test/v4l2_videodevice/buffer_cache.cpp
+++ b/test/v4l2_videodevice/buffer_cache.cpp
@@ -10,6 +10,7 @@
#include <vector>
#include <libcamera/formats.h>
+#include <libcamera/property_ids.h>
#include <libcamera/stream.h>
#include "buffer_source.h"
@@ -145,10 +146,9 @@ public:
StreamConfiguration cfg;
cfg.pixelFormat = formats::YUYV;
cfg.size = Size(600, 800);
- cfg.bufferCount = numBuffers;
BufferSource source;
- int ret = source.allocate(cfg);
+ int ret = source.allocate(cfg, numBuffers);
if (ret != TestPass)
return ret;
--
2.31.1
More information about the libcamera-devel
mailing list