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

Unified Diff: chrome/browser/extensions/api/webcam_private/webcam_private_api_chromeos.cc

Issue 234843006: Send commands from webcamPrivate API to the webcam via V4L2 ioctls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fixes 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webcam_private/webcam_private_api_chromeos.cc
diff --git a/chrome/browser/extensions/api/webcam_private/webcam_private_api_chromeos.cc b/chrome/browser/extensions/api/webcam_private/webcam_private_api_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4ebbc25b7ec3197bd9697759fb5f5b7ee8beb0e
--- /dev/null
+++ b/chrome/browser/extensions/api/webcam_private/webcam_private_api_chromeos.cc
@@ -0,0 +1,164 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
not at google - send to devlin 2014/04/24 16:09:53 if this is effectively the same file then make sur
+
+#include "chrome/browser/extensions/api/webcam_private/webcam_private_api.h"
+
+#include <fcntl.h>
+#include <linux/videodev2.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include "base/files/scoped_file.h"
+#include "base/posix/eintr_wrapper.h"
+#include "chrome/common/extensions/api/webcam_private.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace {
+
+base::ScopedFD OpenWebcam(const std::string& extension_id,
+ content::BrowserContext* browser_context,
+ const std::string& webcam_id) {
+ // TODO(zork): Get device_id from content::MediaStreamManager.
+ std::string device_id = "/dev/video0";
+
+ return base::ScopedFD(HANDLE_EINTR(open(device_id.c_str(), 0)));
+}
+
+void SetWebcamParameter(int fd, int control_id, int value) {
+ struct v4l2_control v4l2_ctrl = {control_id, value};
+ HANDLE_EINTR(ioctl(fd, VIDIOC_S_CTRL, &v4l2_ctrl));
+}
+
+bool GetWebcamParameter(int fd, int control_id, int* value) {
+ struct v4l2_control v4l2_ctrl = {control_id};
+
+ if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl)))
+ return false;
+
+ *value = v4l2_ctrl.value;
+ return true;
+}
+
+const char kUnknownWebcam[] = "Unknown webcam id";
+} // namespace
+
+namespace extensions {
+
+WebcamPrivateSetFunction::WebcamPrivateSetFunction() {
+}
+
+WebcamPrivateSetFunction::~WebcamPrivateSetFunction() {
+}
+
+bool WebcamPrivateSetFunction::RunImpl() {
+ // Get parameters
+ scoped_ptr<api::webcam_private::Set::Params> params(
+ api::webcam_private::Set::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ base::ScopedFD fd =
+ OpenWebcam(extension_id(), browser_context(), params->webcam_id);
+ if (!fd.is_valid()) {
+ SetError(kUnknownWebcam);
+ return false;
+ }
+
+ if (params->config.pan) {
+ SetWebcamParameter(fd.get(), V4L2_CID_PAN_ABSOLUTE,
+ *(params->config.pan));
+ }
+
+ if (params->config.tilt) {
+ SetWebcamParameter(fd.get(), V4L2_CID_TILT_ABSOLUTE,
+ *(params->config.tilt));
+ }
+
+ if (params->config.zoom) {
+ SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE,
+ *(params->config.zoom));
+ }
+
+ return true;
+}
+
+WebcamPrivateGetFunction::WebcamPrivateGetFunction() {
+}
+
+WebcamPrivateGetFunction::~WebcamPrivateGetFunction() {
+}
+
+bool WebcamPrivateGetFunction::RunImpl() {
+ // Get parameters
+ scoped_ptr<api::webcam_private::Get::Params> params(
+ api::webcam_private::Get::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ base::ScopedFD fd =
+ OpenWebcam(extension_id(), browser_context(), params->webcam_id);
+ if (!fd.is_valid()) {
+ SetError(kUnknownWebcam);
+ return false;
+ }
+
+ api::webcam_private::WebcamConfiguration result;
+
+ int pan;
+ if (GetWebcamParameter(fd.get(), V4L2_CID_PAN_ABSOLUTE, &pan))
+ result.pan.reset(new double(pan));
+
+ int tilt;
+ if (GetWebcamParameter(fd.get(), V4L2_CID_TILT_ABSOLUTE, &tilt))
+ result.tilt.reset(new double(tilt));
+
+ int zoom;
+ if (GetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, &zoom))
+ result.zoom.reset(new double(zoom));
+
+ SetResult(result.ToValue().release());
+
+ return true;
+}
+
+WebcamPrivateResetFunction::WebcamPrivateResetFunction() {
+}
+
+WebcamPrivateResetFunction::~WebcamPrivateResetFunction() {
+}
+
+bool WebcamPrivateResetFunction::RunImpl() {
+ // Get parameters
+ scoped_ptr<api::webcam_private::Reset::Params> params(
+ api::webcam_private::Reset::Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ base::ScopedFD fd =
+ OpenWebcam(extension_id(), browser_context(), params->webcam_id);
+ if (!fd.is_valid()) {
+ SetError(kUnknownWebcam);
+ return false;
+ }
+
+ if (params->config.pan) {
+ struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
+ HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
+ }
+
+ if (params->config.tilt) {
+ struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET};
+ HANDLE_EINTR(ioctl(fd.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
+ }
+
+ if (params->config.zoom) {
+ const int kDefaultZoom = 100;
+ SetWebcamParameter(fd.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom);
+ }
+
+ return true;
+}
+
+} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/api/webcam_private/webcam_private_api.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698