blob: 63456c41fe263343db5ba7b6e5a3c3c9915eb114 [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>
21#include "Camera3StreamBufferListener.h"
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -070022#include "Camera3StreamBufferFreedListener.h"
Igor Murashkinae500e52013-04-22 14:03:54 -070023
24struct camera3_stream_buffer;
25
26namespace android {
27
28namespace camera3 {
29
Zhijun He125684a2015-12-26 15:07:30 -080030enum {
31 /**
32 * This stream set ID indicates that the set ID is invalid, and this stream doesn't intend to
33 * share buffers with any other stream. It is illegal to register this kind of stream to
34 * Camera3BufferManager.
35 */
36 CAMERA3_STREAM_SET_ID_INVALID = -1,
37
38 /**
39 * Invalid output stream ID.
40 */
41 CAMERA3_STREAM_ID_INVALID = -1,
42};
43
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070044class StatusTracker;
45
Igor Murashkinae500e52013-04-22 14:03:54 -070046/**
47 * An interface for managing a single stream of input and/or output data from
48 * the camera device.
49 */
50class Camera3StreamInterface : public virtual RefBase {
51 public:
Ruben Brunkc78ac262015-08-13 17:58:46 -070052
53 enum {
54 ALLOCATE_PIPELINE_MAX = 0, // Allocate max buffers used by a given surface
55 };
56
Igor Murashkinae500e52013-04-22 14:03:54 -070057 /**
58 * Get the stream's ID
59 */
60 virtual int getId() const = 0;
61
62 /**
Zhijun He125684a2015-12-26 15:07:30 -080063 * Get the output stream set id.
64 */
65 virtual int getStreamSetId() const = 0;
66
67 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070068 * Get the stream's dimensions and format
69 */
70 virtual uint32_t getWidth() const = 0;
71 virtual uint32_t getHeight() const = 0;
72 virtual int getFormat() const = 0;
Eino-Ville Talvalad46a6b92015-05-14 17:26:24 -070073 virtual android_dataspace getDataSpace() const = 0;
Emilian Peev710c1422017-08-30 11:19:38 +010074 virtual void setFormatOverride(bool formatOverriden) = 0;
75 virtual bool isFormatOverridden() = 0;
76 virtual void setOriginalFormat(int originalFormat) = 0;
77 virtual int getOriginalFormat() = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -070078
79 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080080 * Get a HAL3 handle for the stream, without starting stream configuration.
81 */
82 virtual camera3_stream* asHalStream() = 0;
83
84 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070085 * Start the stream configuration process. Returns a handle to the stream's
86 * information to be passed into the HAL device's configure_streams call.
87 *
88 * Until finishConfiguration() is called, no other methods on the stream may
89 * be called. The usage and max_buffers fields of camera3_stream may be
90 * modified between start/finishConfiguration, but may not be changed after
91 * that. The priv field of camera3_stream may be modified at any time after
92 * startConfiguration.
93 *
94 * Returns NULL in case of error starting configuration.
95 */
96 virtual camera3_stream* startConfiguration() = 0;
97
98 /**
99 * Check if the stream is mid-configuration (start has been called, but not
100 * finish). Used for lazy completion of configuration.
101 */
102 virtual bool isConfiguring() const = 0;
103
104 /**
105 * Completes the stream configuration process. During this call, the stream
106 * may call the device's register_stream_buffers() method. The stream
107 * information structure returned by startConfiguration() may no longer be
108 * modified after this call, but can still be read until the destruction of
109 * the stream.
110 *
111 * Returns:
112 * OK on a successful configuration
113 * NO_INIT in case of a serious error from the HAL device
114 * NO_MEMORY in case of an error registering buffers
115 * INVALID_OPERATION in case connecting to the consumer failed
116 */
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800117 virtual status_t finishConfiguration() = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700118
119 /**
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700120 * Cancels the stream configuration process. This returns the stream to the
121 * initial state, allowing it to be configured again later.
122 * This is done if the HAL rejects the proposed combined stream configuration
123 */
124 virtual status_t cancelConfiguration() = 0;
125
126 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700127 * Determine whether the stream has already become in-use (has received
128 * a valid filled buffer), which determines if a stream can still have
129 * prepareNextBuffer called on it.
130 */
131 virtual bool isUnpreparable() = 0;
132
133 /**
134 * Start stream preparation. May only be called in the CONFIGURED state,
Ruben Brunkc78ac262015-08-13 17:58:46 -0700135 * when no valid buffers have yet been returned to this stream. Prepares
136 * up to maxCount buffers, or the maximum number of buffers needed by the
137 * pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700138 *
139 * If no prepartion is necessary, returns OK and does not transition to
140 * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions
141 * to PREPARING.
142 *
143 * Returns:
144 * OK if no more buffers need to be preallocated
145 * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish
146 * buffer pre-allocation, and transitions to the PREPARING state.
147 * NO_INIT in case of a serious error from the HAL device
148 * INVALID_OPERATION if called when not in CONFIGURED state, or a
149 * valid buffer has already been returned to this stream.
150 */
Ruben Brunkc78ac262015-08-13 17:58:46 -0700151 virtual status_t startPrepare(int maxCount) = 0;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700152
153 /**
154 * Check if the stream is mid-preparing.
155 */
156 virtual bool isPreparing() const = 0;
157
158 /**
159 * Continue stream buffer preparation by allocating the next
160 * buffer for this stream. May only be called in the PREPARED state.
161 *
162 * Returns OK and transitions to the CONFIGURED state if all buffers
163 * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA.
164 *
165 * Returns:
166 * OK if no more buffers need to be preallocated, and transitions
167 * to the CONFIGURED state.
168 * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish
169 * buffer pre-allocation.
170 * NO_INIT in case of a serious error from the HAL device
171 * INVALID_OPERATION if called when not in CONFIGURED state, or a
172 * valid buffer has already been returned to this stream.
173 */
174 virtual status_t prepareNextBuffer() = 0;
175
176 /**
177 * Cancel stream preparation early. In case allocation needs to be
178 * stopped, this method transitions the stream back to the CONFIGURED state.
179 * Buffers that have been allocated with prepareNextBuffer remain that way,
180 * but a later use of prepareNextBuffer will require just as many
181 * calls as if the earlier prepare attempt had not existed.
182 *
183 * Returns:
184 * OK if cancellation succeeded, and transitions to the CONFIGURED state
185 * INVALID_OPERATION if not in the PREPARING state
186 * NO_INIT in case of a serious error from the HAL device
187 */
188 virtual status_t cancelPrepare() = 0;
189
190 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700191 * Tear down memory for this stream. This frees all unused gralloc buffers
192 * allocated for this stream, but leaves it ready for operation afterward.
193 *
194 * May only be called in the CONFIGURED state, and keeps the stream in
195 * the CONFIGURED state.
196 *
197 * Returns:
198 * OK if teardown succeeded.
199 * INVALID_OPERATION if not in the CONFIGURED state
200 * NO_INIT in case of a serious error from the HAL device
201 */
202 virtual status_t tearDown() = 0;
203
204 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700205 * Fill in the camera3_stream_buffer with the next valid buffer for this
206 * stream, to hand over to the HAL.
207 *
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800208 * Multiple surfaces could share the same HAL stream, but a request may
209 * be only for a subset of surfaces. In this case, the
210 * Camera3StreamInterface object needs the surface ID information to acquire
211 * buffers for those surfaces. For the case of single surface for a HAL
212 * stream, surface_ids parameter has no effect.
213 *
Igor Murashkinae500e52013-04-22 14:03:54 -0700214 * This method may only be called once finishConfiguration has been called.
215 * For bidirectional streams, this method applies to the output-side
216 * buffers.
217 *
218 */
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800219 virtual status_t getBuffer(camera3_stream_buffer *buffer,
220 const std::vector<size_t>& surface_ids = std::vector<size_t>()) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700221
222 /**
223 * Return a buffer to the stream after use by the HAL.
224 *
225 * This method may only be called for buffers provided by getBuffer().
226 * For bidirectional streams, this method applies to the output-side buffers
227 */
228 virtual status_t returnBuffer(const camera3_stream_buffer &buffer,
229 nsecs_t timestamp) = 0;
230
231 /**
232 * Fill in the camera3_stream_buffer with the next valid buffer for this
233 * stream, to hand over to the HAL.
234 *
235 * This method may only be called once finishConfiguration has been called.
236 * For bidirectional streams, this method applies to the input-side
237 * buffers.
238 *
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700239 * Normally this call will block until the handed out buffer count is less than the stream
240 * max buffer count; if respectHalLimit is set to false, this is ignored.
Igor Murashkinae500e52013-04-22 14:03:54 -0700241 */
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700242 virtual status_t getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit = true) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700243
244 /**
245 * Return a buffer to the stream after use by the HAL.
246 *
247 * This method may only be called for buffers provided by getBuffer().
248 * For bidirectional streams, this method applies to the input-side buffers
249 */
250 virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0;
251
252 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700253 * Get the buffer producer of the input buffer queue.
254 *
255 * This method only applies to input streams.
256 */
257 virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0;
258
259 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700260 * Whether any of the stream's buffers are currently in use by the HAL,
261 * including buffers that have been returned but not yet had their
262 * release fence signaled.
263 */
264 virtual bool hasOutstandingBuffers() const = 0;
265
266 enum {
267 TIMEOUT_NEVER = -1
268 };
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700269
Igor Murashkinae500e52013-04-22 14:03:54 -0700270 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700271 * Set the state tracker to use for signaling idle transitions.
Igor Murashkinae500e52013-04-22 14:03:54 -0700272 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700273 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700274
275 /**
276 * Disconnect stream from its non-HAL endpoint. After this,
277 * start/finishConfiguration must be called before the stream can be used
278 * again. This cannot be called if the stream has outstanding dequeued
279 * buffers.
280 */
281 virtual status_t disconnect() = 0;
282
283 /**
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700284 * Return if the buffer queue of the stream is abandoned.
285 */
286 virtual bool isAbandoned() const = 0;
287
288 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700289 * Debug dump of the stream's state.
290 */
291 virtual void dump(int fd, const Vector<String16> &args) const = 0;
292
293 virtual void addBufferListener(
294 wp<Camera3StreamBufferListener> listener) = 0;
295 virtual void removeBufferListener(
296 const sp<Camera3StreamBufferListener>& listener) = 0;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700297
298 /**
299 * Setting listner will remove previous listener (if exists)
300 * Only allow set listener during stream configuration because stream is guaranteed to be IDLE
301 * at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks.
302 * Client is responsible to keep the listener object alive throughout the lifecycle of this
303 * Camera3Stream.
304 */
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700305 virtual void setBufferFreedListener(wp<Camera3StreamBufferFreedListener> listener) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700306};
307
308} // namespace camera3
309
310} // namespace android
311
312#endif