Zhijun He | 8486e41 | 2016-09-12 15:30:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.hardware.camera.device@3.2; |
| 18 | |
| 19 | import android.hardware.camera.common@1.0::types; |
| 20 | |
| 21 | /** |
| 22 | * Camera device active session interface. |
| 23 | * |
| 24 | * Obtained via ICameraDevice::open(), this interface contains the methods to |
| 25 | * configure and request captures from an active camera device. |
| 26 | * |
| 27 | */ |
| 28 | interface ICameraDeviceSession { |
| 29 | |
| 30 | /** |
| 31 | * constructDefaultRequestSettings: |
| 32 | * |
| 33 | * Create capture settings for standard camera use cases. |
| 34 | * |
| 35 | * The device must return a settings buffer that is configured to meet the |
| 36 | * requested use case, which must be one of the CAMERA3_TEMPLATE_* |
| 37 | * enums. All request control fields must be included. |
| 38 | * |
| 39 | * Performance requirements: |
| 40 | * |
| 41 | * This must be a non-blocking call. The HAL should return from this call |
| 42 | * in 1ms, and must return from this call in 5ms. |
| 43 | * |
| 44 | * Return values: |
| 45 | * @return status Status code for the operation, one of: |
| 46 | * OK: |
| 47 | * On a successful construction of default settings. |
| 48 | * INTERNAL_ERROR: |
| 49 | * An unexpected internal error occurred, and the default settings |
| 50 | * are not available. |
| 51 | * CAMERA_DISCONNECTED: |
| 52 | * An external camera device has been disconnected, and is no longer |
| 53 | * available. This camera device interface is now stale, and a new |
| 54 | * instance must be acquired if the device is reconnected. All |
| 55 | * subsequent calls on this interface must return |
| 56 | * CAMERA_DISCONNECTED. |
| 57 | * @return template The default capture request settings for the requested |
| 58 | * use case, or an empty metadata structure if status is not OK. |
| 59 | * |
| 60 | */ |
| 61 | constructDefaultRequestSettings(RequestTemplate type) generates |
| 62 | (Status status, CameraMetadata requestTemplate); |
| 63 | |
| 64 | /** |
| 65 | * configureStreams: |
| 66 | * |
| 67 | * Reset the HAL camera device processing pipeline and set up new input and |
| 68 | * output streams. This call replaces any existing stream configuration with |
| 69 | * the streams defined in the streamList. This method must be called at |
| 70 | * least once before a request is submitted with processCaptureRequest(). |
| 71 | * |
| 72 | * The streamList must contain at least one output-capable stream, and may |
| 73 | * not contain more than one input-capable stream. |
| 74 | * |
| 75 | * The streamList may contain streams that are also in the currently-active |
| 76 | * set of streams (from the previous call to configureStreams()). These |
| 77 | * streams must already have valid values for usage, maxBuffers, and the |
| 78 | * private pointer. |
| 79 | * |
| 80 | * If the HAL needs to change the stream configuration for an existing |
| 81 | * stream due to the new configuration, it may rewrite the values of usage |
| 82 | * and/or maxBuffers during the configure call. |
| 83 | * |
| 84 | * The framework must detect such a change, and may then reallocate the |
| 85 | * stream buffers before using buffers from that stream in a request. |
| 86 | * |
| 87 | * If a currently-active stream is not included in streamList, the HAL may |
| 88 | * safely remove any references to that stream. It must not be reused in a |
| 89 | * later configureStreams() call by the framework, and all the gralloc |
| 90 | * buffers for it must be freed after the configureStreams() call returns. |
| 91 | * |
| 92 | * If the stream is new, the maxBuffer field of the stream structure must be |
| 93 | * set to 0. The usage must be set to the consumer usage flags. The HAL |
| 94 | * device must set these fields in the configureStreams() return values. |
| 95 | * These fields are then used by the framework and the platform gralloc |
| 96 | * module to allocate the gralloc buffers for each stream. |
| 97 | * |
| 98 | * Newly allocated buffers may be included in a capture request at any time |
| 99 | * by the framework. Once a gralloc buffer is returned to the framework |
| 100 | * with processCaptureResult (and its respective releaseFence has been |
| 101 | * signaled) the framework may free or reuse it at any time. |
| 102 | * |
| 103 | * ------------------------------------------------------------------------ |
| 104 | * |
| 105 | * Preconditions: |
| 106 | * |
| 107 | * The framework must only call this method when no captures are being |
| 108 | * processed. That is, all results have been returned to the framework, and |
| 109 | * all in-flight input and output buffers have been returned and their |
| 110 | * release sync fences have been signaled by the HAL. The framework must not |
| 111 | * submit new requests for capture while the configureStreams() call is |
| 112 | * underway. |
| 113 | * |
| 114 | * Postconditions: |
| 115 | * |
| 116 | * The HAL device must configure itself to provide maximum possible output |
| 117 | * frame rate given the sizes and formats of the output streams, as |
| 118 | * documented in the camera device's static metadata. |
| 119 | * |
| 120 | * Performance requirements: |
| 121 | * |
| 122 | * This call is expected to be heavyweight and possibly take several hundred |
| 123 | * milliseconds to complete, since it may require resetting and |
| 124 | * reconfiguring the image sensor and the camera processing pipeline. |
| 125 | * Nevertheless, the HAL device should attempt to minimize the |
| 126 | * reconfiguration delay to minimize the user-visible pauses during |
| 127 | * application operational mode changes (such as switching from still |
| 128 | * capture to video recording). |
| 129 | * |
| 130 | * The HAL should return from this call in 500ms, and must return from this |
| 131 | * call in 1000ms. |
| 132 | * |
| 133 | * @return Status Status code for the operation, one of: |
| 134 | * OK: |
| 135 | * On successful stream configuration. |
| 136 | * INTERNAL_ERROR: |
| 137 | * If there has been a fatal error and the device is no longer |
| 138 | * operational. Only close() can be called successfully by the |
| 139 | * framework after this error is returned. |
| 140 | * ILLEGAL_ARGUMENT: |
| 141 | * If the requested stream configuration is invalid. Some examples |
| 142 | * of invalid stream configurations include: |
| 143 | * - Including more than 1 INPUT stream |
| 144 | * - Not including any OUTPUT streams |
| 145 | * - Including streams with unsupported formats, or an unsupported |
| 146 | * size for that format. |
| 147 | * - Including too many output streams of a certain format. |
| 148 | * - Unsupported rotation configuration |
| 149 | * - Stream sizes/formats don't satisfy the |
| 150 | * camera3_stream_configuration_t->operation_mode requirements |
| 151 | * for non-NORMAL mode, or the requested operation_mode is not |
| 152 | * supported by the HAL. |
| 153 | * The camera service cannot filter out all possible illegal stream |
| 154 | * configurations, since some devices may support more simultaneous |
| 155 | * streams or larger stream resolutions than the minimum required |
| 156 | * for a given camera device hardware level. The HAL must return an |
| 157 | * ILLEGAL_ARGUMENT for any unsupported stream set, and then be |
| 158 | * ready to accept a future valid stream configuration in a later |
| 159 | * configureStreams call. |
| 160 | * @return finalConfiguration The stream parameters desired by the HAL for |
| 161 | * each stream, including maximum buffers, the usage flags, and the |
| 162 | * override format. |
| 163 | * |
| 164 | */ |
| 165 | configureStreams(StreamConfiguration requestedConfiguration) |
| 166 | generates (Status status, |
| 167 | HalStreamConfiguration halConfiguration); |
| 168 | |
| 169 | /** |
| 170 | * processCaptureRequest: |
| 171 | * |
| 172 | * Send a new capture request to the HAL. The HAL must not return from |
| 173 | * this call until it is ready to accept the next request to process. Only |
| 174 | * one call to processCaptureRequest() must be made at a time by the |
| 175 | * framework, and the calls must all be from the same thread. The next call |
| 176 | * to processCaptureRequest() must be made as soon as a new request and |
| 177 | * its associated buffers are available. In a normal preview scenario, this |
| 178 | * means the function is generally called again by the framework almost |
| 179 | * instantly. |
| 180 | * |
| 181 | * The actual request processing is asynchronous, with the results of |
| 182 | * capture being returned by the HAL through the processCaptureResult() |
| 183 | * call. This call requires the result metadata to be available, but output |
| 184 | * buffers may simply provide sync fences to wait on. Multiple requests are |
| 185 | * expected to be in flight at once, to maintain full output frame rate. |
| 186 | * |
| 187 | * The framework retains ownership of the request structure. It is only |
| 188 | * guaranteed to be valid during this call. The HAL device must make copies |
| 189 | * of the information it needs to retain for the capture processing. The HAL |
| 190 | * is responsible for waiting on and closing the buffers' fences and |
| 191 | * returning the buffer handles to the framework. |
| 192 | * |
| 193 | * The HAL must write the file descriptor for the input buffer's release |
| 194 | * sync fence into input_buffer->release_fence, if input_buffer is not |
| 195 | * valid. If the HAL returns -1 for the input buffer release sync fence, the |
| 196 | * framework is free to immediately reuse the input buffer. Otherwise, the |
| 197 | * framework must wait on the sync fence before refilling and reusing the |
| 198 | * input buffer. |
| 199 | * |
| 200 | * The input/output buffers provided by the framework in each request |
| 201 | * may be brand new (having never before seen by the HAL). |
| 202 | * |
| 203 | * ------------------------------------------------------------------------ |
| 204 | * Performance considerations: |
| 205 | * |
| 206 | * Handling a new buffer should be extremely lightweight and there must be |
| 207 | * no frame rate degradation or frame jitter introduced. |
| 208 | * |
| 209 | * This call must return fast enough to ensure that the requested frame |
| 210 | * rate can be sustained, especially for streaming cases (post-processing |
| 211 | * quality settings set to FAST). The HAL should return this call in 1 |
| 212 | * frame interval, and must return from this call in 4 frame intervals. |
| 213 | * |
| 214 | * @return status Status code for the operation, one of: |
| 215 | * OK: |
| 216 | * On a successful start to processing the capture request |
| 217 | * ILLEGAL_ARGUMENT: |
| 218 | * If the input is malformed (the settings are empty when not |
| 219 | * allowed, there are 0 output buffers, etc) and capture processing |
| 220 | * cannot start. Failures during request processing must be |
| 221 | * handled by calling ICameraDeviceCallback::notify(). In case of |
| 222 | * this error, the framework retains responsibility for the |
| 223 | * stream buffers' fences and the buffer handles; the HAL must not |
| 224 | * close the fences or return these buffers with |
| 225 | * ICameraDeviceCallback::processCaptureResult(). |
| 226 | * INTERNAL_ERROR: |
| 227 | * If the camera device has encountered a serious error. After this |
| 228 | * error is returned, only the close() method can be successfully |
| 229 | * called by the framework. |
| 230 | * |
| 231 | */ |
| 232 | processCaptureRequest(CaptureRequest request) |
| 233 | generates (Status status); |
| 234 | |
| 235 | /** |
| 236 | * flush: |
| 237 | * |
| 238 | * Flush all currently in-process captures and all buffers in the pipeline |
| 239 | * on the given device. Generally, this method is used to dump all state as |
| 240 | * quickly as possible in order to prepare for a configure_streams() call. |
| 241 | * |
| 242 | * No buffers are required to be successfully returned, so every buffer |
| 243 | * held at the time of flush() (whether successfully filled or not) may be |
| 244 | * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed |
| 245 | * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call, |
| 246 | * provided they are successfully filled. |
| 247 | * |
| 248 | * All requests currently in the HAL are expected to be returned as soon as |
| 249 | * possible. Not-in-process requests must return errors immediately. Any |
| 250 | * interruptible hardware blocks must be stopped, and any uninterruptible |
| 251 | * blocks must be waited on. |
| 252 | * |
| 253 | * flush() may be called concurrently to processCaptureRequest(), with the |
| 254 | * expectation that processCaptureRequest returns quickly and the |
| 255 | * request submitted in that processCaptureRequest call is treated like |
| 256 | * all other in-flight requests. Due to concurrency issues, it is possible |
| 257 | * that from the HAL's point of view, a processCaptureRequest() call may |
| 258 | * be started after flush has been invoked but has not returned yet. If such |
| 259 | * a call happens before flush() returns, the HAL must treat the new |
| 260 | * capture request like other in-flight pending requests (see #4 below). |
| 261 | * |
| 262 | * More specifically, the HAL must follow below requirements for various |
| 263 | * cases: |
| 264 | * |
| 265 | * 1. For captures that are too late for the HAL to cancel/stop, and must be |
| 266 | * completed normally by the HAL; i.e. the HAL can send shutter/notify |
| 267 | * and processCaptureResult and buffers as normal. |
| 268 | * |
| 269 | * 2. For pending requests that have not done any processing, the HAL must |
| 270 | * call notify CAMERA3_MSG_ERROR_REQUEST, and return all the output |
| 271 | * buffers with processCaptureResult in the error state |
| 272 | * (CAMERA3_BUFFER_STATUS_ERROR). The HAL must not place the release |
| 273 | * fence into an error state, instead, the release fences must be set to |
| 274 | * the acquire fences passed by the framework, or -1 if they have been |
| 275 | * waited on by the HAL already. This is also the path to follow for any |
| 276 | * captures for which the HAL already called notify() with |
| 277 | * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers |
| 278 | * for. After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only |
| 279 | * processCaptureResults with buffers in CAMERA3_BUFFER_STATUS_ERROR |
| 280 | * are allowed. No further notifys or processCaptureResult with |
| 281 | * non-empty metadata is allowed. |
| 282 | * |
| 283 | * 3. For partially completed pending requests that do not have all the |
| 284 | * output buffers or perhaps missing metadata, the HAL must follow |
| 285 | * below: |
| 286 | * |
| 287 | * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected |
| 288 | * result metadata (i.e. one or more partial metadata) won't be |
| 289 | * available for the capture. |
| 290 | * |
| 291 | * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that |
| 292 | * won't be produced for the capture. |
| 293 | * |
| 294 | * 3.3. Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp |
| 295 | * before any buffers/metadata are returned with |
| 296 | * processCaptureResult. |
| 297 | * |
| 298 | * 3.4. For captures that will produce some results, the HAL must not |
| 299 | * call CAMERA3_MSG_ERROR_REQUEST, since that indicates complete |
| 300 | * failure. |
| 301 | * |
| 302 | * 3.5. Valid buffers/metadata must be passed to the framework as |
| 303 | * normal. |
| 304 | * |
| 305 | * 3.6. Failed buffers must be returned to the framework as described |
| 306 | * for case 2. But failed buffers do not have to follow the strict |
| 307 | * ordering valid buffers do, and may be out-of-order with respect |
| 308 | * to valid buffers. For example, if buffers A, B, C, D, E are sent, |
| 309 | * D and E are failed, then A, E, B, D, C is an acceptable return |
| 310 | * order. |
| 311 | * |
| 312 | * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is |
| 313 | * sufficient, no need to call processCaptureResult with empty |
| 314 | * metadata or equivalent. |
| 315 | * |
| 316 | * 4. If a flush() is invoked while a processCaptureRequest() invocation |
| 317 | * is active, that process call must return as soon as possible. In |
| 318 | * addition, if a processCaptureRequest() call is made after flush() |
| 319 | * has been invoked but before flush() has returned, the capture request |
| 320 | * provided by the late processCaptureRequest call must be treated |
| 321 | * like a pending request in case #2 above. |
| 322 | * |
| 323 | * flush() must only return when there are no more outstanding buffers or |
| 324 | * requests left in the HAL. The framework may call configure_streams (as |
| 325 | * the HAL state is now quiesced) or may issue new requests. |
| 326 | * |
| 327 | * Note that it's sufficient to only support fully-succeeded and |
| 328 | * fully-failed result cases. However, it is highly desirable to support |
| 329 | * the partial failure cases as well, as it could help improve the flush |
| 330 | * call overall performance. |
| 331 | * |
| 332 | * Performance requirements: |
| 333 | * |
| 334 | * The HAL should return from this call in 100ms, and must return from this |
| 335 | * call in 1000ms. And this call must not be blocked longer than pipeline |
| 336 | * latency (see S7 for definition). |
| 337 | * |
| 338 | * @return status Status code for the operation, one of: |
| 339 | * OK: |
| 340 | * On a successful flush of the camera HAL. |
| 341 | * INTERNAL_ERROR: |
| 342 | * If the camera device has encountered a serious error. After this |
| 343 | * error is returned, only the close() method can be successfully |
| 344 | * called by the framework. |
| 345 | */ |
| 346 | flush() generates (Status status); |
| 347 | |
| 348 | /** |
| 349 | * close: |
| 350 | * |
| 351 | * Shut down the camera device. |
| 352 | * |
| 353 | * After this call, all calls to this session instance must return |
| 354 | * INTERNAL_ERROR. |
| 355 | * |
| 356 | * This method must always succeed, even if the device has encountered a |
| 357 | * serious error. |
| 358 | */ |
| 359 | close(); |
| 360 | }; |