Skip to content

Commit

Permalink
Set valid pix format in add()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephematician committed Jan 14, 2025
1 parent 5931810 commit e40cf90
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions v4l2loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,7 @@ static int v4l2_loopback_add(struct v4l2_loopback_config *conf, int *ret_nr)
!(V4L2LOOPBACK_DEFAULT_EXCLUSIVECAPS);
int _max_buffers = DEFAULT_FROM_CONF(max_buffers, <= 0, max_buffers);
int _max_openers = DEFAULT_FROM_CONF(max_openers, <= 0, max_openers);
struct v4l2_format _fmt;

int nr = -1;

Expand Down Expand Up @@ -2771,19 +2772,17 @@ static int v4l2_loopback_add(struct v4l2_loopback_config *conf, int *ret_nr)
if (_height > _max_height)
_height = _max_height;

dev->pix_format.width = _width;
dev->pix_format.height = _height;
dev->pix_format.pixelformat = formats[0].fourcc;
dev->pix_format.colorspace =
V4L2_COLORSPACE_DEFAULT; /* do we need to set this ? */
dev->pix_format.field = V4L2_FIELD_NONE;

dev->buffer_size = PAGE_ALIGN(dev->pix_format.sizeimage);
dprintk("buffer_size = %ld (=%d)\n", dev->buffer_size,
dev->pix_format.sizeimage);

if (dev->buffer_size && ((err = allocate_buffers(dev)) < 0))
goto out_free_handler;
_fmt = (struct v4l2_format){
.type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
.fmt.pix = { .width = _width,
.height = _height,
.pixelformat = formats[0].fourcc,
.colorspace = V4L2_COLORSPACE_DEFAULT,
.field = V4L2_FIELD_NONE }
};
v4l2l_fill_format(&_fmt, 1, _min_width, _max_width, _min_height,
_max_height);
dev->pix_format = _fmt.fmt.pix;

init_waitqueue_head(&dev->read_event);

Expand Down

0 comments on commit e40cf90

Please sign in to comment.