@@ -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_; }
@@ -94,7 +94,7 @@ int CameraStream::configure()
buffers_.push_back(frameBuffer.get());
}
- camera3Stream_->max_buffers = configuration().bufferCount;
+ camera3Stream_->max_buffers = bufferCount;
return 0;
}
@@ -214,7 +214,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;
}
@@ -38,7 +38,6 @@ namespace libcamera {
LOG_DEFINE_CATEGORY(IPU3)
-static constexpr unsigned int IPU3_BUFFER_COUNT = 4;
static constexpr unsigned int IPU3_MAX_STREAMS = 3;
static const Size IMGU_OUTPUT_MIN_SIZE = { 2, 2 };
static const Size IMGU_OUTPUT_MAX_SIZE = { 4480, 34004 };
@@ -295,7 +294,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_));
@@ -339,7 +337,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);
@@ -407,7 +404,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;
@@ -428,7 +424,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;
@@ -438,7 +433,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();
@@ -457,7 +451,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;
@@ -474,7 +467,6 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera,
StreamConfiguration cfg(formats);
cfg.size = size;
cfg.pixelFormat = pixelFormat;
- cfg.bufferCount = bufferCount;
config->addConfiguration(cfg);
}
@@ -473,7 +473,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;
@@ -491,7 +490,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
sensorFormat = findBestMode(fmts, size);
pixelFormat = sensorFormat.fourcc.toPixelFormat();
ASSERT(pixelFormat.isValid());
- bufferCount = 2;
rawCount++;
break;
@@ -500,7 +498,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
pixelFormat = formats::NV12;
/* Return the largest sensor resolution. */
size = data->sensor_->resolution();
- bufferCount = 1;
outCount++;
break;
@@ -516,7 +513,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
fmts = data->isp_[Isp::Output0].dev()->formats();
pixelFormat = formats::YUV420;
size = { 1920, 1080 };
- bufferCount = 4;
outCount++;
break;
@@ -524,7 +520,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
fmts = data->isp_[Isp::Output0].dev()->formats();
pixelFormat = formats::ARGB8888;
size = { 800, 600 };
- bufferCount = 4;
outCount++;
break;
@@ -554,7 +549,6 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,
StreamConfiguration cfg(formats);
cfg.size = size;
cfg.pixelFormat = pixelFormat;
- cfg.bufferCount = bufferCount;
config->addConfiguration(cfg);
}
@@ -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);
@@ -89,9 +89,6 @@ int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg,
return -EINVAL;
}
- inputBufferCount_ = inputCfg.bufferCount;
- outputBufferCount_ = outputCfg.bufferCount;
-
return 0;
}
@@ -87,9 +87,6 @@ private:
SimpleConverter *converter_;
unsigned int index_;
std::unique_ptr<V4L2M2MDevice> m2m_;
-
- unsigned int inputBufferCount_;
- unsigned int outputBufferCount_;
};
std::string deviceNode_;
@@ -628,7 +628,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);
@@ -646,8 +646,6 @@ CameraConfiguration::Status SimpleCameraConfiguration::validate()
cfg.stride = format.planes[0].bpl;
cfg.frameSize = format.planes[0].size;
}
-
- cfg.bufferCount = 3;
}
return status;
@@ -770,7 +768,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);
}
@@ -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);
@@ -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);
@@ -280,7 +280,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)
{
}
@@ -289,7 +289,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)
{
}
@@ -324,11 +324,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
@@ -12,6 +12,8 @@
#include <libcamera/base/log.h>
+#include <libcamera/property_ids.h>
+
using namespace libcamera;
LOG_DECLARE_CATEGORY(V4L2Compat)
@@ -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);
+}
@@ -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);
@@ -349,8 +349,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;
@@ -491,14 +490,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);
@@ -16,6 +16,8 @@
#include <libcamera/base/thread.h>
#include <libcamera/base/timer.h>
+#include <libcamera/property_ids.h>
+
#include "libcamera/internal/device_enumerator.h"
#include "libcamera/internal/media_device.h"
#include "libcamera/internal/v4l2_videodevice.h"
@@ -92,10 +94,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;
@@ -139,10 +143,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;
}
@@ -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;
}
@@ -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:
@@ -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;
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@collabora.com> --- Changes in v6: - Removed IPU3_BUFFER_COUNT as it was unused include/libcamera/stream.h | 2 -- src/android/camera_stream.cpp | 2 +- src/libcamera/pipeline/ipu3/cio2.cpp | 1 - src/libcamera/pipeline/ipu3/ipu3.cpp | 8 -------- 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(+), 62 deletions(-)