v4l2: probe number of buffers as well

Instead of just probing with 2 buffers, probe with the MAX_BUFFERS and
remember how many buffers we received.

Some drivers (v4l2loopback) work with less than MAX_BUFFERS (8) and we
need to set the max number of buffers in the Buffers param.
This commit is contained in:
Wim Taymans 2024-11-07 15:33:04 +01:00
parent 71f6d269db
commit 877c262e78
2 changed files with 7 additions and 2 deletions

View file

@ -75,6 +75,7 @@ struct port {
bool alloc_buffers; bool alloc_buffers;
bool probed_expbuf; bool probed_expbuf;
bool have_expbuf; bool have_expbuf;
uint32_t max_buffers;
bool next_fmtdesc; bool next_fmtdesc;
struct v4l2_fmtdesc fmtdesc; struct v4l2_fmtdesc fmtdesc;
@ -578,10 +579,13 @@ static int impl_node_port_enum_params(void *object, int seq,
return -EIO; return -EIO;
if (result.index > 0) if (result.index > 0)
return 0; return 0;
if (port->max_buffers == 0)
return -EIO;
param = spa_pod_builder_add_object(&b.b, param = spa_pod_builder_add_object(&b.b,
SPA_TYPE_OBJECT_ParamBuffers, id, SPA_TYPE_OBJECT_ParamBuffers, id,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(4, 1, MAX_BUFFERS), SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(SPA_MIN(4u, port->max_buffers),
1, port->max_buffers),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(port->fmt.fmt.pix.sizeimage), SPA_PARAM_BUFFERS_size, SPA_POD_Int(port->fmt.fmt.pix.sizeimage),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->fmt.fmt.pix.bytesperline)); SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->fmt.fmt.pix.bytesperline));

View file

@ -911,12 +911,13 @@ static int probe_expbuf(struct impl *this)
spa_zero(reqbuf); spa_zero(reqbuf);
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.memory = V4L2_MEMORY_MMAP;
reqbuf.count = 2; reqbuf.count = port->max_buffers = MAX_BUFFERS;
if (xioctl(dev->fd, VIDIOC_REQBUFS, &reqbuf) < 0) { if (xioctl(dev->fd, VIDIOC_REQBUFS, &reqbuf) < 0) {
spa_log_error(this->log, "'%s' VIDIOC_REQBUFS: %m", this->props.device); spa_log_error(this->log, "'%s' VIDIOC_REQBUFS: %m", this->props.device);
return -errno; return -errno;
} }
port->max_buffers = reqbuf.count;
spa_zero(expbuf); spa_zero(expbuf);
expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;