File linux-v4l2-device-path.patch of Package obs-studio
Common subdirectories: obs-studio-26.1.2/plugins/linux-v4l2/data and obs-studio-26.1.2-fixed/plugins/linux-v4l2/data
diff -u obs-studio-26.1.2/plugins/linux-v4l2/v4l2-input.c obs-studio-26.1.2-fixed/plugins/linux-v4l2/v4l2-input.c
--- obs-studio-26.1.2/plugins/linux-v4l2/v4l2-input.c 2021-01-09 00:43:39.000000000 +0100
+++ obs-studio-26.1.2-fixed/plugins/linux-v4l2/v4l2-input.c 2021-04-10 16:48:05.995426766 +0200
@@ -53,11 +53,11 @@
#define timeval2ns(tv) \
(((uint64_t)tv.tv_sec * 1000000000) + ((uint64_t)tv.tv_usec * 1000))
-#define V4L2_FOURCC_STR(code) \
- (char[5]) \
- { \
- code & 0xFF, (code >> 8) & 0xFF, (code >> 16) & 0xFF, \
- (code >> 24) & 0xFF, 0 \
+#define V4L2_FOURCC_STR(code) \
+ (char[5]) \
+ { \
+ (code >> 24) & 0xFF, (code >> 16) & 0xFF, (code >> 8) & 0xFF, \
+ code & 0xFF, 0 \
}
#define blog(level, msg, ...) blog(level, "v4l2-input: " msg, ##__VA_ARGS__)
@@ -123,7 +123,7 @@
switch (data->pixfmt) {
case V4L2_PIX_FMT_NV12:
frame->linesize[0] = data->linesize;
- frame->linesize[1] = data->linesize;
+ frame->linesize[1] = data->linesize / 2;
plane_offsets[1] = data->linesize * data->height;
break;
case V4L2_PIX_FMT_YVU420:
@@ -276,10 +276,12 @@
const char *cur_device_name;
#ifdef __FreeBSD__
- dirp = opendir("/dev");
+ const char *basedir = "/dev/";
#else
- dirp = opendir("/sys/class/video4linux");
+ const char *basedir = "/dev/v4l/by-path/";
#endif
+
+ dirp = opendir(basedir);
if (!dirp)
return;
@@ -288,7 +290,7 @@
obs_property_list_clear(prop);
- dstr_init_copy(&device, "/dev/");
+ dstr_init(&device);
while ((dp = readdir(dirp)) != NULL) {
int fd;
@@ -303,8 +305,16 @@
if (dp->d_type == DT_DIR)
continue;
- dstr_resize(&device, 5);
- dstr_cat(&device, dp->d_name);
+ char *dev_path = dp->d_name;
+
+ char buf[1024];
+ ssize_t len;
+ if ((len = readlink(dp->d_name, buf, sizeof(buf) - 1)) != -1) {
+ buf[len] = '\0';
+ dev_path = &buf[0];
+ }
+ dstr_copy(&device, basedir);
+ dstr_cat(&device, dev_path);
if ((fd = v4l2_open(device.array, O_RDWR | O_NONBLOCK)) == -1) {
blog(LOG_INFO, "Unable to open %s", device.array);