diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index bc920dd26..79e347491 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -58,7 +58,7 @@ static void reset_props(struct props *props) strncpy(props->device, default_device, 64); } -#define MAX_BUFFERS 64 +#define MAX_BUFFERS 32 #define BUFFER_FLAG_OUTSTANDING (1<<0) #define BUFFER_FLAG_ALLOCATED (1<<1) @@ -567,6 +567,7 @@ static int port_set_format(void *object, spa_v4l2_stream_off(this); spa_v4l2_clear_buffers(this); port->have_format = false; + port->dev.have_format = false; spa_v4l2_close(&port->dev); goto done; } else { diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index c2113be0c..2cbdb7535 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -110,7 +110,7 @@ int spa_v4l2_close(struct spa_v4l2_device *dev) if (dev->fd == -1) return 0; - if (dev->active) + if (dev->active || dev->have_format) return 0; spa_log_info(dev->log, "v4l2: close"); @@ -916,6 +916,7 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format, if (try_only) return 0; + dev->have_format = true; size->width = fmt.fmt.pix.width; size->height = fmt.fmt.pix.height; port->rate.denom = framerate->num = streamparm.parm.capture.timeperframe.denominator; @@ -1474,6 +1475,9 @@ static int spa_v4l2_stream_on(struct impl *this) if (dev->fd == -1) return -EIO; + if (!dev->have_format) + return -EIO; + if (dev->active) return 0; diff --git a/spa/plugins/v4l2/v4l2.h b/spa/plugins/v4l2/v4l2.h index 46d62e43f..4f85f68b2 100644 --- a/spa/plugins/v4l2/v4l2.h +++ b/spa/plugins/v4l2/v4l2.h @@ -28,7 +28,8 @@ struct spa_v4l2_device { struct spa_log *log; int fd; struct v4l2_capability cap; - bool active; + unsigned int active:1; + unsigned int have_format:1; }; int spa_v4l2_open(struct spa_v4l2_device *dev, const char *path);