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 <a href="https://cs.android.com/android/platform/superproject/+/master:frameworks/av/camera/ndk/include/camera/NdkCameraMetadataTags.h">NdkCameraMetadataTags.h</a> 213 * for more details.</p> 214 * 215 * <p>The caller must call {@link ACameraMetadata_free} to free the memory of the output 216 * characteristics.</p> 217 * 218 * @param manager the {@link ACameraManager} of interest. 219 * @param cameraId the ID string of the camera device of interest. 220 * @param characteristics the output {@link ACameraMetadata} will be filled here if the method call 221 * succeeds. 222 * 223 * @return <ul> 224 * <li>{@link ACAMERA_OK} if the method call succeeds.</li> 225 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager, cameraId, or characteristics 226 * is NULL, or cameraId does not match any camera devices connected.</li> 227 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if connection to camera service fails.</li> 228 * <li>{@link ACAMERA_ERROR_NOT_ENOUGH_MEMORY} if allocating memory fails.</li> 229 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul> 230 */ 231 camera_status_t ACameraManager_getCameraCharacteristics( 232 ACameraManager* manager, const char* cameraId, 233 /*out*/ACameraMetadata** characteristics) __INTRODUCED_IN(24); 234 235 /** 236 * Open a connection to a camera with the given ID. The opened camera device will be 237 * returned in the `device` parameter. 238 * 239 * <p>Use {@link ACameraManager_getCameraIdList} to get the list of available camera 240 * devices. Note that even if an id is listed, open may fail if the device 241 * is disconnected between the calls to {@link ACameraManager_getCameraIdList} and 242 * {@link ACameraManager_openCamera}, or if a higher-priority camera API client begins using the 243 * camera device.</p> 244 * 245 * <p>Devices for which the 246 * {@link ACameraManager_AvailabilityCallbacks#onCameraUnavailable} callback has been called due to 247 * the device being in use by a lower-priority, background camera API client can still potentially 248 * be opened by calling this method when the calling camera API client has a higher priority 249 * than the current camera API client using this device. In general, if the top, foreground 250 * activity is running within your application process, your process will be given the highest 251 * priority when accessing the camera, and this method will succeed even if the camera device is 252 * in use by another camera API client. Any lower-priority application that loses control of the 253 * camera in this way will receive an 254 * {@link ACameraDevice_StateCallbacks#onDisconnected} callback.</p> 255 * 256 * <p>Once the camera is successfully opened,the ACameraDevice can then be set up 257 * for operation by calling {@link ACameraDevice_createCaptureSession} and 258 * {@link ACameraDevice_createCaptureRequest}.</p> 259 * 260 * <p>If the camera becomes disconnected after this function call returns, 261 * {@link ACameraDevice_StateCallbacks#onDisconnected} with a 262 * ACameraDevice in the disconnected state will be called.</p> 263 * 264 * <p>If the camera runs into error after this function call returns, 265 * {@link ACameraDevice_StateCallbacks#onError} with a 266 * ACameraDevice in the error state will be called.</p> 267 * 268 * @param manager the {@link ACameraManager} of interest. 269 * @param cameraId the ID string of the camera device to be opened. 270 * @param callback the {@link ACameraDevice_StateCallbacks} associated with the opened camera device. 271 * @param device the opened {@link ACameraDevice} will be filled here if the method call succeeds. 272 * 273 * @return <ul> 274 * <li>{@link ACAMERA_OK} if the method call succeeds.</li> 275 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager, cameraId, callback, or device 276 * is NULL, or cameraId does not match any camera devices connected.</li> 277 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if connection to camera service fails.</li> 278 * <li>{@link ACAMERA_ERROR_NOT_ENOUGH_MEMORY} if allocating memory fails.</li> 279 * <li>{@link ACAMERA_ERROR_CAMERA_IN_USE} if camera device is being used by a higher 280 * priority camera API client.</li> 281 * <li>{@link ACAMERA_ERROR_MAX_CAMERA_IN_USE} if the system-wide limit for number of open 282 * cameras or camera resources has been reached, and more camera devices cannot be 283 * opened until previous instances are closed.</li> 284 * <li>{@link ACAMERA_ERROR_CAMERA_DISABLED} if the camera is disabled due to a device 285 * policy, and cannot be opened.</li> 286 * <li>{@link ACAMERA_ERROR_PERMISSION_DENIED} if the application does not have permission 287 * to open camera.</li> 288 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons.</li></ul> 289 */ 290 camera_status_t ACameraManager_openCamera( 291 ACameraManager* manager, const char* cameraId, 292 ACameraDevice_StateCallbacks* callback, 293 /*out*/ACameraDevice** device) __INTRODUCED_IN(24); 294 295 /** 296 * Definition of camera access permission change callback. 297 * 298 * <p>Notification that camera access priorities have changed and the camera may 299 * now be openable. An application that was previously denied camera access due to 300 * a higher-priority user already using the camera, or that was disconnected from an 301 * active camera session due to a higher-priority user trying to open the camera, 302 * should try to open the camera again if it still wants to use it. Note that 303 * multiple applications may receive this callback at the same time, and only one of 304 * them will succeed in opening the camera in practice, depending on exact access 305 * priority levels and timing. This method is useful in cases where multiple 306 * applications may be in the resumed state at the same time, and the user switches 307 * focus between them, or if the current camera-using application moves between 308 * full-screen and Picture-in-Picture (PiP) states. In such cases, the camera 309 * available/unavailable callbacks will not be invoked, but another application may 310 * now have higher priority for camera access than the current camera-using 311 * application.</p> 312 313 * @param context The optional application context provided by user in 314 * {@link ACameraManager_AvailabilityListener}. 315 */ 316 typedef void (*ACameraManager_AccessPrioritiesChangedCallback)(void* context); 317 318 /** 319 * A listener for camera devices becoming available/unavailable to open or when 320 * the camera access permissions change. 321 * 322 * <p>Cameras become available when they are no longer in use, or when a new 323 * removable camera is connected. They become unavailable when some 324 * application or service starts using a camera, or when a removable camera 325 * is disconnected.</p> 326 * 327 * @see ACameraManager_registerExtendedAvailabilityCallback 328 */ 329 typedef struct ACameraManager_ExtendedAvailabilityListener { 330 /// Called when a camera becomes available or unavailable 331 ACameraManager_AvailabilityCallbacks availabilityCallbacks; 332 333 /// Called when there is camera access permission change 334 ACameraManager_AccessPrioritiesChangedCallback onCameraAccessPrioritiesChanged; 335 336 /// Called when a physical camera becomes available 337 ACameraManager_PhysicalCameraAvailabilityCallback onPhysicalCameraAvailable __INTRODUCED_IN(30); 338 339 /// Called when a physical camera becomes unavailable 340 ACameraManager_PhysicalCameraAvailabilityCallback onPhysicalCameraUnavailable 341 __INTRODUCED_IN(30); 342 343 /// Reserved for future use, please ensure that all entries are set to NULL 344 void *reserved[4]; 345 } ACameraManager_ExtendedAvailabilityCallbacks; 346 347 /** 348 * Register camera extended availability callbacks. 349 * 350 * <p>onCameraUnavailable will be called whenever a camera device is opened by any camera API 351 * client. Other camera API clients may still be able to open such a camera device, evicting the 352 * existing client if they have higher priority than the existing client of a camera device. 353 * See {@link ACameraManager_openCamera} for more details.</p> 354 * 355 * <p>The callbacks will be called on a dedicated thread shared among all ACameraManager 356 * instances.</p> 357 * 358 * <p>Since this callback will be registered with the camera service, remember to unregister it 359 * once it is no longer needed; otherwise the callback will continue to receive events 360 * indefinitely and it may prevent other resources from being released. Specifically, the 361 * callbacks will be invoked independently of the general activity lifecycle and independently 362 * of the state of individual ACameraManager instances.</p> 363 * 364 * @param manager the {@link ACameraManager} of interest. 365 * @param callback the {@link ACameraManager_ExtendedAvailabilityCallbacks} to be registered. 366 * 367 * @return <ul> 368 * <li>{@link ACAMERA_OK} if the method call succeeds.</li> 369 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if manager or callback is NULL, or 370 * {ACameraManager_ExtendedAvailabilityCallbacks#onCameraAccessPrioritiesChanged} 371 * or {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or 372 * {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul> 373 */ 374 camera_status_t ACameraManager_registerExtendedAvailabilityCallback( 375 ACameraManager* manager, 376 const ACameraManager_ExtendedAvailabilityCallbacks* callback) __INTRODUCED_IN(29); 377 378 /** 379 * Unregister camera extended availability callbacks. 380 * 381 * <p>Removing a callback that isn't registered has no effect.</p> 382 * 383 * <p>This function must not be called with a mutex lock also held by 384 * the extended availability callbacks.</p> 385 * 386 * @param manager the {@link ACameraManager} of interest. 387 * @param callback the {@link ACameraManager_ExtendedAvailabilityCallbacks} to be unregistered. 388 * 389 * @return <ul> 390 * <li>{@link ACAMERA_OK} if the method call succeeds.</li> 391 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if callback, 392 * {ACameraManager_ExtendedAvailabilityCallbacks#onCameraAccessPrioritiesChanged} 393 * or {ACameraManager_AvailabilityCallbacks#onCameraAvailable} or 394 * {ACameraManager_AvailabilityCallbacks#onCameraUnavailable} is NULL.</li></ul> 395 */ 396 camera_status_t ACameraManager_unregisterExtendedAvailabilityCallback( 397 ACameraManager* manager, 398 const ACameraManager_ExtendedAvailabilityCallbacks* callback) __INTRODUCED_IN(29); 399 400 #ifdef __ANDROID_VNDK__ 401 /** 402 * Retrieve the tag value, given the tag name and camera id. 403 * This method is device specific since some metadata might be defined by device manufacturers 404 * and might only be accessible for specific cameras. 405 * @param manager The {@link ACameraManager} of interest. 406 * @param cameraId The cameraId, which is used to query camera characteristics. 407 * @param name The name of the tag being queried. 408 * @param tag The output tag assigned by this method. 409 * 410 * @return ACAMERA_OK only if the function call was successful. 411 */ 412 camera_status_t ACameraManager_getTagFromName(ACameraManager *manager, const char* cameraId, 413 const char *name, /*out*/uint32_t *tag) 414 __INTRODUCED_IN(29); 415 #endif 416 417 __END_DECLS 418 419 #endif /* _NDK_CAMERA_MANAGER_H */ 420 421 /** @} */ 422