diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 20ae2fc95..dcc7bb3ad 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -75,6 +75,7 @@ struct port { bool alloc_buffers; bool probed_expbuf; bool have_expbuf; + uint32_t max_buffers; bool next_fmtdesc; struct v4l2_fmtdesc fmtdesc; @@ -578,10 +579,13 @@ static int impl_node_port_enum_params(void *object, int seq, return -EIO; if (result.index > 0) return 0; + if (port->max_buffers == 0) + return -EIO; param = spa_pod_builder_add_object(&b.b, 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_size, SPA_POD_Int(port->fmt.fmt.pix.sizeimage), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->fmt.fmt.pix.bytesperline)); diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index a03639f51..a30a09512 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -911,12 +911,13 @@ static int probe_expbuf(struct impl *this) spa_zero(reqbuf); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; - reqbuf.count = 2; + reqbuf.count = port->max_buffers = MAX_BUFFERS; if (xioctl(dev->fd, VIDIOC_REQBUFS, &reqbuf) < 0) { spa_log_error(this->log, "'%s' VIDIOC_REQBUFS: %m", this->props.device); return -errno; } + port->max_buffers = reqbuf.count; spa_zero(expbuf); expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;