Skip to content

Commit

Permalink
V4L2LOOBACK_IS_FIXED_FMT() to check if the format is changeable
Browse files Browse the repository at this point in the history
  • Loading branch information
IOhannes m zmölnig authored and IOhannes m zmölnig committed Apr 27, 2023
1 parent 1a5098e commit d12e7d7
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions v4l2loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ struct v4l2l_format {
(type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
#endif /* V4L2_TYPE_IS_OUTPUT */

/* whether the format can be changed */
/* the format is fixated if we
- have writers (ready_for_capture>0)
- and/or have readers (active_readers>0)
*/
#define V4L2LOOPBACK_IS_FIXED_FMT(device) \
(device->ready_for_capture > 0 || device->active_readers > 0)

static const unsigned int FORMATS = ARRAY_SIZE(formats);

static char *fourcc2str(unsigned int fourcc, char buf[4])
Expand Down Expand Up @@ -570,12 +578,7 @@ static int inner_try_setfmt(struct file *file, struct v4l2_format *fmt)
dev = v4l2loopback_getdevice(file);

needschange = !(pix_format_eq(&dev->pix_format, &fmt->fmt.pix, 0));
if (dev->ready_for_capture > 0 || dev->active_readers > 0) {
/* the format is fixated if we
- have readers (active_readers>0)
- and/or have writers (ready_for_capture>0)
*/

if (V4L2LOOPBACK_IS_FIXED_FMT(dev)) {
fmt->fmt.pix = dev->pix_format;
if (needschange) {
if (dev->active_readers > 0 && capture) {
Expand Down Expand Up @@ -907,7 +910,7 @@ static int vidioc_enum_framesizes(struct file *file, void *fh,
return -EINVAL;

dev = v4l2loopback_getdevice(file);
if (dev->ready_for_capture) {
if (V4L2LOOPBACK_IS_FIXED_FMT(dev)) {
/* format has already been negotiated
* cannot change during runtime
*/
Expand Down Expand Up @@ -950,7 +953,7 @@ static int vidioc_enum_frameintervals(struct file *file, void *fh,
if (argp->index)
return -EINVAL;

if (dev->ready_for_capture) {
if (V4L2LOOPBACK_IS_FIXED_FMT(dev)) {
if (argp->width != dev->pix_format.width ||
argp->height != dev->pix_format.height ||
argp->pixel_format != dev->pix_format.pixelformat)
Expand Down Expand Up @@ -993,7 +996,9 @@ static int vidioc_enum_fmt_cap(struct file *file, void *fh,

if (f->index)
return -EINVAL;
if (dev->ready_for_capture) {

if (V4L2LOOPBACK_IS_FIXED_FMT(dev)) {
/* format has been fixed, so only one single format is supported */
const __u32 format = dev->pix_format.pixelformat;

snprintf(f->description, sizeof(f->description), "[%c%c%c%c]",
Expand Down Expand Up @@ -1078,10 +1083,10 @@ static int vidioc_enum_fmt_out(struct file *file, void *fh,

dev = v4l2loopback_getdevice(file);

if (dev->ready_for_capture) {
if (V4L2LOOPBACK_IS_FIXED_FMT(dev)) {
/* format has been fixed, so only one single format is supported */
const __u32 format = dev->pix_format.pixelformat;

/* format has been fixed by the writer, so only one single format is supported */
if (f->index)
return -EINVAL;

Expand Down

0 comments on commit d12e7d7

Please sign in to comment.