Bug 1880804 [wpt PR 44645] - Implement constructor in RTCEncodedVideoFrame, a=testonly
[gecko.git] / third_party / libwebrtc / moz-patch-stack / 0027.patch
blobf7b3a22adf991bc20b7b4bacedea599c6c3740df
1 From: Dan Minor <dminor@mozilla.com>
2 Date: Wed, 8 Jul 2020 17:35:00 +0000
3 Subject: Bug 1650572 - Check V4L2_CAP_DEVICE_CAPS before accessing
4 device_caps; r=ng
6 The capabilities field is for the physical device, device_caps is for the
7 specific /dev/videoX device that has been opened. The device_caps field is
8 only populated if V4L2_CAP_DEVICE_CAPS is set, so we should check that, and
9 fall back to capabilities if it is not set.
11 Differential Revision: https://phabricator.services.mozilla.com/D82377
12 Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/b5acbf536c46a66c939a61bde34ad93b1977a604
13 ---
14 modules/video_capture/linux/device_info_v4l2.cc | 17 ++++++++++++-----
15 modules/video_capture/linux/device_info_v4l2.h | 3 +++
16 2 files changed, 15 insertions(+), 5 deletions(-)
18 diff --git a/modules/video_capture/linux/device_info_v4l2.cc b/modules/video_capture/linux/device_info_v4l2.cc
19 index a2435bcd4f..cd0ba6e3df 100644
20 --- a/modules/video_capture/linux/device_info_v4l2.cc
21 +++ b/modules/video_capture/linux/device_info_v4l2.cc
22 @@ -220,8 +220,7 @@ uint32_t DeviceInfoV4l2::NumberOfDevices() {
23 snprintf(device, sizeof(device), "/dev/video%d", n);
24 if ((fd = open(device, O_RDONLY)) != -1) {
25 // query device capabilities and make sure this is a video capture device
26 - if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 ||
27 - !(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) {
28 + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 || !IsVideoCaptureDevice(&cap)) {
29 close(fd);
30 continue;
32 @@ -252,8 +251,7 @@ int32_t DeviceInfoV4l2::GetDeviceName(uint32_t deviceNumber,
33 snprintf(device, sizeof(device), "/dev/video%d", n);
34 if ((fd = open(device, O_RDONLY)) != -1) {
35 // query device capabilities and make sure this is a video capture device
36 - if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 ||
37 - !(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) {
38 + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 || !IsVideoCaptureDevice(&cap)) {
39 close(fd);
40 continue;
42 @@ -331,7 +329,7 @@ int32_t DeviceInfoV4l2::CreateCapabilityMap(const char* deviceUniqueIdUTF8) {
43 struct v4l2_capability cap;
44 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) {
45 // skip devices without video capture capability
46 - if (!(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) {
47 + if (!IsVideoCaptureDevice(&cap)) {
48 continue;
51 @@ -393,6 +391,15 @@ bool DeviceInfoV4l2::IsDeviceNameMatches(const char* name,
52 return false;
55 +bool DeviceInfoV4l2::IsVideoCaptureDevice(struct v4l2_capability* cap)
57 + if (cap->capabilities & V4L2_CAP_DEVICE_CAPS) {
58 + return cap->device_caps & V4L2_CAP_VIDEO_CAPTURE;
59 + } else {
60 + return cap->capabilities & V4L2_CAP_VIDEO_CAPTURE;
61 + }
64 int32_t DeviceInfoV4l2::FillCapabilities(int fd) {
65 // set image format
66 struct v4l2_format video_fmt;
67 diff --git a/modules/video_capture/linux/device_info_v4l2.h b/modules/video_capture/linux/device_info_v4l2.h
68 index 95432a509d..e3c2395f49 100644
69 --- a/modules/video_capture/linux/device_info_v4l2.h
70 +++ b/modules/video_capture/linux/device_info_v4l2.h
71 @@ -18,6 +18,8 @@
72 #include "rtc_base/platform_thread.h"
73 #include <sys/inotify.h>
75 +struct v4l2_capability;
77 namespace webrtc {
78 namespace videocapturemodule {
79 class DeviceInfoV4l2 : public DeviceInfoImpl {
80 @@ -49,6 +51,7 @@ class DeviceInfoV4l2 : public DeviceInfoImpl {
82 private:
83 bool IsDeviceNameMatches(const char* name, const char* deviceUniqueIdUTF8);
84 + bool IsVideoCaptureDevice(struct v4l2_capability* cap);
86 #ifdef WEBRTC_LINUX
87 void HandleEvent(inotify_event* event, int fd);