umlaeute / v4l2loopback

v4l2-loopback device
GNU General Public License v2.0
3.69k stars 523 forks source link

Failed to stream on for some special test #553

Closed sanbrother closed 6 months ago

sanbrother commented 1 year ago

Step 2: Describe your environment

Step 3: Describe the problem:

Steps to reproduce:

  1. Reload the module sudo modprobe -r v4l2loopback && sudo modprobe v4l2loopback video_nr=10,11 max_buffers=8
  2. Poll some event
    # V4L2_EVENT_PRI_CLIENT_USAGE => 283115521
    v4l2-ctl --poll-for-event=283115521 -d /dev/video10
  3. Run test app
    ./producer -d /dev/video10

Observed Results:

VIDIOC_STREAMON error 22, Invalid argument

Relevant Code:

    if (dev->image) {
        dprintk("allocating buffers again: %ld %ld\n",
            dev->buffer_size * dev->buffers_number, dev->imagesize);
        /* FIXME: prevent double allocation more intelligently! */
        if (dev->buffer_size * dev->buffers_number == dev->imagesize)
            return 0;

        /* if there is only one writer, no problem should occur */
        if (dev->open_count.counter == 1)
            free_buffers(dev);
        else
            return -EINVAL;
    }

I guess, v4l2-ctl makes counter == 1, and then the producer increases it to 2. So, EINVAL is returned.