blob: 4a8057d3f26b59cc9a6303846228fb67c2029639 [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera;
18
Sascha Haeberling8e963a52013-08-06 11:43:02 -070019import java.io.IOException;
20
Michael Kolb8872c232013-01-29 10:33:22 -080021import android.annotation.TargetApi;
22import android.graphics.SurfaceTexture;
Angus Kong9e765522013-07-31 14:05:20 -070023import android.hardware.Camera;
Michael Kolb8872c232013-01-29 10:33:22 -080024import android.hardware.Camera.ErrorCallback;
Michael Kolb8872c232013-01-29 10:33:22 -080025import android.hardware.Camera.OnZoomChangeListener;
26import android.hardware.Camera.Parameters;
Michael Kolb8872c232013-01-29 10:33:22 -080027import android.os.Handler;
Angus Kongdcb0ef12013-03-25 23:11:43 -070028import android.view.SurfaceHolder;
Michael Kolb8872c232013-01-29 10:33:22 -080029
Angus Kongb50b5cb2013-08-09 14:55:20 -070030import com.android.camera.util.ApiHelper;
Michael Kolb8872c232013-01-29 10:33:22 -080031
Angus Kong9ef99252013-07-18 18:04:19 -070032/**
Angus Kong9e765522013-07-31 14:05:20 -070033 * An interface which provides possible camera device operations.
Angus Kong9ef99252013-07-18 18:04:19 -070034 *
35 * The client should call {@code CameraManager.cameraOpen} to get an instance
36 * of {@link CameraManager.CameraProxy} to control the camera. Classes
37 * implementing this interface should have its own one unique {@code Thread}
38 * other than the main thread for camera operations. Camera device callbacks
39 * are wrapped since the client should not deal with
40 * {@code android.hardware.Camera} directly.
41 *
42 * TODO: provide callback interfaces for:
43 * {@code android.hardware.Camera.ErrorCallback},
Angus Kong9ef99252013-07-18 18:04:19 -070044 * {@code android.hardware.Camera.OnZoomChangeListener}, and
45 * {@code android.hardware.Camera.Parameters}.
46 */
47public interface CameraManager {
Michael Kolb8872c232013-01-29 10:33:22 -080048
Angus Kong9ef99252013-07-18 18:04:19 -070049 /**
50 * An interface which wraps
51 * {@link android.hardware.Camera.AutoFocusCallback}.
52 */
53 public interface CameraAFCallback {
54 public void onAutoFocus(boolean focused, CameraProxy camera);
Angus Kongdcb0ef12013-03-25 23:11:43 -070055 }
56
Angus Kong9ef99252013-07-18 18:04:19 -070057 /**
58 * An interface which wraps
59 * {@link android.hardware.Camera.AutoFocusMoveCallback}.
60 */
61 public interface CameraAFMoveCallback {
62 public void onAutoFocusMoving(boolean moving, CameraProxy camera);
Michael Kolb8872c232013-01-29 10:33:22 -080063 }
64
Angus Kong9ef99252013-07-18 18:04:19 -070065 /**
66 * An interface which wraps
67 * {@link android.hardware.Camera.ShutterCallback}.
68 */
69 public interface CameraShutterCallback {
70 public void onShutter(CameraProxy camera);
Michael Kolb8872c232013-01-29 10:33:22 -080071 }
72
Angus Kong9ef99252013-07-18 18:04:19 -070073 /**
74 * An interface which wraps
75 * {@link android.hardware.Camera.PictureCallback}.
76 */
77 public interface CameraPictureCallback {
78 public void onPictureTaken(byte[] data, CameraProxy camera);
79 }
Michael Kolb8872c232013-01-29 10:33:22 -080080
Angus Kong9ef99252013-07-18 18:04:19 -070081 /**
82 * An interface which wraps
83 * {@link android.hardware.Camera.PreviewCallback}.
84 */
85 public interface CameraPreviewDataCallback {
86 public void onPreviewFrame(byte[] data, CameraProxy camera);
87 }
Michael Kolb8872c232013-01-29 10:33:22 -080088
Angus Kong9ef99252013-07-18 18:04:19 -070089 /**
Angus Kong9e765522013-07-31 14:05:20 -070090 * An interface which wraps
91 * {@link android.hardware.Camera.FaceDetectionListener}.
92 */
93 public interface CameraFaceDetectionCallback {
94 /**
95 * Callback for face detection.
96 *
97 * @param faces Recognized face in the preview.
98 * @param camera The camera which the preview image comes from.
99 */
100 public void onFaceDetection(Camera.Face[] faces, CameraProxy camera);
101 }
102
103 /**
Angus Kong9ef99252013-07-18 18:04:19 -0700104 * Opens the camera of the specified ID synchronously.
105 *
106 * @param cameraId The camera ID to open.
107 * @return An instance of {@link CameraProxy} on success. null on failure.
108 */
109 public CameraProxy cameraOpen(int cameraId);
Michael Kolb8872c232013-01-29 10:33:22 -0800110
Angus Kong9ef99252013-07-18 18:04:19 -0700111 /**
112 * An interface that takes camera operation requests and post messages to the
113 * camera handler thread. All camera operations made through this interface is
114 * asynchronous by default except those mentioned specifically.
115 */
116 public interface CameraProxy {
Michael Kolb8872c232013-01-29 10:33:22 -0800117
Angus Kong9ef99252013-07-18 18:04:19 -0700118 /**
119 * Returns the underlying {@link android.hardware.Camera} object used
120 * by this proxy. This method should only be used when handing the
121 * camera device over to {@link android.media.MediaRecorder} for
122 * recording.
Michael Kolb8872c232013-01-29 10:33:22 -0800123 */
Angus Kong9ef99252013-07-18 18:04:19 -0700124 public android.hardware.Camera getCamera();
Michael Kolb8872c232013-01-29 10:33:22 -0800125
Angus Kong9ef99252013-07-18 18:04:19 -0700126 /**
127 * Releases the camera device synchronously.
128 * This function must be synchronous so the caller knows exactly when the camera
129 * is released and can continue on.
130 */
131 public void release();
Michael Kolb8872c232013-01-29 10:33:22 -0800132
Angus Kong9ef99252013-07-18 18:04:19 -0700133 /**
134 * Reconnects to the camera device.
135 *
136 * @see android.hardware.Camera#reconnect()
137 */
138 public void reconnect() throws IOException;
Michael Kolb8872c232013-01-29 10:33:22 -0800139
Angus Kong9ef99252013-07-18 18:04:19 -0700140 /**
141 * Unlocks the camera device.
142 *
143 * @see android.hardware.Camera#unlock()
144 */
145 public void unlock();
Michael Kolb8872c232013-01-29 10:33:22 -0800146
Angus Kong9ef99252013-07-18 18:04:19 -0700147 /**
148 * Locks the camera device.
149 * @see android.hardware.Camera#lock()
150 */
151 public void lock();
Michael Kolb8872c232013-01-29 10:33:22 -0800152
Angus Kong9ef99252013-07-18 18:04:19 -0700153 /**
154 * Sets the {@link android.graphics.SurfaceTexture} for preview.
155 *
156 * @param surfaceTexture The {@link SurfaceTexture} for preview.
157 */
Michael Kolb8872c232013-01-29 10:33:22 -0800158 @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
Angus Kong9ef99252013-07-18 18:04:19 -0700159 public void setPreviewTexture(final SurfaceTexture surfaceTexture);
Michael Kolb8872c232013-01-29 10:33:22 -0800160
Angus Kong9ef99252013-07-18 18:04:19 -0700161 /**
162 * Sets the {@link android.view.SurfaceHolder} for preview.
163 *
164 * @param surfaceHolder The {@link SurfaceHolder} for preview.
165 */
166 public void setPreviewDisplay(final SurfaceHolder surfaceHolder);
Michael Kolb8872c232013-01-29 10:33:22 -0800167
Angus Kong9ef99252013-07-18 18:04:19 -0700168 /**
169 * Starts the camera preview.
170 */
171 public void startPreview();
Michael Kolb8872c232013-01-29 10:33:22 -0800172
Angus Kong9ef99252013-07-18 18:04:19 -0700173 /**
174 * Stops the camera preview synchronously.
175 * {@code stopPreview()} must be synchronous to ensure that the caller can
176 * continues to release resources related to camera preview.
177 */
178 public void stopPreview();
Michael Kolb8872c232013-01-29 10:33:22 -0800179
Angus Kong9ef99252013-07-18 18:04:19 -0700180 /**
181 * Sets the callback for preview data.
182 *
183 * @param handler handler in which the callback was handled.
184 * @param cb The callback to be invoked when the preview data is available.
185 * @see android.hardware.Camera#setPreviewCallback(android.hardware.Camera.PreviewCallback)
186 */
187 public void setPreviewDataCallback(Handler handler, CameraPreviewDataCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800188
Angus Kong9ef99252013-07-18 18:04:19 -0700189 /**
190 * Sets the callback for preview data.
191 *
192 * @param handler The handler in which the callback will be invoked.
193 * @param cb The callback to be invoked when the preview data is available.
194 * @see android.hardware.Camera#setPreviewCallbackWithBuffer(android.hardware.Camera.PreviewCallback)
195 */
196 public void setPreviewDataCallbackWithBuffer(Handler handler, CameraPreviewDataCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800197
Angus Kong9ef99252013-07-18 18:04:19 -0700198 /**
199 * Adds buffer for the preview callback.
200 *
201 * @param callbackBuffer The buffer allocated for the preview data.
202 */
203 public void addCallbackBuffer(byte[] callbackBuffer);
Michael Kolb8872c232013-01-29 10:33:22 -0800204
Angus Kong9ef99252013-07-18 18:04:19 -0700205 /**
206 * Starts the auto-focus process. The result will be returned through the callback.
207 *
208 * @param handler The handler in which the callback will be invoked.
209 * @param cb The auto-focus callback.
210 */
211 public void autoFocus(Handler handler, CameraAFCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800212
Angus Kong9ef99252013-07-18 18:04:19 -0700213 /**
214 * Cancels the auto-focus process.
215 */
216 public void cancelAutoFocus();
Michael Kolb8872c232013-01-29 10:33:22 -0800217
Angus Kong9ef99252013-07-18 18:04:19 -0700218 /**
219 * Sets the auto-focus callback
220 *
221 * @param handler The handler in which the callback will be invoked.
222 * @param cb The callback to be invoked when the preview data is available.
223 */
Michael Kolb8872c232013-01-29 10:33:22 -0800224 @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
Angus Kong9ef99252013-07-18 18:04:19 -0700225 public void setAutoFocusMoveCallback(Handler handler, CameraAFMoveCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800226
Angus Kong9ef99252013-07-18 18:04:19 -0700227 /**
228 * Instrument the camera to take a picture.
229 *
230 * @param handler The handler in which the callback will be invoked.
231 * @param shutter The callback for shutter action, may be null.
232 * @param raw The callback for uncompressed data, may be null.
233 * @param postview The callback for postview image data, may be null.
234 * @param jpeg The callback for jpeg image data, may be null.
235 * @see android.hardware.Camera#takePicture(
236 * android.hardware.Camera.ShutterCallback,
237 * android.hardware.Camera.PictureCallback,
238 * android.hardware.Camera.PictureCallback)
239 */
240 public void takePicture(
241 Handler handler,
242 CameraShutterCallback shutter,
243 CameraPictureCallback raw,
244 CameraPictureCallback postview,
245 CameraPictureCallback jpeg);
Michael Kolb8872c232013-01-29 10:33:22 -0800246
Angus Kong9ef99252013-07-18 18:04:19 -0700247 /**
248 * Sets the display orientation for camera to adjust the preview orientation.
249 *
250 * @param degrees The rotation in degrees. Should be 0, 90, 180 or 270.
251 */
252 public void setDisplayOrientation(int degrees);
Michael Kolb8872c232013-01-29 10:33:22 -0800253
Angus Kong9ef99252013-07-18 18:04:19 -0700254 /**
255 * Sets the listener for zoom change.
256 *
257 * @param listener The listener.
258 */
259 public void setZoomChangeListener(OnZoomChangeListener listener);
Michael Kolb8872c232013-01-29 10:33:22 -0800260
Angus Kong9ef99252013-07-18 18:04:19 -0700261 /**
262 * Sets the face detection listener.
263 *
Angus Kong9e765522013-07-31 14:05:20 -0700264 * @param handler The handler in which the callback will be invoked.
265 * @param callback The callback for face detection results.
Angus Kong9ef99252013-07-18 18:04:19 -0700266 */
Michael Kolb8872c232013-01-29 10:33:22 -0800267 @TargetApi(ApiHelper.VERSION_CODES.ICE_CREAM_SANDWICH)
Angus Kong9e765522013-07-31 14:05:20 -0700268 public void setFaceDetectionCallback(Handler handler, CameraFaceDetectionCallback callback);
Michael Kolb8872c232013-01-29 10:33:22 -0800269
Angus Kong9ef99252013-07-18 18:04:19 -0700270 /**
271 * Starts the face detection.
272 */
273 public void startFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800274
Angus Kong9ef99252013-07-18 18:04:19 -0700275 /**
276 * Stops the face detection.
277 */
278 public void stopFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800279
Angus Kong9ef99252013-07-18 18:04:19 -0700280 /**
281 * Registers an error callback.
282 *
283 * @param cb The error callback.
284 * @see android.hardware.Camera#setErrorCallback(android.hardware.Camera.ErrorCallback)
285 */
286 public void setErrorCallback(ErrorCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800287
Angus Kong9ef99252013-07-18 18:04:19 -0700288 /**
289 * Sets the camera parameters.
290 *
291 * @param params The camera parameters to use.
292 */
293 public void setParameters(Parameters params);
Michael Kolb8872c232013-01-29 10:33:22 -0800294
Angus Kong9ef99252013-07-18 18:04:19 -0700295 /**
296 * Gets the current camera parameters synchronously. This method is
297 * synchronous since the caller has to wait for the camera to return
298 * the parameters. If the parameters are already cached, it returns
299 * immediately.
300 */
301 public Parameters getParameters();
Michael Kolb8872c232013-01-29 10:33:22 -0800302
Angus Kong9ef99252013-07-18 18:04:19 -0700303 /**
304 * Forces {@code CameraProxy} to update the cached version of the camera
305 * parameters regardless of the dirty bit.
306 */
307 public void refreshParameters();
Angus Kong104e0012013-04-03 16:56:18 -0700308
Angus Kong9ef99252013-07-18 18:04:19 -0700309 /**
310 * Enables/Disables the camera shutter sound.
311 *
312 * @param enable {@code true} to enable the shutter sound,
313 * {@code false} to disable it.
314 */
315 public void enableShutterSound(boolean enable);
Michael Kolb8872c232013-01-29 10:33:22 -0800316 }
317}