obsproject / obs-studio

OBS Studio - Free and open source software for live streaming and screen recording
https://obsproject.com
GNU General Public License v2.0
60.36k stars 7.99k forks source link

error attempting to open more then 16 video devices #5422

Open jclab-joseph opened 3 years ago

jclab-joseph commented 3 years ago

Operating System Info

Ubuntu 20.10

Other OS

No response

OBS Studio Version

Git

OBS Studio Version (Other)

39aedc6c2ffdca9a89940117ee6dfcbfd0d955c4 (Sun Jun 6 11:01:40 2021 +0200)

OBS Studio Log URL

https://gist.github.com/jclab-joseph/442d197f0adbb27cac0a523a304e2f34

The red text is the logging I added. The device number continues to increment. (the leak seems to be happening)

OBS Studio Crash Log URL

No response

Expected Behavior

Regardless of the number of video devices, and even if an error occurs, it should be ignored and work fine.

Current Behavior

If there is a video device that is un-normal camera device (can't get parameters normally?), If click the device list on the v4l2 settings page, or click an un-normal device, After that, v4l2 no longer works.

There are currently 9 v4l2 devices, some may not get the parameters properly. (Not sure.)

Steps to Reproduce

  1. Create a V4L2 input.
  2. Enter V4L2 settings.
  3. (It is still normal.)
  4. Select an un-normal device.
  5. After that, v4l2 no longer works.

Anything else we should know?

A device expressed as an un-normal device is a v4l2-m2m codec device.

jclab-joseph commented 3 years ago

https://github.com/obsproject/obs-studio/blob/8f1d2458bf57b178107524a9e00f44314ffebc42/plugins/linux-v4l2/v4l2-input.c#L696

-   if (v4l2_get_input_caps(dev, input, &caps) < 0)
+   if (v4l2_get_input_caps(dev, input, &caps) < 0) {
+       v4l2_close(dev);
        return false;
+   }

I found a leak in this part. But if I fix this part, I get an infinite loop now.

Log: https://gist.github.com/jclab-joseph/1db7cfe71b4c48b6d8391fd0fd6f9215

image

kkartaltepe commented 3 years ago

The red text is the logging I added. The device number continues to increment. (the leak seems to be happening)

Im not convinced this is a sign of a leak. Instead a new device id is likely chosen every time you open a new device.

The proposed change seems good if you want to submit a PR for it.

If you find yourself in a infinite loop consider rebuilding at head now that https://github.com/obsproject/obs-studio/commit/08d4456339339b90892f268afa3dab3073bdd292 is applied and see if that fixes the loop issue for your device.

jclab-joseph commented 3 years ago

Applying the latest commits has the same problem. When entering the settings page, input_selected is called infinitely.

Log : https://gist.github.com/jclab-joseph/b4ac47a6f8d3b166282d442e72f32aa3 Branch : https://github.com/jclab-joseph/obs-studio/tree/fix/v4l2-leak

kkartaltepe commented 3 years ago

Hmmm I think i can replicate this by just returning false in input_selected with a c920.

jclab-joseph commented 3 years ago

https://gist.github.com/jclab-joseph/cac9faa679164a8a365c432ac730262a

obs_property_modified : pixelformat / 6 / Video Format
obs_property_modified : resolution / 6 / Resolution
obs_property_modified : framerate / 6 / Frame Rate
obs_property_modified : input / 6 / Input

Four obs_property_modified above causes infinity. Can you tell me who triggers obs_property_modified? I'm debugging to fix this issue.

gruzilla commented 2 years ago

I just experienced the same problem on a raspberry pi 4.

as a workaround i rmmod bcm2835_isp and rmmod bcm2835_v4l2 to reduce the amount of v4l2 devices and it worked around.

ethagnawl commented 9 months ago

@gruzilla's workaround worked for me on a Pi 4 B, too.

vicary commented 9 months ago

The workaround doesn't work for Raspberry Pi 5, I guess the latest OS is not using these mods?