blob: ceea08a8e27acd41bfc7bee87546eeccdb35b92f [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"
22
23struct camera3_stream_buffer;
24
25namespace android {
26
27namespace camera3 {
28
Zhijun He125684a2015-12-26 15:07:30 -080029enum {
30 /**
31 * This stream set ID indicates that the set ID is invalid, and this stream doesn't intend to
32 * share buffers with any other stream. It is illegal to register this kind of stream to
33 * Camera3BufferManager.
34 */
35 CAMERA3_STREAM_SET_ID_INVALID = -1,
36
37 /**
38 * Invalid output stream ID.
39 */
40 CAMERA3_STREAM_ID_INVALID = -1,
41};
42
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070043class StatusTracker;
44
Igor Murashkinae500e52013-04-22 14:03:54 -070045/**
46 * An interface for managing a single stream of input and/or output data from
47 * the camera device.
48 */
49class Camera3StreamInterface : public virtual RefBase {
50 public:
Ruben Brunkc78ac262015-08-13 17:58:46 -070051
52 enum {
53 ALLOCATE_PIPELINE_MAX = 0, // Allocate max buffers used by a given surface
54 };
55
Igor Murashkinae500e52013-04-22 14:03:54 -070056 /**
57 * Get the stream's ID
58 */
59 virtual int getId() const = 0;
60
61 /**
Zhijun He125684a2015-12-26 15:07:30 -080062 * Get the output stream set id.
63 */
64 virtual int getStreamSetId() const = 0;
65
66 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070067 * Get the stream's dimensions and format
68 */
69 virtual uint32_t getWidth() const = 0;
70 virtual uint32_t getHeight() const = 0;
71 virtual int getFormat() const = 0;
Eino-Ville Talvalad46a6b92015-05-14 17:26:24 -070072 virtual android_dataspace getDataSpace() const = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -070073
74 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -080075 * Get a HAL3 handle for the stream, without starting stream configuration.
76 */
77 virtual camera3_stream* asHalStream() = 0;
78
79 /**
Igor Murashkinae500e52013-04-22 14:03:54 -070080 * Start the stream configuration process. Returns a handle to the stream's
81 * information to be passed into the HAL device's configure_streams call.
82 *
83 * Until finishConfiguration() is called, no other methods on the stream may
84 * be called. The usage and max_buffers fields of camera3_stream may be
85 * modified between start/finishConfiguration, but may not be changed after
86 * that. The priv field of camera3_stream may be modified at any time after
87 * startConfiguration.
88 *
89 * Returns NULL in case of error starting configuration.
90 */
91 virtual camera3_stream* startConfiguration() = 0;
92
93 /**
94 * Check if the stream is mid-configuration (start has been called, but not
95 * finish). Used for lazy completion of configuration.
96 */
97 virtual bool isConfiguring() const = 0;
98
99 /**
100 * Completes the stream configuration process. During this call, the stream
101 * may call the device's register_stream_buffers() method. The stream
102 * information structure returned by startConfiguration() may no longer be
103 * modified after this call, but can still be read until the destruction of
104 * the stream.
105 *
106 * Returns:
107 * OK on a successful configuration
108 * NO_INIT in case of a serious error from the HAL device
109 * NO_MEMORY in case of an error registering buffers
110 * INVALID_OPERATION in case connecting to the consumer failed
111 */
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800112 virtual status_t finishConfiguration() = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700113
114 /**
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700115 * Cancels the stream configuration process. This returns the stream to the
116 * initial state, allowing it to be configured again later.
117 * This is done if the HAL rejects the proposed combined stream configuration
118 */
119 virtual status_t cancelConfiguration() = 0;
120
121 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700122 * Determine whether the stream has already become in-use (has received
123 * a valid filled buffer), which determines if a stream can still have
124 * prepareNextBuffer called on it.
125 */
126 virtual bool isUnpreparable() = 0;
127
128 /**
129 * Start stream preparation. May only be called in the CONFIGURED state,
Ruben Brunkc78ac262015-08-13 17:58:46 -0700130 * when no valid buffers have yet been returned to this stream. Prepares
131 * up to maxCount buffers, or the maximum number of buffers needed by the
132 * pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700133 *
134 * If no prepartion is necessary, returns OK and does not transition to
135 * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions
136 * to PREPARING.
137 *
138 * Returns:
139 * OK if no more buffers need to be preallocated
140 * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish
141 * buffer pre-allocation, and transitions to the PREPARING state.
142 * NO_INIT in case of a serious error from the HAL device
143 * INVALID_OPERATION if called when not in CONFIGURED state, or a
144 * valid buffer has already been returned to this stream.
145 */
Ruben Brunkc78ac262015-08-13 17:58:46 -0700146 virtual status_t startPrepare(int maxCount) = 0;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700147
148 /**
149 * Check if the stream is mid-preparing.
150 */
151 virtual bool isPreparing() const = 0;
152
153 /**
154 * Continue stream buffer preparation by allocating the next
155 * buffer for this stream. May only be called in the PREPARED state.
156 *
157 * Returns OK and transitions to the CONFIGURED state if all buffers
158 * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA.
159 *
160 * Returns:
161 * OK if no more buffers need to be preallocated, and transitions
162 * to the CONFIGURED state.
163 * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish
164 * buffer pre-allocation.
165 * NO_INIT in case of a serious error from the HAL device
166 * INVALID_OPERATION if called when not in CONFIGURED state, or a
167 * valid buffer has already been returned to this stream.
168 */
169 virtual status_t prepareNextBuffer() = 0;
170
171 /**
172 * Cancel stream preparation early. In case allocation needs to be
173 * stopped, this method transitions the stream back to the CONFIGURED state.
174 * Buffers that have been allocated with prepareNextBuffer remain that way,
175 * but a later use of prepareNextBuffer will require just as many
176 * calls as if the earlier prepare attempt had not existed.
177 *
178 * Returns:
179 * OK if cancellation succeeded, and transitions to the CONFIGURED state
180 * INVALID_OPERATION if not in the PREPARING state
181 * NO_INIT in case of a serious error from the HAL device
182 */
183 virtual status_t cancelPrepare() = 0;
184
185 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700186 * Tear down memory for this stream. This frees all unused gralloc buffers
187 * allocated for this stream, but leaves it ready for operation afterward.
188 *
189 * May only be called in the CONFIGURED state, and keeps the stream in
190 * the CONFIGURED state.
191 *
192 * Returns:
193 * OK if teardown succeeded.
194 * INVALID_OPERATION if not in the CONFIGURED state
195 * NO_INIT in case of a serious error from the HAL device
196 */
197 virtual status_t tearDown() = 0;
198
199 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700200 * Fill in the camera3_stream_buffer with the next valid buffer for this
201 * stream, to hand over to the HAL.
202 *
203 * This method may only be called once finishConfiguration has been called.
204 * For bidirectional streams, this method applies to the output-side
205 * buffers.
206 *
207 */
208 virtual status_t getBuffer(camera3_stream_buffer *buffer) = 0;
209
210 /**
211 * Return a buffer to the stream after use by the HAL.
212 *
213 * This method may only be called for buffers provided by getBuffer().
214 * For bidirectional streams, this method applies to the output-side buffers
215 */
216 virtual status_t returnBuffer(const camera3_stream_buffer &buffer,
217 nsecs_t timestamp) = 0;
218
219 /**
220 * Fill in the camera3_stream_buffer with the next valid buffer for this
221 * stream, to hand over to the HAL.
222 *
223 * This method may only be called once finishConfiguration has been called.
224 * For bidirectional streams, this method applies to the input-side
225 * buffers.
226 *
227 */
228 virtual status_t getInputBuffer(camera3_stream_buffer *buffer) = 0;
229
230 /**
231 * Return a buffer to the stream after use by the HAL.
232 *
233 * This method may only be called for buffers provided by getBuffer().
234 * For bidirectional streams, this method applies to the input-side buffers
235 */
236 virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0;
237
238 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700239 * Get the buffer producer of the input buffer queue.
240 *
241 * This method only applies to input streams.
242 */
243 virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0;
244
245 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700246 * Whether any of the stream's buffers are currently in use by the HAL,
247 * including buffers that have been returned but not yet had their
248 * release fence signaled.
249 */
250 virtual bool hasOutstandingBuffers() const = 0;
251
252 enum {
253 TIMEOUT_NEVER = -1
254 };
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700255
Igor Murashkinae500e52013-04-22 14:03:54 -0700256 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700257 * Set the state tracker to use for signaling idle transitions.
Igor Murashkinae500e52013-04-22 14:03:54 -0700258 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700259 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700260
261 /**
262 * Disconnect stream from its non-HAL endpoint. After this,
263 * start/finishConfiguration must be called before the stream can be used
264 * again. This cannot be called if the stream has outstanding dequeued
265 * buffers.
266 */
267 virtual status_t disconnect() = 0;
268
269 /**
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700270 * Return if the buffer queue of the stream is abandoned.
271 */
272 virtual bool isAbandoned() const = 0;
273
274 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700275 * Debug dump of the stream's state.
276 */
277 virtual void dump(int fd, const Vector<String16> &args) const = 0;
278
279 virtual void addBufferListener(
280 wp<Camera3StreamBufferListener> listener) = 0;
281 virtual void removeBufferListener(
282 const sp<Camera3StreamBufferListener>& listener) = 0;
283};
284
285} // namespace camera3
286
287} // namespace android
288
289#endif