Skip to content

Commit ed4760e

Browse files
committed
linux-virtualcam: Fix for v4l2loopback v0.14
1 parent 25c8399 commit ed4760e

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

plugins/linux-virtualcam/v4l2-output.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct v4l2_output_data {
1818
obs_output_t *output;
1919
int device;
2020
uint32_t frame_size;
21+
bool use_caps_workaround;
2122
};
2223

2324
static bool loopback_module_loaded()
@@ -43,8 +44,7 @@ static int loopback_module_load()
4344

4445
static int loopback_module_add_card()
4546
{
46-
return run_command(
47-
"pkexec ./v4l2loopback-ctl add -n '" OBS_V4L2_CARD_LABEL
47+
return run_command("pkexec ./v4l2loopback-ctl add -x 1 -n '" OBS_V4L2_CARD_LABEL
4848
"' && sleep 0.5");
4949
}
5050

@@ -73,6 +73,9 @@ static bool try_connect(void *data, const char *device, const char *name)
7373
goto fail_close_device;
7474
}
7575

76+
if (!(capability.device_caps & V4L2_CAP_VIDEO_OUTPUT))
77+
goto fail_close_device;
78+
7679
format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
7780

7881
if (ioctl(vcam->device, VIDIOC_G_FMT, &format) < 0)
@@ -111,11 +114,9 @@ static bool try_connect(void *data, const char *device, const char *name)
111114
memset(&parm, 0, sizeof(parm));
112115
parm.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
113116

114-
if (ioctl(vcam->device, VIDIOC_STREAMON, &parm) < 0) {
115-
blog(LOG_ERROR, "Failed to start streaming on '%s' (%s)",
116-
device, strerror(errno));
117-
goto fail_close_device;
118-
}
117+
// Use of STREAMON/OFF is a workaround for v4l2loopback 0.12.x-0.13.x
118+
// This fails in latest versions of v4l2loopback and can be skipped
119+
vcam->use_caps_workaround = (ioctl(vcam->device, VIDIOC_STREAMON, &format.type) == 0);
119120

120121
blog(LOG_INFO, "v4l2-output: Using device '%s' at '%s'",
121122
capability.card, device);
@@ -218,6 +219,13 @@ void video_stop(void *data)
218219

219220
struct v4l2_output_data *vcam = (struct v4l2_output_data *)data;
220221

222+
struct v4l2_format format;
223+
format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
224+
225+
if (vcam->use_caps_workaround && ioctl(vcam->device, VIDIOC_STREAMOFF, &format.type) < 0) {
226+
blog(LOG_WARNING, "Failed to stop streaming on video device %d (%s)", vcam->device, strerror(errno));
227+
}
228+
221229
close(vcam->device);
222230
bfree(data);
223231
}

0 commit comments

Comments
 (0)