blob: 9d3e50fab62a92bee374867ffb4ba96050469a9a [file] [log] [blame]
Igor Murashkinae500e52013-04-22 14:03:54 -07001/*
2 * Copyright (C) 2013 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#ifndef ANDROID_SERVERS_CAMERA3_STREAM_INTERFACE_H
18#define ANDROID_SERVERS_CAMERA3_STREAM_INTERFACE_H
19
20#include <utils/RefBase.h>
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -080021
22#include <camera/CameraMetadata.h>
Igor Murashkinae500e52013-04-22 14:03:54 -070023#include "Camera3StreamBufferListener.h"
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -070024#include "Camera3StreamBufferFreedListener.h"
Igor Murashkinae500e52013-04-22 14:03:54 -070025
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -080026struct camera3_stream;
Igor Murashkinae500e52013-04-22 14:03:54 -070027struct camera3_stream_buffer;
28
29namespace android {
30
31namespace camera3 {
32
Zhijun He125684a2015-12-26 15:07:30 -080033enum {
34 /**
35 * This stream set ID indicates that the set ID is invalid, and this stream doesn't intend to
36 * share buffers with any other stream. It is illegal to register this kind of stream to
37 * Camera3BufferManager.
38 */
39 CAMERA3_STREAM_SET_ID_INVALID = -1,
40
41 /**
42 * Invalid output stream ID.
43 */
44 CAMERA3_STREAM_ID_INVALID = -1,
45};
46
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070047class StatusTracker;
48
Emilian Peev40ead602017-09-26 15:46:36 +010049// OutputStreamInfo describes the property of a camera stream.
50class OutputStreamInfo {
51 public:
52 int width;
53 int height;
54 int format;
55 android_dataspace dataSpace;
56 uint64_t consumerUsage;
57 bool finalized = false;
58 OutputStreamInfo() :
59 width(-1), height(-1), format(-1), dataSpace(HAL_DATASPACE_UNKNOWN),
60 consumerUsage(0) {}
61 OutputStreamInfo(int _width, int _height, int _format, android_dataspace _dataSpace,
62 uint64_t _consumerUsage) :
63 width(_width), height(_height), format(_format),
64 dataSpace(_dataSpace), consumerUsage(_consumerUsage) {}
65};
66
Igor Murashkinae500e52013-04-22 14:03:54 -070067/**
68 * An interface for managing a single stream of input and/or output data from
69 * the camera device.
70 */
71class Camera3StreamInterface : public virtual RefBase {
72 public:
Ruben Brunkc78ac262015-08-13 17:58:46 -070073
74 enum {
75 ALLOCATE_PIPELINE_MAX = 0, // Allocate max buffers used by a given surface
76 };
77
Igor Murashkinae500e52013-04-22 14:03:54 -070078 /**
79 * Get the stream's ID
80 */
81 virtual int getId() const = 0;
82
83 /**
Zhijun He125684a2015-12-26 15:07:30 -080084 * Get the output stream set id.
85 */
86 virtual int getStreamSetId() const = 0;
87
88 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070089 * Get the stream's dimensions and format
90 */
91 virtual uint32_t getWidth() const = 0;
92 virtual uint32_t getHeight() const = 0;
93 virtual int getFormat() const = 0;
Eino-Ville Talvalad46a6b92015-05-14 17:26:24 -070094 virtual android_dataspace getDataSpace() const = 0;
Emilian Peev710c1422017-08-30 11:19:38 +010095 virtual void setFormatOverride(bool formatOverriden) = 0;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -070096 virtual bool isFormatOverridden() const = 0;
97 virtual int getOriginalFormat() const = 0;
98 virtual void setDataSpaceOverride(bool dataSpaceOverriden) = 0;
99 virtual bool isDataSpaceOverridden() const = 0;
100 virtual android_dataspace getOriginalDataSpace() const = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700101
102 /**
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800103 * Offline processing
104 */
105 virtual void setOfflineProcessingSupport(bool support) = 0;
106 virtual bool getOfflineProcessingSupport() const = 0;
107
108 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800109 * Get a HAL3 handle for the stream, without starting stream configuration.
110 */
111 virtual camera3_stream* asHalStream() = 0;
112
113 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700114 * Start the stream configuration process. Returns a handle to the stream's
115 * information to be passed into the HAL device's configure_streams call.
116 *
117 * Until finishConfiguration() is called, no other methods on the stream may
118 * be called. The usage and max_buffers fields of camera3_stream may be
119 * modified between start/finishConfiguration, but may not be changed after
120 * that. The priv field of camera3_stream may be modified at any time after
121 * startConfiguration.
122 *
123 * Returns NULL in case of error starting configuration.
124 */
125 virtual camera3_stream* startConfiguration() = 0;
126
127 /**
128 * Check if the stream is mid-configuration (start has been called, but not
129 * finish). Used for lazy completion of configuration.
130 */
131 virtual bool isConfiguring() const = 0;
132
133 /**
134 * Completes the stream configuration process. During this call, the stream
135 * may call the device's register_stream_buffers() method. The stream
136 * information structure returned by startConfiguration() may no longer be
137 * modified after this call, but can still be read until the destruction of
138 * the stream.
139 *
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700140 * streamReconfigured: set to true when a stream is being reconfigured.
141 *
Igor Murashkinae500e52013-04-22 14:03:54 -0700142 * Returns:
143 * OK on a successful configuration
144 * NO_INIT in case of a serious error from the HAL device
145 * NO_MEMORY in case of an error registering buffers
146 * INVALID_OPERATION in case connecting to the consumer failed
147 */
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700148 virtual status_t finishConfiguration(/*out*/bool* streamReconfigured = nullptr) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700149
150 /**
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700151 * Cancels the stream configuration process. This returns the stream to the
152 * initial state, allowing it to be configured again later.
153 * This is done if the HAL rejects the proposed combined stream configuration
154 */
155 virtual status_t cancelConfiguration() = 0;
156
157 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700158 * Determine whether the stream has already become in-use (has received
159 * a valid filled buffer), which determines if a stream can still have
160 * prepareNextBuffer called on it.
161 */
162 virtual bool isUnpreparable() = 0;
163
164 /**
165 * Start stream preparation. May only be called in the CONFIGURED state,
Ruben Brunkc78ac262015-08-13 17:58:46 -0700166 * when no valid buffers have yet been returned to this stream. Prepares
167 * up to maxCount buffers, or the maximum number of buffers needed by the
168 * pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700169 *
170 * If no prepartion is necessary, returns OK and does not transition to
171 * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions
172 * to PREPARING.
173 *
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700174 * blockRequest specifies whether prepare will block upcoming capture
175 * request. This flag should only be set to false if the caller guarantees
176 * the whole buffer preparation process is done before capture request
177 * comes in.
178 *
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700179 * Returns:
180 * OK if no more buffers need to be preallocated
181 * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish
182 * buffer pre-allocation, and transitions to the PREPARING state.
183 * NO_INIT in case of a serious error from the HAL device
184 * INVALID_OPERATION if called when not in CONFIGURED state, or a
185 * valid buffer has already been returned to this stream.
186 */
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700187 virtual status_t startPrepare(int maxCount, bool blockRequest) = 0;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700188
189 /**
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700190 * Check if the request on a stream is blocked by prepare.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700191 */
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700192 virtual bool isBlockedByPrepare() const = 0;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700193
194 /**
195 * Continue stream buffer preparation by allocating the next
196 * buffer for this stream. May only be called in the PREPARED state.
197 *
198 * Returns OK and transitions to the CONFIGURED state if all buffers
199 * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA.
200 *
201 * Returns:
202 * OK if no more buffers need to be preallocated, and transitions
203 * to the CONFIGURED state.
204 * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish
205 * buffer pre-allocation.
206 * NO_INIT in case of a serious error from the HAL device
207 * INVALID_OPERATION if called when not in CONFIGURED state, or a
208 * valid buffer has already been returned to this stream.
209 */
210 virtual status_t prepareNextBuffer() = 0;
211
212 /**
213 * Cancel stream preparation early. In case allocation needs to be
214 * stopped, this method transitions the stream back to the CONFIGURED state.
215 * Buffers that have been allocated with prepareNextBuffer remain that way,
216 * but a later use of prepareNextBuffer will require just as many
217 * calls as if the earlier prepare attempt had not existed.
218 *
219 * Returns:
220 * OK if cancellation succeeded, and transitions to the CONFIGURED state
221 * INVALID_OPERATION if not in the PREPARING state
222 * NO_INIT in case of a serious error from the HAL device
223 */
224 virtual status_t cancelPrepare() = 0;
225
226 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700227 * Tear down memory for this stream. This frees all unused gralloc buffers
228 * allocated for this stream, but leaves it ready for operation afterward.
229 *
230 * May only be called in the CONFIGURED state, and keeps the stream in
231 * the CONFIGURED state.
232 *
233 * Returns:
234 * OK if teardown succeeded.
235 * INVALID_OPERATION if not in the CONFIGURED state
236 * NO_INIT in case of a serious error from the HAL device
237 */
238 virtual status_t tearDown() = 0;
239
240 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700241 * Fill in the camera3_stream_buffer with the next valid buffer for this
242 * stream, to hand over to the HAL.
243 *
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800244 * Multiple surfaces could share the same HAL stream, but a request may
245 * be only for a subset of surfaces. In this case, the
246 * Camera3StreamInterface object needs the surface ID information to acquire
247 * buffers for those surfaces. For the case of single surface for a HAL
248 * stream, surface_ids parameter has no effect.
249 *
Igor Murashkinae500e52013-04-22 14:03:54 -0700250 * This method may only be called once finishConfiguration has been called.
251 * For bidirectional streams, this method applies to the output-side
252 * buffers.
253 *
254 */
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800255 virtual status_t getBuffer(camera3_stream_buffer *buffer,
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700256 nsecs_t waitBufferTimeout,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800257 const std::vector<size_t>& surface_ids = std::vector<size_t>()) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700258
259 /**
260 * Return a buffer to the stream after use by the HAL.
261 *
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700262 * Multiple surfaces could share the same HAL stream, but a request may
263 * be only for a subset of surfaces. In this case, the
264 * Camera3StreamInterface object needs the surface ID information to attach
265 * buffers for those surfaces. For the case of single surface for a HAL
266 * stream, surface_ids parameter has no effect.
267 *
Igor Murashkinae500e52013-04-22 14:03:54 -0700268 * This method may only be called for buffers provided by getBuffer().
269 * For bidirectional streams, this method applies to the output-side buffers
270 */
271 virtual status_t returnBuffer(const camera3_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700272 nsecs_t timestamp, bool timestampIncreasing = true,
Emilian Peev538c90e2018-12-17 18:03:19 +0000273 const std::vector<size_t>& surface_ids = std::vector<size_t>(),
274 uint64_t frameNumber = 0) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700275
276 /**
277 * Fill in the camera3_stream_buffer with the next valid buffer for this
278 * stream, to hand over to the HAL.
279 *
280 * This method may only be called once finishConfiguration has been called.
281 * For bidirectional streams, this method applies to the input-side
282 * buffers.
283 *
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700284 * Normally this call will block until the handed out buffer count is less than the stream
285 * max buffer count; if respectHalLimit is set to false, this is ignored.
Igor Murashkinae500e52013-04-22 14:03:54 -0700286 */
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700287 virtual status_t getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit = true) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700288
289 /**
290 * Return a buffer to the stream after use by the HAL.
291 *
292 * This method may only be called for buffers provided by getBuffer().
293 * For bidirectional streams, this method applies to the input-side buffers
294 */
295 virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0;
296
297 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700298 * Get the buffer producer of the input buffer queue.
299 *
300 * This method only applies to input streams.
301 */
302 virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0;
303
304 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700305 * Whether any of the stream's buffers are currently in use by the HAL,
306 * including buffers that have been returned but not yet had their
307 * release fence signaled.
308 */
309 virtual bool hasOutstandingBuffers() const = 0;
310
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700311 /**
312 * Get number of buffers currently handed out to HAL
313 */
314 virtual size_t getOutstandingBuffersCount() const = 0;
315
Igor Murashkinae500e52013-04-22 14:03:54 -0700316 enum {
317 TIMEOUT_NEVER = -1
318 };
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700319
Igor Murashkinae500e52013-04-22 14:03:54 -0700320 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700321 * Set the state tracker to use for signaling idle transitions.
Igor Murashkinae500e52013-04-22 14:03:54 -0700322 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700323 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700324
325 /**
326 * Disconnect stream from its non-HAL endpoint. After this,
327 * start/finishConfiguration must be called before the stream can be used
328 * again. This cannot be called if the stream has outstanding dequeued
329 * buffers.
330 */
331 virtual status_t disconnect() = 0;
332
333 /**
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700334 * Return if the buffer queue of the stream is abandoned.
335 */
336 virtual bool isAbandoned() const = 0;
337
338 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700339 * Debug dump of the stream's state.
340 */
341 virtual void dump(int fd, const Vector<String16> &args) const = 0;
342
343 virtual void addBufferListener(
344 wp<Camera3StreamBufferListener> listener) = 0;
345 virtual void removeBufferListener(
346 const sp<Camera3StreamBufferListener>& listener) = 0;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700347
348 /**
349 * Setting listner will remove previous listener (if exists)
350 * Only allow set listener during stream configuration because stream is guaranteed to be IDLE
351 * at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks.
352 * Client is responsible to keep the listener object alive throughout the lifecycle of this
353 * Camera3Stream.
354 */
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700355 virtual void setBufferFreedListener(wp<Camera3StreamBufferFreedListener> listener) = 0;
Emilian Peev538c90e2018-12-17 18:03:19 +0000356
357 /**
358 * Notify buffer stream listeners about incoming request with particular frame number.
359 */
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800360 virtual void fireBufferRequestForFrameNumber(uint64_t frameNumber,
361 const CameraMetadata& settings) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700362};
363
364} // namespace camera3
365
366} // namespace android
367
368#endif