• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 /**
18  * @addtogroup Camera
19  * @{
20  */
21 
22 /**
23  * @file NdkCameraManager.h
24  */
25 
26 /*
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 #ifndef _NDK_CAMERA_MANAGER_H
37 #define _NDK_CAMERA_MANAGER_H
38 
39 #include <sys/cdefs.h>
40 
41 #include "NdkCameraError.h"
42 #include "NdkCameraMetadata.h"
43 #include "NdkCameraDevice.h"
44 
45 __BEGIN_DECLS
46 
47 /**
48  * ACameraManager is opaque type that provides access to camera service.
49  *
50  * A pointer can be obtained using {@link ACameraManager_create} method.
51  */
52 typedef struct ACameraManager ACameraManager;
53 
54 /**
55  * Create ACameraManager instance.
56  *
57  * <p>The ACameraManager is responsible for
58  * detecting, characterizing, and connecting to {@link ACameraDevice}s.</p>
59  *
60  * <p>The caller must call {@link ACameraManager_delete} to free the resources once it is done
61  * using the ACameraManager instance.</p>
62  *
63  * @return a {@link ACameraManager} instance.
64  *
65  */
66 ACameraManager* ACameraManager_create() __INTRODUCED_IN(24);
67 
68 /**
69  * <p>Delete the {@link ACameraManager} instance and free its resources. </p>
70  *
71  * @param manager the {@link ACameraManager} instance to be deleted.
72  */
73 void ACameraManager_delete(ACameraManager* manager) __INTRODUCED_IN(24);
74 
75 /**
76  * Create a list of currently connected camera devices, including
77  * cameras that may be in use by other camera API clients.
78  *
79  * <p>Non-removable cameras use integers starting at 0 for their
80  * identifiers, while removable cameras have a unique identifier for each
81  * individual device, even if they are the same model.</p>
82  *
83  * <p>ACameraManager_getCameraIdList will allocate and return an {@link ACameraIdList}.
84  * The caller must call {@link ACameraManager_deleteCameraIdList} to free the memory</p>
85  *
86  * <p>Note: the returned camera list might be a subset to the output of <a href=
87  * "https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList()">
88  * SDK CameraManager#getCameraIdList API</a> as the NDK API does not support some legacy camera
89  * hardware.</p>
90  *
91  * @param manager the {@link ACameraManager} of interest
92  * @param cameraIdList the output {@link ACameraIdList} will be filled in here if the method call
93  *        succeeds.
94  *
95  * @return <ul>
96  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
97  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager or cameraIdList is NULL.</li>
98  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if connection to camera service fails.</li>
99  *         <li>{@link ACAMERA_ERROR_NOT_ENOUGH_MEMORY} if allocating memory fails.</li></ul>
100  */
101 camera_status_t ACameraManager_getCameraIdList(ACameraManager* manager,
102         /*out*/ACameraIdList** cameraIdList) __INTRODUCED_IN(24);
103 
104 /**
105  * Delete a list of camera devices allocated via {@link ACameraManager_getCameraIdList}.
106  *
107  * @param cameraIdList the {@link ACameraIdList} to be deleted.
108  */
109 void ACameraManager_deleteCameraIdList(ACameraIdList* cameraIdList) __INTRODUCED_IN(24);
110 
111 /**
112  * Definition of camera availability callbacks.
113  *
114  * @param context The optional application context provided by user in
115  *                {@link ACameraManager_AvailabilityCallbacks}.
116  * @param cameraId The ID of the camera device whose availability is changing. The memory of this
117  *                 argument is owned by camera framework and will become invalid immediately after
118  *                 this callback returns.
119  */
120 typedef void (*ACameraManager_AvailabilityCallback)(void* context,
121         const char* cameraId);
122 
123 /**
124  * Definition of physical camera availability callbacks.
125  *
126  * @param context The optional application context provided by user in
127  *                {@link ACameraManager_AvailabilityCallbacks}.
128  * @param cameraId The ID of the logical multi-camera device whose physical camera status is
129  *                 changing. The memory of this argument is owned by camera framework and will
130  *                 become invalid immediately after this callback returns.
131  * @param physicalCameraId The ID of the physical camera device whose status is changing. The
132  *                 memory of this argument is owned by camera framework and will become invalid
133  *                 immediately after this callback returns.
134  */
135 typedef void (*ACameraManager_PhysicalCameraAvailabilityCallback)(void* context,
136         const char* cameraId, const char* physicalCameraId);
137 
138 /**
139  * A listener for camera devices becoming available or unavailable to open.
140  *
141  * <p>Cameras become available when they are no longer in use, or when a new
142  * removable camera is connected. They become unavailable when some
143  * application or service starts using a camera, or when a removable camera
144  * is disconnected.</p>
145  *
146  * @see ACameraManager_registerAvailabilityCallback
147  */
148 typedef struct ACameraManager_AvailabilityListener {
149     /// Optional application context.
150     void*                               context;
151     /// Called when a camera becomes available
152     ACameraManager_AvailabilityCallback onCameraAvailable;
153     /// Called when a camera becomes unavailable
154     ACameraManager_AvailabilityCallback onCameraUnavailable;
155 } ACameraManager_AvailabilityCallbacks;
156 
157 /**
158  * Register camera availability callbacks.
159  *
160  * <p>onCameraUnavailable will be called whenever a camera device is opened by any camera API client.
161  * Other camera API clients may still be able to open such a camera device, evicting the existing
162  * client if they have higher priority than the existing client of a camera device.
163  * See {@link ACameraManager_openCamera} for more details.</p>
164  *
165  * <p>The callbacks will be called on a dedicated thread shared among all ACameraManager
166  * instances.</p>
167  *
168  * <p>Since this callback will be registered with the camera service, remember to unregister it
169  * once it is no longer needed; otherwise the callback will continue to receive events
170  * indefinitely and it may prevent other resources from being released. Specifically, the
171  * callbacks will be invoked independently of the general activity lifecycle and independently
172  * of the state of individual ACameraManager instances.</p>
173  *
174  * @param manager the {@link ACameraManager} of interest.
175  * @param callback the {@link ACameraManager_AvailabilityCallbacks} to be registered.
176  *
177  * @return <ul>
178  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
179  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager or callback is NULL, or
180  *                  {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or
181  *                  {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul>
182  */
183 camera_status_t ACameraManager_registerAvailabilityCallback(
184         ACameraManager* manager,
185         const ACameraManager_AvailabilityCallbacks* callback) __INTRODUCED_IN(24);
186 
187 /**
188  * Unregister camera availability callbacks.
189  *
190  * <p>Removing a callback that isn't registered has no effect.</p>
191  *
192  * <p>This function must not be called with a mutex lock also held by
193  * the availability callbacks.</p>
194  *
195  * @param manager the {@link ACameraManager} of interest.
196  * @param callback the {@link ACameraManager_AvailabilityCallbacks} to be unregistered.
197  *
198  * @return <ul>
199  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
200  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if callback,
201  *                  {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or
202  *                  {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul>
203  */
204 camera_status_t ACameraManager_unregisterAvailabilityCallback(
205         ACameraManager* manager,
206         const ACameraManager_AvailabilityCallbacks* callback) __INTRODUCED_IN(24);
207 
208 /**
209  * Query the capabilities of a camera device. These capabilities are
210  * immutable for a given camera.
211  *
212  * <p>See {@link ACameraMetadata} document and {@link NdkCameraMetadataTags.h} for more details.</p>
213  *
214  * <p>The caller must call {@link ACameraMetadata_free} to free the memory of the output
215  * characteristics.</p>
216  *
217  * @param manager the {@link ACameraManager} of interest.
218  * @param cameraId the ID string of the camera device of interest.
219  * @param characteristics the output {@link ACameraMetadata} will be filled here if the method call
220  *        succeeeds.
221  *
222  * @return <ul>
223  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
224  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager, cameraId, or characteristics
225  *                  is NULL, or cameraId does not match any camera devices connected.</li>
226  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if connection to camera service fails.</li>
227  *         <li>{@link ACAMERA_ERROR_NOT_ENOUGH_MEMORY} if allocating memory fails.</li>
228  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul>
229  */
230 camera_status_t ACameraManager_getCameraCharacteristics(
231         ACameraManager* manager, const char* cameraId,
232         /*out*/ACameraMetadata** characteristics) __INTRODUCED_IN(24);
233 
234 /**
235  * Open a connection to a camera with the given ID. The opened camera device will be
236  * returned in the `device` parameter.
237  *
238  * <p>Use {@link ACameraManager_getCameraIdList} to get the list of available camera
239  * devices. Note that even if an id is listed, open may fail if the device
240  * is disconnected between the calls to {@link ACameraManager_getCameraIdList} and
241  * {@link ACameraManager_openCamera}, or if a higher-priority camera API client begins using the
242  * camera device.</p>
243  *
244  * <p>Devices for which the
245  * {@link ACameraManager_AvailabilityCallbacks#onCameraUnavailable} callback has been called due to
246  * the device being in use by a lower-priority, background camera API client can still potentially
247  * be opened by calling this method when the calling camera API client has a higher priority
248  * than the current camera API client using this device.  In general, if the top, foreground
249  * activity is running within your application process, your process will be given the highest
250  * priority when accessing the camera, and this method will succeed even if the camera device is
251  * in use by another camera API client. Any lower-priority application that loses control of the
252  * camera in this way will receive an
253  * {@link ACameraDevice_StateCallbacks#onDisconnected} callback.</p>
254  *
255  * <p>Once the camera is successfully opened,the ACameraDevice can then be set up
256  * for operation by calling {@link ACameraDevice_createCaptureSession} and
257  * {@link ACameraDevice_createCaptureRequest}.</p>
258  *
259  * <p>If the camera becomes disconnected after this function call returns,
260  * {@link ACameraDevice_StateCallbacks#onDisconnected} with a
261  * ACameraDevice in the disconnected state will be called.</p>
262  *
263  * <p>If the camera runs into error after this function call returns,
264  * {@link ACameraDevice_StateCallbacks#onError} with a
265  * ACameraDevice in the error state will be called.</p>
266  *
267  * @param manager the {@link ACameraManager} of interest.
268  * @param cameraId the ID string of the camera device to be opened.
269  * @param callback the {@link ACameraDevice_StateCallbacks} associated with the opened camera device.
270  * @param device the opened {@link ACameraDevice} will be filled here if the method call succeeds.
271  *
272  * @return <ul>
273  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
274  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager, cameraId, callback, or device
275  *                  is NULL, or cameraId does not match any camera devices connected.</li>
276  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if connection to camera service fails.</li>
277  *         <li>{@link ACAMERA_ERROR_NOT_ENOUGH_MEMORY} if allocating memory fails.</li>
278  *         <li>{@link ACAMERA_ERROR_CAMERA_IN_USE} if camera device is being used by a higher
279  *                   priority camera API client.</li>
280  *         <li>{@link ACAMERA_ERROR_MAX_CAMERA_IN_USE} if the system-wide limit for number of open
281  *                   cameras or camera resources has been reached, and more camera devices cannot be
282  *                   opened until previous instances are closed.</li>
283  *         <li>{@link ACAMERA_ERROR_CAMERA_DISABLED} if the camera is disabled due to a device
284  *                   policy, and cannot be opened.</li>
285  *         <li>{@link ACAMERA_ERROR_PERMISSION_DENIED} if the application does not have permission
286  *                   to open camera.</li>
287  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul>
288  */
289 camera_status_t ACameraManager_openCamera(
290         ACameraManager* manager, const char* cameraId,
291         ACameraDevice_StateCallbacks* callback,
292         /*out*/ACameraDevice** device) __INTRODUCED_IN(24);
293 
294 /**
295  * Definition of camera access permission change callback.
296  *
297  * <p>Notification that camera access priorities have changed and the camera may
298  * now be openable. An application that was previously denied camera access due to
299  * a higher-priority user already using the camera, or that was disconnected from an
300  * active camera session due to a higher-priority user trying to open the camera,
301  * should try to open the camera again if it still wants to use it.  Note that
302  * multiple applications may receive this callback at the same time, and only one of
303  * them will succeed in opening the camera in practice, depending on exact access
304  * priority levels and timing. This method is useful in cases where multiple
305  * applications may be in the resumed state at the same time, and the user switches
306  * focus between them, or if the current camera-using application moves between
307  * full-screen and Picture-in-Picture (PiP) states. In such cases, the camera
308  * available/unavailable callbacks will not be invoked, but another application may
309  * now have higher priority for camera access than the current camera-using
310  * application.</p>
311 
312  * @param context The optional application context provided by user in
313  *                {@link ACameraManager_AvailabilityListener}.
314  */
315 typedef void (*ACameraManager_AccessPrioritiesChangedCallback)(void* context);
316 
317 /**
318  * A listener for camera devices becoming available/unavailable to open or when
319  * the camera access permissions change.
320  *
321  * <p>Cameras become available when they are no longer in use, or when a new
322  * removable camera is connected. They become unavailable when some
323  * application or service starts using a camera, or when a removable camera
324  * is disconnected.</p>
325  *
326  * @see ACameraManager_registerExtendedAvailabilityCallback
327  */
328 typedef struct ACameraManager_ExtendedAvailabilityListener {
329     /// Called when a camera becomes available or unavailable
330     ACameraManager_AvailabilityCallbacks availabilityCallbacks;
331 
332     /// Called when there is camera access permission change
333     ACameraManager_AccessPrioritiesChangedCallback onCameraAccessPrioritiesChanged;
334 
335     /// Called when a physical camera becomes available
336     ACameraManager_PhysicalCameraAvailabilityCallback onPhysicalCameraAvailable __INTRODUCED_IN(30);
337 
338     /// Called when a physical camera becomes unavailable
339     ACameraManager_PhysicalCameraAvailabilityCallback onPhysicalCameraUnavailable
340             __INTRODUCED_IN(30);
341 
342     /// Reserved for future use, please ensure that all entries are set to NULL
343     void *reserved[4];
344 } ACameraManager_ExtendedAvailabilityCallbacks;
345 
346 /**
347  * Register camera extended availability callbacks.
348  *
349  * <p>onCameraUnavailable will be called whenever a camera device is opened by any camera API
350  * client. Other camera API clients may still be able to open such a camera device, evicting the
351  * existing client if they have higher priority than the existing client of a camera device.
352  * See {@link ACameraManager_openCamera} for more details.</p>
353  *
354  * <p>The callbacks will be called on a dedicated thread shared among all ACameraManager
355  * instances.</p>
356  *
357  * <p>Since this callback will be registered with the camera service, remember to unregister it
358  * once it is no longer needed; otherwise the callback will continue to receive events
359  * indefinitely and it may prevent other resources from being released. Specifically, the
360  * callbacks will be invoked independently of the general activity lifecycle and independently
361  * of the state of individual ACameraManager instances.</p>
362  *
363  * @param manager the {@link ACameraManager} of interest.
364  * @param callback the {@link ACameraManager_ExtendedAvailabilityCallbacks} to be registered.
365  *
366  * @return <ul>
367  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
368  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager or callback is NULL, or
369  *                  {ACameraManager_ExtendedAvailabilityCallbacks#onCameraAccessPrioritiesChanged}
370  *                  or {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or
371  *                  {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul>
372  */
373 camera_status_t ACameraManager_registerExtendedAvailabilityCallback(
374         ACameraManager* manager,
375         const ACameraManager_ExtendedAvailabilityCallbacks* callback) __INTRODUCED_IN(29);
376 
377 /**
378  * Unregister camera extended availability callbacks.
379  *
380  * <p>Removing a callback that isn't registered has no effect.</p>
381  *
382  * <p>This function must not be called with a mutex lock also held by
383  * the extended availability callbacks.</p>
384  *
385  * @param manager the {@link ACameraManager} of interest.
386  * @param callback the {@link ACameraManager_ExtendedAvailabilityCallbacks} to be unregistered.
387  *
388  * @return <ul>
389  *         <li>{@link ACAMERA_OK} if the method call succeeds.</li>
390  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if callback,
391  *                  {ACameraManager_ExtendedAvailabilityCallbacks#onCameraAccessPrioritiesChanged}
392  *                  or {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or
393  *                  {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul>
394  */
395 camera_status_t ACameraManager_unregisterExtendedAvailabilityCallback(
396         ACameraManager* manager,
397         const ACameraManager_ExtendedAvailabilityCallbacks* callback) __INTRODUCED_IN(29);
398 
399 #ifdef __ANDROID_VNDK__
400 /**
401  * Retrieve the tag value, given the tag name and camera id.
402  * This method is device specific since some metadata might be defined by device manufacturers
403  * and might only be accessible for specific cameras.
404  * @param manager The {@link ACameraManager} of interest.
405  * @param cameraId The cameraId, which is used to query camera characteristics.
406  * @param name The name of the tag being queried.
407  * @param tag The output tag assigned by this method.
408  *
409  * @return ACAMERA_OK only if the function call was successful.
410  */
411 camera_status_t ACameraManager_getTagFromName(ACameraManager *manager, const char* cameraId,
412         const char *name, /*out*/uint32_t *tag)
413         __INTRODUCED_IN(29);
414 #endif
415 
416 __END_DECLS
417 
418 #endif /* _NDK_CAMERA_MANAGER_H */
419 
420 /** @} */
421