Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.camera; |
| 18 | |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 21 | import android.annotation.TargetApi; |
| 22 | import android.graphics.SurfaceTexture; |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 23 | import android.hardware.Camera; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 24 | import android.hardware.Camera.ErrorCallback; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 25 | import android.hardware.Camera.OnZoomChangeListener; |
| 26 | import android.hardware.Camera.Parameters; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 27 | import android.os.Handler; |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 28 | import android.view.SurfaceHolder; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 29 | |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 30 | import com.android.camera.util.ApiHelper; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 31 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 32 | /** |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 33 | * An interface which provides possible camera device operations. |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 34 | * |
| 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 Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 44 | * {@code android.hardware.Camera.OnZoomChangeListener}, and |
| 45 | * {@code android.hardware.Camera.Parameters}. |
| 46 | */ |
| 47 | public interface CameraManager { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 48 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 49 | /** |
| 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 Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 57 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 65 | /** |
| 66 | * An interface which wraps |
| 67 | * {@link android.hardware.Camera.ShutterCallback}. |
| 68 | */ |
| 69 | public interface CameraShutterCallback { |
| 70 | public void onShutter(CameraProxy camera); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 73 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 80 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 81 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 88 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 89 | /** |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 90 | * 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 Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 104 | * 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 110 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 111 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 117 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 118 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 123 | */ |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 124 | public android.hardware.Camera getCamera(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 125 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 126 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 132 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Reconnects to the camera device. |
| 135 | * |
| 136 | * @see android.hardware.Camera#reconnect() |
| 137 | */ |
| 138 | public void reconnect() throws IOException; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 139 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Unlocks the camera device. |
| 142 | * |
| 143 | * @see android.hardware.Camera#unlock() |
| 144 | */ |
| 145 | public void unlock(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 146 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 147 | /** |
| 148 | * Locks the camera device. |
| 149 | * @see android.hardware.Camera#lock() |
| 150 | */ |
| 151 | public void lock(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 152 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 153 | /** |
| 154 | * Sets the {@link android.graphics.SurfaceTexture} for preview. |
| 155 | * |
| 156 | * @param surfaceTexture The {@link SurfaceTexture} for preview. |
| 157 | */ |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 158 | @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB) |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 159 | public void setPreviewTexture(final SurfaceTexture surfaceTexture); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 160 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 161 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 167 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 168 | /** |
| 169 | * Starts the camera preview. |
| 170 | */ |
| 171 | public void startPreview(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 172 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 173 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 179 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 180 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 188 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 189 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 197 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 198 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 204 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 205 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 212 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Cancels the auto-focus process. |
| 215 | */ |
| 216 | public void cancelAutoFocus(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 217 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 218 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 224 | @TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN) |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 225 | public void setAutoFocusMoveCallback(Handler handler, CameraAFMoveCallback cb); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 226 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 227 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 246 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 247 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 253 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 254 | /** |
| 255 | * Sets the listener for zoom change. |
| 256 | * |
| 257 | * @param listener The listener. |
| 258 | */ |
| 259 | public void setZoomChangeListener(OnZoomChangeListener listener); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 260 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 261 | /** |
| 262 | * Sets the face detection listener. |
| 263 | * |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 264 | * @param handler The handler in which the callback will be invoked. |
| 265 | * @param callback The callback for face detection results. |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 266 | */ |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 267 | @TargetApi(ApiHelper.VERSION_CODES.ICE_CREAM_SANDWICH) |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 268 | public void setFaceDetectionCallback(Handler handler, CameraFaceDetectionCallback callback); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 269 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 270 | /** |
| 271 | * Starts the face detection. |
| 272 | */ |
| 273 | public void startFaceDetection(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 274 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 275 | /** |
| 276 | * Stops the face detection. |
| 277 | */ |
| 278 | public void stopFaceDetection(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 279 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 280 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 287 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Sets the camera parameters. |
| 290 | * |
| 291 | * @param params The camera parameters to use. |
| 292 | */ |
| 293 | public void setParameters(Parameters params); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 294 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 295 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 302 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 303 | /** |
| 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 Kong | 104e001 | 2013-04-03 16:56:18 -0700 | [diff] [blame] | 308 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 309 | /** |
| 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 Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 316 | } |
| 317 | } |