niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | a9b74ad | 2013-07-12 10:03:52 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/video_capture/linux/device_info_linux.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | #include <errno.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
pbos@webrtc.org | a9b74ad | 2013-07-12 10:03:52 +0000 | [diff] [blame] | 17 | #include <sys/ioctl.h> |
| 18 | #include <sys/stat.h> |
| 19 | #include <unistd.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | //v4l includes |
| 21 | #include <linux/videodev2.h> |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 22 | |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 23 | #include "webrtc/rtc_base/logging.h" |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 24 | |
| 25 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | namespace webrtc |
| 27 | { |
perkj@webrtc.org | 0cc68dc | 2011-09-12 08:53:36 +0000 | [diff] [blame] | 28 | namespace videocapturemodule |
| 29 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 30 | VideoCaptureModule::DeviceInfo* |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 31 | VideoCaptureImpl::CreateDeviceInfo() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | { |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 33 | return new videocapturemodule::DeviceInfoLinux(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
nisse | b29b9c8 | 2016-12-12 00:22:56 -0800 | [diff] [blame] | 36 | DeviceInfoLinux::DeviceInfoLinux() |
| 37 | : DeviceInfoImpl() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | { |
| 39 | } |
| 40 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 41 | int32_t DeviceInfoLinux::Init() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | DeviceInfoLinux::~DeviceInfoLinux() |
| 47 | { |
| 48 | } |
| 49 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 50 | uint32_t DeviceInfoLinux::NumberOfDevices() |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 52 | LOG(LS_INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 54 | uint32_t count = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | char device[20]; |
| 56 | int fd = -1; |
| 57 | |
| 58 | /* detect /dev/video [0-63]VideoCaptureModule entries */ |
| 59 | for (int n = 0; n < 64; n++) |
| 60 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 61 | sprintf(device, "/dev/video%d", n); |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 62 | if ((fd = open(device, O_RDONLY)) != -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | { |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 64 | close(fd); |
| 65 | count++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | return count; |
| 70 | } |
| 71 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 72 | int32_t DeviceInfoLinux::GetDeviceName( |
| 73 | uint32_t deviceNumber, |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 74 | char* deviceNameUTF8, |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 75 | uint32_t deviceNameLength, |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 76 | char* deviceUniqueIdUTF8, |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 77 | uint32_t deviceUniqueIdUTF8Length, |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 78 | char* /*productUniqueIdUTF8*/, |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 79 | uint32_t /*productUniqueIdUTF8Length*/) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 81 | LOG(LS_INFO) << __FUNCTION__; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
wu@webrtc.org | 221b522 | 2011-09-21 16:57:15 +0000 | [diff] [blame] | 83 | // Travel through /dev/video [0-63] |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 84 | uint32_t count = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | char device[20]; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | int fd = -1; |
wu@webrtc.org | 221b522 | 2011-09-21 16:57:15 +0000 | [diff] [blame] | 87 | bool found = false; |
| 88 | for (int n = 0; n < 64; n++) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | { |
wu@webrtc.org | 221b522 | 2011-09-21 16:57:15 +0000 | [diff] [blame] | 90 | sprintf(device, "/dev/video%d", n); |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 91 | if ((fd = open(device, O_RDONLY)) != -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | { |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 93 | if (count == deviceNumber) { |
| 94 | // Found the device |
| 95 | found = true; |
| 96 | break; |
| 97 | } else { |
| 98 | close(fd); |
| 99 | count++; |
wu@webrtc.org | 221b522 | 2011-09-21 16:57:15 +0000 | [diff] [blame] | 100 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
wu@webrtc.org | 221b522 | 2011-09-21 16:57:15 +0000 | [diff] [blame] | 104 | if (!found) |
| 105 | return -1; |
| 106 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | // query device capabilities |
| 108 | struct v4l2_capability cap; |
| 109 | if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) |
| 110 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 111 | LOG(LS_INFO) << "error in querying the device capability for device " |
| 112 | << device << ". errno = " << errno; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 113 | close(fd); |
| 114 | return -1; |
| 115 | } |
| 116 | |
| 117 | close(fd); |
| 118 | |
| 119 | char cameraName[64]; |
| 120 | memset(deviceNameUTF8, 0, deviceNameLength); |
| 121 | memcpy(cameraName, cap.card, sizeof(cap.card)); |
| 122 | |
| 123 | if (deviceNameLength >= strlen(cameraName)) |
| 124 | { |
| 125 | memcpy(deviceNameUTF8, cameraName, strlen(cameraName)); |
| 126 | } |
| 127 | else |
| 128 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 129 | LOG(LS_INFO) << "buffer passed is too small"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 130 | return -1; |
| 131 | } |
| 132 | |
| 133 | if (cap.bus_info[0] != 0) // may not available in all drivers |
| 134 | { |
phoglund@webrtc.org | 8ff3ff1 | 2012-10-01 10:04:26 +0000 | [diff] [blame] | 135 | // copy device id |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 136 | if (deviceUniqueIdUTF8Length >= strlen((const char*) cap.bus_info)) |
| 137 | { |
| 138 | memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length); |
| 139 | memcpy(deviceUniqueIdUTF8, cap.bus_info, |
| 140 | strlen((const char*) cap.bus_info)); |
| 141 | } |
| 142 | else |
| 143 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 144 | LOG(LS_INFO) << "buffer passed is too small"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | return -1; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 152 | int32_t DeviceInfoLinux::CreateCapabilityMap( |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 153 | const char* deviceUniqueIdUTF8) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 154 | { |
| 155 | int fd; |
| 156 | char device[32]; |
| 157 | bool found = false; |
| 158 | |
pbos@webrtc.org | dfc5bb9 | 2013-04-10 08:23:13 +0000 | [diff] [blame] | 159 | const int32_t deviceUniqueIdUTF8Length = |
| 160 | (int32_t) strlen((char*) deviceUniqueIdUTF8); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 161 | if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) |
| 162 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 163 | LOG(LS_INFO) << "Device name too long"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 164 | return -1; |
| 165 | } |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 166 | LOG(LS_INFO) << "CreateCapabilityMap called for device " |
| 167 | << deviceUniqueIdUTF8; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | |
| 169 | /* detect /dev/video [0-63] entries */ |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 170 | for (int n = 0; n < 64; ++n) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 172 | sprintf(device, "/dev/video%d", n); |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 173 | fd = open(device, O_RDONLY); |
| 174 | if (fd == -1) |
| 175 | continue; |
| 176 | |
| 177 | // query device capabilities |
| 178 | struct v4l2_capability cap; |
| 179 | if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 180 | { |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 181 | if (cap.bus_info[0] != 0) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 182 | { |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 183 | if (strncmp((const char*) cap.bus_info, |
| 184 | (const char*) deviceUniqueIdUTF8, |
| 185 | strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 186 | { |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 187 | found = true; |
| 188 | break; // fd matches with device unique id supplied |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 189 | } |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 190 | } |
| 191 | else //match for device name |
| 192 | { |
| 193 | if (IsDeviceNameMatches((const char*) cap.card, |
| 194 | (const char*) deviceUniqueIdUTF8)) |
| 195 | { |
| 196 | found = true; |
| 197 | break; |
| 198 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
mallinath@webrtc.org | 12984f0 | 2012-02-16 18:18:21 +0000 | [diff] [blame] | 201 | close(fd); // close since this is not the matching device |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | if (!found) |
| 205 | { |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 206 | LOG(LS_INFO) << "no matching device found"; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | return -1; |
| 208 | } |
| 209 | |
| 210 | // now fd will point to the matching device |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 211 | // reset old capability list. |
pbos@webrtc.org | 4ca7d3f | 2013-08-12 19:51:57 +0000 | [diff] [blame] | 212 | _captureCapabilities.clear(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 213 | |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 214 | int size = FillCapabilities(fd); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 215 | close(fd); |
| 216 | |
| 217 | // Store the new used device name |
| 218 | _lastUsedDeviceNameLength = deviceUniqueIdUTF8Length; |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 219 | _lastUsedDeviceName = (char*) realloc(_lastUsedDeviceName, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | _lastUsedDeviceNameLength + 1); |
| 221 | memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength + 1); |
| 222 | |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 223 | LOG(LS_INFO) << "CreateCapabilityMap " << _captureCapabilities.size(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 224 | |
| 225 | return size; |
| 226 | } |
| 227 | |
| 228 | bool DeviceInfoLinux::IsDeviceNameMatches(const char* name, |
leozwang@webrtc.org | 1745e93 | 2012-03-01 16:30:40 +0000 | [diff] [blame] | 229 | const char* deviceUniqueIdUTF8) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 230 | { |
| 231 | if (strncmp(deviceUniqueIdUTF8, name, strlen(name)) == 0) |
| 232 | return true; |
| 233 | return false; |
| 234 | } |
| 235 | |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 236 | int32_t DeviceInfoLinux::FillCapabilities(int fd) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 237 | { |
| 238 | |
| 239 | // set image format |
| 240 | struct v4l2_format video_fmt; |
| 241 | memset(&video_fmt, 0, sizeof(struct v4l2_format)); |
| 242 | |
| 243 | video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 244 | video_fmt.fmt.pix.sizeimage = 0; |
| 245 | |
will.newton | c675ddd | 2015-09-24 01:11:25 -0700 | [diff] [blame] | 246 | int totalFmts = 4; |
mflodman@webrtc.org | 4f9e44f | 2012-02-23 09:00:26 +0000 | [diff] [blame] | 247 | unsigned int videoFormats[] = { |
| 248 | V4L2_PIX_FMT_MJPEG, |
| 249 | V4L2_PIX_FMT_YUV420, |
will.newton | c675ddd | 2015-09-24 01:11:25 -0700 | [diff] [blame] | 250 | V4L2_PIX_FMT_YUYV, |
| 251 | V4L2_PIX_FMT_UYVY }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 252 | |
| 253 | int sizes = 13; |
| 254 | unsigned int size[][2] = { { 128, 96 }, { 160, 120 }, { 176, 144 }, |
| 255 | { 320, 240 }, { 352, 288 }, { 640, 480 }, |
| 256 | { 704, 576 }, { 800, 600 }, { 960, 720 }, |
| 257 | { 1280, 720 }, { 1024, 768 }, { 1440, 1080 }, |
| 258 | { 1920, 1080 } }; |
| 259 | |
| 260 | int index = 0; |
| 261 | for (int fmts = 0; fmts < totalFmts; fmts++) |
| 262 | { |
| 263 | for (int i = 0; i < sizes; i++) |
| 264 | { |
| 265 | video_fmt.fmt.pix.pixelformat = videoFormats[fmts]; |
| 266 | video_fmt.fmt.pix.width = size[i][0]; |
| 267 | video_fmt.fmt.pix.height = size[i][1]; |
| 268 | |
| 269 | if (ioctl(fd, VIDIOC_TRY_FMT, &video_fmt) >= 0) |
| 270 | { |
| 271 | if ((video_fmt.fmt.pix.width == size[i][0]) |
| 272 | && (video_fmt.fmt.pix.height == size[i][1])) |
| 273 | { |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 274 | VideoCaptureCapability cap; |
| 275 | cap.width = video_fmt.fmt.pix.width; |
| 276 | cap.height = video_fmt.fmt.pix.height; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 277 | if (videoFormats[fmts] == V4L2_PIX_FMT_YUYV) |
| 278 | { |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 279 | cap.videoType = VideoType::kYUY2; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 280 | } |
fischman@webrtc.org | d6134c7 | 2013-07-29 20:43:15 +0000 | [diff] [blame] | 281 | else if (videoFormats[fmts] == V4L2_PIX_FMT_YUV420) |
| 282 | { |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 283 | cap.videoType = VideoType::kI420; |
fischman@webrtc.org | d6134c7 | 2013-07-29 20:43:15 +0000 | [diff] [blame] | 284 | } |
mflodman@webrtc.org | 4f9e44f | 2012-02-23 09:00:26 +0000 | [diff] [blame] | 285 | else if (videoFormats[fmts] == V4L2_PIX_FMT_MJPEG) |
| 286 | { |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 287 | cap.videoType = VideoType::kMJPEG; |
mflodman@webrtc.org | 4f9e44f | 2012-02-23 09:00:26 +0000 | [diff] [blame] | 288 | } |
will.newton | c675ddd | 2015-09-24 01:11:25 -0700 | [diff] [blame] | 289 | else if (videoFormats[fmts] == V4L2_PIX_FMT_UYVY) |
| 290 | { |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 291 | cap.videoType = VideoType::kUYVY; |
will.newton | c675ddd | 2015-09-24 01:11:25 -0700 | [diff] [blame] | 292 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 293 | |
| 294 | // get fps of current camera mode |
| 295 | // V4l2 does not have a stable method of knowing so we just guess. |
nisse | eb44b39 | 2017-04-28 07:18:05 -0700 | [diff] [blame] | 296 | if (cap.width >= 800 && |
| 297 | cap.videoType != VideoType::kMJPEG) { |
| 298 | cap.maxFPS = 15; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | { |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 302 | cap.maxFPS = 30; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 303 | } |
| 304 | |
fischman@webrtc.org | 69fc315 | 2013-09-25 17:01:42 +0000 | [diff] [blame] | 305 | _captureCapabilities.push_back(cap); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 306 | index++; |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 307 | LOG(LS_VERBOSE) << "Camera capability, width:" << cap.width |
| 308 | << " height:" << cap.height << " type:" |
| 309 | << static_cast<int32_t>(cap.videoType) |
| 310 | << " fps:" << cap.maxFPS; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | |
Sam Zackrisson | 2ed6e4f | 2017-08-16 13:39:25 +0200 | [diff] [blame] | 316 | LOG(LS_INFO) << "CreateCapabilityMap " << _captureCapabilities.size(); |
pbos@webrtc.org | 4ca7d3f | 2013-08-12 19:51:57 +0000 | [diff] [blame] | 317 | return _captureCapabilities.size(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 318 | } |
| 319 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 320 | } // namespace videocapturemodule |
| 321 | } // namespace webrtc |