Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
umlaeute committed Oct 12, 2020
1 parent 0d2780b commit aa24455
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions v4l2loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,7 @@ static long v4l2loopback_control_ioctl(struct file *file, unsigned int cmd,
default:
ret = -ENOSYS;
break;
/* add a v4l2loopback device (pair), based on the user-provided specs */
case V4L2LOOPBACK_CTL_ADD:
if (parm) {
if ((ret = copy_from_user(&conf, (void *)parm,
Expand All @@ -2540,6 +2541,7 @@ static long v4l2loopback_control_ioctl(struct file *file, unsigned int cmd,
if (ret >= 0)
ret = devnr;
break;
/* remove a v4l2loopback device (both capture and output) */
case V4L2LOOPBACK_CTL_REMOVE:
ret = v4l2loopback_lookup((int)parm, &dev);
if (ret >= 0 && dev) {
Expand All @@ -2552,6 +2554,9 @@ static long v4l2loopback_control_ioctl(struct file *file, unsigned int cmd,
ret = 0;
};
break;
/* get information for a loopback device.
* this is mostly about limits (which cannot be queried directly with VIDIOC_G_FMT and friends
*/
case V4L2LOOPBACK_CTL_QUERY:
if (!parm)
break;
Expand All @@ -2560,18 +2565,26 @@ static long v4l2loopback_control_ioctl(struct file *file, unsigned int cmd,
break;
devnr = (conf.output_nr < 0) ? conf.capture_nr : conf.output_nr;
MARK();
/* get the device from either capture_nr or output_nr (whatever is valid) */
if ((ret = v4l2loopback_lookup(devnr, &dev)) < 0)
break;
MARK();
/* if we got the device from output_nr and there is a valid capture_nr,
* make sure that both refer to the same device (or bail out)
*/
if ((devnr != conf.capture_nr) && (conf.capture_nr >= 0) &&
(ret != v4l2loopback_lookup(conf.capture_nr, 0)))
break;
MARK();
/* if otoh, we got the device from capture_nr and there is a valid output_nr,
* make sure that both refer to the same device (or bail out)
*/
if ((devnr != conf.output_nr) && (conf.output_nr >= 0) &&
(ret != v4l2loopback_lookup(conf.output_nr, 0)))
break;
MARK();

/* v4l2_loopback_config identified a single device, so fetch the data */
snprintf(conf.card_label, sizeof(conf.card_label), "%s",
dev->card_label);
MARK();
Expand Down
4 changes: 2 additions & 2 deletions v4l2loopback.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct v4l2_loopback_config {
/**
* the device-number (/dev/video<nr>)
* V4L2LOOPBACK_CTL_ADD:
* setting this to "-1" will allocate an available one
* setting this to a value<0, will allocate an available one
* if nr>=0 and the device already exists, the ioctl will EEXIST
* if output_nr and capture_nr are the same, only a single device will be created
*
Expand Down Expand Up @@ -82,7 +82,7 @@ struct v4l2_loopback_config {

/* a pointer to a (struct v4l2_loopback_config) that has output_nr and/or capture_nr set
* (the two values must either refer to video-devices associated with the same loopback device
* or one of them must be -1
* or exactly one of them must be <0
*/
#define V4L2LOOPBACK_CTL_QUERY 0x4C82

Expand Down

0 comments on commit aa24455

Please sign in to comment.