blob: 24e0a5c34a0743039c5ba362972a576cc4e3c52a [file] [log] [blame]
Sascha Haeberling00c122a2014-07-29 15:46:39 -07001/*
2 * Copyright (C) 2014 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.one;
18
Sascha Haeberlingcbe861e2014-08-21 10:04:35 -070019import android.content.Context;
Sascha Haeberling95817302014-08-26 18:03:22 -070020import android.location.Location;
Sascha Haeberling57bcd922014-07-31 16:05:57 -070021import android.net.Uri;
Sascha Haeberling00c122a2014-07-29 15:46:39 -070022import android.view.Surface;
23
24import com.android.camera.session.CaptureSession;
Sascha Haeberlinge3dfd5a2014-08-05 15:54:42 -070025import com.android.camera.util.Size;
Sascha Haeberling00c122a2014-07-29 15:46:39 -070026
Sascha Haeberling59c784b2014-08-05 10:53:08 -070027import java.io.File;
28
Sascha Haeberling00c122a2014-07-29 15:46:39 -070029/**
30 * OneCamera is a camera API tailored around our Google Camera application
31 * needs. It's not a general purpose API but instead offers an API with exactly
32 * what's needed from the app's side.
33 */
34public interface OneCamera {
35
36 /** Which way the camera is facing. */
37 public static enum Facing {
38 FRONT, BACK;
39 }
40
41 /**
Andy Huibersb8682742014-08-27 15:28:42 -070042 * Auto focus system status; 1:1 mapping from camera2 AF_STATE.
Andy Huibers30ffce02014-07-31 16:31:43 -070043 * <ul>
44 * <li>{@link #INACTIVE}</li>
Andy Huibersb8682742014-08-27 15:28:42 -070045 * <li>{@link #ACTIVE_SCAN}</li>
46 * <li>{@link #ACTIVE_FOCUSED}</li>
47 * <li>{@link #ACTIVE_UNFOCUSED}</li>
48 * <li>{@link #PASSIVE_SCAN}</li>
49 * <li>{@link #PASSIVE_FOCUSED}</li>
50 * <li>{@link #PASSIVE_UNFOCUSED}</li>
Andy Huibers30ffce02014-07-31 16:31:43 -070051 * </ul>
52 */
53 public static enum AutoFocusState {
54 /** Indicates AF system is inactive for some reason (could be an error). */
55 INACTIVE,
Andy Huibersb8682742014-08-27 15:28:42 -070056 /** Indicates active scan in progress. */
57 ACTIVE_SCAN,
58 /** Indicates active scan success (in focus). */
59 ACTIVE_FOCUSED,
60 /** Indicates active scan failure (not in focus). */
61 ACTIVE_UNFOCUSED,
62 /** Indicates passive scan in progress. */
63 PASSIVE_SCAN,
64 /** Indicates passive scan success (in focus). */
65 PASSIVE_FOCUSED,
66 /** Indicates passive scan failure (not in focus). */
67 PASSIVE_UNFOCUSED
Andy Huibers30ffce02014-07-31 16:31:43 -070068 }
69
70 /**
71 * Auto focus system mode.
72 * <ul>
73 * <li>{@link #CONTINUOUS_PICTURE}</li>
74 * <li>{@link #AUTO}</li>
75 * </ul>
76 */
77 public static enum AutoFocusMode {
78 /** System is continuously focusing. */
79 CONTINUOUS_PICTURE,
80 /** System is running a triggered scan. */
81 AUTO
82 }
83
84 /**
Sascha Haeberling00c122a2014-07-29 15:46:39 -070085 * Classes implementing this interface will be called when the camera was
86 * opened or failed to open.
87 */
88 public static interface OpenCallback {
89 /**
90 * Called when the camera was opened successfully.
91 *
92 * @param camera the camera instance that was successfully opened
93 */
94 public void onCameraOpened(OneCamera camera);
95
96 /**
97 * Called if opening the camera failed.
98 */
99 public void onFailure();
Puneet Lall022ce612014-09-25 21:35:15 -0700100
101 /**
102 * Called if the camera is closed or disconnected while attempting to
103 * open.
104 */
105 public void onCameraClosed();
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700106 }
107
108 /**
109 * Classes implementing this interface will be called when the camera was
110 * closed.
111 */
112 public static interface CloseCallback {
113 /** Called when the camera was fully closed. */
114 public void onCameraClosed();
115 }
116
117 /**
118 * Classes implementing this interface can be informed when we're ready to
119 * take a picture of if setting up the capture pipeline failed.
120 */
121 public static interface CaptureReadyCallback {
122 /** After this is called, the system is ready for capture requests. */
123 public void onReadyForCapture();
124
125 /**
126 * Indicates that something went wrong during setup and the system is
127 * not ready for capture requests.
128 */
129 public void onSetupFailed();
130 }
131
132 /**
Sascha Haeberlinge3ad4352014-08-15 10:52:37 -0700133 * Classes implementing this interface can be informed when the state of
134 * capture changes.
135 */
136 public static interface ReadyStateChangedListener {
137 /**
138 * Called when the camera is either ready or not ready to take a picture
139 * right now.
140 */
141 public void onReadyStateChanged(boolean readyForCapture);
142 }
143
144 /**
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700145 * A class implementing this interface can be passed into the call to take a
Sascha Haeberling8c34b302014-07-29 16:02:52 -0700146 * picture in order to receive the resulting image or updated about the
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700147 * progress.
148 */
149 public static interface PictureCallback {
150 /**
Andy Huibers17d90842014-08-28 15:05:57 -0700151 * Called near the the when an image is being exposed for cameras which
152 * are exposing a single frame, so that a UI can be presented for the
153 * capture.
154 */
155 public void onQuickExpose();
156
157 /**
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700158 * Called when a thumbnail image is provided before the final image is
159 * finished.
160 */
Sascha Haeberlingc7beaf12014-10-27 17:53:12 -0700161 public void onThumbnailResult(byte[] jpegData);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700162
163 /**
164 * Called when the final picture is done taking
165 *
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700166 * @param session the capture session
167 */
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700168 public void onPictureTaken(CaptureSession session);
169
170 /**
171 * Called when the picture has been saved to disk.
172 *
Sascha Haeberlinge3ad4352014-08-15 10:52:37 -0700173 * @param uri the URI of the stored data.
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700174 */
175 public void onPictureSaved(Uri uri);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700176
177 /**
178 * Called when picture taking failed.
179 */
180 public void onPictureTakenFailed();
181
182 /**
Sascha Haeberling90f15832014-08-20 16:14:29 -0700183 * Called when capture session is reporting a processing update. This
184 * should only be called by capture sessions that require the user to
185 * hold still for a while.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700186 *
Sascha Haeberling90f15832014-08-20 16:14:29 -0700187 * @param progress a value from 0...1, indicating the current processing
188 * progress.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700189 */
Sascha Haeberling90f15832014-08-20 16:14:29 -0700190 public void onTakePictureProgress(float progress);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700191 }
192
193 /**
194 * Classes implementing this interface will be called whenever the camera
195 * encountered an error.
196 */
197 public static interface CameraErrorListener {
198 /** Called when the camera encountered an error. */
199 public void onCameraError();
200 }
201
202 /**
203 * Classes implementing this interface will be called when the state of the
Sascha Haeberlinge3ad4352014-08-15 10:52:37 -0700204 * focus changes. Guaranteed not to stay stuck in scanning state past some
Andy Huibers30ffce02014-07-31 16:31:43 -0700205 * reasonable timeout even if Camera API is stuck.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700206 */
207 public static interface FocusStateListener {
208 /**
Andy Huibersb8682742014-08-27 15:28:42 -0700209 * Called when state of auto focus system changes.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700210 *
Andy Huibersb8682742014-08-27 15:28:42 -0700211 * @param state Current auto focus state.
Andy Huibersca3c5642014-09-06 20:44:25 -0700212 * @param frameNumber Frame number if available.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700213 */
Andy Huibersca3c5642014-09-06 20:44:25 -0700214 public void onFocusStatusUpdate(AutoFocusState state, long frameNumber);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700215 }
216
217 /**
218 * Parameters to be given to photo capture requests.
219 */
220 public static final class PhotoCaptureParameters {
Sascha Haeberling0cf4a022014-07-31 11:36:58 -0700221 /**
222 * Flash modes.
223 * <p>
224 * Has to be in sync with R.arrays.pref_camera_flashmode_entryvalues.
225 */
226 public static enum Flash {
227 AUTO, OFF, ON
228 }
229
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700230 /** The title/filename (without suffix) for this capture. */
231 public String title = null;
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700232 /** Called when the capture is completed or failed. */
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700233 public PictureCallback callback = null;
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700234 /** The device orientation so we can compute the right JPEG rotation. */
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700235 public int orientation = Integer.MIN_VALUE;
236 /** The heading of the device at time of capture. In degrees. */
237 public int heading = Integer.MIN_VALUE;
Sascha Haeberling0cf4a022014-07-31 11:36:58 -0700238 /** Flash mode for this capture. */
239 public Flash flashMode = Flash.AUTO;
Sascha Haeberling95817302014-08-26 18:03:22 -0700240 /** The location of this capture. */
241 public Location location = null;
Andy Huibers7a02c112014-10-02 14:56:34 -0700242 /** Zoom value. */
243 public float zoom = 1f;
244 /** Timer duration in seconds or null for no timer. */
245 public Float timerSeconds = null;
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700246
Sascha Haeberling59c784b2014-08-05 10:53:08 -0700247 /** Set this to provide a debug folder for this capture. */
248 public File debugDataFolder;
249
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700250 /**
251 * Checks whether all required values are set. If one is missing, it
252 * throws a {@link RuntimeException}.
253 */
254 public void checkSanity() {
255 checkRequired(title);
256 checkRequired(callback);
257 checkRequired(orientation);
258 checkRequired(heading);
259 }
260
261 private void checkRequired(int num) {
262 if (num == Integer.MIN_VALUE) {
263 throw new RuntimeException("Photo capture parameter missing.");
264 }
265 }
266
267 private void checkRequired(Object obj) {
268 if (obj == null) {
269 throw new RuntimeException("Photo capture parameter missing.");
270 }
271 }
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700272 }
273
274 /**
Andy Huibers30ffce02014-07-31 16:31:43 -0700275 * Meters and triggers auto focus scan with ROI around tap point.
276 * <p/>
Jiawen Chen09713762014-09-16 17:05:37 -0700277 * Normalized coordinates are referenced to portrait preview window with
278 * (0, 0) top left and (1, 1) bottom right. Rotation has no effect.
Andy Huibers30ffce02014-07-31 16:31:43 -0700279 *
280 * @param nx normalized x coordinate.
Jiawen Chen09713762014-09-16 17:05:37 -0700281 * @param ny normalized y coordinate.
Andy Huibers30ffce02014-07-31 16:31:43 -0700282 */
283 public void triggerFocusAndMeterAtPoint(float nx, float ny);
284
285 /**
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700286 * Call this to take a picture.
287 *
288 * @param params parameters for taking pictures.
Sascha Haeberling57bcd922014-07-31 16:05:57 -0700289 * @param session the capture session for this picture.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700290 */
291 public void takePicture(PhotoCaptureParameters params, CaptureSession session);
292
293 /**
Sascha Haeberling8c34b302014-07-29 16:02:52 -0700294 * Sets or replaces a listener that is called whenever the camera encounters
295 * an error.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700296 */
Sascha Haeberling8c34b302014-07-29 16:02:52 -0700297 public void setCameraErrorListener(CameraErrorListener listener);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700298
299 /**
Sascha Haeberling8c34b302014-07-29 16:02:52 -0700300 * Sets or replaces a listener that is called whenever the focus state of
301 * the camera changes.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700302 */
Sascha Haeberling8c34b302014-07-29 16:02:52 -0700303 public void setFocusStateListener(FocusStateListener listener);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700304
305 /**
Sascha Haeberlinge3ad4352014-08-15 10:52:37 -0700306 * Sets or replaces a listener that is called whenever the state of the
307 * camera changes to be either ready or not ready to take another picture.
308 */
309 public void setReadyStateChangedListener(ReadyStateChangedListener listener);
310
311 /**
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700312 * Starts a preview stream and renders it to the given surface.
313 */
314 public void startPreview(Surface surface, CaptureReadyCallback listener);
315
316 /**
317 * Sets the size of the viewfinder.
318 * <p>
319 * The preview size requested from the camera device will depend on this as
320 * well as the requested photo/video aspect ratio.
321 */
Jiawen Chen9cefdd42014-09-09 14:14:39 -0700322 public void setViewfinderSize(int width, int height);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700323
324 /**
325 * @return Whether this camera supports flash.
326 * @param if true, returns whether flash is supported in enhanced mode. If
327 * false, whether flash is supported in normal capture mode.
328 */
329 public boolean isFlashSupported(boolean enhanced);
330
331 /**
332 * @return Whether this camera supports enhanced mode, such as HDR.
333 */
334 public boolean isSupportingEnhancedMode();
335
336 /**
337 * Closes the camera.
338 *
339 * @param closeCallback Optional. Called as soon as the camera is fully
340 * closed.
341 */
342 public void close(CloseCallback closeCallback);
343
344 /**
Sascha Haeberlingc6da1a12014-11-06 09:50:51 -0800345 * @return A list of all supported preview resolutions.
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700346 */
Sascha Haeberlingc6da1a12014-11-06 09:50:51 -0800347 public Size[] getSupportedPreviewSizes();
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700348
349 /**
350 * @return The aspect ratio of the full size capture (usually the native
351 * resolution of the camera).
352 */
Jiawen Chen9cefdd42014-09-09 14:14:39 -0700353 public float getFullSizeAspectRatio();
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700354
355 /**
356 * @return Whether this camera is facing to the back.
357 */
358 public boolean isBackFacing();
359
360 /**
361 * @return Whether this camera is facing to the front.
362 */
363 public boolean isFrontFacing();
Andy Huibers26b33342014-08-20 00:02:19 -0700364
365 /**
366 * Get the maximum zoom value.
367 *
368 * @return A float number to represent the maximum zoom value(>= 1.0).
369 */
370 public float getMaxZoom();
371
372 /**
373 * This function sets the current zoom ratio value.
374 * <p>
Sascha Haeberling90f15832014-08-20 16:14:29 -0700375 * The zoom range must be [1.0, maxZoom]. The maxZoom can be queried by
376 * {@link #getMaxZoom}.
Andy Huibers26b33342014-08-20 00:02:19 -0700377 *
378 * @param zoom Zoom ratio value passed to scaler.
379 */
380 public void setZoom(float zoom);
Sascha Haeberlingcbe861e2014-08-21 10:04:35 -0700381
382 /**
383 * Based on the selected picture size, this returns the best preview size.
384 *
385 * @param pictureSize the picture size as selected by the user. A camera
386 * might choose not to obey these and therefore the returned
387 * preview size might not match the aspect ratio of the given
388 * size.
389 * @param context the android application context
390 * @return The preview size that best matches the picture aspect ratio that
391 * will be taken.
392 */
393 public Size pickPreviewSize(Size pictureSize, Context context);
Sascha Haeberling00c122a2014-07-29 15:46:39 -0700394}