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

Side by Side Diff: chrome/browser/extensions/api/webcam_private/webcam_private_api.cc

Issue 205243005: Add chrome.webcamPrivate idl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WIP Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/webcam_private/webcam_private_api.h"
6
7 #include "chrome/common/extensions/api/webcam_private.h"
8
9 #include "content/browser/browser_main_loop.h"
10 #include "content/public/common/media_stream_request.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/resource_context.h"
13 #include "content/browser/renderer_host/media/media_stream_manager.h"
14
15 #include <stdio.h>
16 #include <sys/ioctl.h>
17 #include <fcntl.h>
18 #include <unistd.h>
19 #include <linux/videodev2.h>
20
21 namespace {
22 int OpenWebcam(const std::string& extension_id,
23 content::BrowserContext* browser_context,
24 const std::string& webcam_id) {
25 content::MediaStreamManager* manager =
26 content::BrowserMainLoop::GetInstance()->media_stream_manager();
27
28 GURL security_origin =
29 extensions::Extension::GetBaseURLFromExtensionId(extension_id);
30
31 std::string device_id;
32 bool success = manager->TranslateSourceIdToDeviceId(
33 content::MEDIA_DEVICE_VIDEO_CAPTURE,
34 browser_context->GetResourceContext()->GetMediaDeviceIDSalt(),
35 security_origin,
36 webcam_id,
37 &device_id);
38
39 if (!success)
40 return -1;
41
42 return open(device_id.c_str(), 0);
43 }
44
45 const char kUnknownWebcam[] = "Unknown webcam id";
46 const char kCommandFailed[] = "Failed to send command to webcam";
47 } // namespace
48
49 namespace extensions {
50
51 WebcamPrivateSetFunction::WebcamPrivateSetFunction() {
52 }
53
54 WebcamPrivateSetFunction::~WebcamPrivateSetFunction() {
55 }
56
57 bool WebcamPrivateSetFunction::RunImpl() {
58 // Get parameters
59 scoped_ptr<api::webcam_private::Set::Params> params(
60 api::webcam_private::Set::Params::Create(*args_));
61 EXTENSION_FUNCTION_VALIDATE(params.get());
62
63 int fd = OpenWebcam(extension_id(), browser_context(), params->webcam_id);
64 if (fd < 0) {
65 SetError(kUnknownWebcam);
66 return false;
67 }
68
69 struct v4l2_control v4l2_ctrl;
70 v4l2_ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
71 v4l2_ctrl.value = *(params->config.zoom);
72
73 if (ioctl(fd, VIDIOC_S_CTRL, &v4l2_ctrl)) {
74 SetError(kCommandFailed);
75 return false;
76 }
77
78 close(fd);
79
80 return true;
81 }
82
83 WebcamPrivateGetFunction::WebcamPrivateGetFunction() {
84 }
85
86 WebcamPrivateGetFunction::~WebcamPrivateGetFunction() {
87 }
88
89 bool WebcamPrivateGetFunction::RunImpl() {
90 // Get parameters
91 scoped_ptr<api::webcam_private::Get::Params> params(
92 api::webcam_private::Get::Params::Create(*args_));
93 EXTENSION_FUNCTION_VALIDATE(params.get());
94
95 int fd = OpenWebcam(extension_id(), browser_context(), params->webcam_id);
96 if (fd < 0) {
97 SetError(kUnknownWebcam);
98 return false;
99 }
100
101 struct v4l2_control v4l2_ctrl;
102 v4l2_ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
103
104 if (ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl)) {
105 SetError(kCommandFailed);
106 return false;
107 }
108
109 close(fd);
110
111 api::webcam_private::WebcamConfiguration result;
112 result.zoom = make_scoped_ptr(new double(v4l2_ctrl.value));
not at google - send to devlin 2014/04/10 20:06:00 result.zoom.reset(new double(..)) would be slightl
113 SetResult(result.ToValue().release());
114
115 return true;
116 }
117
118 WebcamPrivateResetFunction::WebcamPrivateResetFunction() {
119 }
120
121 WebcamPrivateResetFunction::~WebcamPrivateResetFunction() {
122 }
123
124 bool WebcamPrivateResetFunction::RunImpl() {
125 // Get parameters
126 scoped_ptr<api::webcam_private::Reset::Params> params(
127 api::webcam_private::Reset::Params::Create(*args_));
128 EXTENSION_FUNCTION_VALIDATE(params.get());
129
130 int fd = OpenWebcam(extension_id(), browser_context(), params->webcam_id);
131 if (fd < 0) {
132 SetError(kUnknownWebcam);
133 return false;
134 }
135
136 struct v4l2_control v4l2_ctrl;
137 v4l2_ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
138 v4l2_ctrl.value = 100;
139
140 if (ioctl(fd, VIDIOC_S_CTRL, &v4l2_ctrl)) {
141 SetError(kCommandFailed);
142 return false;
143 }
144
145 close(fd);
146
147 return true;
148 }
149
150 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698