OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <linux/videodev2.h> | 21 #include <linux/videodev2.h> |
22 | 22 |
23 #include "webrtc/system_wrappers/include/trace.h" | 23 #include "webrtc/system_wrappers/include/trace.h" |
24 | 24 |
25 | 25 |
26 namespace webrtc | 26 namespace webrtc |
27 { | 27 { |
28 namespace videocapturemodule | 28 namespace videocapturemodule |
29 { | 29 { |
30 VideoCaptureModule::DeviceInfo* | 30 VideoCaptureModule::DeviceInfo* |
31 VideoCaptureImpl::CreateDeviceInfo(const int32_t id) | 31 VideoCaptureImpl::CreateDeviceInfo() |
32 { | 32 { |
33 return new videocapturemodule::DeviceInfoLinux(id); | 33 return new videocapturemodule::DeviceInfoLinux(); |
34 } | 34 } |
35 | 35 |
36 DeviceInfoLinux::DeviceInfoLinux(const int32_t id) | 36 DeviceInfoLinux::DeviceInfoLinux() |
37 : DeviceInfoImpl(id) | 37 : DeviceInfoImpl() |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 int32_t DeviceInfoLinux::Init() | 41 int32_t DeviceInfoLinux::Init() |
42 { | 42 { |
43 return 0; | 43 return 0; |
44 } | 44 } |
45 | 45 |
46 DeviceInfoLinux::~DeviceInfoLinux() | 46 DeviceInfoLinux::~DeviceInfoLinux() |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 uint32_t DeviceInfoLinux::NumberOfDevices() | 50 uint32_t DeviceInfoLinux::NumberOfDevices() |
51 { | 51 { |
52 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideoCapture, _id, "%s", _
_FUNCTION__); | 52 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideoCapture, 0, "%s", __F
UNCTION__); |
53 | 53 |
54 uint32_t count = 0; | 54 uint32_t count = 0; |
55 char device[20]; | 55 char device[20]; |
56 int fd = -1; | 56 int fd = -1; |
57 | 57 |
58 /* detect /dev/video [0-63]VideoCaptureModule entries */ | 58 /* detect /dev/video [0-63]VideoCaptureModule entries */ |
59 for (int n = 0; n < 64; n++) | 59 for (int n = 0; n < 64; n++) |
60 { | 60 { |
61 sprintf(device, "/dev/video%d", n); | 61 sprintf(device, "/dev/video%d", n); |
62 if ((fd = open(device, O_RDONLY)) != -1) | 62 if ((fd = open(device, O_RDONLY)) != -1) |
63 { | 63 { |
64 close(fd); | 64 close(fd); |
65 count++; | 65 count++; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 return count; | 69 return count; |
70 } | 70 } |
71 | 71 |
72 int32_t DeviceInfoLinux::GetDeviceName( | 72 int32_t DeviceInfoLinux::GetDeviceName( |
73 uint32_t deviceNumber, | 73 uint32_t deviceNumber, |
74 char* deviceNameUTF8, | 74 char* deviceNameUTF8, |
75 uint32_t deviceNameLength, | 75 uint32_t deviceNameLength, |
76 char* deviceUniqueIdUTF8, | 76 char* deviceUniqueIdUTF8, |
77 uint32_t deviceUniqueIdUTF8Length, | 77 uint32_t deviceUniqueIdUTF8Length, |
78 char* /*productUniqueIdUTF8*/, | 78 char* /*productUniqueIdUTF8*/, |
79 uint32_t /*productUniqueIdUTF8Length*/) | 79 uint32_t /*productUniqueIdUTF8Length*/) |
80 { | 80 { |
81 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideoCapture, _id, "%s", _
_FUNCTION__); | 81 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideoCapture, 0, "%s", __F
UNCTION__); |
82 | 82 |
83 // Travel through /dev/video [0-63] | 83 // Travel through /dev/video [0-63] |
84 uint32_t count = 0; | 84 uint32_t count = 0; |
85 char device[20]; | 85 char device[20]; |
86 int fd = -1; | 86 int fd = -1; |
87 bool found = false; | 87 bool found = false; |
88 for (int n = 0; n < 64; n++) | 88 for (int n = 0; n < 64; n++) |
89 { | 89 { |
90 sprintf(device, "/dev/video%d", n); | 90 sprintf(device, "/dev/video%d", n); |
91 if ((fd = open(device, O_RDONLY)) != -1) | 91 if ((fd = open(device, O_RDONLY)) != -1) |
92 { | 92 { |
93 if (count == deviceNumber) { | 93 if (count == deviceNumber) { |
94 // Found the device | 94 // Found the device |
95 found = true; | 95 found = true; |
96 break; | 96 break; |
97 } else { | 97 } else { |
98 close(fd); | 98 close(fd); |
99 count++; | 99 count++; |
100 } | 100 } |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 if (!found) | 104 if (!found) |
105 return -1; | 105 return -1; |
106 | 106 |
107 // query device capabilities | 107 // query device capabilities |
108 struct v4l2_capability cap; | 108 struct v4l2_capability cap; |
109 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) | 109 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) |
110 { | 110 { |
111 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, | 111 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
112 "error in querying the device capability for device %s. errno
= %d", | 112 "error in querying the device capability for device %s. errno
= %d", |
113 device, errno); | 113 device, errno); |
114 close(fd); | 114 close(fd); |
115 return -1; | 115 return -1; |
116 } | 116 } |
117 | 117 |
118 close(fd); | 118 close(fd); |
119 | 119 |
120 char cameraName[64]; | 120 char cameraName[64]; |
121 memset(deviceNameUTF8, 0, deviceNameLength); | 121 memset(deviceNameUTF8, 0, deviceNameLength); |
122 memcpy(cameraName, cap.card, sizeof(cap.card)); | 122 memcpy(cameraName, cap.card, sizeof(cap.card)); |
123 | 123 |
124 if (deviceNameLength >= strlen(cameraName)) | 124 if (deviceNameLength >= strlen(cameraName)) |
125 { | 125 { |
126 memcpy(deviceNameUTF8, cameraName, strlen(cameraName)); | 126 memcpy(deviceNameUTF8, cameraName, strlen(cameraName)); |
127 } | 127 } |
128 else | 128 else |
129 { | 129 { |
130 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "buff
er passed is too small"); | 130 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, "buffer
passed is too small"); |
131 return -1; | 131 return -1; |
132 } | 132 } |
133 | 133 |
134 if (cap.bus_info[0] != 0) // may not available in all drivers | 134 if (cap.bus_info[0] != 0) // may not available in all drivers |
135 { | 135 { |
136 // copy device id | 136 // copy device id |
137 if (deviceUniqueIdUTF8Length >= strlen((const char*) cap.bus_info)) | 137 if (deviceUniqueIdUTF8Length >= strlen((const char*) cap.bus_info)) |
138 { | 138 { |
139 memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length); | 139 memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length); |
140 memcpy(deviceUniqueIdUTF8, cap.bus_info, | 140 memcpy(deviceUniqueIdUTF8, cap.bus_info, |
141 strlen((const char*) cap.bus_info)); | 141 strlen((const char*) cap.bus_info)); |
142 } | 142 } |
143 else | 143 else |
144 { | 144 { |
145 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, | 145 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
146 "buffer passed is too small"); | 146 "buffer passed is too small"); |
147 return -1; | 147 return -1; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 return 0; | 151 return 0; |
152 } | 152 } |
153 | 153 |
154 int32_t DeviceInfoLinux::CreateCapabilityMap( | 154 int32_t DeviceInfoLinux::CreateCapabilityMap( |
155 const char* deviceUniqueIdUTF8) | 155 const char* deviceUniqueIdUTF8) |
156 { | 156 { |
157 int fd; | 157 int fd; |
158 char device[32]; | 158 char device[32]; |
159 bool found = false; | 159 bool found = false; |
160 | 160 |
161 const int32_t deviceUniqueIdUTF8Length = | 161 const int32_t deviceUniqueIdUTF8Length = |
162 (int32_t) strlen((char*) deviceUniqueIdUTF8); | 162 (int32_t) strlen((char*) deviceUniqueIdUTF8); |
163 if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) | 163 if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) |
164 { | 164 { |
165 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "Devi
ce name too long"); | 165 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, "Device
name too long"); |
166 return -1; | 166 return -1; |
167 } | 167 } |
168 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, | 168 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0, |
169 "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8); | 169 "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8); |
170 | 170 |
171 /* detect /dev/video [0-63] entries */ | 171 /* detect /dev/video [0-63] entries */ |
172 for (int n = 0; n < 64; ++n) | 172 for (int n = 0; n < 64; ++n) |
173 { | 173 { |
174 sprintf(device, "/dev/video%d", n); | 174 sprintf(device, "/dev/video%d", n); |
175 fd = open(device, O_RDONLY); | 175 fd = open(device, O_RDONLY); |
176 if (fd == -1) | 176 if (fd == -1) |
177 continue; | 177 continue; |
178 | 178 |
(...skipping 19 matching lines...) Expand all Loading... |
198 found = true; | 198 found = true; |
199 break; | 199 break; |
200 } | 200 } |
201 } | 201 } |
202 } | 202 } |
203 close(fd); // close since this is not the matching device | 203 close(fd); // close since this is not the matching device |
204 } | 204 } |
205 | 205 |
206 if (!found) | 206 if (!found) |
207 { | 207 { |
208 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "no m
atching device found"); | 208 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, "no mat
ching device found"); |
209 return -1; | 209 return -1; |
210 } | 210 } |
211 | 211 |
212 // now fd will point to the matching device | 212 // now fd will point to the matching device |
213 // reset old capability list. | 213 // reset old capability list. |
214 _captureCapabilities.clear(); | 214 _captureCapabilities.clear(); |
215 | 215 |
216 int size = FillCapabilities(fd); | 216 int size = FillCapabilities(fd); |
217 close(fd); | 217 close(fd); |
218 | 218 |
219 // Store the new used device name | 219 // Store the new used device name |
220 _lastUsedDeviceNameLength = deviceUniqueIdUTF8Length; | 220 _lastUsedDeviceNameLength = deviceUniqueIdUTF8Length; |
221 _lastUsedDeviceName = (char*) realloc(_lastUsedDeviceName, | 221 _lastUsedDeviceName = (char*) realloc(_lastUsedDeviceName, |
222 _lastUsedDeviceNameLength + 1
); | 222 _lastUsedDeviceNameLength + 1
); |
223 memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength +
1); | 223 memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength +
1); |
224 | 224 |
225 WEBRTC_TRACE(webrtc::kTraceInfo, | 225 WEBRTC_TRACE(webrtc::kTraceInfo, |
226 webrtc::kTraceVideoCapture, | 226 webrtc::kTraceVideoCapture, |
227 _id, | 227 0, |
228 "CreateCapabilityMap %u", | 228 "CreateCapabilityMap %u", |
229 static_cast<unsigned int>(_captureCapabilities.size())); | 229 static_cast<unsigned int>(_captureCapabilities.size())); |
230 | 230 |
231 return size; | 231 return size; |
232 } | 232 } |
233 | 233 |
234 bool DeviceInfoLinux::IsDeviceNameMatches(const char* name, | 234 bool DeviceInfoLinux::IsDeviceNameMatches(const char* name, |
235 const char* deviceUniqueIdUTF8) | 235 const char* deviceUniqueIdUTF8) |
236 { | 236 { |
237 if (strncmp(deviceUniqueIdUTF8, name, strlen(name)) == 0) | 237 if (strncmp(deviceUniqueIdUTF8, name, strlen(name)) == 0) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 { | 304 { |
305 cap.maxFPS = 15; | 305 cap.maxFPS = 15; |
306 } | 306 } |
307 else | 307 else |
308 { | 308 { |
309 cap.maxFPS = 30; | 309 cap.maxFPS = 30; |
310 } | 310 } |
311 | 311 |
312 _captureCapabilities.push_back(cap); | 312 _captureCapabilities.push_back(cap); |
313 index++; | 313 index++; |
314 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture,
_id, | 314 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture,
0, |
315 "Camera capability, width:%d height:%d type:%d fp
s:%d", | 315 "Camera capability, width:%d height:%d type:%d fp
s:%d", |
316 cap.width, cap.height, cap.rawType, cap.maxFPS); | 316 cap.width, cap.height, cap.rawType, cap.maxFPS); |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 WEBRTC_TRACE(webrtc::kTraceInfo, | 322 WEBRTC_TRACE(webrtc::kTraceInfo, |
323 webrtc::kTraceVideoCapture, | 323 webrtc::kTraceVideoCapture, |
324 _id, | 324 0, |
325 "CreateCapabilityMap %u", | 325 "CreateCapabilityMap %u", |
326 static_cast<unsigned int>(_captureCapabilities.size())); | 326 static_cast<unsigned int>(_captureCapabilities.size())); |
327 return _captureCapabilities.size(); | 327 return _captureCapabilities.size(); |
328 } | 328 } |
329 | 329 |
330 } // namespace videocapturemodule | 330 } // namespace videocapturemodule |
331 } // namespace webrtc | 331 } // namespace webrtc |
OLD | NEW |