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

Side by Side Diff: extensions/browser/api/webcam_private/webcam_private_api_chromeos.cc

Issue 830673005: Add support for resetting pan and tilt on Logitech webcams. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/webcam_private/webcam_private_api.h" 5 #include "extensions/browser/api/webcam_private/webcam_private_api.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <linux/uvcvideo.h>
8 #include <linux/videodev2.h> 9 #include <linux/videodev2.h>
9 #include <stdio.h> 10 #include <stdio.h>
10 #include <sys/ioctl.h> 11 #include <sys/ioctl.h>
11 #include <unistd.h> 12 #include <unistd.h>
12 13
13 #include "base/files/scoped_file.h" 14 #include "base/files/scoped_file.h"
14 #include "base/posix/eintr_wrapper.h" 15 #include "base/posix/eintr_wrapper.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/media_device_id.h" 17 #include "content/public/browser/media_device_id.h"
17 #include "content/public/browser/resource_context.h" 18 #include "content/public/browser/resource_context.h"
18 #include "content/public/common/media_stream_request.h" 19 #include "content/public/common/media_stream_request.h"
19 #include "extensions/common/api/webcam_private.h" 20 #include "extensions/common/api/webcam_private.h"
20 21
21 #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32) 22 #define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32)
22 #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33) 23 #define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33)
24 #define V4L2_CID_PANTILT_CMD (V4L2_CID_CAMERA_CLASS_BASE+34)
25
26 /*
tommi (sloooow) - chröme 2015/01/13 16:37:39 use // type comments
Zachary Kuznia 2015/01/13 20:54:59 Done.
27 * GUID of the Extension Unit for Logitech CC3300e motor control:
28 * {212de5ff-3080-2c4e-82d9-f587d00540bd}
29 */
30 #define UVC_GUID_LOGITECH_CC3000E_MOTORS \
31 {0x21, 0x2d, 0xe5, 0xff, 0x30, 0x80, 0x2c, 0x4e, \
32 0x82, 0xd9, 0xf5, 0x87, 0xd0, 0x05, 0x40, 0xbd}
33
34 #define LOGITECH_MOTORCONTROL_PANTILT_CMD 2
23 35
24 namespace webcam_private = extensions::core_api::webcam_private; 36 namespace webcam_private = extensions::core_api::webcam_private;
25 37
26 namespace content { 38 namespace content {
27 class BrowserContext; 39 class BrowserContext;
28 } // namespace content 40 } // namespace content
29 41
30 namespace { 42 namespace {
43 const int kLogitechMenuIndexGoHome = 2;
44
45 const uvc_menu_info kLogitechCmdMenu[3] = {
tommi (sloooow) - chröme 2015/01/13 16:37:39 since you're using sizeof to derive this size, do
Zachary Kuznia 2015/01/13 20:54:59 Done.
46 {1, "Set Preset"}, {2, "Get Preset"}, {3, "Go Home"}
47 };
48
49 const uvc_xu_control_mapping kLogitechCmdMapping = {
50 V4L2_CID_PANTILT_CMD,
51 "Pan/Tilt Go",
52 UVC_GUID_LOGITECH_CC3000E_MOTORS,
53 LOGITECH_MOTORCONTROL_PANTILT_CMD,
54 8,
55 0,
56 V4L2_CTRL_TYPE_MENU,
57 UVC_CTRL_DATA_TYPE_ENUM,
58 const_cast<uvc_menu_info*>(kLogitechCmdMenu),
tommi (sloooow) - chröme 2015/01/13 16:37:39 nit: &kLogitechCmdMenu[0]
Zachary Kuznia 2015/01/13 20:54:59 Done.
59 sizeof(kLogitechCmdMenu)/sizeof(struct uvc_menu_info),
tommi (sloooow) - chröme 2015/01/13 16:37:40 arraysize()
Zachary Kuznia 2015/01/13 20:54:59 Done.
60 };
31 61
32 base::ScopedFD OpenWebcam(const std::string& extension_id, 62 base::ScopedFD OpenWebcam(const std::string& extension_id,
33 content::BrowserContext* browser_context, 63 content::BrowserContext* browser_context,
34 const std::string& webcam_id) { 64 const std::string& webcam_id) {
35 GURL security_origin = 65 GURL security_origin =
36 extensions::Extension::GetBaseURLFromExtensionId(extension_id); 66 extensions::Extension::GetBaseURLFromExtensionId(extension_id);
37 67
38 std::string device_id; 68 std::string device_id;
39 bool success = content::GetMediaDeviceIDForHMAC( 69 bool success = content::GetMediaDeviceIDForHMAC(
40 content::MEDIA_DEVICE_VIDEO_CAPTURE, 70 content::MEDIA_DEVICE_VIDEO_CAPTURE,
(...skipping 16 matching lines...) Expand all
57 bool GetWebcamParameter(int fd, uint32_t control_id, int* value) { 87 bool GetWebcamParameter(int fd, uint32_t control_id, int* value) {
58 struct v4l2_control v4l2_ctrl = {control_id}; 88 struct v4l2_control v4l2_ctrl = {control_id};
59 89
60 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl))) 90 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl)))
61 return false; 91 return false;
62 92
63 *value = v4l2_ctrl.value; 93 *value = v4l2_ctrl.value;
64 return true; 94 return true;
65 } 95 }
66 96
97 bool EnsureLogitechCommandsMapped(int fd) {
98 int res = ioctl(fd, UVCIOC_CTRL_MAP, &kLogitechCmdMapping);
99 if (res < 0) {
tommi (sloooow) - chröme 2015/01/13 16:37:40 nit: return res < 0 || errno == EEXIST;
Zachary Kuznia 2015/01/13 20:54:59 Done.
100 if (errno == EEXIST) {
101 // Already mapped, success.
102 return true;
103 } else {
104 // Cannot map, camera doesn't support this command.
105 return false;
106 }
107 } else {
108 return true;
109 }
110 }
111
67 const char kUnknownWebcam[] = "Unknown webcam id"; 112 const char kUnknownWebcam[] = "Unknown webcam id";
68 } // namespace 113 } // namespace
69 114
70 namespace extensions { 115 namespace extensions {
71 116
72 WebcamPrivateSetFunction::WebcamPrivateSetFunction() { 117 WebcamPrivateSetFunction::WebcamPrivateSetFunction() {
73 } 118 }
74 119
75 WebcamPrivateSetFunction::~WebcamPrivateSetFunction() { 120 WebcamPrivateSetFunction::~WebcamPrivateSetFunction() {
76 } 121 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 webcam_private::Reset::Params::Create(*args_)); 240 webcam_private::Reset::Params::Create(*args_));
196 EXTENSION_FUNCTION_VALIDATE(params.get()); 241 EXTENSION_FUNCTION_VALIDATE(params.get());
197 242
198 base::ScopedFD fd = 243 base::ScopedFD fd =
199 OpenWebcam(extension_id(), browser_context(), params->webcam_id); 244 OpenWebcam(extension_id(), browser_context(), params->webcam_id);
200 if (!fd.is_valid()) { 245 if (!fd.is_valid()) {
201 SetError(kUnknownWebcam); 246 SetError(kUnknownWebcam);
202 return false; 247 return false;
203 } 248 }
204 249
250 if (params->config.pan || params->config.tilt) {
251 if (EnsureLogitechCommandsMapped(fd.get())) {
252 SetWebcamParameter(fd.get(), V4L2_CID_PANTILT_CMD,
253 kLogitechMenuIndexGoHome);
254 }
255 }
256
205 if (params->config.pan) { 257 if (params->config.pan) {
206 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET}; 258 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
207 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl)); 259 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
208 } 260 }
209 261
210 if (params->config.tilt) { 262 if (params->config.tilt) {
211 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET}; 263 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET};
212 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl)); 264 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
213 } 265 }
214 266
215 if (params->config.zoom) { 267 if (params->config.zoom) {
216 const int kDefaultZoom = 100; 268 const int kDefaultZoom = 100;
217 SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom); 269 SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom);
218 } 270 }
219 271
220 return true; 272 return true;
221 } 273 }
222 274
223 } // namespace extensions 275 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698