blob: 278be5d09103758af7bdf5d00157acc596b235cb [file] [log] [blame]
Zhijun He8486e412016-09-12 15:30:51 -07001/*
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
17package android.hardware.camera.device@3.2;
18
19import 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 */
28interface 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.
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070051 * ILLEGAL_ARGUMENT:
52 * The camera HAL does not support the input template type
Zhijun He8486e412016-09-12 15:30:51 -070053 * CAMERA_DISCONNECTED:
54 * An external camera device has been disconnected, and is no longer
55 * available. This camera device interface is now stale, and a new
56 * instance must be acquired if the device is reconnected. All
57 * subsequent calls on this interface must return
58 * CAMERA_DISCONNECTED.
59 * @return template The default capture request settings for the requested
60 * use case, or an empty metadata structure if status is not OK.
61 *
62 */
63 constructDefaultRequestSettings(RequestTemplate type) generates
64 (Status status, CameraMetadata requestTemplate);
65
66 /**
67 * configureStreams:
68 *
69 * Reset the HAL camera device processing pipeline and set up new input and
70 * output streams. This call replaces any existing stream configuration with
71 * the streams defined in the streamList. This method must be called at
72 * least once before a request is submitted with processCaptureRequest().
73 *
74 * The streamList must contain at least one output-capable stream, and may
75 * not contain more than one input-capable stream.
76 *
77 * The streamList may contain streams that are also in the currently-active
78 * set of streams (from the previous call to configureStreams()). These
79 * streams must already have valid values for usage, maxBuffers, and the
80 * private pointer.
81 *
82 * If the HAL needs to change the stream configuration for an existing
83 * stream due to the new configuration, it may rewrite the values of usage
84 * and/or maxBuffers during the configure call.
85 *
86 * The framework must detect such a change, and may then reallocate the
87 * stream buffers before using buffers from that stream in a request.
88 *
89 * If a currently-active stream is not included in streamList, the HAL may
90 * safely remove any references to that stream. It must not be reused in a
91 * later configureStreams() call by the framework, and all the gralloc
92 * buffers for it must be freed after the configureStreams() call returns.
93 *
Shuzhen Wang49fcad22018-12-12 08:49:00 -080094 * If the stream is new, the client must set the consumer usage flags in
95 * requestedConfiguration. Upon return, the HAL device must set producerUsage,
96 * maxBuffers, and other fields in the configureStreams() return values. These
97 * fields are then used by the framework and the platform gralloc module to
98 * allocate the gralloc buffers for each stream.
Zhijun He8486e412016-09-12 15:30:51 -070099 *
100 * Newly allocated buffers may be included in a capture request at any time
101 * by the framework. Once a gralloc buffer is returned to the framework
102 * with processCaptureResult (and its respective releaseFence has been
103 * signaled) the framework may free or reuse it at any time.
104 *
105 * ------------------------------------------------------------------------
106 *
107 * Preconditions:
108 *
109 * The framework must only call this method when no captures are being
110 * processed. That is, all results have been returned to the framework, and
111 * all in-flight input and output buffers have been returned and their
112 * release sync fences have been signaled by the HAL. The framework must not
113 * submit new requests for capture while the configureStreams() call is
114 * underway.
115 *
116 * Postconditions:
117 *
118 * The HAL device must configure itself to provide maximum possible output
119 * frame rate given the sizes and formats of the output streams, as
120 * documented in the camera device's static metadata.
121 *
122 * Performance requirements:
123 *
124 * This call is expected to be heavyweight and possibly take several hundred
125 * milliseconds to complete, since it may require resetting and
126 * reconfiguring the image sensor and the camera processing pipeline.
127 * Nevertheless, the HAL device should attempt to minimize the
128 * reconfiguration delay to minimize the user-visible pauses during
129 * application operational mode changes (such as switching from still
130 * capture to video recording).
131 *
132 * The HAL should return from this call in 500ms, and must return from this
133 * call in 1000ms.
134 *
135 * @return Status Status code for the operation, one of:
136 * OK:
137 * On successful stream configuration.
138 * INTERNAL_ERROR:
139 * If there has been a fatal error and the device is no longer
140 * operational. Only close() can be called successfully by the
141 * framework after this error is returned.
142 * ILLEGAL_ARGUMENT:
143 * If the requested stream configuration is invalid. Some examples
144 * of invalid stream configurations include:
145 * - Including more than 1 INPUT stream
146 * - Not including any OUTPUT streams
147 * - Including streams with unsupported formats, or an unsupported
148 * size for that format.
149 * - Including too many output streams of a certain format.
150 * - Unsupported rotation configuration
151 * - Stream sizes/formats don't satisfy the
Yin-Chia Yeh6a6fe0f2018-09-06 15:38:34 -0700152 * StreamConfigurationMode requirements for non-NORMAL mode, or
153 * the requested operation_mode is not supported by the HAL.
Shuzhen Wang43698a22017-03-20 09:35:12 -0700154 * - Unsupported usage flag
Zhijun He8486e412016-09-12 15:30:51 -0700155 * The camera service cannot filter out all possible illegal stream
156 * configurations, since some devices may support more simultaneous
157 * streams or larger stream resolutions than the minimum required
158 * for a given camera device hardware level. The HAL must return an
159 * ILLEGAL_ARGUMENT for any unsupported stream set, and then be
160 * ready to accept a future valid stream configuration in a later
161 * configureStreams call.
162 * @return finalConfiguration The stream parameters desired by the HAL for
163 * each stream, including maximum buffers, the usage flags, and the
164 * override format.
165 *
166 */
167 configureStreams(StreamConfiguration requestedConfiguration)
168 generates (Status status,
169 HalStreamConfiguration halConfiguration);
170
171 /**
172 * processCaptureRequest:
173 *
Yin-Chia Yehbed3a942017-03-06 14:14:17 -0800174 * Send a list of capture requests to the HAL. The HAL must not return from
175 * this call until it is ready to accept the next set of requests to
176 * process. Only one call to processCaptureRequest() must be made at a time
177 * by the framework, and the calls must all be from the same thread. The
178 * next call to processCaptureRequest() must be made as soon as a new
179 * request and its associated buffers are available. In a normal preview
180 * scenario, this means the function is generally called again by the
181 * framework almost instantly. If more than one request is provided by the
182 * client, the HAL must process the requests in order of lowest index to
183 * highest index.
Zhijun He8486e412016-09-12 15:30:51 -0700184 *
Yin-Chia Yeh28eebbf2017-03-30 15:06:20 -0700185 * The cachesToRemove argument contains a list of buffer caches (see
186 * StreamBuffer document for more information on buffer cache) to be removed
187 * by camera HAL. Camera HAL must remove these cache entries whether or not
188 * this method returns OK.
189 *
Zhijun He8486e412016-09-12 15:30:51 -0700190 * The actual request processing is asynchronous, with the results of
191 * capture being returned by the HAL through the processCaptureResult()
192 * call. This call requires the result metadata to be available, but output
193 * buffers may simply provide sync fences to wait on. Multiple requests are
194 * expected to be in flight at once, to maintain full output frame rate.
195 *
196 * The framework retains ownership of the request structure. It is only
197 * guaranteed to be valid during this call. The HAL device must make copies
198 * of the information it needs to retain for the capture processing. The HAL
199 * is responsible for waiting on and closing the buffers' fences and
200 * returning the buffer handles to the framework.
201 *
202 * The HAL must write the file descriptor for the input buffer's release
203 * sync fence into input_buffer->release_fence, if input_buffer is not
204 * valid. If the HAL returns -1 for the input buffer release sync fence, the
205 * framework is free to immediately reuse the input buffer. Otherwise, the
206 * framework must wait on the sync fence before refilling and reusing the
207 * input buffer.
208 *
209 * The input/output buffers provided by the framework in each request
210 * may be brand new (having never before seen by the HAL).
211 *
212 * ------------------------------------------------------------------------
213 * Performance considerations:
214 *
215 * Handling a new buffer should be extremely lightweight and there must be
216 * no frame rate degradation or frame jitter introduced.
217 *
218 * This call must return fast enough to ensure that the requested frame
219 * rate can be sustained, especially for streaming cases (post-processing
220 * quality settings set to FAST). The HAL should return this call in 1
221 * frame interval, and must return from this call in 4 frame intervals.
222 *
223 * @return status Status code for the operation, one of:
224 * OK:
225 * On a successful start to processing the capture request
226 * ILLEGAL_ARGUMENT:
227 * If the input is malformed (the settings are empty when not
228 * allowed, there are 0 output buffers, etc) and capture processing
229 * cannot start. Failures during request processing must be
230 * handled by calling ICameraDeviceCallback::notify(). In case of
231 * this error, the framework retains responsibility for the
232 * stream buffers' fences and the buffer handles; the HAL must not
233 * close the fences or return these buffers with
234 * ICameraDeviceCallback::processCaptureResult().
235 * INTERNAL_ERROR:
236 * If the camera device has encountered a serious error. After this
237 * error is returned, only the close() method can be successfully
238 * called by the framework.
Yin-Chia Yehbed3a942017-03-06 14:14:17 -0800239 * @return numRequestProcessed Number of requests successfully processed by
240 * camera HAL. When status is OK, this must be equal to the size of
241 * requests. When the call fails, this number is the number of requests
242 * that HAL processed successfully before HAL runs into an error.
Zhijun He8486e412016-09-12 15:30:51 -0700243 *
244 */
Yin-Chia Yeh28eebbf2017-03-30 15:06:20 -0700245 processCaptureRequest(vec<CaptureRequest> requests,
246 vec<BufferCache> cachesToRemove)
Yin-Chia Yehbed3a942017-03-06 14:14:17 -0800247 generates (Status status, uint32_t numRequestProcessed);
Zhijun He8486e412016-09-12 15:30:51 -0700248
249 /**
Yifan Hong1192e1d2017-04-11 14:45:00 -0700250 * getCaptureRequestMetadataQueue:
251 *
252 * Retrieves the queue used along with processCaptureRequest. If
253 * client decides to use fast message queue to pass request metadata,
254 * it must:
255 * - Call getCaptureRequestMetadataQueue to retrieve the fast message queue;
256 * - In each of the requests sent in processCaptureRequest, set
257 * fmqSettingsSize field of CaptureRequest to be the size to read from the
258 * fast message queue; leave settings field of CaptureRequest empty.
259 *
260 * @return queue the queue that client writes request metadata to.
261 */
262 getCaptureRequestMetadataQueue() generates (fmq_sync<uint8_t> queue);
263
264 /**
Yifan Hong993e3d02017-04-12 16:31:23 -0700265 * getCaptureResultMetadataQueue:
266 *
267 * Retrieves the queue used along with
268 * ICameraDeviceCallback.processCaptureResult.
269 *
270 * Clients to ICameraDeviceSession must:
271 * - Call getCaptureRequestMetadataQueue to retrieve the fast message queue;
272 * - In implementation of ICameraDeviceCallback, test whether
273 * .fmqResultSize field is zero.
274 * - If .fmqResultSize != 0, read result metadata from the fast message
275 * queue;
276 * - otherwise, read result metadata in CaptureResult.result.
277 *
278 * @return queue the queue that implementation writes result metadata to.
279 */
280 getCaptureResultMetadataQueue() generates (fmq_sync<uint8_t> queue);
281
282 /**
Zhijun He8486e412016-09-12 15:30:51 -0700283 * flush:
284 *
285 * Flush all currently in-process captures and all buffers in the pipeline
286 * on the given device. Generally, this method is used to dump all state as
287 * quickly as possible in order to prepare for a configure_streams() call.
288 *
289 * No buffers are required to be successfully returned, so every buffer
290 * held at the time of flush() (whether successfully filled or not) may be
291 * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
292 * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
293 * provided they are successfully filled.
294 *
295 * All requests currently in the HAL are expected to be returned as soon as
296 * possible. Not-in-process requests must return errors immediately. Any
297 * interruptible hardware blocks must be stopped, and any uninterruptible
298 * blocks must be waited on.
299 *
300 * flush() may be called concurrently to processCaptureRequest(), with the
301 * expectation that processCaptureRequest returns quickly and the
302 * request submitted in that processCaptureRequest call is treated like
303 * all other in-flight requests. Due to concurrency issues, it is possible
304 * that from the HAL's point of view, a processCaptureRequest() call may
305 * be started after flush has been invoked but has not returned yet. If such
306 * a call happens before flush() returns, the HAL must treat the new
307 * capture request like other in-flight pending requests (see #4 below).
308 *
309 * More specifically, the HAL must follow below requirements for various
310 * cases:
311 *
312 * 1. For captures that are too late for the HAL to cancel/stop, and must be
313 * completed normally by the HAL; i.e. the HAL can send shutter/notify
314 * and processCaptureResult and buffers as normal.
315 *
316 * 2. For pending requests that have not done any processing, the HAL must
317 * call notify CAMERA3_MSG_ERROR_REQUEST, and return all the output
318 * buffers with processCaptureResult in the error state
319 * (CAMERA3_BUFFER_STATUS_ERROR). The HAL must not place the release
320 * fence into an error state, instead, the release fences must be set to
321 * the acquire fences passed by the framework, or -1 if they have been
322 * waited on by the HAL already. This is also the path to follow for any
323 * captures for which the HAL already called notify() with
324 * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers
325 * for. After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only
326 * processCaptureResults with buffers in CAMERA3_BUFFER_STATUS_ERROR
327 * are allowed. No further notifys or processCaptureResult with
328 * non-empty metadata is allowed.
329 *
330 * 3. For partially completed pending requests that do not have all the
331 * output buffers or perhaps missing metadata, the HAL must follow
332 * below:
333 *
334 * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected
335 * result metadata (i.e. one or more partial metadata) won't be
336 * available for the capture.
337 *
338 * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that
339 * won't be produced for the capture.
340 *
341 * 3.3. Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp
342 * before any buffers/metadata are returned with
343 * processCaptureResult.
344 *
345 * 3.4. For captures that will produce some results, the HAL must not
346 * call CAMERA3_MSG_ERROR_REQUEST, since that indicates complete
347 * failure.
348 *
349 * 3.5. Valid buffers/metadata must be passed to the framework as
350 * normal.
351 *
352 * 3.6. Failed buffers must be returned to the framework as described
353 * for case 2. But failed buffers do not have to follow the strict
354 * ordering valid buffers do, and may be out-of-order with respect
355 * to valid buffers. For example, if buffers A, B, C, D, E are sent,
356 * D and E are failed, then A, E, B, D, C is an acceptable return
357 * order.
358 *
359 * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is
360 * sufficient, no need to call processCaptureResult with empty
361 * metadata or equivalent.
362 *
363 * 4. If a flush() is invoked while a processCaptureRequest() invocation
364 * is active, that process call must return as soon as possible. In
365 * addition, if a processCaptureRequest() call is made after flush()
366 * has been invoked but before flush() has returned, the capture request
367 * provided by the late processCaptureRequest call must be treated
368 * like a pending request in case #2 above.
369 *
370 * flush() must only return when there are no more outstanding buffers or
371 * requests left in the HAL. The framework may call configure_streams (as
372 * the HAL state is now quiesced) or may issue new requests.
373 *
374 * Note that it's sufficient to only support fully-succeeded and
375 * fully-failed result cases. However, it is highly desirable to support
376 * the partial failure cases as well, as it could help improve the flush
377 * call overall performance.
378 *
379 * Performance requirements:
380 *
381 * The HAL should return from this call in 100ms, and must return from this
382 * call in 1000ms. And this call must not be blocked longer than pipeline
383 * latency (see S7 for definition).
384 *
385 * @return status Status code for the operation, one of:
386 * OK:
387 * On a successful flush of the camera HAL.
388 * INTERNAL_ERROR:
389 * If the camera device has encountered a serious error. After this
390 * error is returned, only the close() method can be successfully
391 * called by the framework.
392 */
393 flush() generates (Status status);
394
395 /**
396 * close:
397 *
398 * Shut down the camera device.
399 *
400 * After this call, all calls to this session instance must return
401 * INTERNAL_ERROR.
402 *
403 * This method must always succeed, even if the device has encountered a
404 * serious error.
405 */
406 close();
407};