blob: 6c295c8c24b828611e6bfcb04107c3838d500fbd [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
Angus Kong20fad242013-11-11 18:23:46 -080017package com.android.camera.app;
Michael Kolb8872c232013-01-29 10:33:22 -080018
Michael Kolb8872c232013-01-29 10:33:22 -080019import android.annotation.TargetApi;
20import android.graphics.SurfaceTexture;
Angus Kong9e765522013-07-31 14:05:20 -070021import android.hardware.Camera;
Michael Kolb8872c232013-01-29 10:33:22 -080022import android.hardware.Camera.OnZoomChangeListener;
23import android.hardware.Camera.Parameters;
Sascha Haeberling638e6f02013-09-18 14:28:51 -070024import android.os.Build;
Michael Kolb8872c232013-01-29 10:33:22 -080025import android.os.Handler;
Angus Kongdcb0ef12013-03-25 23:11:43 -070026import android.view.SurfaceHolder;
Michael Kolb8872c232013-01-29 10:33:22 -080027
Angus Kong9ef99252013-07-18 18:04:19 -070028/**
Angus Kong9e765522013-07-31 14:05:20 -070029 * An interface which provides possible camera device operations.
Angus Kong9ef99252013-07-18 18:04:19 -070030 *
31 * The client should call {@code CameraManager.cameraOpen} to get an instance
32 * of {@link CameraManager.CameraProxy} to control the camera. Classes
33 * implementing this interface should have its own one unique {@code Thread}
34 * other than the main thread for camera operations. Camera device callbacks
35 * are wrapped since the client should not deal with
36 * {@code android.hardware.Camera} directly.
37 *
38 * TODO: provide callback interfaces for:
39 * {@code android.hardware.Camera.ErrorCallback},
Angus Kong9ef99252013-07-18 18:04:19 -070040 * {@code android.hardware.Camera.OnZoomChangeListener}, and
41 * {@code android.hardware.Camera.Parameters}.
42 */
43public interface CameraManager {
Michael Kolb8872c232013-01-29 10:33:22 -080044
Angus Kong9ef99252013-07-18 18:04:19 -070045 /**
Erin Dahlgren630d55b2014-03-10 14:40:59 -070046 * A handler for all camera api runtime exceptions.
47 * The default behavior is to throw the runtime exception.
48 */
49 public interface CameraExceptionCallback {
50 public void onCameraException(RuntimeException e);
51 }
52
53 /**
Angus Kong9ef99252013-07-18 18:04:19 -070054 * An interface which wraps
Angus Kong2bca2102014-03-11 16:27:30 -070055 * {@link android.hardware.Camera.ErrorCallback}
56 */
57 public interface CameraErrorCallback {
58 public void onError(int error, CameraProxy camera);
59 }
60
61 /**
62 * An interface which wraps
Angus Kong9ef99252013-07-18 18:04:19 -070063 * {@link android.hardware.Camera.AutoFocusCallback}.
64 */
65 public interface CameraAFCallback {
66 public void onAutoFocus(boolean focused, CameraProxy camera);
Angus Kongdcb0ef12013-03-25 23:11:43 -070067 }
68
Angus Kong9ef99252013-07-18 18:04:19 -070069 /**
70 * An interface which wraps
71 * {@link android.hardware.Camera.AutoFocusMoveCallback}.
72 */
73 public interface CameraAFMoveCallback {
74 public void onAutoFocusMoving(boolean moving, CameraProxy camera);
Michael Kolb8872c232013-01-29 10:33:22 -080075 }
76
Angus Kong9ef99252013-07-18 18:04:19 -070077 /**
78 * An interface which wraps
79 * {@link android.hardware.Camera.ShutterCallback}.
80 */
81 public interface CameraShutterCallback {
82 public void onShutter(CameraProxy camera);
Michael Kolb8872c232013-01-29 10:33:22 -080083 }
84
Angus Kong9ef99252013-07-18 18:04:19 -070085 /**
86 * An interface which wraps
87 * {@link android.hardware.Camera.PictureCallback}.
88 */
89 public interface CameraPictureCallback {
90 public void onPictureTaken(byte[] data, CameraProxy camera);
91 }
Michael Kolb8872c232013-01-29 10:33:22 -080092
Angus Kong9ef99252013-07-18 18:04:19 -070093 /**
94 * An interface which wraps
95 * {@link android.hardware.Camera.PreviewCallback}.
96 */
97 public interface CameraPreviewDataCallback {
98 public void onPreviewFrame(byte[] data, CameraProxy camera);
99 }
Michael Kolb8872c232013-01-29 10:33:22 -0800100
Angus Kong9ef99252013-07-18 18:04:19 -0700101 /**
Angus Kong9e765522013-07-31 14:05:20 -0700102 * An interface which wraps
103 * {@link android.hardware.Camera.FaceDetectionListener}.
104 */
105 public interface CameraFaceDetectionCallback {
106 /**
107 * Callback for face detection.
108 *
109 * @param faces Recognized face in the preview.
110 * @param camera The camera which the preview image comes from.
111 */
112 public void onFaceDetection(Camera.Face[] faces, CameraProxy camera);
113 }
114
115 /**
Angus Kong4f795b82013-09-16 14:25:35 -0700116 * An interface to be called for any exception caught when opening the
117 * camera device. This error callback is different from the one defined
118 * in the framework, {@link android.hardware.Camera.ErrorCallback}, which
119 * is used after the camera is opened.
120 */
Angus Kong62848152013-11-08 17:25:29 -0800121 public interface CameraOpenCallback {
122 /**
123 * Callback when camera open succeeds.
124 */
125 public void onCameraOpened(CameraProxy camera);
126
Angus Kong4f795b82013-09-16 14:25:35 -0700127 /**
128 * Callback when {@link com.android.camera.CameraDisabledException} is
129 * caught.
130 *
131 * @param cameraId The disabled camera.
132 */
133 public void onCameraDisabled(int cameraId);
134
135 /**
136 * Callback when {@link com.android.camera.CameraHardwareException} is
137 * caught.
138 *
139 * @param cameraId The camera with the hardware failure.
140 */
141 public void onDeviceOpenFailure(int cameraId);
142
143 /**
Angus Kong62753ae2014-02-10 10:53:54 -0800144 * Callback when trying to open the camera which is already opened.
145 *
146 * @param cameraId The camera which is causing the open error.
147 */
148 public void onDeviceOpenedAlready(int cameraId);
149
150 /**
Angus Kong4f795b82013-09-16 14:25:35 -0700151 * Callback when {@link java.io.IOException} is caught during
152 * {@link android.hardware.Camera#reconnect()}.
153 *
Angus Kong20fad242013-11-11 18:23:46 -0800154 * @param mgr The {@link CameraManager}
Angus Kong4f795b82013-09-16 14:25:35 -0700155 * with the reconnect failure.
156 */
157 public void onReconnectionFailure(CameraManager mgr);
158 }
159
160 /**
Angus Kong20fad242013-11-11 18:23:46 -0800161 * Opens the camera of the specified ID asynchronously. The camera device
162 * will be opened in the camera handler thread and will be returned through
163 * the {@link CameraManager.CameraOpenCallback#
164 * onCameraOpened(com.android.camera.app.CameraManager.CameraProxy)}.
Angus Kong9ef99252013-07-18 18:04:19 -0700165 *
Angus Kong4f795b82013-09-16 14:25:35 -0700166 * @param handler The {@link android.os.Handler} in which the callback
167 * was handled.
168 * @param callback The callback when any error happens.
169 * @param cameraId The camera ID to open.
Angus Kong9ef99252013-07-18 18:04:19 -0700170 */
Angus Kong20fad242013-11-11 18:23:46 -0800171 public void cameraOpen(Handler handler, int cameraId, CameraOpenCallback callback);
172
Angus Kong9ef99252013-07-18 18:04:19 -0700173 /**
174 * An interface that takes camera operation requests and post messages to the
175 * camera handler thread. All camera operations made through this interface is
176 * asynchronous by default except those mentioned specifically.
177 */
178 public interface CameraProxy {
Michael Kolb8872c232013-01-29 10:33:22 -0800179
Angus Kong9ef99252013-07-18 18:04:19 -0700180 /**
181 * Returns the underlying {@link android.hardware.Camera} object used
182 * by this proxy. This method should only be used when handing the
183 * camera device over to {@link android.media.MediaRecorder} for
184 * recording.
Michael Kolb8872c232013-01-29 10:33:22 -0800185 */
Angus Kong62753ae2014-02-10 10:53:54 -0800186 @Deprecated
Angus Kong9ef99252013-07-18 18:04:19 -0700187 public android.hardware.Camera getCamera();
Michael Kolb8872c232013-01-29 10:33:22 -0800188
Angus Kong9ef99252013-07-18 18:04:19 -0700189 /**
Angus Kong20fad242013-11-11 18:23:46 -0800190 * Returns the camera ID associated to by this
191 * {@link CameraManager.CameraProxy}.
192 * @return
193 */
194 public int getCameraId();
195
196 /**
Angus Kong9ef99252013-07-18 18:04:19 -0700197 * Releases the camera device synchronously.
198 * This function must be synchronous so the caller knows exactly when the camera
199 * is released and can continue on.
Angus Kong20fad242013-11-11 18:23:46 -0800200 * TODO: make this package-private after this interface is refactored under app.
201 *
202 * @param synchronous Whether this call should be synchronous.
Angus Kong9ef99252013-07-18 18:04:19 -0700203 */
Angus Kong20fad242013-11-11 18:23:46 -0800204 public void release(boolean synchronous);
Michael Kolb8872c232013-01-29 10:33:22 -0800205
Angus Kong9ef99252013-07-18 18:04:19 -0700206 /**
Angus Kong20fad242013-11-11 18:23:46 -0800207 * Reconnects to the camera device. On success, the camera device will
208 * be returned through {@link CameraManager
209 * .CameraOpenCallback#onCameraOpened(com.android.camera.app.CameraManager
210 * .CameraProxy)}.
Angus Kong9ef99252013-07-18 18:04:19 -0700211 * @see android.hardware.Camera#reconnect()
Angus Kong4f795b82013-09-16 14:25:35 -0700212 *
213 * @param handler The {@link android.os.Handler} in which the callback
214 * was handled.
215 * @param cb The callback when any error happens.
Angus Kong9ef99252013-07-18 18:04:19 -0700216 */
Angus Kong20fad242013-11-11 18:23:46 -0800217 public void reconnect(Handler handler, CameraOpenCallback cb);
218
Angus Kong9ef99252013-07-18 18:04:19 -0700219 /**
220 * Unlocks the camera device.
221 *
222 * @see android.hardware.Camera#unlock()
223 */
224 public void unlock();
Michael Kolb8872c232013-01-29 10:33:22 -0800225
Angus Kong9ef99252013-07-18 18:04:19 -0700226 /**
227 * Locks the camera device.
228 * @see android.hardware.Camera#lock()
229 */
230 public void lock();
Michael Kolb8872c232013-01-29 10:33:22 -0800231
Angus Kong9ef99252013-07-18 18:04:19 -0700232 /**
233 * Sets the {@link android.graphics.SurfaceTexture} for preview.
234 *
235 * @param surfaceTexture The {@link SurfaceTexture} for preview.
236 */
Angus Kong9ef99252013-07-18 18:04:19 -0700237 public void setPreviewTexture(final SurfaceTexture surfaceTexture);
Michael Kolb8872c232013-01-29 10:33:22 -0800238
Angus Kong9ef99252013-07-18 18:04:19 -0700239 /**
Erin Dahlgrend8de0772014-02-03 10:12:27 -0800240 * Blocks until a {@link android.graphics.SurfaceTexture} has been set
241 * for preview.
242 *
243 * @param surfaceTexture The {@link SurfaceTexture} for preview.
244 */
245 public void setPreviewTextureSync(final SurfaceTexture surfaceTexture);
246
247 /**
Angus Kong9ef99252013-07-18 18:04:19 -0700248 * Sets the {@link android.view.SurfaceHolder} for preview.
249 *
250 * @param surfaceHolder The {@link SurfaceHolder} for preview.
251 */
252 public void setPreviewDisplay(final SurfaceHolder surfaceHolder);
Michael Kolb8872c232013-01-29 10:33:22 -0800253
Angus Kong9ef99252013-07-18 18:04:19 -0700254 /**
255 * Starts the camera preview.
256 */
257 public void startPreview();
Michael Kolb8872c232013-01-29 10:33:22 -0800258
Angus Kong9ef99252013-07-18 18:04:19 -0700259 /**
Erin Dahlgrend05374f2014-03-11 16:23:29 -0700260 * Starts the camera preview and executes a callback on a handler once
261 * the preview starts.
262 */
263 public void startPreviewWithCallback(Handler h, CameraStartPreviewCallback cb);
264
265 /**
Angus Kong9ef99252013-07-18 18:04:19 -0700266 * Stops the camera preview synchronously.
267 * {@code stopPreview()} must be synchronous to ensure that the caller can
268 * continues to release resources related to camera preview.
269 */
270 public void stopPreview();
Michael Kolb8872c232013-01-29 10:33:22 -0800271
Angus Kong9ef99252013-07-18 18:04:19 -0700272 /**
273 * Sets the callback for preview data.
274 *
Angus Kong4f795b82013-09-16 14:25:35 -0700275 * @param handler The {@link android.os.Handler} in which the callback was handled.
Angus Kong9ef99252013-07-18 18:04:19 -0700276 * @param cb The callback to be invoked when the preview data is available.
277 * @see android.hardware.Camera#setPreviewCallback(android.hardware.Camera.PreviewCallback)
278 */
279 public void setPreviewDataCallback(Handler handler, CameraPreviewDataCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800280
Angus Kong9ef99252013-07-18 18:04:19 -0700281 /**
Doris Liu4d4a4bc2013-12-19 18:55:54 -0800282 * Sets the one-time callback for preview data.
283 *
284 * @param handler The {@link android.os.Handler} in which the callback was handled.
285 * @param cb The callback to be invoked when the preview data for
286 * next frame is available.
287 * @see android.hardware.Camera#setPreviewCallback(android.hardware.Camera.PreviewCallback)
288 */
289 public void setOneShotPreviewCallback(Handler handler, CameraPreviewDataCallback cb);
290
291 /**
Angus Kong9ef99252013-07-18 18:04:19 -0700292 * Sets the callback for preview data.
293 *
294 * @param handler The handler in which the callback will be invoked.
295 * @param cb The callback to be invoked when the preview data is available.
296 * @see android.hardware.Camera#setPreviewCallbackWithBuffer(android.hardware.Camera.PreviewCallback)
297 */
298 public void setPreviewDataCallbackWithBuffer(Handler handler, CameraPreviewDataCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800299
Angus Kong9ef99252013-07-18 18:04:19 -0700300 /**
301 * Adds buffer for the preview callback.
302 *
303 * @param callbackBuffer The buffer allocated for the preview data.
304 */
305 public void addCallbackBuffer(byte[] callbackBuffer);
Michael Kolb8872c232013-01-29 10:33:22 -0800306
Angus Kong9ef99252013-07-18 18:04:19 -0700307 /**
308 * Starts the auto-focus process. The result will be returned through the callback.
309 *
310 * @param handler The handler in which the callback will be invoked.
311 * @param cb The auto-focus callback.
312 */
313 public void autoFocus(Handler handler, CameraAFCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800314
Angus Kong9ef99252013-07-18 18:04:19 -0700315 /**
316 * Cancels the auto-focus process.
317 */
318 public void cancelAutoFocus();
Michael Kolb8872c232013-01-29 10:33:22 -0800319
Angus Kong9ef99252013-07-18 18:04:19 -0700320 /**
321 * Sets the auto-focus callback
322 *
323 * @param handler The handler in which the callback will be invoked.
324 * @param cb The callback to be invoked when the preview data is available.
325 */
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700326 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Angus Kong9ef99252013-07-18 18:04:19 -0700327 public void setAutoFocusMoveCallback(Handler handler, CameraAFMoveCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800328
Angus Kong9ef99252013-07-18 18:04:19 -0700329 /**
330 * Instrument the camera to take a picture.
331 *
332 * @param handler The handler in which the callback will be invoked.
333 * @param shutter The callback for shutter action, may be null.
334 * @param raw The callback for uncompressed data, may be null.
335 * @param postview The callback for postview image data, may be null.
336 * @param jpeg The callback for jpeg image data, may be null.
337 * @see android.hardware.Camera#takePicture(
338 * android.hardware.Camera.ShutterCallback,
339 * android.hardware.Camera.PictureCallback,
340 * android.hardware.Camera.PictureCallback)
341 */
342 public void takePicture(
343 Handler handler,
344 CameraShutterCallback shutter,
345 CameraPictureCallback raw,
346 CameraPictureCallback postview,
347 CameraPictureCallback jpeg);
Michael Kolb8872c232013-01-29 10:33:22 -0800348
Angus Kong9ef99252013-07-18 18:04:19 -0700349 /**
350 * Sets the display orientation for camera to adjust the preview orientation.
351 *
352 * @param degrees The rotation in degrees. Should be 0, 90, 180 or 270.
353 */
354 public void setDisplayOrientation(int degrees);
Michael Kolb8872c232013-01-29 10:33:22 -0800355
Angus Kong9ef99252013-07-18 18:04:19 -0700356 /**
357 * Sets the listener for zoom change.
358 *
359 * @param listener The listener.
360 */
361 public void setZoomChangeListener(OnZoomChangeListener listener);
Michael Kolb8872c232013-01-29 10:33:22 -0800362
Angus Kong9ef99252013-07-18 18:04:19 -0700363 /**
364 * Sets the face detection listener.
365 *
Angus Kong9e765522013-07-31 14:05:20 -0700366 * @param handler The handler in which the callback will be invoked.
367 * @param callback The callback for face detection results.
Angus Kong9ef99252013-07-18 18:04:19 -0700368 */
Angus Kong9e765522013-07-31 14:05:20 -0700369 public void setFaceDetectionCallback(Handler handler, CameraFaceDetectionCallback callback);
Michael Kolb8872c232013-01-29 10:33:22 -0800370
Angus Kong9ef99252013-07-18 18:04:19 -0700371 /**
372 * Starts the face detection.
373 */
374 public void startFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800375
Angus Kong9ef99252013-07-18 18:04:19 -0700376 /**
377 * Stops the face detection.
378 */
379 public void stopFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800380
Angus Kong9ef99252013-07-18 18:04:19 -0700381 /**
382 * Registers an error callback.
383 *
Angus Kong2bca2102014-03-11 16:27:30 -0700384 * @param handler The handler on which the callback will be invoked.
Angus Kong9ef99252013-07-18 18:04:19 -0700385 * @param cb The error callback.
386 * @see android.hardware.Camera#setErrorCallback(android.hardware.Camera.ErrorCallback)
387 */
Angus Kong2bca2102014-03-11 16:27:30 -0700388 public void setErrorCallback(Handler handler, CameraErrorCallback cb);
Michael Kolb8872c232013-01-29 10:33:22 -0800389
Angus Kong9ef99252013-07-18 18:04:19 -0700390 /**
391 * Sets the camera parameters.
392 *
393 * @param params The camera parameters to use.
394 */
395 public void setParameters(Parameters params);
Michael Kolb8872c232013-01-29 10:33:22 -0800396
Angus Kong9ef99252013-07-18 18:04:19 -0700397 /**
398 * Gets the current camera parameters synchronously. This method is
399 * synchronous since the caller has to wait for the camera to return
400 * the parameters. If the parameters are already cached, it returns
401 * immediately.
402 */
403 public Parameters getParameters();
Michael Kolb8872c232013-01-29 10:33:22 -0800404
Angus Kong9ef99252013-07-18 18:04:19 -0700405 /**
406 * Forces {@code CameraProxy} to update the cached version of the camera
407 * parameters regardless of the dirty bit.
408 */
409 public void refreshParameters();
Angus Kong104e0012013-04-03 16:56:18 -0700410
Angus Kong9ef99252013-07-18 18:04:19 -0700411 /**
412 * Enables/Disables the camera shutter sound.
413 *
414 * @param enable {@code true} to enable the shutter sound,
415 * {@code false} to disable it.
416 */
417 public void enableShutterSound(boolean enable);
Michael Kolb8872c232013-01-29 10:33:22 -0800418 }
Erin Dahlgren630d55b2014-03-10 14:40:59 -0700419
420 /**
Erin Dahlgrend05374f2014-03-11 16:23:29 -0700421 * An interface to be called when the camera preview has started.
422 */
423 public interface CameraStartPreviewCallback {
424 /**
425 * Callback when the preview starts.
426 */
427 public void onPreviewStarted();
428 }
429
430 /**
Erin Dahlgren630d55b2014-03-10 14:40:59 -0700431 * Sets a callback for handling camera api runtime exceptions on
432 * a handler.
433 */
434 public void setCameraDefaultExceptionCallback(CameraExceptionCallback callback,
435 Handler handler);
Michael Kolb8872c232013-01-29 10:33:22 -0800436}