summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/moz-patch-stack/0097.patch
blob: c113b33563a8022378ef303b58e40a7e73462f35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From: Andreas Pehrson <apehrson@mozilla.com>
Date: Wed, 10 May 2023 07:06:00 +0000
Subject: Bug 1810949 - cherry-pick upstream libwebrtc commit 32b64e895c.
 r=webrtc-reviewers,mjf

Upstream commit: https://webrtc.googlesource.com/src/+/32b64e895c0231fe6891a8f6335d66f1dad4f1f5
    Improve ergonomics of dealing with pixel formats in v4l2 camera backend

    Bug: webrtc:14830
    Change-Id: Ib49bf65895fe008e75223abb03867d412c1b5a60
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/291531
    Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
    Reviewed-by: Stefan Holmer <stefan@webrtc.org>
    Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#39976}

Differential Revision: https://phabricator.services.mozilla.com/D177231
Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/f0afe1a1097f3e02d59fd06d5e83d00a0f4d69ae
---
 .../video_capture/linux/device_info_v4l2.cc   |  4 ++-
 .../video_capture/linux/video_capture_v4l2.cc | 31 +++++++++----------
 2 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/modules/video_capture/linux/device_info_v4l2.cc b/modules/video_capture/linux/device_info_v4l2.cc
index 7651dd6651..f854c2ccc7 100644
--- a/modules/video_capture/linux/device_info_v4l2.cc
+++ b/modules/video_capture/linux/device_info_v4l2.cc
@@ -391,10 +391,10 @@ int32_t DeviceInfoV4l2::FillCapabilities(int fd) {
   video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   video_fmt.fmt.pix.sizeimage = 0;
 
-  int totalFmts = 5;
   unsigned int videoFormats[] = {V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_YUV420,
                                  V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_UYVY,
                                  V4L2_PIX_FMT_NV12};
+  constexpr int totalFmts = sizeof(videoFormats) / sizeof(unsigned int);
 
   int sizes = 13;
   unsigned int size[][2] = {{128, 96},   {160, 120},  {176, 144},  {320, 240},
@@ -424,6 +424,8 @@ int32_t DeviceInfoV4l2::FillCapabilities(int fd) {
             cap.videoType = VideoType::kUYVY;
           } else if (videoFormats[fmts] == V4L2_PIX_FMT_NV12) {
             cap.videoType = VideoType::kNV12;
+          } else {
+            RTC_DCHECK_NOTREACHED();
           }
 
           // get fps of current camera mode
diff --git a/modules/video_capture/linux/video_capture_v4l2.cc b/modules/video_capture/linux/video_capture_v4l2.cc
index c7dcb722bc..baf1916331 100644
--- a/modules/video_capture/linux/video_capture_v4l2.cc
+++ b/modules/video_capture/linux/video_capture_v4l2.cc
@@ -130,23 +130,18 @@ int32_t VideoCaptureModuleV4L2::StartCapture(
   // Supported video formats in preferred order.
   // If the requested resolution is larger than VGA, we prefer MJPEG. Go for
   // I420 otherwise.
-  const int nFormats = 6;
-  unsigned int fmts[nFormats];
-  if (capability.width > 640 || capability.height > 480) {
-    fmts[0] = V4L2_PIX_FMT_MJPEG;
-    fmts[1] = V4L2_PIX_FMT_YUV420;
-    fmts[2] = V4L2_PIX_FMT_YUYV;
-    fmts[3] = V4L2_PIX_FMT_UYVY;
-    fmts[4] = V4L2_PIX_FMT_NV12;
-    fmts[5] = V4L2_PIX_FMT_JPEG;
-  } else {
-    fmts[0] = V4L2_PIX_FMT_YUV420;
-    fmts[1] = V4L2_PIX_FMT_YUYV;
-    fmts[2] = V4L2_PIX_FMT_UYVY;
-    fmts[3] = V4L2_PIX_FMT_NV12;
-    fmts[4] = V4L2_PIX_FMT_MJPEG;
-    fmts[5] = V4L2_PIX_FMT_JPEG;
-  }
+  unsigned int hdFmts[] = {
+      V4L2_PIX_FMT_MJPEG,  V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YUYV,
+      V4L2_PIX_FMT_UYVY,   V4L2_PIX_FMT_NV12,   V4L2_PIX_FMT_JPEG,
+  };
+  unsigned int sdFmts[] = {
+      V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_YUYV,   V4L2_PIX_FMT_UYVY,
+      V4L2_PIX_FMT_NV12,   V4L2_PIX_FMT_MJPEG,  V4L2_PIX_FMT_JPEG,
+  };
+  const bool isHd = capability.width > 640 || capability.height > 480;
+  unsigned int* fmts = isHd ? hdFmts : sdFmts;
+  static_assert(sizeof(hdFmts) == sizeof(sdFmts));
+  constexpr int nFormats = sizeof(hdFmts) / sizeof(unsigned int);
 
   // Enumerate image formats.
   struct v4l2_fmtdesc fmt;
@@ -195,6 +190,8 @@ int32_t VideoCaptureModuleV4L2::StartCapture(
   else if (video_fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG ||
            video_fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
     _captureVideoType = VideoType::kMJPEG;
+  else
+    RTC_DCHECK_NOTREACHED();
 
   // set format and frame size now
   if (ioctl(_deviceFd, VIDIOC_S_FMT, &video_fmt) < 0) {
-- 
2.34.1