blob: 9090f8371da4476e5de69a37447af04ed58fb434 [file] [log] [blame]
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08001/*
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_H
18#define ANDROID_SERVERS_CAMERA3_STREAM_H
19
20#include <gui/Surface.h>
21#include <utils/RefBase.h>
22#include <utils/String8.h>
23#include <utils/String16.h>
Igor Murashkin2fba5842013-04-22 14:03:54 -070024#include <utils/List.h>
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080025
26#include "hardware/camera3.h"
27
Shuzhen Wang686f6442017-06-20 16:16:04 -070028#include "utils/LatencyHistogram.h"
Igor Murashkin2fba5842013-04-22 14:03:54 -070029#include "Camera3StreamBufferListener.h"
30#include "Camera3StreamInterface.h"
31
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080032namespace android {
33
34namespace camera3 {
35
36/**
37 * A class for managing a single stream of input or output data from the camera
38 * device.
39 *
40 * The stream has an internal state machine to track whether it's
41 * connected/configured/etc.
42 *
43 * States:
44 *
45 * STATE_ERROR: A serious error has occurred, stream is unusable. Outstanding
46 * buffers may still be returned.
47 *
48 * STATE_CONSTRUCTED: The stream is ready for configuration, but buffers cannot
49 * be gotten yet. Not connected to any endpoint, no buffers are registered
50 * with the HAL.
51 *
52 * STATE_IN_CONFIG: Configuration has started, but not yet concluded. During this
53 * time, the usage, max_buffers, and priv fields of camera3_stream returned by
54 * startConfiguration() may be modified.
55 *
56 * STATE_IN_RE_CONFIG: Configuration has started, and the stream has been
57 * configured before. Need to track separately from IN_CONFIG to avoid
58 * re-registering buffers with HAL.
59 *
60 * STATE_CONFIGURED: Stream is configured, and has registered buffers with the
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -070061 * HAL (if necessary). The stream's getBuffer/returnBuffer work. The priv
62 * pointer may still be modified.
63 *
64 * STATE_PREPARING: The stream's buffers are being pre-allocated for use. On
65 * older HALs, this is done as part of configuration, but in newer HALs
66 * buffers may be allocated at time of first use. But some use cases require
67 * buffer allocation upfront, to minmize disruption due to lengthy allocation
68 * duration. In this state, only prepareNextBuffer() and cancelPrepare()
69 * may be called.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080070 *
71 * Transition table:
72 *
73 * <none> => STATE_CONSTRUCTED:
74 * When constructed with valid arguments
75 * <none> => STATE_ERROR:
76 * When constructed with invalid arguments
77 * STATE_CONSTRUCTED => STATE_IN_CONFIG:
78 * When startConfiguration() is called
79 * STATE_IN_CONFIG => STATE_CONFIGURED:
80 * When finishConfiguration() is called
81 * STATE_IN_CONFIG => STATE_ERROR:
82 * When finishConfiguration() fails to allocate or register buffers.
83 * STATE_CONFIGURED => STATE_IN_RE_CONFIG: *
84 * When startConfiguration() is called again, after making sure stream is
85 * idle with waitUntilIdle().
86 * STATE_IN_RE_CONFIG => STATE_CONFIGURED:
87 * When finishConfiguration() is called.
88 * STATE_IN_RE_CONFIG => STATE_ERROR:
89 * When finishConfiguration() fails to allocate or register buffers.
90 * STATE_CONFIGURED => STATE_CONSTRUCTED:
91 * When disconnect() is called after making sure stream is idle with
92 * waitUntilIdle().
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -070093 * STATE_CONFIGURED => STATE_PREPARING:
94 * When startPrepare is called before the stream has a buffer
95 * queued back into it for the first time.
96 * STATE_PREPARING => STATE_CONFIGURED:
97 * When sufficient prepareNextBuffer calls have been made to allocate
98 * all stream buffers, or cancelPrepare is called.
Chien-Yu Chene8c535e2016-04-14 12:18:26 -070099 * STATE_CONFIGURED => STATE_ABANDONED:
100 * When the buffer queue of the stream is abandoned.
Igor Murashkin13d315e2014-04-03 18:09:04 -0700101 *
102 * Status Tracking:
103 * Each stream is tracked by StatusTracker as a separate component,
104 * depending on the handed out buffer count. The state must be STATE_CONFIGURED
105 * in order for the component to be marked.
106 *
107 * It's marked in one of two ways:
108 *
109 * - ACTIVE: One or more buffers have been handed out (with #getBuffer).
110 * - IDLE: All buffers have been returned (with #returnBuffer), and their
111 * respective release_fence(s) have been signaled.
112 *
113 * A typical use case is output streams. When the HAL has any buffers
114 * dequeued, the stream is marked ACTIVE. When the HAL returns all buffers
115 * (e.g. if no capture requests are active), the stream is marked IDLE.
116 * In this use case, the app consumer does not affect the component status.
117 *
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800118 */
119class Camera3Stream :
120 protected camera3_stream,
Igor Murashkin2fba5842013-04-22 14:03:54 -0700121 public virtual Camera3StreamInterface,
122 public virtual RefBase {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800123 public:
124
125 virtual ~Camera3Stream();
126
127 static Camera3Stream* cast(camera3_stream *stream);
128 static const Camera3Stream* cast(const camera3_stream *stream);
129
130 /**
131 * Get the stream's ID
132 */
133 int getId() const;
134
135 /**
Zhijun He125684a2015-12-26 15:07:30 -0800136 * Get the output stream set id.
137 */
138 int getStreamSetId() const;
139
140 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800141 * Get the stream's dimensions and format
142 */
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800143 uint32_t getWidth() const;
144 uint32_t getHeight() const;
145 int getFormat() const;
146 android_dataspace getDataSpace() const;
Emilian Peev050f5dc2017-05-18 14:43:56 +0100147 uint64_t getUsage() const;
148 void setUsage(uint64_t usage);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800149
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800150 camera3_stream* asHalStream() override {
151 return this;
152 }
153
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800154 /**
155 * Start the stream configuration process. Returns a handle to the stream's
156 * information to be passed into the HAL device's configure_streams call.
157 *
158 * Until finishConfiguration() is called, no other methods on the stream may be
159 * called. The usage and max_buffers fields of camera3_stream may be modified
160 * between start/finishConfiguration, but may not be changed after that.
161 * The priv field of camera3_stream may be modified at any time after
162 * startConfiguration.
163 *
164 * Returns NULL in case of error starting configuration.
165 */
166 camera3_stream* startConfiguration();
167
168 /**
169 * Check if the stream is mid-configuration (start has been called, but not
170 * finish). Used for lazy completion of configuration.
171 */
172 bool isConfiguring() const;
173
174 /**
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800175 * Completes the stream configuration process. The stream information
176 * structure returned by startConfiguration() may no longer be modified
177 * after this call, but can still be read until the destruction of the
178 * stream.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800179 *
180 * Returns:
181 * OK on a successful configuration
182 * NO_INIT in case of a serious error from the HAL device
183 * NO_MEMORY in case of an error registering buffers
Zhijun He5d677d12016-05-29 16:52:39 -0700184 * INVALID_OPERATION in case connecting to the consumer failed or consumer
185 * doesn't exist yet.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800186 */
Eino-Ville Talvala0b1cb142016-12-19 16:29:17 -0800187 status_t finishConfiguration();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800188
189 /**
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700190 * Cancels the stream configuration process. This returns the stream to the
191 * initial state, allowing it to be configured again later.
192 * This is done if the HAL rejects the proposed combined stream configuration
193 */
194 status_t cancelConfiguration();
195
196 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700197 * Determine whether the stream has already become in-use (has received
198 * a valid filled buffer), which determines if a stream can still have
199 * prepareNextBuffer called on it.
200 */
201 bool isUnpreparable();
202
203 /**
204 * Start stream preparation. May only be called in the CONFIGURED state,
Ruben Brunkc78ac262015-08-13 17:58:46 -0700205 * when no valid buffers have yet been returned to this stream. Prepares
206 * up to maxCount buffers, or the maximum number of buffers needed by the
207 * pipeline if maxCount is ALLOCATE_PIPELINE_MAX.
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700208 *
209 * If no prepartion is necessary, returns OK and does not transition to
210 * PREPARING state. Otherwise, returns NOT_ENOUGH_DATA and transitions
211 * to PREPARING.
212 *
213 * This call performs no allocation, so is quick to call.
214 *
215 * Returns:
216 * OK if no more buffers need to be preallocated
217 * NOT_ENOUGH_DATA if calls to prepareNextBuffer are needed to finish
218 * buffer pre-allocation, and transitions to the PREPARING state.
219 * NO_INIT in case of a serious error from the HAL device
220 * INVALID_OPERATION if called when not in CONFIGURED state, or a
221 * valid buffer has already been returned to this stream.
222 */
Ruben Brunkc78ac262015-08-13 17:58:46 -0700223 status_t startPrepare(int maxCount);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700224
225 /**
226 * Check if the stream is mid-preparing.
227 */
228 bool isPreparing() const;
229
230 /**
231 * Continue stream buffer preparation by allocating the next
232 * buffer for this stream. May only be called in the PREPARED state.
233 *
234 * Returns OK and transitions to the CONFIGURED state if all buffers
235 * are allocated after the call concludes. Otherwise returns NOT_ENOUGH_DATA.
236 *
237 * This call allocates one buffer, which may take several milliseconds for
238 * large buffers.
239 *
240 * Returns:
241 * OK if no more buffers need to be preallocated, and transitions
242 * to the CONFIGURED state.
243 * NOT_ENOUGH_DATA if more calls to prepareNextBuffer are needed to finish
244 * buffer pre-allocation.
245 * NO_INIT in case of a serious error from the HAL device
246 * INVALID_OPERATION if called when not in CONFIGURED state, or a
247 * valid buffer has already been returned to this stream.
248 */
249 status_t prepareNextBuffer();
250
251 /**
252 * Cancel stream preparation early. In case allocation needs to be
253 * stopped, this method transitions the stream back to the CONFIGURED state.
254 * Buffers that have been allocated with prepareNextBuffer remain that way,
255 * but a later use of prepareNextBuffer will require just as many
256 * calls as if the earlier prepare attempt had not existed.
257 *
258 * Returns:
259 * OK if cancellation succeeded, and transitions to the CONFIGURED state
260 * INVALID_OPERATION if not in the PREPARING state
261 * NO_INIT in case of a serious error from the HAL device
262 */
263 status_t cancelPrepare();
264
265 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700266 * Tear down memory for this stream. This frees all unused gralloc buffers
267 * allocated for this stream, but leaves it ready for operation afterward.
268 *
269 * May only be called in the CONFIGURED state, and keeps the stream in
270 * the CONFIGURED state.
271 *
272 * Returns:
273 * OK if teardown succeeded.
274 * INVALID_OPERATION if not in the CONFIGURED state
275 * NO_INIT in case of a serious error from the HAL device
276 */
277 status_t tearDown();
278
279 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800280 * Fill in the camera3_stream_buffer with the next valid buffer for this
281 * stream, to hand over to the HAL.
282 *
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800283 * Multiple surfaces could share the same HAL stream, but a request may
284 * be only for a subset of surfaces. In this case, the
285 * Camera3StreamInterface object needs the surface ID information to acquire
286 * buffers for those surfaces.
287 *
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800288 * This method may only be called once finishConfiguration has been called.
289 * For bidirectional streams, this method applies to the output-side
290 * buffers.
291 *
292 */
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800293 status_t getBuffer(camera3_stream_buffer *buffer,
294 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800295
296 /**
297 * Return a buffer to the stream after use by the HAL.
298 *
299 * This method may only be called for buffers provided by getBuffer().
300 * For bidirectional streams, this method applies to the output-side buffers
301 */
302 status_t returnBuffer(const camera3_stream_buffer &buffer,
303 nsecs_t timestamp);
304
305 /**
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700306 * Fill in the camera3_stream_buffer with the next valid buffer for this
307 * stream, to hand over to the HAL.
308 *
309 * This method may only be called once finishConfiguration has been called.
310 * For bidirectional streams, this method applies to the input-side
311 * buffers.
312 *
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700313 * Normally this call will block until the handed out buffer count is less than the stream
314 * max buffer count; if respectHalLimit is set to false, this is ignored.
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700315 */
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700316 status_t getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit = true);
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700317
318 /**
319 * Return a buffer to the stream after use by the HAL.
320 *
321 * This method may only be called for buffers provided by getBuffer().
322 * For bidirectional streams, this method applies to the input-side buffers
323 */
324 status_t returnInputBuffer(const camera3_stream_buffer &buffer);
325
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700326 // get the buffer producer of the input buffer queue.
327 // only apply to input streams.
328 status_t getInputBufferProducer(sp<IGraphicBufferProducer> *producer);
329
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700330 /**
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800331 * Whether any of the stream's buffers are currently in use by the HAL,
332 * including buffers that have been returned but not yet had their
333 * release fence signaled.
334 */
335 bool hasOutstandingBuffers() const;
336
337 enum {
338 TIMEOUT_NEVER = -1
339 };
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700340
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800341 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700342 * Set the status tracker to notify about idle transitions
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800343 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700344 virtual status_t setStatusTracker(sp<StatusTracker> statusTracker);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800345
346 /**
347 * Disconnect stream from its non-HAL endpoint. After this,
348 * start/finishConfiguration must be called before the stream can be used
349 * again. This cannot be called if the stream has outstanding dequeued
350 * buffers.
351 */
352 status_t disconnect();
353
354 /**
355 * Debug dump of the stream's state.
356 */
Shuzhen Wang686f6442017-06-20 16:16:04 -0700357 virtual void dump(int fd, const Vector<String16> &args) const;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800358
Zhijun Hef0d962a2014-06-30 10:24:11 -0700359 /**
360 * Add a camera3 buffer listener. Adding the same listener twice has
361 * no effect.
362 */
Igor Murashkin2fba5842013-04-22 14:03:54 -0700363 void addBufferListener(
364 wp<Camera3StreamBufferListener> listener);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700365
366 /**
367 * Remove a camera3 buffer listener. Removing the same listener twice
368 * or the listener that was never added has no effect.
369 */
Igor Murashkin2fba5842013-04-22 14:03:54 -0700370 void removeBufferListener(
371 const sp<Camera3StreamBufferListener>& listener);
372
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700373
374 // Setting listener will remove previous listener (if exists)
375 virtual void setBufferFreedListener(
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700376 wp<Camera3StreamBufferFreedListener> listener) override;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700377
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700378 /**
379 * Return if the buffer queue of the stream is abandoned.
380 */
381 bool isAbandoned() const;
382
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800383 protected:
384 const int mId;
Zhijun He125684a2015-12-26 15:07:30 -0800385 /**
386 * Stream set id, used to indicate which group of this stream belongs to for buffer sharing
387 * across multiple streams.
388 *
389 * The default value is set to CAMERA3_STREAM_SET_ID_INVALID, which indicates that this stream
390 * doesn't intend to share buffers with any other streams, and this stream will fall back to
391 * the existing BufferQueue mechanism to manage the buffer allocations and buffer circulation.
392 * When a valid stream set id is set, this stream intends to use the Camera3BufferManager to
393 * manage the buffer allocations; the BufferQueue will only handle the buffer transaction
394 * between the producer and consumer. For this case, upon successfully registration, the streams
395 * with the same stream set id will potentially share the buffers allocated by
396 * Camera3BufferManager.
397 */
398 const int mSetId;
399
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800400 const String8 mName;
401 // Zero for formats with fixed buffer size for given dimensions.
402 const size_t mMaxSize;
403
404 enum {
405 STATE_ERROR,
406 STATE_CONSTRUCTED,
407 STATE_IN_CONFIG,
408 STATE_IN_RECONFIG,
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700409 STATE_CONFIGURED,
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700410 STATE_PREPARING,
411 STATE_ABANDONED
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800412 } mState;
413
414 mutable Mutex mLock;
415
416 Camera3Stream(int id, camera3_stream_type type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800417 uint32_t width, uint32_t height, size_t maxSize, int format,
Zhijun He125684a2015-12-26 15:07:30 -0800418 android_dataspace dataSpace, camera3_stream_rotation_t rotation,
419 int setId);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800420
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700421 wp<Camera3StreamBufferFreedListener> mBufferFreedListener;
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700422
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800423 /**
424 * Interface to be implemented by derived classes
425 */
426
427 // getBuffer / returnBuffer implementations
428
429 // Since camera3_stream_buffer includes a raw pointer to the stream,
430 // cast to camera3_stream*, implementations must increment the
431 // refcount of the stream manually in getBufferLocked, and decrement it in
432 // returnBufferLocked.
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800433 virtual status_t getBufferLocked(camera3_stream_buffer *buffer,
434 const std::vector<size_t>& surface_ids = std::vector<size_t>());
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800435 virtual status_t returnBufferLocked(const camera3_stream_buffer &buffer,
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700436 nsecs_t timestamp);
437 virtual status_t getInputBufferLocked(camera3_stream_buffer *buffer);
438 virtual status_t returnInputBufferLocked(
439 const camera3_stream_buffer &buffer);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800440 virtual bool hasOutstandingBuffersLocked() const = 0;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700441 // Get the buffer producer of the input buffer queue. Only apply to input streams.
442 virtual status_t getInputBufferProducerLocked(sp<IGraphicBufferProducer> *producer);
443
Igor Murashkine2172be2013-05-28 15:31:39 -0700444 // Can return -ENOTCONN when we are already disconnected (not an error)
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800445 virtual status_t disconnectLocked() = 0;
446
447 // Configure the buffer queue interface to the other end of the stream,
448 // after the HAL has provided usage and max_buffers values. After this call,
449 // the stream must be ready to produce all buffers for registration with
450 // HAL.
451 virtual status_t configureQueueLocked() = 0;
452
453 // Get the total number of buffers in the queue
454 virtual size_t getBufferCountLocked() = 0;
455
Zhijun He6adc9cc2014-04-15 14:09:55 -0700456 // Get handout output buffer count.
457 virtual size_t getHandoutOutputBufferCountLocked() = 0;
458
459 // Get handout input buffer count.
460 virtual size_t getHandoutInputBufferCountLocked() = 0;
461
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700462 // Get the usage flags for the other endpoint, or return
463 // INVALID_OPERATION if they cannot be obtained.
Emilian Peev050f5dc2017-05-18 14:43:56 +0100464 virtual status_t getEndpointUsage(uint64_t *usage) const = 0;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700465
Emilian Peev889234d2017-07-18 18:21:26 -0700466 // Return whether the buffer is in the list of outstanding buffers.
467 bool isOutstandingBuffer(const camera3_stream_buffer& buffer) const;
468
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700469 // Tracking for idle state
470 wp<StatusTracker> mStatusTracker;
471 // Status tracker component ID
472 int mStatusId;
473
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700474 // Tracking for stream prepare - whether this stream can still have
475 // prepareNextBuffer called on it.
476 bool mStreamUnpreparable;
477
Emilian Peev050f5dc2017-05-18 14:43:56 +0100478 uint64_t mUsage;
479
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800480 private:
Emilian Peev050f5dc2017-05-18 14:43:56 +0100481 uint64_t mOldUsage;
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800482 uint32_t mOldMaxBuffers;
Zhijun He6adc9cc2014-04-15 14:09:55 -0700483 Condition mOutputBufferReturnedSignal;
484 Condition mInputBufferReturnedSignal;
485 static const nsecs_t kWaitForBufferDuration = 3000000000LL; // 3000 ms
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800486
Igor Murashkin2fba5842013-04-22 14:03:54 -0700487 void fireBufferListenersLocked(const camera3_stream_buffer& buffer,
488 bool acquired, bool output);
489 List<wp<Camera3StreamBufferListener> > mBufferListenerList;
490
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700491 status_t cancelPrepareLocked();
492
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700493 // Remove the buffer from the list of outstanding buffers.
494 void removeOutstandingBuffer(const camera3_stream_buffer& buffer);
495
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700496 // Tracking for PREPARING state
497
498 // State of buffer preallocation. Only true if either prepareNextBuffer
499 // has been called sufficient number of times, or stream configuration
500 // had to register buffers with the HAL
501 bool mPrepared;
502
503 Vector<camera3_stream_buffer_t> mPreparedBuffers;
504 size_t mPreparedBufferIdx;
505
Ruben Brunkc78ac262015-08-13 17:58:46 -0700506 // Number of buffers allocated on last prepare call.
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800507 size_t mLastMaxCount;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700508
Emilian Peev889234d2017-07-18 18:21:26 -0700509 mutable Mutex mOutstandingBuffersLock;
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700510 // Outstanding buffers dequeued from the stream's buffer queue.
511 List<buffer_handle_t> mOutstandingBuffers;
512
Shuzhen Wang686f6442017-06-20 16:16:04 -0700513 // Latency histogram of the wait time for handout buffer count to drop below
514 // max_buffers.
515 static const int32_t kBufferLimitLatencyBinSize = 33; //in ms
516 CameraLatencyHistogram mBufferLimitLatency;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800517}; // class Camera3Stream
518
519}; // namespace camera3
520
521}; // namespace android
522
523#endif