10000 allow limited number of formats/framesizes once the format is negotia… · v4l2loopback/v4l2loopback@7c09d0b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c09d0b

Browse files
committed
allow limited number of formats/framesizes once the format is negotiated/fixed
1 parent 6aabf9f commit 7c09d0b

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

v4l2loopback.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ static int vidioc_querycap(struct file *file, void *fh,
717717
static int vidioc_enum_framesizes(struct file *file, void *fh,
718718
struct v4l2_frmsizeenum *argp)
719719
{
720-
#warning handle pre-negotiated formats
721720
struct v4l2_loopback_device *dev;
722721

723722
/* there can be only one... */
@@ -726,6 +725,18 @@ static int vidioc_enum_framesizes(struct file *file, void *fh,
726725

727726
dev = file_to_loopdev(file);
728727

728+
if (is_format_locked(dev)) {
729+
/* format is negotiated, so there's only a single valid format */
730+
if (dev->pix_format.pixelformat != argp->pixel_format)
731+
return -EINVAL;
732+
argp->type = V4L2_FRMSIZE_TYPE_DISCRETE;
733+
734+
argp->discrete.width = dev->pix_format.width;
735+
argp->discrete.height = dev->pix_format.height;
736+
737+
return 0;
738+
}
739+
729740
if (NULL == format_by_fourcc(argp->pixel_format))
730741
return -EINVAL;
731742

@@ -872,11 +883,30 @@ static int vidioc_s_fmt_cap(struct file *file, void *fh,
872883
static int vidioc_enum_fmt_out(struct file *file, void *fh,
873884
struct v4l2_fmtdesc *f)
874885
{
886+
struct v4l2_loopback_device *dev = file_to_loopdev(file);
875887
const struct v4l2l_format *fmt;
876-
877888
if (f->index < 0 || f->index >= FORMATS)
878889
return -EINVAL;
879890

891+
if (is_format_locked(dev)) {
892+
int i;
893+
MARK();
894+
if (f->index)
895+
return -EINVAL;
896+
f->index = -1;
897+
MARK();
898+
for (i = 0; i < FORMATS; i++) {
899+
printk(KERN_ERR "JMZ: format#%d", i);
900+
if (formats[i].fourcc == dev->pix_format.pixelformat) {
901+
f->index = i;
902+
break;
903+
}
904+
}
905+
if (f->index < 0)
906+
return -EINVAL;
907+
MARK();
908+
}
909+
880910
fmt = &formats[f->index];
881911
f->pixelformat = fmt->fourcc;
882912
snprintf(f->description, sizeof(f->description), "%s", fmt->name);
@@ -918,7 +948,6 @@ static int vidioc_g_fmt_out(struct file *file, void *fh,
918948
static int vidioc_try_fmt_out(struct file *file, void *fh,
919949
struct v4l2_format *fmt)
920950
{
921-
#warning handle pre-negotiated formats
922951
struct v4l2_loopback_device *dev = file_to_loopdev(file);
923952
__u32 w = fmt->fmt.pix.width;
924953
__u32 h = fmt->fmt.pix.height;
@@ -932,6 +961,12 @@ static int vidioc_try_fmt_out(struct file *file, void *fh,
932961
V4L2LOOPBACK_SIZE_DEFAULT_HEIGHT;
933962
dprintk("trying image %dx%d\n", w, h);
934963

964+
if (is_format_locked(dev)) {
965+
w = dev->pix_format.width;
966+
h = dev->pix_format.height;
967+
pixfmt = dev->pix_format.pixelformat;
968+
}
969+
935970
format = format_by_fourcc(pixfmt);
936971
if (NULL == format)
937972
format = &formats[0];

0 commit comments

Comments
 (0)
0