Thursday, January 02, 2025

Re: support multiply webcam in chromium-based browsers

31.12.2024 23:11, Kirill A. Korinsky пишет:
> Robert,
>
> I'd like to adjust one patch on all chrome-based browsers in ports tree.
>
> A few days ago I had commited a fix [1] in uvideo.c which allows user to
> select in Firefox between connected webcams.
>
> Thus, the same can be done in Chrome-based browsers, but it needs small
> adjustment in the patch.
>
> I had used the same limit of number of possible devices with libwebrtc [2],
> and updated unveil files to allow /dev/video0 and /dev/video1 which is
> created by default.ta

Makes sense to unveil all default devices, but trying to open 64 of them like
libWebRTC? I guess we'd be fine with probing just the first two, matching unveil.

No objection, I can see how matching similar code might make sense, but that
limit sounds absurdly high.

>
> I had tested the patch only in ungoogled-chromium which I use at
> https://webrtc.github.io/samples/src/content/devices/input-output/
> but other browsers used the same patch and I assume that it works.
>
> Ok?
>
> Footnotes:
> [1] https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/usb/uvideo.c?rev=1.232&content-type=text/x-cvsweb-markup
>
> [2] https://github.com/mozilla/libwebrtc/blob/1389c76d9c79839a2ca069df1db48aa3f2e6a1ac/modules/video_capture/linux/device_info_v4l2.cc#L40-L63
>
> The diff:
>
> Index: www/chromium/Makefile
> ===================================================================
> RCS file: /home/cvs/ports/www/chromium/Makefile,v
> diff -u -p -u -p -r1.820 Makefile
> --- www/chromium/Makefile 21 Dec 2024 11:39:11 -0000 1.820
> +++ www/chromium/Makefile 31 Dec 2024 19:54:02 -0000
> @@ -11,6 +11,7 @@ DPB_PROPERTIES+= lonesome
> COMMENT= Chromium browser
>
> V= 131.0.6778.204
> +REVISION= 0
>
> DISTNAME= chromium-${V}
>
> Index: www/chromium/files/unveil.main
> ===================================================================
> RCS file: /home/cvs/ports/www/chromium/files/unveil.main,v
> diff -u -p -u -p -r1.16 unveil.main
> --- www/chromium/files/unveil.main 15 Nov 2024 14:03:20 -0000 1.16
> +++ www/chromium/files/unveil.main 31 Dec 2024 19:53:06 -0000
> @@ -1,5 +1,6 @@
> # needed for video(4)
> -/dev/video rw
> +/dev/video0 rw
> +/dev/video1 rw

Two here...

>
> # needed for FIDO authentication
> /dev/fido rw
> Index: www/chromium/files/unveil.utility_video
> ===================================================================
> RCS file: /home/cvs/ports/www/chromium/files/unveil.utility_video,v
> diff -u -p -u -p -r1.2 unveil.utility_video
> --- www/chromium/files/unveil.utility_video 11 Mar 2022 20:09:41 -0000 1.2
> +++ www/chromium/files/unveil.utility_video 31 Dec 2024 19:53:17 -0000
> @@ -5,4 +5,5 @@
> /tmp rwc
>
> # needed for video(4)
> -/dev/video rw
> +/dev/video0 rw
> +/dev/video1 rw
> Index: www/chromium/patches/patch-media_capture_video_linux_video_capture_device_factory_v4l2_cc
> ===================================================================
> RCS file: /home/cvs/ports/www/chromium/patches/patch-media_capture_video_linux_video_capture_device_factory_v4l2_cc,v
> diff -u -p -u -p -r1.3 patch-media_capture_video_linux_video_capture_device_factory_v4l2_cc
> --- www/chromium/patches/patch-media_capture_video_linux_video_capture_device_factory_v4l2_cc 21 Apr 2024 10:14:33 -0000 1.3
> +++ www/chromium/patches/patch-media_capture_video_linux_video_capture_device_factory_v4l2_cc 31 Dec 2024 20:02:41 -0000
> @@ -9,7 +9,7 @@ Index: media/capture/video/linux/video_c
> // USB VID and PID are both 4 bytes long.
> const size_t kVidPidSize = 4;
> const size_t kMaxInterfaceNameSize = 256;
> -@@ -70,11 +71,15 @@ std::string ExtractFileNameFromDeviceId(const std::str
> +@@ -70,11 +71,24 @@ std::string ExtractFileNameFromDeviceId(const std::str
> DCHECK(base::StartsWith(device_id, kDevDir, base::CompareCase::SENSITIVE));
> return device_id.substr(strlen(kDevDir), device_id.length());
> }
> @@ -20,12 +20,21 @@ Index: media/capture/video/linux/video_c
> public:
> void GetDeviceIds(std::vector<std::string>* target_container) override {
> +#if BUILDFLAG(IS_OPENBSD)
> -+ target_container->emplace_back("/dev/video");
> ++ char device[13];
> ++ int fd;
> ++ /* unveil(2) limits access to /dev/, try /dev/video[0-63] */
> ++ for (int n = 0; n < 64; n++) {

... so why not just two here as well?

> ++ snprintf(device, sizeof(device), "/dev/video%d", n);
> ++ if ((fd = open(device, O_RDONLY)) != -1) {
> ++ close(fd);
> ++ target_container->emplace_back(device);
> ++ }
> ++ }
> +#else
> const base::FilePath path("/dev/");
> base::FileEnumerator enumerator(path, false, base::FileEnumerator::FILES,
> "video*");
> -@@ -82,9 +87,13 @@ class DevVideoFilePathsDeviceProvider
> +@@ -82,9 +96,13 @@ class DevVideoFilePathsDeviceProvider
> const base::FileEnumerator::FileInfo info = enumerator.GetInfo();
> target_container->emplace_back(path.value() + info.GetName().value());
> }
> @@ -39,7 +48,7 @@ Index: media/capture/video/linux/video_c
> const std::string file_name = ExtractFileNameFromDeviceId(device_id);
> std::string usb_id;
> const std::string vid_path =
> -@@ -101,9 +110,13 @@ class DevVideoFilePathsDeviceProvider
> +@@ -101,9 +119,13 @@ class DevVideoFilePathsDeviceProvider
> }
>
> return usb_id;
> @@ -53,7 +62,7 @@ Index: media/capture/video/linux/video_c
> const std::string file_name = ExtractFileNameFromDeviceId(device_id);
> const std::string interface_path =
> base::StringPrintf(kInterfacePathTemplate, file_name.c_str());
> -@@ -114,6 +127,7 @@ class DevVideoFilePathsDeviceProvider
> +@@ -114,6 +136,7 @@ class DevVideoFilePathsDeviceProvider
> return std::string();
> }
> return display_name;
> @@ -61,7 +70,7 @@ Index: media/capture/video/linux/video_c
> }
> };
>
> -@@ -219,7 +233,7 @@ void VideoCaptureDeviceFactoryV4L2::GetDevicesInfo(
> +@@ -219,7 +242,7 @@ void VideoCaptureDeviceFactoryV4L2::GetDevicesInfo(
> std::move(callback).Run(std::move(devices_info));
> }

No comments:

Post a Comment