blob: d177b576d4b918b3c15e10b4e133c4f5bd775d7e [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
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070029class StatusTracker;
30
Igor Murashkinae500e52013-04-22 14:03:54 -070031/**
32 * An interface for managing a single stream of input and/or output data from
33 * the camera device.
34 */
35class Camera3StreamInterface : public virtual RefBase {
36 public:
37 /**
38 * Get the stream's ID
39 */
40 virtual int getId() const = 0;
41
42 /**
43 * Get the stream's dimensions and format
44 */
45 virtual uint32_t getWidth() const = 0;
46 virtual uint32_t getHeight() const = 0;
47 virtual int getFormat() const = 0;
48
49 /**
50 * Start the stream configuration process. Returns a handle to the stream's
51 * information to be passed into the HAL device's configure_streams call.
52 *
53 * Until finishConfiguration() is called, no other methods on the stream may
54 * be called. The usage and max_buffers fields of camera3_stream may be
55 * modified between start/finishConfiguration, but may not be changed after
56 * that. The priv field of camera3_stream may be modified at any time after
57 * startConfiguration.
58 *
59 * Returns NULL in case of error starting configuration.
60 */
61 virtual camera3_stream* startConfiguration() = 0;
62
63 /**
64 * Check if the stream is mid-configuration (start has been called, but not
65 * finish). Used for lazy completion of configuration.
66 */
67 virtual bool isConfiguring() const = 0;
68
69 /**
70 * Completes the stream configuration process. During this call, the stream
71 * may call the device's register_stream_buffers() method. The stream
72 * information structure returned by startConfiguration() may no longer be
73 * modified after this call, but can still be read until the destruction of
74 * the stream.
75 *
76 * Returns:
77 * OK on a successful configuration
78 * NO_INIT in case of a serious error from the HAL device
79 * NO_MEMORY in case of an error registering buffers
80 * INVALID_OPERATION in case connecting to the consumer failed
81 */
82 virtual status_t finishConfiguration(camera3_device *hal3Device) = 0;
83
84 /**
Eino-Ville Talvala17543512014-08-06 14:32:02 -070085 * Cancels the stream configuration process. This returns the stream to the
86 * initial state, allowing it to be configured again later.
87 * This is done if the HAL rejects the proposed combined stream configuration
88 */
89 virtual status_t cancelConfiguration() = 0;
90
91 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -070092 * Determine whether the stream has already become in-use (has received
93 * a valid filled buffer), which determines if a stream can still have
94 * prepareNextBuffer called on it.
95 */
96 virtual bool isUnpreparable() = 0;
97
98 /**
99 * Start stream preparation. May only be called in the CONFIGURED state,
100 * when no valid buffers have yet been returned to this stream.
101 *
102 * If no prepartion is necessary, returns OK and does not transition to
103 * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions
104 * to PREPARING.
105 *
106 * Returns:
107 * OK if no more buffers need to be preallocated
108 * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish
109 * buffer pre-allocation, and transitions to the PREPARING state.
110 * NO_INIT in case of a serious error from the HAL device
111 * INVALID_OPERATION if called when not in CONFIGURED state, or a
112 * valid buffer has already been returned to this stream.
113 */
114 virtual status_t startPrepare() = 0;
115
116 /**
117 * Check if the stream is mid-preparing.
118 */
119 virtual bool isPreparing() const = 0;
120
121 /**
122 * Continue stream buffer preparation by allocating the next
123 * buffer for this stream. May only be called in the PREPARED state.
124 *
125 * Returns OK and transitions to the CONFIGURED state if all buffers
126 * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA.
127 *
128 * Returns:
129 * OK if no more buffers need to be preallocated, and transitions
130 * to the CONFIGURED state.
131 * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish
132 * buffer pre-allocation.
133 * NO_INIT in case of a serious error from the HAL device
134 * INVALID_OPERATION if called when not in CONFIGURED state, or a
135 * valid buffer has already been returned to this stream.
136 */
137 virtual status_t prepareNextBuffer() = 0;
138
139 /**
140 * Cancel stream preparation early. In case allocation needs to be
141 * stopped, this method transitions the stream back to the CONFIGURED state.
142 * Buffers that have been allocated with prepareNextBuffer remain that way,
143 * but a later use of prepareNextBuffer will require just as many
144 * calls as if the earlier prepare attempt had not existed.
145 *
146 * Returns:
147 * OK if cancellation succeeded, and transitions to the CONFIGURED state
148 * INVALID_OPERATION if not in the PREPARING state
149 * NO_INIT in case of a serious error from the HAL device
150 */
151 virtual status_t cancelPrepare() = 0;
152
153 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700154 * Fill in the camera3_stream_buffer with the next valid buffer for this
155 * stream, to hand over to the HAL.
156 *
157 * This method may only be called once finishConfiguration has been called.
158 * For bidirectional streams, this method applies to the output-side
159 * buffers.
160 *
161 */
162 virtual status_t getBuffer(camera3_stream_buffer *buffer) = 0;
163
164 /**
165 * Return a buffer to the stream after use by the HAL.
166 *
167 * This method may only be called for buffers provided by getBuffer().
168 * For bidirectional streams, this method applies to the output-side buffers
169 */
170 virtual status_t returnBuffer(const camera3_stream_buffer &buffer,
171 nsecs_t timestamp) = 0;
172
173 /**
174 * Fill in the camera3_stream_buffer with the next valid buffer for this
175 * stream, to hand over to the HAL.
176 *
177 * This method may only be called once finishConfiguration has been called.
178 * For bidirectional streams, this method applies to the input-side
179 * buffers.
180 *
181 */
182 virtual status_t getInputBuffer(camera3_stream_buffer *buffer) = 0;
183
184 /**
185 * Return a buffer to the stream after use by the HAL.
186 *
187 * This method may only be called for buffers provided by getBuffer().
188 * For bidirectional streams, this method applies to the input-side buffers
189 */
190 virtual status_t returnInputBuffer(const camera3_stream_buffer &buffer) = 0;
191
192 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700193 * Get the buffer producer of the input buffer queue.
194 *
195 * This method only applies to input streams.
196 */
197 virtual status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer) = 0;
198
199 /**
Igor Murashkinae500e52013-04-22 14:03:54 -0700200 * Whether any of the stream's buffers are currently in use by the HAL,
201 * including buffers that have been returned but not yet had their
202 * release fence signaled.
203 */
204 virtual bool hasOutstandingBuffers() const = 0;
205
206 enum {
207 TIMEOUT_NEVER = -1
208 };
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700209
Igor Murashkinae500e52013-04-22 14:03:54 -0700210 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700211 * Set the state tracker to use for signaling idle transitions.
Igor Murashkinae500e52013-04-22 14:03:54 -0700212 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700213 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker) = 0;
Igor Murashkinae500e52013-04-22 14:03:54 -0700214
215 /**
216 * Disconnect stream from its non-HAL endpoint. After this,
217 * start/finishConfiguration must be called before the stream can be used
218 * again. This cannot be called if the stream has outstanding dequeued
219 * buffers.
220 */
221 virtual status_t disconnect() = 0;
222
223 /**
224 * Debug dump of the stream's state.
225 */
226 virtual void dump(int fd, const Vector<String16> &args) const = 0;
227
228 virtual void addBufferListener(
229 wp<Camera3StreamBufferListener> listener) = 0;
230 virtual void removeBufferListener(
231 const sp<Camera3StreamBufferListener>& listener) = 0;
232};
233
234} // namespace camera3
235
236} // namespace android
237
238#endif