Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: webrtc/modules/video_capture/linux/device_info_linux.cc

Issue 2534553002: Replace VideoCaptureDataCallback by VideoSinkInterface. (Closed)
Patch Set: Break overlong lines. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
53 webrtc::kTraceVideoCapture, 0, "%s", __FUNCTION__);
53 54
54 uint32_t count = 0; 55 uint32_t count = 0;
55 char device[20]; 56 char device[20];
56 int fd = -1; 57 int fd = -1;
57 58
58 /* detect /dev/video [0-63]VideoCaptureModule entries */ 59 /* detect /dev/video [0-63]VideoCaptureModule entries */
59 for (int n = 0; n < 64; n++) 60 for (int n = 0; n < 64; n++)
60 { 61 {
61 sprintf(device, "/dev/video%d", n); 62 sprintf(device, "/dev/video%d", n);
62 if ((fd = open(device, O_RDONLY)) != -1) 63 if ((fd = open(device, O_RDONLY)) != -1)
63 { 64 {
64 close(fd); 65 close(fd);
65 count++; 66 count++;
66 } 67 }
67 } 68 }
68 69
69 return count; 70 return count;
70 } 71 }
71 72
72 int32_t DeviceInfoLinux::GetDeviceName( 73 int32_t DeviceInfoLinux::GetDeviceName(
73 uint32_t deviceNumber, 74 uint32_t deviceNumber,
74 char* deviceNameUTF8, 75 char* deviceNameUTF8,
75 uint32_t deviceNameLength, 76 uint32_t deviceNameLength,
76 char* deviceUniqueIdUTF8, 77 char* deviceUniqueIdUTF8,
77 uint32_t deviceUniqueIdUTF8Length, 78 uint32_t deviceUniqueIdUTF8Length,
78 char* /*productUniqueIdUTF8*/, 79 char* /*productUniqueIdUTF8*/,
79 uint32_t /*productUniqueIdUTF8Length*/) 80 uint32_t /*productUniqueIdUTF8Length*/)
80 { 81 {
81 WEBRTC_TRACE(webrtc::kTraceApiCall, webrtc::kTraceVideoCapture, _id, "%s", _ _FUNCTION__); 82 WEBRTC_TRACE(webrtc::kTraceApiCall,
83 webrtc::kTraceVideoCapture, 0, "%s", __FUNCTION__);
82 84
83 // Travel through /dev/video [0-63] 85 // Travel through /dev/video [0-63]
84 uint32_t count = 0; 86 uint32_t count = 0;
85 char device[20]; 87 char device[20];
86 int fd = -1; 88 int fd = -1;
87 bool found = false; 89 bool found = false;
88 for (int n = 0; n < 64; n++) 90 for (int n = 0; n < 64; n++)
89 { 91 {
90 sprintf(device, "/dev/video%d", n); 92 sprintf(device, "/dev/video%d", n);
91 if ((fd = open(device, O_RDONLY)) != -1) 93 if ((fd = open(device, O_RDONLY)) != -1)
92 { 94 {
93 if (count == deviceNumber) { 95 if (count == deviceNumber) {
94 // Found the device 96 // Found the device
95 found = true; 97 found = true;
96 break; 98 break;
97 } else { 99 } else {
98 close(fd); 100 close(fd);
99 count++; 101 count++;
100 } 102 }
101 } 103 }
102 } 104 }
103 105
104 if (!found) 106 if (!found)
105 return -1; 107 return -1;
106 108
107 // query device capabilities 109 // query device capabilities
108 struct v4l2_capability cap; 110 struct v4l2_capability cap;
109 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) 111 if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0)
110 { 112 {
111 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, 113 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
112 "error in querying the device capability for device %s. errno = %d", 114 "error in querying the device capability for device %s. errno = %d",
113 device, errno); 115 device, errno);
114 close(fd); 116 close(fd);
115 return -1; 117 return -1;
116 } 118 }
117 119
118 close(fd); 120 close(fd);
119 121
120 char cameraName[64]; 122 char cameraName[64];
121 memset(deviceNameUTF8, 0, deviceNameLength); 123 memset(deviceNameUTF8, 0, deviceNameLength);
122 memcpy(cameraName, cap.card, sizeof(cap.card)); 124 memcpy(cameraName, cap.card, sizeof(cap.card));
123 125
124 if (deviceNameLength >= strlen(cameraName)) 126 if (deviceNameLength >= strlen(cameraName))
125 { 127 {
126 memcpy(deviceNameUTF8, cameraName, strlen(cameraName)); 128 memcpy(deviceNameUTF8, cameraName, strlen(cameraName));
127 } 129 }
128 else 130 else
129 { 131 {
130 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "buff er passed is too small"); 132 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
133 "buffer passed is too small");
131 return -1; 134 return -1;
132 } 135 }
133 136
134 if (cap.bus_info[0] != 0) // may not available in all drivers 137 if (cap.bus_info[0] != 0) // may not available in all drivers
135 { 138 {
136 // copy device id 139 // copy device id
137 if (deviceUniqueIdUTF8Length >= strlen((const char*) cap.bus_info)) 140 if (deviceUniqueIdUTF8Length >= strlen((const char*) cap.bus_info))
138 { 141 {
139 memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length); 142 memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length);
140 memcpy(deviceUniqueIdUTF8, cap.bus_info, 143 memcpy(deviceUniqueIdUTF8, cap.bus_info,
141 strlen((const char*) cap.bus_info)); 144 strlen((const char*) cap.bus_info));
142 } 145 }
143 else 146 else
144 { 147 {
145 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, 148 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0,
146 "buffer passed is too small"); 149 "buffer passed is too small");
147 return -1; 150 return -1;
148 } 151 }
149 } 152 }
150 153
151 return 0; 154 return 0;
152 } 155 }
153 156
154 int32_t DeviceInfoLinux::CreateCapabilityMap( 157 int32_t DeviceInfoLinux::CreateCapabilityMap(
155 const char* deviceUniqueIdUTF8) 158 const char* deviceUniqueIdUTF8)
156 { 159 {
157 int fd; 160 int fd;
158 char device[32]; 161 char device[32];
159 bool found = false; 162 bool found = false;
160 163
161 const int32_t deviceUniqueIdUTF8Length = 164 const int32_t deviceUniqueIdUTF8Length =
162 (int32_t) strlen((char*) deviceUniqueIdUTF8); 165 (int32_t) strlen((char*) deviceUniqueIdUTF8);
163 if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) 166 if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength)
164 { 167 {
165 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "Devi ce name too long"); 168 WEBRTC_TRACE(webrtc::kTraceError,
169 webrtc::kTraceVideoCapture, 0, "Device name too long");
166 return -1; 170 return -1;
167 } 171 }
168 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, 172 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
169 "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8); 173 "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8);
170 174
171 /* detect /dev/video [0-63] entries */ 175 /* detect /dev/video [0-63] entries */
172 for (int n = 0; n < 64; ++n) 176 for (int n = 0; n < 64; ++n)
173 { 177 {
174 sprintf(device, "/dev/video%d", n); 178 sprintf(device, "/dev/video%d", n);
175 fd = open(device, O_RDONLY); 179 fd = open(device, O_RDONLY);
176 if (fd == -1) 180 if (fd == -1)
177 continue; 181 continue;
178 182
(...skipping 19 matching lines...) Expand all
198 found = true; 202 found = true;
199 break; 203 break;
200 } 204 }
201 } 205 }
202 } 206 }
203 close(fd); // close since this is not the matching device 207 close(fd); // close since this is not the matching device
204 } 208 }
205 209
206 if (!found) 210 if (!found)
207 { 211 {
208 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "no m atching device found"); 212 WEBRTC_TRACE(webrtc::kTraceError,
213 webrtc::kTraceVideoCapture, 0, "no matching device found");
209 return -1; 214 return -1;
210 } 215 }
211 216
212 // now fd will point to the matching device 217 // now fd will point to the matching device
213 // reset old capability list. 218 // reset old capability list.
214 _captureCapabilities.clear(); 219 _captureCapabilities.clear();
215 220
216 int size = FillCapabilities(fd); 221 int size = FillCapabilities(fd);
217 close(fd); 222 close(fd);
218 223
219 // Store the new used device name 224 // Store the new used device name
220 _lastUsedDeviceNameLength = deviceUniqueIdUTF8Length; 225 _lastUsedDeviceNameLength = deviceUniqueIdUTF8Length;
221 _lastUsedDeviceName = (char*) realloc(_lastUsedDeviceName, 226 _lastUsedDeviceName = (char*) realloc(_lastUsedDeviceName,
222 _lastUsedDeviceNameLength + 1 ); 227 _lastUsedDeviceNameLength + 1 );
223 memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength + 1); 228 memcpy(_lastUsedDeviceName, deviceUniqueIdUTF8, _lastUsedDeviceNameLength + 1);
224 229
225 WEBRTC_TRACE(webrtc::kTraceInfo, 230 WEBRTC_TRACE(webrtc::kTraceInfo,
226 webrtc::kTraceVideoCapture, 231 webrtc::kTraceVideoCapture,
227 _id, 232 0,
228 "CreateCapabilityMap %u", 233 "CreateCapabilityMap %u",
229 static_cast<unsigned int>(_captureCapabilities.size())); 234 static_cast<unsigned int>(_captureCapabilities.size()));
230 235
231 return size; 236 return size;
232 } 237 }
233 238
234 bool DeviceInfoLinux::IsDeviceNameMatches(const char* name, 239 bool DeviceInfoLinux::IsDeviceNameMatches(const char* name,
235 const char* deviceUniqueIdUTF8) 240 const char* deviceUniqueIdUTF8)
236 { 241 {
237 if (strncmp(deviceUniqueIdUTF8, name, strlen(name)) == 0) 242 if (strncmp(deviceUniqueIdUTF8, name, strlen(name)) == 0)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 { 309 {
305 cap.maxFPS = 15; 310 cap.maxFPS = 15;
306 } 311 }
307 else 312 else
308 { 313 {
309 cap.maxFPS = 30; 314 cap.maxFPS = 30;
310 } 315 }
311 316
312 _captureCapabilities.push_back(cap); 317 _captureCapabilities.push_back(cap);
313 index++; 318 index++;
314 WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, 319 WEBRTC_TRACE(
315 "Camera capability, width:%d height:%d type:%d fp s:%d", 320 webrtc::kTraceInfo, webrtc::kTraceVideoCapture, 0,
316 cap.width, cap.height, cap.rawType, cap.maxFPS); 321 "Camera capability, width:%d height:%d type:%d fps:%d",
322 cap.width, cap.height, cap.rawType, cap.maxFPS);
317 } 323 }
318 } 324 }
319 } 325 }
320 } 326 }
321 327
322 WEBRTC_TRACE(webrtc::kTraceInfo, 328 WEBRTC_TRACE(webrtc::kTraceInfo,
323 webrtc::kTraceVideoCapture, 329 webrtc::kTraceVideoCapture,
324 _id, 330 0,
325 "CreateCapabilityMap %u", 331 "CreateCapabilityMap %u",
326 static_cast<unsigned int>(_captureCapabilities.size())); 332 static_cast<unsigned int>(_captureCapabilities.size()));
327 return _captureCapabilities.size(); 333 return _captureCapabilities.size();
328 } 334 }
329 335
330 } // namespace videocapturemodule 336 } // namespace videocapturemodule
331 } // namespace webrtc 337 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_capture/linux/device_info_linux.h ('k') | webrtc/modules/video_capture/linux/video_capture_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698