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

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: Code review fix 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 // GUID of the Extension Unit for Logitech CC3300e motor control:
27 // {212de5ff-3080-2c4e-82d9-f587d00540bd}
28 #define UVC_GUID_LOGITECH_CC3000E_MOTORS \
29 {0x21, 0x2d, 0xe5, 0xff, 0x30, 0x80, 0x2c, 0x4e, \
30 0x82, 0xd9, 0xf5, 0x87, 0xd0, 0x05, 0x40, 0xbd}
31
32 #define LOGITECH_MOTORCONTROL_PANTILT_CMD 2
23 33
24 namespace webcam_private = extensions::core_api::webcam_private; 34 namespace webcam_private = extensions::core_api::webcam_private;
25 35
26 namespace content { 36 namespace content {
27 class BrowserContext; 37 class BrowserContext;
28 } // namespace content 38 } // namespace content
29 39
30 namespace { 40 namespace {
41 const int kLogitechMenuIndexGoHome = 2;
42
43 const uvc_menu_info kLogitechCmdMenu[] = {
44 {1, "Set Preset"}, {2, "Get Preset"}, {3, "Go Home"}
45 };
46
47 const uvc_xu_control_mapping kLogitechCmdMapping = {
48 V4L2_CID_PANTILT_CMD,
49 "Pan/Tilt Go",
50 UVC_GUID_LOGITECH_CC3000E_MOTORS,
51 LOGITECH_MOTORCONTROL_PANTILT_CMD,
52 8,
53 0,
54 V4L2_CTRL_TYPE_MENU,
55 UVC_CTRL_DATA_TYPE_ENUM,
56 const_cast<uvc_menu_info*>(&kLogitechCmdMenu[0]),
57 arraysize(kLogitechCmdMenu),
58 };
31 59
32 base::ScopedFD OpenWebcam(const std::string& extension_id, 60 base::ScopedFD OpenWebcam(const std::string& extension_id,
33 content::BrowserContext* browser_context, 61 content::BrowserContext* browser_context,
34 const std::string& webcam_id) { 62 const std::string& webcam_id) {
35 GURL security_origin = 63 GURL security_origin =
36 extensions::Extension::GetBaseURLFromExtensionId(extension_id); 64 extensions::Extension::GetBaseURLFromExtensionId(extension_id);
37 65
38 std::string device_id; 66 std::string device_id;
39 bool success = content::GetMediaDeviceIDForHMAC( 67 bool success = content::GetMediaDeviceIDForHMAC(
40 content::MEDIA_DEVICE_VIDEO_CAPTURE, 68 content::MEDIA_DEVICE_VIDEO_CAPTURE,
(...skipping 16 matching lines...) Expand all
57 bool GetWebcamParameter(int fd, uint32_t control_id, int* value) { 85 bool GetWebcamParameter(int fd, uint32_t control_id, int* value) {
58 struct v4l2_control v4l2_ctrl = {control_id}; 86 struct v4l2_control v4l2_ctrl = {control_id};
59 87
60 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl))) 88 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl)))
61 return false; 89 return false;
62 90
63 *value = v4l2_ctrl.value; 91 *value = v4l2_ctrl.value;
64 return true; 92 return true;
65 } 93 }
66 94
95 bool EnsureLogitechCommandsMapped(int fd) {
96 int res = ioctl(fd, UVCIOC_CTRL_MAP, &kLogitechCmdMapping);
97 // If mapping is successful or it's already mapped, this is a Logitech camera.
98 return res >= 0 || errno == EEXIST;
99 }
100
67 const char kUnknownWebcam[] = "Unknown webcam id"; 101 const char kUnknownWebcam[] = "Unknown webcam id";
68 } // namespace 102 } // namespace
69 103
70 namespace extensions { 104 namespace extensions {
71 105
72 WebcamPrivateSetFunction::WebcamPrivateSetFunction() { 106 WebcamPrivateSetFunction::WebcamPrivateSetFunction() {
73 } 107 }
74 108
75 WebcamPrivateSetFunction::~WebcamPrivateSetFunction() { 109 WebcamPrivateSetFunction::~WebcamPrivateSetFunction() {
76 } 110 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 webcam_private::Reset::Params::Create(*args_)); 229 webcam_private::Reset::Params::Create(*args_));
196 EXTENSION_FUNCTION_VALIDATE(params.get()); 230 EXTENSION_FUNCTION_VALIDATE(params.get());
197 231
198 base::ScopedFD fd = 232 base::ScopedFD fd =
199 OpenWebcam(extension_id(), browser_context(), params->webcam_id); 233 OpenWebcam(extension_id(), browser_context(), params->webcam_id);
200 if (!fd.is_valid()) { 234 if (!fd.is_valid()) {
201 SetError(kUnknownWebcam); 235 SetError(kUnknownWebcam);
202 return false; 236 return false;
203 } 237 }
204 238
239 if (params->config.pan || params->config.tilt) {
240 if (EnsureLogitechCommandsMapped(fd.get())) {
241 SetWebcamParameter(fd.get(), V4L2_CID_PANTILT_CMD,
242 kLogitechMenuIndexGoHome);
243 }
244 }
245
205 if (params->config.pan) { 246 if (params->config.pan) {
206 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET}; 247 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
207 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl)); 248 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
208 } 249 }
209 250
210 if (params->config.tilt) { 251 if (params->config.tilt) {
211 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET}; 252 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET};
212 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl)); 253 HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
213 } 254 }
214 255
215 if (params->config.zoom) { 256 if (params->config.zoom) {
216 const int kDefaultZoom = 100; 257 const int kDefaultZoom = 100;
217 SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom); 258 SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom);
218 } 259 }
219 260
220 return true; 261 return true;
221 } 262 }
222 263
223 } // namespace extensions 264 } // 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