blob: fb124a0c7fd6faea5b0a44730f237948dd63d861 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 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
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070017/**
18 * @addtogroup Camera
19 * @{
20 */
21
22/**
23 * @file NdkCameraDevice.h
24 */
25
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080026/*
27 * This file defines an NDK API.
28 * Do not remove methods.
29 * Do not change method signatures.
30 * Do not change the value of constants.
31 * Do not change the size of any of the classes defined in here.
32 * Do not reference types that are not part of the NDK.
33 * Do not #include files that aren't part of the NDK.
34 */
35
36#include <android/native_window.h>
37#include "NdkCameraError.h"
38#include "NdkCaptureRequest.h"
39#include "NdkCameraCaptureSession.h"
40
41#ifndef _NDK_CAMERA_DEVICE_H
42#define _NDK_CAMERA_DEVICE_H
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070048/**
49 * ACameraDevice is opaque type that provides access to a camera device.
50 *
51 * A pointer can be obtained using {@link ACameraManager_openCamera} method.
52 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080053typedef struct ACameraDevice ACameraDevice;
54
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070055/// Enum for ACameraDevice_ErrorStateCallback error code
56enum {
57 /**
58 * The camera device is in use already.
59 */
60 ERROR_CAMERA_IN_USE = 1,
61
62 /**
63 * The system-wide limit for number of open cameras or camera resources has
64 * been reached, and more camera devices cannot be opened until previous
65 * instances are closed.
66 */
67 ERROR_MAX_CAMERAS_IN_USE = 2,
68
69 /**
70 * The camera is disabled due to a device policy, and cannot be opened.
71 */
72 ERROR_CAMERA_DISABLED = 3,
73
74 /**
75 * The camera device has encountered a fatal error.
76 * <p>The camera device needs to be re-opened to be used again.</p>
77 */
78 ERROR_CAMERA_DEVICE = 4,
79
80 /**
81 * The camera service has encountered a fatal error.
82 * <p>The Android device may need to be shut down and restarted to restore
83 * camera function, or there may be a persistent hardware problem.
84 * An attempt at recovery may be possible by closing the
85 * CameraDevice and the CameraManager, and trying to acquire all resources
86 * again from scratch.</p>
87 */
88 ERROR_CAMERA_SERVICE = 5
89};
90
91/**
92 * Camera device state callbacks to be used in {@link ACameraDevice_stateCallbacks}.
93 *
94 * @param context The optional context in {@link ACameraDevice_stateCallbacks} will be
95 * passed to this callback.
96 * @param device The {@link ACameraDevice} that is being disconnected.
97 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080098typedef void (*ACameraDevice_StateCallback)(void* context, ACameraDevice* device);
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070099
100/**
101 * Camera device error state callbacks to be used in {@link ACameraDevice_stateCallbacks}.
102 *
103 * @param context The optional context in {@link ACameraDevice_stateCallbacks} will be
104 * passed to this callback.
105 * @param device The {@link ACameraDevice} that is being disconnected.
106 * @param error The error code describes the cause of this error callback. See the folowing
107 * links for more detail.
108 *
109 * @see ERROR_CAMERA_IN_USE
110 * @see ERROR_MAX_CAMERAS_IN_USE
111 * @see ERROR_CAMERA_DISABLED
112 * @see ERROR_CAMERA_DEVICE
113 * @see ERROR_CAMERA_SERVICE
114 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800115typedef void (*ACameraDevice_ErrorStateCallback)(void* context, ACameraDevice* device, int error);
116
117typedef struct ACameraDevice_StateCallbacks {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700118 /// optional application context.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800119 void* context;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700120
121 /**
122 * The function is called when a camera device is no longer available for use.
123 *
124 * <p>Any attempt to call API methods on this ACameraDevice will return
125 * {@link ACAMERA_ERROR_CAMERA_DISCONNECTED}. The disconnection could be due to a
126 * change in security policy or permissions; the physical disconnection
127 * of a removable camera device; or the camera being needed for a
128 * higher-priority camera API client.</p>
129 *
130 * <p>Application should clean up the camera with {@link ACameraDevice_close} after
131 * this happens, as it is not recoverable until the camera can be opened
132 * again.</p>
133 *
134 */
135 ACameraDevice_StateCallback onDisconnected;
136
137 /**
138 * The function called when a camera device has encountered a serious error.
139 *
140 * <p>This indicates a failure of the camera device or camera service in some way.
141 * Any attempt to call API methods on this ACameraDevice in the future will return
142 * {@link ACAMERA_ERROR_CAMERA_DISCONNECTED}.</p>
143 *
144 * <p>There may still be capture completion or camera stream callbacks that will be called
145 * after this error is received.</p>
146 *
147 * <p>Application should clean up the camera with {@link ACameraDevice_close} after this
148 * happens. Further attempts at recovery are error-code specific.</p>
149 *
150 */
151 ACameraDevice_ErrorStateCallback onError;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800152} ACameraDevice_stateCallbacks;
153
154/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700155 * Close the connection and free this ACameraDevice synchronously. Access to the ACameraDevice
156 * after calling this method will cause a crash.
157 *
158 * <p>After this call, all calls to the active ACameraCaptureSession associated to this
159 * ACameraDevice will return {@link ACAMERA_ERROR_SESSION_CLOSED} except for calls to
160 * {@link ACameraCaptureSession_close}.</p>
161 *
162 * <p>This method will stop all repeating captures sent via
163 * {@link ACameraCaptureSession_setRepeatingRequest} and block until all capture requests sent via
164 * {@link ACameraCaptureSession_capture} is complete. Once the method returns, the camera device
165 * will be removed from memory and access to the closed camera device pointer will cause a crash.</p>
166 *
167 * @param device the camera device to be closed
168 *
169 * @return <ul>
170 * <li>{@link ACAMERA_OK} if the method call succeeds.</li>
171 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if device is NULL.</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800172 */
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700173camera_status_t ACameraDevice_close(ACameraDevice* device);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800174
175/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700176 * Return the camera id associated with this camera device.
177 *
178 * @param device the camera device to be closed
179 *
180 * @return camera ID string. The returned string is managed by framework and should not be
181 * delete/free by the application. Also the returned string must not be used after the device
182 * has been closed.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800183 */
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700184const char* ACameraDevice_getId(const ACameraDevice* device);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800185
186typedef enum {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700187 /**
188 * Create a request suitable for a camera preview window. Specifically, this
189 * means that high frame rate is given priority over the highest-quality
190 * post-processing. These requests would normally be used with the
191 * {@link ACameraCaptureSession_setRepeatingRequest} method.
192 * This template is guaranteed to be supported on all camera devices.
193 *
194 * @see ACameraDevice_createCaptureRequest
195 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800196 TEMPLATE_PREVIEW = 1,
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700197
198 /**
199 * Create a request suitable for still image capture. Specifically, this
200 * means prioritizing image quality over frame rate. These requests would
201 * commonly be used with the {@link ACameraCaptureSession_capture} method.
202 * This template is guaranteed to be supported on all camera devices.
203 *
204 * @see ACameraDevice_createCaptureRequest
205 */
206 TEMPLATE_STILL_CAPTURE = 2,
207
208 /**
209 * Create a request suitable for video recording. Specifically, this means
210 * that a stable frame rate is used, and post-processing is set for
211 * recording quality. These requests would commonly be used with the
212 * {@link ACameraCaptureSession_setRepeatingRequest} method.
213 * This template is guaranteed to be supported on all camera devices.
214 *
215 * @see ACameraDevice_createCaptureRequest
216 */
217 TEMPLATE_RECORD = 3,
218
219 /**
220 * Create a request suitable for still image capture while recording
221 * video. Specifically, this means maximizing image quality without
222 * disrupting the ongoing recording. These requests would commonly be used
223 * with the {@link ACameraCaptureSession_capture} method while a request based on
224 * {@link TEMPLATE_RECORD} is is in use with {@link ACameraCaptureSession_setRepeatingRequest}.
225 * This template is guaranteed to be supported on all camera devices.
226 *
227 * @see ACameraDevice_createCaptureRequest
228 */
229 TEMPLATE_VIDEO_SNAPSHOT = 4,
230
231 /**
232 * Create a request suitable for zero shutter lag still capture. This means
233 * means maximizing image quality without compromising preview frame rate.
234 * AE/AWB/AF should be on auto mode.
235 *
236 * @see ACameraDevice_createCaptureRequest
237 */
238 TEMPLATE_ZERO_SHUTTER_LAG = 5,
239
240 /**
241 * A basic template for direct application control of capture
242 * parameters. All automatic control is disabled (auto-exposure, auto-white
243 * balance, auto-focus), and post-processing parameters are set to preview
244 * quality. The manual capture parameters (exposure, sensitivity, and so on)
245 * are set to reasonable defaults, but should be overriden by the
246 * application depending on the intended use case.
247 * This template is guaranteed to be supported on camera devices that support the
248 * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR} capability.
249 *
250 * @see ACameraDevice_createCaptureRequest
251 */
252 TEMPLATE_MANUAL = 6,
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800253} ACameraDevice_request_template;
254
255/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700256 * Create a ACaptureRequest for capturing images, initialized with template
257 * for a target use case.
258 *
259 * <p>The settings are chosen to be the best options for this camera device,
260 * so it is not recommended to reuse the same request for a different camera device.</p>
261 *
262 * @param device the camera device of interest
263 * @param templateId the type of capture request to be created.
264 * See {@link ACameraDevice_request_template}.
265 * @param request the output request will be stored here if the method call succeeds.
266 *
267 * @return <ul>
268 * <li>{@link ACAMERA_OK} if the method call succeeds. The created capture request will be
269 * filled in request argument.</li>
270 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if device or request is NULL, or templateId
271 * is undefined.</li>
272 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed.</li>
273 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error.</li>
274 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error.</li>
275 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul>
276 *
277 * @see TEMPLATE_PREVIEW
278 * @see TEMPLATE_RECORD
279 * @see TEMPLATE_STILL_CAPTURE
280 * @see TEMPLATE_VIDEO_SNAPSHOT
281 * @see TEMPLATE_MANUAL
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800282 */
283camera_status_t ACameraDevice_createCaptureRequest(
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700284 const ACameraDevice* device, ACameraDevice_request_template templateId,
285 /*out*/ACaptureRequest** request);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800286
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700287
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800288typedef struct ACaptureSessionOutputContainer ACaptureSessionOutputContainer;
289
290typedef struct ACaptureSessionOutput ACaptureSessionOutput;
291
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700292/**
293 * Create a capture session output container.
294 *
295 * <p>The container is used in {@link ACameraDevice_createCaptureSession} method to create a capture
296 * session. Use {@link ACaptureSessionOutputContainer_free} to free the container and its memory
297 * after application no longer needs the ACaptureSessionOutputContainer.</p>
298 *
299 * @param container the output {@link ACaptureSessionOutputContainer} will be stored here if the
300 * method call succeeds.
301 *
302 * @return <ul>
303 * <li>{@link ACAMERA_OK} if the method call succeeds. The created container will be
304 * filled in container argument.</li>
305 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if container is NULL.</li></ul>
306 */
307camera_status_t ACaptureSessionOutputContainer_create(
308 /*out*/ACaptureSessionOutputContainer** container);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800309
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700310/**
311 * Free a capture session output container.
312 *
313 * @param container the {@link ACaptureSessionOutputContainer} to be freed.
314 *
315 * @see ACaptureSessionOutputContainer_create
316 */
317void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800318
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700319/**
320 * Create a ACaptureSessionOutput object.
321 *
322 * <p>The ACaptureSessionOutput is used in {@link ACaptureSessionOutputContainer_add} method to add
323 * an output {@link ANativeWindow} to ACaptureSessionOutputContainer. Use
324 * {@link ACaptureSessionOutput_free} to free the object and its memory after application no longer
325 * needs the {@link ACaptureSessionOutput}.</p>
326 *
327 * @param anw the {@link ANativeWindow} to be associated with the {@link ACaptureSessionOutput}
328 * @param output the output {@link ACaptureSessionOutput} will be stored here if the
329 * method call succeeds.
330 *
331 * @return <ul>
332 * <li>{@link ACAMERA_OK} if the method call succeeds. The created container will be
333 * filled in the output argument.</li>
334 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if anw or output is NULL.</li></ul>
335 *
336 * @see ACaptureSessionOutputContainer_add
337 */
338camera_status_t ACaptureSessionOutput_create(
339 ANativeWindow* anw, /*out*/ACaptureSessionOutput** output);
340
341/**
342 * Free a ACaptureSessionOutput object.
343 *
344 * @param output the {@link ACaptureSessionOutput} to be freed.
345 *
346 * @see ACaptureSessionOutput_create
347 */
348void ACaptureSessionOutput_free(ACaptureSessionOutput* output);
349
350/**
351 * Add an {@link ACaptureSessionOutput} object to {@link ACaptureSessionOutputContainer}.
352 *
353 * @param container the {@link ACaptureSessionOutputContainer} of interest.
354 * @param output the output {@link ACaptureSessionOutput} to be added to container.
355 *
356 * @return <ul>
357 * <li>{@link ACAMERA_OK} if the method call succeeds.</li>
358 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if container or output is NULL.</li></ul>
359 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800360camera_status_t ACaptureSessionOutputContainer_add(
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700361 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800362
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700363/**
364 * Remove an {@link ACaptureSessionOutput} object from {@link ACaptureSessionOutputContainer}.
365 *
366 * <p>This method has no effect if the ACaptureSessionOutput does not exist in
367 * ACaptureSessionOutputContainer.</p>
368 *
369 * @param container the {@link ACaptureSessionOutputContainer} of interest.
370 * @param output the output {@link ACaptureSessionOutput} to be removed from container.
371 *
372 * @return <ul>
373 * <li>{@link ACAMERA_OK} if the method call succeeds.</li>
374 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if container or output is NULL.</li></ul>
375 */
376camera_status_t ACaptureSessionOutputContainer_remove(
377 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output);
378
379/**
380 * Create a new camera capture session by providing the target output set of {@link ANativeWindow}
381 * to the camera device.
382 *
383 * <p>If there is a preexisting session, the previous session will be closed
384 * automatically. However, app still needs to call {@link ACameraCaptureSession_close} on previous
385 * session. Otherwise the resources held by previous session will NOT be freed.</p>
386 *
387 * <p>The active capture session determines the set of potential output {@link ANativeWindow}s for
388 * the camera device for each capture request. A given request may use all
389 * or only some of the outputs. Once the ACameraCaptureSession is created, requests can be
390 * submitted with {@link ACameraCaptureSession_capture} or
391 * {@link ACameraCaptureSession_setRepeatingRequest}.</p>
392 *
393 * <p>Often the {@link ANativeWindow} used with this method can be obtained from a <a href=
394 * "http://developer.android.com/reference/android/view/Surface.html">Surface</a> java object by
395 * {@link ANativeWindow_fromSurface} NDK method. Surfaces or ANativeWindow suitable for inclusion as a camera
396 * output can be created for various use cases and targets:</p>
397 *
398 * <ul>
399 *
400 * <li>For drawing to a
401 * <a href="http://developer.android.com/reference/android/view/SurfaceView.html">SurfaceView</a>:
402 * Once the SurfaceView's Surface is created, set the size
403 * of the Surface with
404 * <a href="http://developer.android.com/reference/android/view/SurfaceHolder.html#setFixedSize(int, int)">
405 * android.view.SurfaceHolder\#setFixedSize</a> to be one of the PRIVATE output sizes
406 * returned by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}
407 * and then obtain the Surface by calling <a href=
408 * "http://developer.android.com/reference/android/view/SurfaceHolder.html#getSurface()">
409 * android.view.SurfaceHolder\#getSurface</a>. If the size is not set by the application, it will
410 * be rounded to the nearest supported size less than 1080p, by the camera device.</li>
411 *
412 * <li>For accessing through an OpenGL texture via a <a href=
413 * "http://developer.android.com/reference/android/graphics/SurfaceTexture.html">SurfaceTexture</a>:
414 * Set the size of the SurfaceTexture with <a href=
415 * "http://developer.android.com/reference/android/graphics/SurfaceTexture.html#setDefaultBufferSize(int, int)">
416 * setDefaultBufferSize</a> to be one of the PRIVATE output sizes
417 * returned by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}
418 * before creating a Surface from the SurfaceTexture with <a href=
419 * "http://developer.android.com/reference/android/view/Surface.html#Surface(android.graphics.SurfaceTexture)">
420 * Surface\#Surface(SurfaceTextrue)</a>. If the size is not set by the application, it will be set to be the
421 * smallest supported size less than 1080p, by the camera device.</li>
422 *
423 * <li>For recording with <a href=
424 * "http://developer.android.com/reference/android/media/MediaCodec.html">
425 * MediaCodec</a>: Call
426 * <a href=
427 * "http://developer.android.com/reference/android/media/MediaCodec.html#createInputSurface()">
428 * android.media.MediaCodec\#createInputSurface</a> after configuring
429 * the media codec to use one of the PRIVATE output sizes
430 * returned by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}.
431 * </li>
432 *
433 * <li>For recording with <a href=
434 * "http://developer.android.com/reference/android/media/MediaRecorder.html">
435 * MediaRecorder</a>: Call
436 * <a href="http://developer.android.com/reference/android/media/MediaRecorder.html#getSurface()">
437 * android.media.MediaRecorder\#getSurface</a> after configuring the media recorder to use
438 * one of the PRIVATE output sizes returned by
439 * {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}, or configuring it to use one of the supported
440 * <a href="http://developer.android.com/reference/android/media/CamcorderProfile.html">
441 * CamcorderProfiles</a>.</li>
442 *
443 * <li>For efficient YUV processing with <a href=
444 * "http://developer.android.com/reference/android/renderscript/package-summary.html">
445 * RenderScript</a>:
446 * Create a RenderScript
447 * <a href="http://developer.android.com/reference/android/renderscript/Allocation.html">
448 * Allocation</a> with a supported YUV
449 * type, the IO_INPUT flag, and one of the YUV output sizes returned by
450 * {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS},
451 * Then obtain the Surface with
452 * <a href="http://developer.android.com/reference/android/renderscript/Allocation.html#getSurface()">
453 * Allocation#getSurface}</a>.</li>
454 *
455 * <li>For access to RAW, uncompressed YUV, or compressed JPEG data in the application: Create an
456 * {@link AImageReader} object using the {@link AImageReader_new} method with one of the supported
457 * output formats given by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}. Then obtain a
458 * ANativeWindow from it with {@link AImageReader_getWindow}.
459 * If the AImageReader size is not set to a supported size, it will be rounded to a supported
460 * size less than 1080p by the camera device.
461 * </li>
462 *
463 * </ul>
464 *
465 * <p>The camera device will query each ANativeWindow's size and formats upon this
466 * call, so they must be set to a valid setting at this time.</p>
467 *
468 * <p>It can take several hundred milliseconds for the session's configuration to complete,
469 * since camera hardware may need to be powered on or reconfigured.</p>
470 *
471 * <p>If a prior ACameraCaptureSession already exists when this method is called, the previous
472 * session will no longer be able to accept new capture requests and will be closed. Any
473 * in-progress capture requests made on the prior session will be completed before it's closed.
474 * To minimize the transition time,
475 * the ACameraCaptureSession_abortCaptures method can be used to discard the remaining
476 * requests for the prior capture session before a new one is created. Note that once the new
477 * session is created, the old one can no longer have its captures aborted.</p>
478 *
479 * <p>Using larger resolution outputs, or more outputs, can result in slower
480 * output rate from the device.</p>
481 *
482 * <p>Configuring a session with an empty list will close the current session, if
483 * any. This can be used to release the current session's target surfaces for another use.</p>
484 *
485 * <p>While any of the sizes from {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS} can be used when
486 * a single output stream is configured, a given camera device may not be able to support all
487 * combination of sizes, formats, and targets when multiple outputs are configured at once. The
488 * tables below list the maximum guaranteed resolutions for combinations of streams and targets,
489 * given the capabilities of the camera device.</p>
490 *
491 * <p>If an application tries to create a session using a set of targets that exceed the limits
492 * described in the below tables, one of three possibilities may occur. First, the session may
493 * be successfully created and work normally. Second, the session may be successfully created,
494 * but the camera device won't meet the frame rate guarantees as described in
495 * {@link ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS}. Or third, if the output set
496 * cannot be used at all, session creation will fail entirely, with
497 * {@link ACAMERA_ERROR_STREAM_CONFIGURE_FAIL} being returned.</p>
498 *
499 * <p>For the type column `PRIV` refers to output format {@link AIMAGE_FORMAT_PRIVATE},
500 * `YUV` refers to output format {@link AIMAGE_FORMAT_YUV_420_888},
501 * `JPEG` refers to output format {@link AIMAGE_FORMAT_JPEG},
502 * and `RAW` refers to output format {@link AIMAGE_FORMAT_RAW16}
503 *
504 *
505 * <p>For the maximum size column, `PREVIEW` refers to the best size match to the
506 * device's screen resolution, or to 1080p `(1920x1080)`, whichever is
507 * smaller. `RECORD` refers to the camera device's maximum supported recording resolution,
508 * as determined by <a href="http://developer.android.com/reference/android/media/CamcorderProfile.html">
509 * android.media.CamcorderProfiles</a>. And `MAXIMUM` refers to the
510 * camera device's maximum output resolution for that format or target from
511 * {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}.</p>
512 *
513 * <p>To use these tables, determine the number and the formats/targets of outputs needed, and
514 * find the row(s) of the table with those targets. The sizes indicate the maximum set of sizes
515 * that can be used; it is guaranteed that for those targets, the listed sizes and anything
516 * smaller from the list given by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS} can be
517 * successfully used to create a session. For example, if a row indicates that a 8 megapixel
518 * (MP) YUV_420_888 output can be used together with a 2 MP `PRIV` output, then a session
519 * can be created with targets `[8 MP YUV, 2 MP PRIV]` or targets `[2 MP YUV, 2 MP PRIV]`;
520 * but a session with targets `[8 MP YUV, 4 MP PRIV]`, targets `[4 MP YUV, 4 MP PRIV]`,
521 * or targets `[8 MP PRIV, 2 MP YUV]` would not be guaranteed to work, unless
522 * some other row of the table lists such a combination.</p>
523 *
524 * <p>Legacy devices ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL}
525 * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY}) support at
526 * least the following stream combinations:
527 *
528 * <table>
529 * <tr><th colspan="7">LEGACY-level guaranteed configurations</th></tr>
530 * <tr> <th colspan="2" id="rb">Target 1</th> <th colspan="2" id="rb">Target 2</th> <th colspan="2" id="rb">Target 3</th> <th rowspan="2">Sample use case(s)</th> </tr>
531 * <tr> <th>Type</th><th id="rb">Max size</th> <th>Type</th><th id="rb">Max size</th> <th>Type</th><th id="rb">Max size</th></tr>
532 * <tr> <td>`PRIV`</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td colspan="2" id="rb"></td> <td>Simple preview, GPU video processing, or no-preview video recording.</td> </tr>
533 * <tr> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td colspan="2" id="rb"></td> <td>No-viewfinder still image capture.</td> </tr>
534 * <tr> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td colspan="2" id="rb"></td> <td>In-application video/image processing.</td> </tr>
535 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>Standard still imaging.</td> </tr>
536 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>In-app processing plus still capture.</td> </tr>
537 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td colspan="2" id="rb"></td> <td>Standard recording.</td> </tr>
538 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td colspan="2" id="rb"></td> <td>Preview plus in-app processing.</td> </tr>
539 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>Still capture plus in-app processing.</td> </tr>
540 * </table><br>
541 * </p>
542 *
543 * <p>Limited-level ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL}
544 * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED}) devices
545 * support at least the following stream combinations in addition to those for
546 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY} devices:
547 *
548 * <table>
549 * <tr><th colspan="7">LIMITED-level additional guaranteed configurations</th></tr>
550 * <tr><th colspan="2" id="rb">Target 1</th><th colspan="2" id="rb">Target 2</th><th colspan="2" id="rb">Target 3</th> <th rowspan="2">Sample use case(s)</th> </tr>
551 * <tr><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th></tr>
552 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`RECORD `</td> <td colspan="2" id="rb"></td> <td>High-resolution video recording with preview.</td> </tr>
553 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`RECORD `</td> <td colspan="2" id="rb"></td> <td>High-resolution in-app video processing with preview.</td> </tr>
554 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`RECORD `</td> <td colspan="2" id="rb"></td> <td>Two-input in-app video processing.</td> </tr>
555 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`RECORD `</td> <td>`JPEG`</td><td id="rb">`RECORD `</td> <td>High-resolution recording with video snapshot.</td> </tr>
556 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`RECORD `</td> <td>`JPEG`</td><td id="rb">`RECORD `</td> <td>High-resolution in-app processing with video snapshot.</td> </tr>
557 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>Two-input in-app processing with still capture.</td> </tr>
558 * </table><br>
559 * </p>
560 *
561 * <p>FULL-level ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL}
562 * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL}) devices
563 * support at least the following stream combinations in addition to those for
564 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices:
565 *
566 * <table>
567 * <tr><th colspan="7">FULL-level additional guaranteed configurations</th></tr>
568 * <tr><th colspan="2" id="rb">Target 1</th><th colspan="2" id="rb">Target 2</th><th colspan="2" id="rb">Target 3</th> <th rowspan="2">Sample use case(s)</th> </tr>
569 * <tr><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th> </tr>
570 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>Maximum-resolution GPU processing with preview.</td> </tr>
571 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>Maximum-resolution in-app processing with preview.</td> </tr>
572 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>Maximum-resolution two-input in-app processsing.</td> </tr>
573 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>Video recording with maximum-size video snapshot</td> </tr>
574 * <tr> <td>`YUV `</td><td id="rb">`640x480`</td> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td>Standard video recording plus maximum-resolution in-app processing.</td> </tr>
575 * <tr> <td>`YUV `</td><td id="rb">`640x480`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td>Preview plus two-input maximum-resolution in-app processing.</td> </tr>
576 * </table><br>
577 * </p>
578 *
579 * <p>RAW-capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes
580 * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}) devices additionally support
581 * at least the following stream combinations on both
582 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL} and
583 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices:
584 *
585 * <table>
586 * <tr><th colspan="7">RAW-capability additional guaranteed configurations</th></tr>
587 * <tr><th colspan="2" id="rb">Target 1</th><th colspan="2" id="rb">Target 2</th><th colspan="2" id="rb">Target 3</th> <th rowspan="2">Sample use case(s)</th> </tr>
588 * <tr><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th> </tr>
589 * <tr> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td colspan="2" id="rb"></td> <td>No-preview DNG capture.</td> </tr>
590 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>Standard DNG capture.</td> </tr>
591 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td colspan="2" id="rb"></td> <td>In-app processing plus DNG capture.</td> </tr>
592 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td>Video recording with DNG capture.</td> </tr>
593 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td>Preview with in-app processing and DNG capture.</td> </tr>
594 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td>Two-input in-app processing plus DNG capture.</td> </tr>
595 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td>Still capture with simultaneous JPEG and DNG.</td> </tr>
596 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>`RAW `</td><td id="rb">`MAXIMUM`</td> <td>In-app processing with simultaneous JPEG and DNG.</td> </tr>
597 * </table><br>
598 * </p>
599 *
600 * <p>BURST-capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes
601 * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE BURST_CAPTURE}) devices
602 * support at least the below stream combinations in addition to those for
603 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices. Note that all
604 * FULL-level devices support the BURST capability, and the below list is a strict subset of the
605 * list for FULL-level devices, so this table is only relevant for LIMITED-level devices that
606 * support the BURST_CAPTURE capability.
607 *
608 * <table>
609 * <tr><th colspan="5">BURST-capability additional guaranteed configurations</th></tr>
610 * <tr><th colspan="2" id="rb">Target 1</th><th colspan="2" id="rb">Target 2</th><th rowspan="2">Sample use case(s)</th> </tr>
611 * <tr><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th> </tr>
612 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`MAXIMUM`</td> <td>Maximum-resolution GPU processing with preview.</td> </tr>
613 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td>Maximum-resolution in-app processing with preview.</td> </tr>
614 * <tr> <td>`YUV `</td><td id="rb">`PREVIEW`</td> <td>`YUV `</td><td id="rb">`MAXIMUM`</td> <td>Maximum-resolution two-input in-app processsing.</td> </tr>
615 * </table><br>
616 * </p>
617 *
618 * <p>LEVEL-3 ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL}
619 * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_3 LEVEL_3})
620 * support at least the following stream combinations in addition to the combinations for
621 * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL} and for
622 * RAW capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes
623 * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}):
624 *
625 * <table>
626 * <tr><th colspan="11">LEVEL-3 additional guaranteed configurations</th></tr>
627 * <tr><th colspan="2" id="rb">Target 1</th><th colspan="2" id="rb">Target 2</th><th colspan="2" id="rb">Target 3</th><th colspan="2" id="rb">Target 4</th><th rowspan="2">Sample use case(s)</th> </tr>
628 * <tr><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th><th>Type</th><th id="rb">Max size</th> </tr>
629 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`640x480`</td> <td>`YUV`</td><td id="rb">`MAXIMUM`</td> <td>`RAW`</td><td id="rb">`MAXIMUM`</td> <td>In-app viewfinder analysis with dynamic selection of output format.</td> </tr>
630 * <tr> <td>`PRIV`</td><td id="rb">`PREVIEW`</td> <td>`PRIV`</td><td id="rb">`640x480`</td> <td>`JPEG`</td><td id="rb">`MAXIMUM`</td> <td>`RAW`</td><td id="rb">`MAXIMUM`</td> <td>In-app viewfinder analysis with dynamic selection of output format.</td> </tr>
631 * </table><br>
632 * </p>
633 *
634 * <p>Since the capabilities of camera devices vary greatly, a given camera device may support
635 * target combinations with sizes outside of these guarantees, but this can only be tested for
636 * by attempting to create a session with such targets.</p>
637 *
638 * @param device the camera device of interest.
639 * @param outputs the {@link ACaptureSessionOutputContainer} describes all output streams.
640 * @param callbacks the {@link ACameraCaptureSession_stateCallbacks capture session state callbacks}.
641 * @param session the created {@link ACameraCaptureSession} will be filled here if the method call
642 * succeeds.
643 *
644 * @return <ul>
645 * <li>{@link ACAMERA_OK} if the method call succeeds. The created capture session will be
646 * filled in session argument.</li>
647 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if any of device, outputs, callbacks or
648 * session is NULL.</li>
649 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed.</li>
650 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error.</li>
651 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error.</li>
652 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul>
Yin-Chia Yehead91462016-01-06 16:45:08 -0800653 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800654camera_status_t ACameraDevice_createCaptureSession(
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700655 ACameraDevice* device,
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800656 const ACaptureSessionOutputContainer* outputs,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800657 const ACameraCaptureSession_stateCallbacks* callbacks,
658 /*out*/ACameraCaptureSession** session);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800659
660#ifdef __cplusplus
661} // extern "C"
662#endif
663
664#endif // _NDK_CAMERA_DEVICE_H
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700665
666/** @} */
667