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

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

Issue 1281263003: Change webcamPrivate.set/get/reset to async APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/v4l2_webcam.h" 5 #include "extensions/browser/api/webcam_private/v4l2_webcam.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <linux/uvcvideo.h> 8 #include <linux/uvcvideo.h>
9 #include <linux/videodev2.h> 9 #include <linux/videodev2.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 bool V4L2Webcam::GetWebcamParameter(int fd, uint32_t control_id, int* value) { 78 bool V4L2Webcam::GetWebcamParameter(int fd, uint32_t control_id, int* value) {
79 struct v4l2_control v4l2_ctrl = {control_id}; 79 struct v4l2_control v4l2_ctrl = {control_id};
80 80
81 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl))) 81 if (HANDLE_EINTR(ioctl(fd, VIDIOC_G_CTRL, &v4l2_ctrl)))
82 return false; 82 return false;
83 83
84 *value = v4l2_ctrl.value; 84 *value = v4l2_ctrl.value;
85 return true; 85 return true;
86 } 86 }
87 87
88 void V4L2Webcam::Reset(bool pan, bool tilt, bool zoom) { 88 void V4L2Webcam::GetPan(const GetPTZCompleteCallback& callback) {
89 if (pan || tilt) { 89 int value = 0;
90 if (EnsureLogitechCommandsMapped()) { 90 bool success = GetWebcamParameter(fd_.get(), V4L2_CID_PAN_ABSOLUTE, &value);
91 SetWebcamParameter(fd_.get(), V4L2_CID_PANTILT_CMD, 91 callback.Run(success, value);
92 kLogitechMenuIndexGoHome);
93 } else {
94 if (pan) {
95 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
96 HANDLE_EINTR(ioctl(fd_.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
97 }
98
99 if (tilt) {
100 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET};
101 HANDLE_EINTR(ioctl(fd_.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
102 }
103 }
104 }
105
106 if (zoom) {
107 const int kDefaultZoom = 100;
108 SetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom);
109 }
110 } 92 }
111 93
112 bool V4L2Webcam::GetPan(int* value) { 94 void V4L2Webcam::GetTilt(const GetPTZCompleteCallback& callback) {
113 return GetWebcamParameter(fd_.get(), V4L2_CID_PAN_ABSOLUTE, value); 95 int value = 0;
96 bool success = GetWebcamParameter(fd_.get(), V4L2_CID_TILT_ABSOLUTE, &value);
97 callback.Run(success, value);
114 } 98 }
115 99
116 bool V4L2Webcam::GetTilt(int* value) { 100 void V4L2Webcam::GetZoom(const GetPTZCompleteCallback& callback) {
117 return GetWebcamParameter(fd_.get(), V4L2_CID_TILT_ABSOLUTE, value); 101 int value = 0;
102 bool success = GetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, &value);
103 callback.Run(success, value);
118 } 104 }
119 105
120 bool V4L2Webcam::GetZoom(int* value) { 106 void V4L2Webcam::SetPan(int value, const SetPTZCompleteCallback& callback) {
121 return GetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, value); 107 callback.Run(SetWebcamParameter(fd_.get(), V4L2_CID_PAN_ABSOLUTE, value));
122 } 108 }
123 109
124 bool V4L2Webcam::SetPan(int value) { 110 void V4L2Webcam::SetTilt(int value, const SetPTZCompleteCallback& callback) {
125 return SetWebcamParameter(fd_.get(), V4L2_CID_PAN_ABSOLUTE, value); 111 callback.Run(SetWebcamParameter(fd_.get(), V4L2_CID_TILT_ABSOLUTE, value));
126 } 112 }
127 113
128 bool V4L2Webcam::SetTilt(int value) { 114 void V4L2Webcam::SetZoom(int value, const SetPTZCompleteCallback& callback) {
129 return SetWebcamParameter(fd_.get(), V4L2_CID_TILT_ABSOLUTE, value); 115 callback.Run(SetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, value));
130 } 116 }
131 117
132 bool V4L2Webcam::SetZoom(int value) { 118 void V4L2Webcam::SetPanDirection(PanDirection direction,
133 return SetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, value); 119 const SetPTZCompleteCallback& callback) {
134 }
135
136 bool V4L2Webcam::SetPanDirection(PanDirection direction) {
137 int direction_value = 0; 120 int direction_value = 0;
138 switch (direction) { 121 switch (direction) {
139 case PAN_STOP: 122 case PAN_STOP:
140 direction_value = 0; 123 direction_value = 0;
141 break; 124 break;
142 125
143 case PAN_RIGHT: 126 case PAN_RIGHT:
144 direction_value = 1; 127 direction_value = 1;
145 break; 128 break;
146 129
147 case PAN_LEFT: 130 case PAN_LEFT:
148 direction_value = -1; 131 direction_value = -1;
149 break; 132 break;
150 } 133 }
151 return SetWebcamParameter(fd_.get(), V4L2_CID_PAN_SPEED, direction_value); 134 callback.Run(
135 SetWebcamParameter(fd_.get(), V4L2_CID_PAN_SPEED, direction_value));
152 } 136 }
153 137
154 bool V4L2Webcam::SetTiltDirection(TiltDirection direction) { 138 void V4L2Webcam::SetTiltDirection(TiltDirection direction,
139 const SetPTZCompleteCallback& callback) {
155 int direction_value = 0; 140 int direction_value = 0;
156 switch (direction) { 141 switch (direction) {
157 case TILT_STOP: 142 case TILT_STOP:
158 direction_value = 0; 143 direction_value = 0;
159 break; 144 break;
160 145
161 case TILT_UP: 146 case TILT_UP:
162 direction_value = 1; 147 direction_value = 1;
163 break; 148 break;
164 149
165 case TILT_DOWN: 150 case TILT_DOWN:
166 direction_value = -1; 151 direction_value = -1;
167 break; 152 break;
168 } 153 }
169 return SetWebcamParameter(fd_.get(), V4L2_CID_TILT_SPEED, direction_value); 154 callback.Run(
155 SetWebcamParameter(fd_.get(), V4L2_CID_TILT_SPEED, direction_value));
156 }
157
158 void V4L2Webcam::Reset(bool pan,
159 bool tilt,
160 bool zoom,
161 const SetPTZCompleteCallback& callback) {
162 bool success = true;
163 if (pan || tilt) {
164 if (EnsureLogitechCommandsMapped()) {
165 success &= SetWebcamParameter(fd_.get(), V4L2_CID_PANTILT_CMD,
Zachary Kuznia 2015/08/19 20:49:44 It's not a good idea to use bitwise AND to combine
xdai1 2015/08/21 22:57:02 Done.
166 kLogitechMenuIndexGoHome);
167 } else {
168 if (pan) {
169 struct v4l2_control v4l2_ctrl = {V4L2_CID_PAN_RESET};
170 success &= HANDLE_EINTR(ioctl(fd_.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
171 }
172
173 if (tilt) {
174 struct v4l2_control v4l2_ctrl = {V4L2_CID_TILT_RESET};
175 success &= HANDLE_EINTR(ioctl(fd_.get(), VIDIOC_S_CTRL, &v4l2_ctrl));
176 }
177 }
178 }
179
180 if (zoom) {
181 const int kDefaultZoom = 100;
182 success &=
183 SetWebcamParameter(fd_.get(), V4L2_CID_ZOOM_ABSOLUTE, kDefaultZoom);
184 }
185
186 callback.Run(success);
170 } 187 }
171 188
172 } // namespace extensions 189 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698