blob: f707ef835ad4a9fc8d86a660f98be97888fafa5f [file] [log] [blame]
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08003 *
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#define LOG_TAG "Camera3-Stream"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
19//#define LOG_NDEBUG 0
20
21#include <utils/Log.h>
22#include <utils/Trace.h>
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070023#include "device3/Camera3Stream.h"
24#include "device3/StatusTracker.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080025
Igor Murashkin13d315e2014-04-03 18:09:04 -070026#include <cutils/properties.h>
27
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080028namespace android {
29
30namespace camera3 {
31
32Camera3Stream::~Camera3Stream() {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070033 sp<StatusTracker> statusTracker = mStatusTracker.promote();
34 if (statusTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
35 statusTracker->removeComponent(mStatusId);
36 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080037}
38
39Camera3Stream* Camera3Stream::cast(camera3_stream *stream) {
40 return static_cast<Camera3Stream*>(stream);
41}
42
43const Camera3Stream* Camera3Stream::cast(const camera3_stream *stream) {
44 return static_cast<const Camera3Stream*>(stream);
45}
46
47Camera3Stream::Camera3Stream(int id,
48 camera3_stream_type type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080049 uint32_t width, uint32_t height, size_t maxSize, int format,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080050 android_dataspace dataSpace, camera3_stream_rotation_t rotation,
51 const String8& physicalCameraId, int setId) :
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080052 camera3_stream(),
53 mId(id),
Zhijun He125684a2015-12-26 15:07:30 -080054 mSetId(setId),
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080055 mName(String8::format("Camera3Stream[%d]", id)),
56 mMaxSize(maxSize),
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070057 mState(STATE_CONSTRUCTED),
Ruben Brunkc78ac262015-08-13 17:58:46 -070058 mStatusId(StatusTracker::NO_STATUS_ID),
Zhijun He5d677d12016-05-29 16:52:39 -070059 mStreamUnpreparable(true),
Emilian Peev050f5dc2017-05-18 14:43:56 +010060 mUsage(0),
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -080061 mOldUsage(0),
62 mOldMaxBuffers(0),
Shuzhen Wangf9b4eb92019-06-10 11:06:01 -070063 mOldFormat(-1),
64 mOldDataSpace(HAL_DATASPACE_UNKNOWN),
Zhijun He125684a2015-12-26 15:07:30 -080065 mPrepared(false),
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -070066 mPrepareBlockRequest(true),
Zhijun He125684a2015-12-26 15:07:30 -080067 mPreparedBufferIdx(0),
Shuzhen Wang686f6442017-06-20 16:16:04 -070068 mLastMaxCount(Camera3StreamInterface::ALLOCATE_PIPELINE_MAX),
Emilian Peev710c1422017-08-30 11:19:38 +010069 mBufferLimitLatency(kBufferLimitLatencyBinSize),
70 mFormatOverridden(false),
Yin-Chia Yeh90667662019-07-01 15:45:00 -070071 mOriginalFormat(format),
Shuzhen Wang92653952019-05-07 15:11:43 -070072 mDataSpaceOverridden(false),
Shuzhen Wang2f5010d2019-08-22 12:41:12 -070073 mOriginalDataSpace(dataSpace),
Shuzhen Wang26abaf42018-08-28 15:41:20 -070074 mPhysicalCameraId(physicalCameraId),
75 mLastTimestamp(0) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080076
77 camera3_stream::stream_type = type;
78 camera3_stream::width = width;
79 camera3_stream::height = height;
80 camera3_stream::format = format;
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080081 camera3_stream::data_space = dataSpace;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070082 camera3_stream::rotation = rotation;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080083 camera3_stream::max_buffers = 0;
84 camera3_stream::priv = NULL;
Shuzhen Wangc28189a2017-11-27 23:05:10 -080085 camera3_stream::physical_camera_id = mPhysicalCameraId.string();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080086
Yin-Chia Yehe9154ce2015-12-07 14:38:04 -080087 if ((format == HAL_PIXEL_FORMAT_BLOB || format == HAL_PIXEL_FORMAT_RAW_OPAQUE) &&
88 maxSize == 0) {
89 ALOGE("%s: BLOB or RAW_OPAQUE format with size == 0", __FUNCTION__);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080090 mState = STATE_ERROR;
91 }
92}
93
94int Camera3Stream::getId() const {
95 return mId;
96}
97
Zhijun He125684a2015-12-26 15:07:30 -080098int Camera3Stream::getStreamSetId() const {
99 return mSetId;
100}
101
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800102uint32_t Camera3Stream::getWidth() const {
103 return camera3_stream::width;
104}
105
106uint32_t Camera3Stream::getHeight() const {
107 return camera3_stream::height;
108}
109
110int Camera3Stream::getFormat() const {
111 return camera3_stream::format;
112}
113
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800114android_dataspace Camera3Stream::getDataSpace() const {
115 return camera3_stream::data_space;
116}
117
Emilian Peev050f5dc2017-05-18 14:43:56 +0100118uint64_t Camera3Stream::getUsage() const {
119 return mUsage;
120}
121
122void Camera3Stream::setUsage(uint64_t usage) {
123 mUsage = usage;
124}
125
Emilian Peev710c1422017-08-30 11:19:38 +0100126void Camera3Stream::setFormatOverride(bool formatOverridden) {
127 mFormatOverridden = formatOverridden;
128}
129
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700130bool Camera3Stream::isFormatOverridden() const {
Emilian Peev710c1422017-08-30 11:19:38 +0100131 return mFormatOverridden;
132}
133
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700134int Camera3Stream::getOriginalFormat() const {
135 return mOriginalFormat;
Emilian Peev710c1422017-08-30 11:19:38 +0100136}
137
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700138void Camera3Stream::setDataSpaceOverride(bool dataSpaceOverridden) {
139 mDataSpaceOverridden = dataSpaceOverridden;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700140}
141
142bool Camera3Stream::isDataSpaceOverridden() const {
143 return mDataSpaceOverridden;
144}
145
146android_dataspace Camera3Stream::getOriginalDataSpace() const {
147 return mOriginalDataSpace;
Emilian Peev710c1422017-08-30 11:19:38 +0100148}
149
Shuzhen Wang5c22c152017-12-31 17:12:25 -0800150const String8& Camera3Stream::physicalCameraId() const {
151 return mPhysicalCameraId;
152}
153
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000154status_t Camera3Stream::forceToIdle() {
155 ATRACE_CALL();
156 Mutex::Autolock l(mLock);
157 status_t res;
158
159 switch (mState) {
160 case STATE_ERROR:
161 case STATE_CONSTRUCTED:
162 case STATE_IN_CONFIG:
163 case STATE_PREPARING:
164 case STATE_IN_RECONFIG:
165 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
166 res = NO_INIT;
167 break;
168 case STATE_CONFIGURED:
169 if (hasOutstandingBuffersLocked()) {
170 sp<StatusTracker> statusTracker = mStatusTracker.promote();
171 if (statusTracker != 0) {
172 statusTracker->markComponentIdle(mStatusId, Fence::NO_FENCE);
173 }
174 }
175
176 mState = STATE_IN_IDLE;
177 res = OK;
178
179 break;
180 default:
181 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
182 res = NO_INIT;
183 }
184
185 return res;
186}
187
188status_t Camera3Stream::restoreConfiguredState() {
189 ATRACE_CALL();
190 Mutex::Autolock l(mLock);
191 status_t res;
192
193 switch (mState) {
194 case STATE_ERROR:
195 case STATE_CONSTRUCTED:
196 case STATE_IN_CONFIG:
197 case STATE_PREPARING:
198 case STATE_IN_RECONFIG:
199 case STATE_CONFIGURED:
200 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
201 res = NO_INIT;
202 break;
203 case STATE_IN_IDLE:
204 if (hasOutstandingBuffersLocked()) {
205 sp<StatusTracker> statusTracker = mStatusTracker.promote();
206 if (statusTracker != 0) {
207 statusTracker->markComponentActive(mStatusId);
208 }
209 }
210
211 mState = STATE_CONFIGURED;
212 res = OK;
213
214 break;
215 default:
216 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
217 res = NO_INIT;
218 }
219
220 return res;
221}
222
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800223camera3_stream* Camera3Stream::startConfiguration() {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700224 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800225 Mutex::Autolock l(mLock);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700226 status_t res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800227
228 switch (mState) {
229 case STATE_ERROR:
230 ALOGE("%s: In error state", __FUNCTION__);
231 return NULL;
232 case STATE_CONSTRUCTED:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000233 case STATE_IN_IDLE:
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800234 // OK
235 break;
236 case STATE_IN_CONFIG:
237 case STATE_IN_RECONFIG:
238 // Can start config again with no trouble; but don't redo
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800239 // mOldUsage/mOldMaxBuffers
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800240 return this;
241 case STATE_CONFIGURED:
Chien-Yu Chen90746f42015-04-15 13:50:13 -0700242 if (hasOutstandingBuffersLocked()) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800243 ALOGE("%s: Cannot configure stream; has outstanding buffers",
244 __FUNCTION__);
245 return NULL;
246 }
247 break;
248 default:
249 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
250 return NULL;
251 }
252
Emilian Peev050f5dc2017-05-18 14:43:56 +0100253 mOldUsage = mUsage;
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800254 mOldMaxBuffers = camera3_stream::max_buffers;
Shuzhen Wangf9b4eb92019-06-10 11:06:01 -0700255 mOldFormat = camera3_stream::format;
256 mOldDataSpace = camera3_stream::data_space;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700257
Emilian Peev050f5dc2017-05-18 14:43:56 +0100258 res = getEndpointUsage(&mUsage);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700259 if (res != OK) {
260 ALOGE("%s: Cannot query consumer endpoint usage!",
261 __FUNCTION__);
262 return NULL;
263 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800264
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000265 if (mState == STATE_IN_IDLE) {
266 // Skip configuration.
267 return this;
268 }
269
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700270 // Stop tracking if currently doing so
271 if (mStatusId != StatusTracker::NO_STATUS_ID) {
272 sp<StatusTracker> statusTracker = mStatusTracker.promote();
273 if (statusTracker != 0) {
274 statusTracker->removeComponent(mStatusId);
275 }
276 mStatusId = StatusTracker::NO_STATUS_ID;
277 }
278
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800279 if (mState == STATE_CONSTRUCTED) {
280 mState = STATE_IN_CONFIG;
281 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700282 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800283 mState = STATE_IN_RECONFIG;
284 }
285
286 return this;
287}
288
289bool Camera3Stream::isConfiguring() const {
290 Mutex::Autolock l(mLock);
291 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
292}
293
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700294status_t Camera3Stream::finishConfiguration(/*out*/bool* streamReconfigured) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700295 ATRACE_CALL();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700296 if (streamReconfigured != nullptr) {
297 *streamReconfigured = false;
298 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800299 Mutex::Autolock l(mLock);
300 switch (mState) {
301 case STATE_ERROR:
302 ALOGE("%s: In error state", __FUNCTION__);
303 return INVALID_OPERATION;
304 case STATE_IN_CONFIG:
305 case STATE_IN_RECONFIG:
306 // OK
307 break;
308 case STATE_CONSTRUCTED:
309 case STATE_CONFIGURED:
310 ALOGE("%s: Cannot finish configuration that hasn't been started",
311 __FUNCTION__);
312 return INVALID_OPERATION;
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000313 case STATE_IN_IDLE:
314 //Skip configuration in this state
315 return OK;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800316 default:
317 ALOGE("%s: Unknown state", __FUNCTION__);
318 return INVALID_OPERATION;
319 }
320
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700321 // Register for idle tracking
322 sp<StatusTracker> statusTracker = mStatusTracker.promote();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700323 if (statusTracker != 0 && mStatusId == StatusTracker::NO_STATUS_ID) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700324 mStatusId = statusTracker->addComponent();
325 }
326
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800327 // Check if the stream configuration is unchanged, and skip reallocation if
328 // so. As documented in hardware/camera3.h:configure_streams().
329 if (mState == STATE_IN_RECONFIG &&
Emilian Peev050f5dc2017-05-18 14:43:56 +0100330 mOldUsage == mUsage &&
Shuzhen Wangf9b4eb92019-06-10 11:06:01 -0700331 mOldMaxBuffers == camera3_stream::max_buffers &&
332 mOldDataSpace == camera3_stream::data_space &&
333 mOldFormat == camera3_stream::format) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800334 mState = STATE_CONFIGURED;
335 return OK;
336 }
337
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700338 // Reset prepared state, since buffer config has changed, and existing
339 // allocations are no longer valid
340 mPrepared = false;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700341 mPrepareBlockRequest = true;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700342 mStreamUnpreparable = false;
343
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700344 bool reconfiguring = (mState == STATE_IN_RECONFIG);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800345 status_t res;
346 res = configureQueueLocked();
Shuzhen Wang210ba5c2018-07-25 16:47:40 -0700347 // configureQueueLocked could return error in case of abandoned surface.
348 // Treat as non-fatal error.
349 if (res == NO_INIT || res == DEAD_OBJECT) {
350 ALOGE("%s: Unable to configure stream %d queue (non-fatal): %s (%d)",
351 __FUNCTION__, mId, strerror(-res), res);
352 mState = STATE_ABANDONED;
353 return res;
354 } else if (res != OK) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800355 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
356 __FUNCTION__, mId, strerror(-res), res);
357 mState = STATE_ERROR;
358 return res;
359 }
360
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700361 if (reconfiguring && streamReconfigured != nullptr) {
362 *streamReconfigured = true;
363 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800364 mState = STATE_CONFIGURED;
365
366 return res;
367}
368
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700369status_t Camera3Stream::cancelConfiguration() {
370 ATRACE_CALL();
371 Mutex::Autolock l(mLock);
372 switch (mState) {
373 case STATE_ERROR:
374 ALOGE("%s: In error state", __FUNCTION__);
375 return INVALID_OPERATION;
376 case STATE_IN_CONFIG:
377 case STATE_IN_RECONFIG:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000378 case STATE_IN_IDLE:
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700379 // OK
380 break;
381 case STATE_CONSTRUCTED:
382 case STATE_CONFIGURED:
383 ALOGE("%s: Cannot cancel configuration that hasn't been started",
384 __FUNCTION__);
385 return INVALID_OPERATION;
386 default:
387 ALOGE("%s: Unknown state", __FUNCTION__);
388 return INVALID_OPERATION;
389 }
390
Emilian Peev050f5dc2017-05-18 14:43:56 +0100391 mUsage = mOldUsage;
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800392 camera3_stream::max_buffers = mOldMaxBuffers;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700393
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000394 mState = ((mState == STATE_IN_RECONFIG) || (mState == STATE_IN_IDLE)) ? STATE_CONFIGURED :
395 STATE_CONSTRUCTED;
396
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700397 return OK;
398}
399
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700400bool Camera3Stream::isUnpreparable() {
401 ATRACE_CALL();
402
403 Mutex::Autolock l(mLock);
404 return mStreamUnpreparable;
405}
406
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700407status_t Camera3Stream::startPrepare(int maxCount, bool blockRequest) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700408 ATRACE_CALL();
409
410 Mutex::Autolock l(mLock);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700411
Ruben Brunkc78ac262015-08-13 17:58:46 -0700412 if (maxCount < 0) {
413 ALOGE("%s: Stream %d: Can't prepare stream if max buffer count (%d) is < 0",
414 __FUNCTION__, mId, maxCount);
415 return BAD_VALUE;
416 }
417
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700418 // This function should be only called when the stream is configured already.
419 if (mState != STATE_CONFIGURED) {
420 ALOGE("%s: Stream %d: Can't prepare stream if stream is not in CONFIGURED "
421 "state %d", __FUNCTION__, mId, mState);
422 return INVALID_OPERATION;
423 }
424
425 // This function can't be called if the stream has already received filled
426 // buffers
427 if (mStreamUnpreparable) {
428 ALOGE("%s: Stream %d: Can't prepare stream that's already in use",
429 __FUNCTION__, mId);
430 return INVALID_OPERATION;
431 }
432
433 if (getHandoutOutputBufferCountLocked() > 0) {
434 ALOGE("%s: Stream %d: Can't prepare stream that has outstanding buffers",
435 __FUNCTION__, mId);
436 return INVALID_OPERATION;
437 }
438
Ruben Brunkc78ac262015-08-13 17:58:46 -0700439 size_t pipelineMax = getBufferCountLocked();
440 size_t clampedCount = (pipelineMax < static_cast<size_t>(maxCount)) ?
441 pipelineMax : static_cast<size_t>(maxCount);
442 size_t bufferCount = (maxCount == Camera3StreamInterface::ALLOCATE_PIPELINE_MAX) ?
443 pipelineMax : clampedCount;
444
445 mPrepared = bufferCount <= mLastMaxCount;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700446 mPrepareBlockRequest = blockRequest;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700447
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700448 if (mPrepared) return OK;
449
Ruben Brunkc78ac262015-08-13 17:58:46 -0700450 mLastMaxCount = bufferCount;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700451
452 mPreparedBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount);
453 mPreparedBufferIdx = 0;
454
455 mState = STATE_PREPARING;
456
457 return NOT_ENOUGH_DATA;
458}
459
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700460bool Camera3Stream::isBlockedByPrepare() const {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700461 Mutex::Autolock l(mLock);
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700462 return mState == STATE_PREPARING && mPrepareBlockRequest;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700463}
464
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700465bool Camera3Stream::isAbandoned() const {
466 Mutex::Autolock l(mLock);
467 return mState == STATE_ABANDONED;
468}
469
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700470status_t Camera3Stream::prepareNextBuffer() {
471 ATRACE_CALL();
472
473 Mutex::Autolock l(mLock);
474 status_t res = OK;
475
476 // This function should be only called when the stream is preparing
477 if (mState != STATE_PREPARING) {
478 ALOGE("%s: Stream %d: Can't prepare buffer if stream is not in PREPARING "
479 "state %d", __FUNCTION__, mId, mState);
480 return INVALID_OPERATION;
481 }
482
483 // Get next buffer - this may allocate, and take a while for large buffers
484 res = getBufferLocked( &mPreparedBuffers.editItemAt(mPreparedBufferIdx) );
485 if (res != OK) {
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800486 ALOGE("%s: Stream %d: Unable to allocate buffer %zu during preparation",
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700487 __FUNCTION__, mId, mPreparedBufferIdx);
488 return NO_INIT;
489 }
490
491 mPreparedBufferIdx++;
492
493 // Check if we still have buffers left to allocate
494 if (mPreparedBufferIdx < mPreparedBuffers.size()) {
495 return NOT_ENOUGH_DATA;
496 }
497
498 // Done with prepare - mark stream as such, and return all buffers
499 // via cancelPrepare
500 mPrepared = true;
501
502 return cancelPrepareLocked();
503}
504
505status_t Camera3Stream::cancelPrepare() {
506 ATRACE_CALL();
507
508 Mutex::Autolock l(mLock);
509
510 return cancelPrepareLocked();
511}
512
513status_t Camera3Stream::cancelPrepareLocked() {
514 status_t res = OK;
515
516 // This function should be only called when the stream is mid-preparing.
517 if (mState != STATE_PREPARING) {
518 ALOGE("%s: Stream %d: Can't cancel prepare stream if stream is not in "
519 "PREPARING state %d", __FUNCTION__, mId, mState);
520 return INVALID_OPERATION;
521 }
522
523 // Return all valid buffers to stream, in ERROR state to indicate
524 // they weren't filled.
525 for (size_t i = 0; i < mPreparedBufferIdx; i++) {
526 mPreparedBuffers.editItemAt(i).release_fence = -1;
527 mPreparedBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
528 returnBufferLocked(mPreparedBuffers[i], 0);
529 }
530 mPreparedBuffers.clear();
531 mPreparedBufferIdx = 0;
532
533 mState = STATE_CONFIGURED;
534
535 return res;
536}
537
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700538status_t Camera3Stream::tearDown() {
539 ATRACE_CALL();
540 Mutex::Autolock l(mLock);
541
542 status_t res = OK;
543
544 // This function should be only called when the stream is configured.
545 if (mState != STATE_CONFIGURED) {
546 ALOGE("%s: Stream %d: Can't tear down stream if stream is not in "
547 "CONFIGURED state %d", __FUNCTION__, mId, mState);
548 return INVALID_OPERATION;
549 }
550
551 // If any buffers have been handed to the HAL, the stream cannot be torn down.
552 if (getHandoutOutputBufferCountLocked() > 0) {
553 ALOGE("%s: Stream %d: Can't tear down a stream that has outstanding buffers",
554 __FUNCTION__, mId);
555 return INVALID_OPERATION;
556 }
557
558 // Free buffers by disconnecting and then reconnecting to the buffer queue
559 // Only unused buffers will be dropped immediately; buffers that have been filled
560 // and are waiting to be acquired by the consumer and buffers that are currently
561 // acquired will be freed once they are released by the consumer.
562
563 res = disconnectLocked();
564 if (res != OK) {
565 if (res == -ENOTCONN) {
566 // queue has been disconnected, nothing left to do, so exit with success
567 return OK;
568 }
569 ALOGE("%s: Stream %d: Unable to disconnect to tear down buffers: %s (%d)",
570 __FUNCTION__, mId, strerror(-res), res);
571 return res;
572 }
573
574 mState = STATE_IN_CONFIG;
575
576 res = configureQueueLocked();
577 if (res != OK) {
578 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
579 __FUNCTION__, mId, strerror(-res), res);
580 mState = STATE_ERROR;
581 return res;
582 }
583
584 // Reset prepared state, since we've reconnected to the queue and can prepare again.
585 mPrepared = false;
586 mStreamUnpreparable = false;
587
588 mState = STATE_CONFIGURED;
589
590 return OK;
591}
592
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800593status_t Camera3Stream::getBuffer(camera3_stream_buffer *buffer,
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700594 nsecs_t waitBufferTimeout,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800595 const std::vector<size_t>& surface_ids) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800596 ATRACE_CALL();
597 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700598 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700599
Zhijun He6adc9cc2014-04-15 14:09:55 -0700600 // This function should be only called when the stream is configured already.
601 if (mState != STATE_CONFIGURED) {
602 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
603 __FUNCTION__, mId, mState);
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -0800604 if (mState == STATE_ABANDONED) {
605 return DEAD_OBJECT;
606 } else {
607 return INVALID_OPERATION;
608 }
Zhijun He6adc9cc2014-04-15 14:09:55 -0700609 }
610
611 // Wait for new buffer returned back if we are running into the limit.
612 if (getHandoutOutputBufferCountLocked() == camera3_stream::max_buffers) {
613 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
Shuzhen Wang686f6442017-06-20 16:16:04 -0700614 __FUNCTION__, camera3_stream::max_buffers);
615 nsecs_t waitStart = systemTime(SYSTEM_TIME_MONOTONIC);
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700616 if (waitBufferTimeout < kWaitForBufferDuration) {
617 waitBufferTimeout = kWaitForBufferDuration;
618 }
619 res = mOutputBufferReturnedSignal.waitRelative(mLock, waitBufferTimeout);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700620 nsecs_t waitEnd = systemTime(SYSTEM_TIME_MONOTONIC);
621 mBufferLimitLatency.add(waitStart, waitEnd);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700622 if (res != OK) {
623 if (res == TIMED_OUT) {
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700624 ALOGE("%s: wait for output buffer return timed out after %lldms (max_buffers %d)",
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700625 __FUNCTION__, waitBufferTimeout / 1000000LL,
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700626 camera3_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700627 }
628 return res;
629 }
630 }
631
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800632 res = getBufferLocked(buffer, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700633 if (res == OK) {
634 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700635 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700636 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700637 mOutstandingBuffers.push_back(*buffer->buffer);
638 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700639 }
640
641 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800642}
643
Emilian Peev889234d2017-07-18 18:21:26 -0700644bool Camera3Stream::isOutstandingBuffer(const camera3_stream_buffer &buffer) const{
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700645 if (buffer.buffer == nullptr) {
646 return false;
647 }
648
Emilian Peev889234d2017-07-18 18:21:26 -0700649 Mutex::Autolock l(mOutstandingBuffersLock);
650
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700651 for (auto b : mOutstandingBuffers) {
652 if (b == *buffer.buffer) {
653 return true;
654 }
655 }
656 return false;
657}
658
659void Camera3Stream::removeOutstandingBuffer(const camera3_stream_buffer &buffer) {
660 if (buffer.buffer == nullptr) {
661 return;
662 }
663
Emilian Peev889234d2017-07-18 18:21:26 -0700664 Mutex::Autolock l(mOutstandingBuffersLock);
665
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700666 for (auto b = mOutstandingBuffers.begin(); b != mOutstandingBuffers.end(); b++) {
667 if (*b == *buffer.buffer) {
668 mOutstandingBuffers.erase(b);
669 return;
670 }
671 }
672}
673
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800674status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700675 nsecs_t timestamp, bool timestampIncreasing,
Emilian Peev538c90e2018-12-17 18:03:19 +0000676 const std::vector<size_t>& surface_ids, uint64_t frameNumber) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800677 ATRACE_CALL();
678 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700679
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700680 // Check if this buffer is outstanding.
681 if (!isOutstandingBuffer(buffer)) {
682 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
683 return BAD_VALUE;
684 }
685
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700686 removeOutstandingBuffer(buffer);
687
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700688 // Buffer status may be changed, so make a copy of the stream_buffer struct.
689 camera3_stream_buffer b = buffer;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700690 if (timestampIncreasing && timestamp != 0 && timestamp <= mLastTimestamp) {
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700691 ALOGE("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64,
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700692 __FUNCTION__, mId, timestamp, mLastTimestamp);
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700693 b.status = CAMERA3_BUFFER_STATUS_ERROR;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700694 }
695 mLastTimestamp = timestamp;
696
Igor Murashkin13d315e2014-04-03 18:09:04 -0700697 /**
698 * TODO: Check that the state is valid first.
699 *
700 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
701 * >= HAL3.2 CONFIGURED only
702 *
703 * Do this for getBuffer as well.
704 */
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700705 status_t res = returnBufferLocked(b, timestamp, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700706 if (res == OK) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000707 fireBufferListenersLocked(b, /*acquired*/false, /*output*/true, timestamp, frameNumber);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700708 }
709
Chien-Yu Chenb83c1fe2015-09-10 16:15:21 -0700710 // Even if returning the buffer failed, we still want to signal whoever is waiting for the
711 // buffer to be returned.
712 mOutputBufferReturnedSignal.signal();
713
Igor Murashkin2fba5842013-04-22 14:03:54 -0700714 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800715}
716
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700717status_t Camera3Stream::getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700718 ATRACE_CALL();
719 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700720 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700721
Zhijun He6adc9cc2014-04-15 14:09:55 -0700722 // This function should be only called when the stream is configured already.
723 if (mState != STATE_CONFIGURED) {
724 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
725 __FUNCTION__, mId, mState);
726 return INVALID_OPERATION;
727 }
728
729 // Wait for new buffer returned back if we are running into the limit.
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700730 if (getHandoutInputBufferCountLocked() == camera3_stream::max_buffers && respectHalLimit) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700731 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
732 __FUNCTION__, camera3_stream::max_buffers);
733 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
734 if (res != OK) {
735 if (res == TIMED_OUT) {
736 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
737 kWaitForBufferDuration / 1000000LL);
738 }
739 return res;
740 }
741 }
742
743 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700744 if (res == OK) {
745 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700746 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700747 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700748 mOutstandingBuffers.push_back(*buffer->buffer);
749 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700750 }
751
752 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700753}
754
755status_t Camera3Stream::returnInputBuffer(const camera3_stream_buffer &buffer) {
756 ATRACE_CALL();
757 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700758
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700759 // Check if this buffer is outstanding.
760 if (!isOutstandingBuffer(buffer)) {
761 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
762 return BAD_VALUE;
763 }
764
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700765 removeOutstandingBuffer(buffer);
766
Igor Murashkin2fba5842013-04-22 14:03:54 -0700767 status_t res = returnInputBufferLocked(buffer);
768 if (res == OK) {
769 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700770 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700771 }
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700772
Igor Murashkin2fba5842013-04-22 14:03:54 -0700773 return res;
774}
775
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700776status_t Camera3Stream::getInputBufferProducer(sp<IGraphicBufferProducer> *producer) {
777 ATRACE_CALL();
778 Mutex::Autolock l(mLock);
779
780 return getInputBufferProducerLocked(producer);
781}
782
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800783void Camera3Stream::fireBufferRequestForFrameNumber(uint64_t frameNumber,
784 const CameraMetadata& settings) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000785 ATRACE_CALL();
786 Mutex::Autolock l(mLock);
787
788 for (auto &it : mBufferListenerList) {
789 sp<Camera3StreamBufferListener> listener = it.promote();
790 if (listener.get() != nullptr) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800791 listener->onBufferRequestForFrameNumber(frameNumber, getId(), settings);
Emilian Peev538c90e2018-12-17 18:03:19 +0000792 }
793 }
794}
795
Igor Murashkin2fba5842013-04-22 14:03:54 -0700796void Camera3Stream::fireBufferListenersLocked(
Emilian Peev538c90e2018-12-17 18:03:19 +0000797 const camera3_stream_buffer& buffer, bool acquired, bool output, nsecs_t timestamp,
798 uint64_t frameNumber) {
Igor Murashkin2fba5842013-04-22 14:03:54 -0700799 List<wp<Camera3StreamBufferListener> >::iterator it, end;
800
801 // TODO: finish implementing
802
803 Camera3StreamBufferListener::BufferInfo info =
804 Camera3StreamBufferListener::BufferInfo();
805 info.mOutput = output;
Shuzhen Wangb0fdc1e2016-03-20 23:21:39 -0700806 info.mError = (buffer.status == CAMERA3_BUFFER_STATUS_ERROR);
Emilian Peev538c90e2018-12-17 18:03:19 +0000807 info.mFrameNumber = frameNumber;
808 info.mTimestamp = timestamp;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700809 // TODO: rest of fields
810
811 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
812 it != end;
813 ++it) {
814
815 sp<Camera3StreamBufferListener> listener = it->promote();
816 if (listener != 0) {
817 if (acquired) {
818 listener->onBufferAcquired(info);
819 } else {
820 listener->onBufferReleased(info);
821 }
822 }
823 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700824}
825
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800826bool Camera3Stream::hasOutstandingBuffers() const {
827 ATRACE_CALL();
828 Mutex::Autolock l(mLock);
829 return hasOutstandingBuffersLocked();
830}
831
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700832size_t Camera3Stream::getOutstandingBuffersCount() const {
833 ATRACE_CALL();
834 Mutex::Autolock l(mLock);
835 return getHandoutOutputBufferCountLocked();
836}
837
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700838status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
839 Mutex::Autolock l(mLock);
840 sp<StatusTracker> oldTracker = mStatusTracker.promote();
841 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
842 oldTracker->removeComponent(mStatusId);
843 }
844 mStatusId = StatusTracker::NO_STATUS_ID;
845 mStatusTracker = statusTracker;
846
847 return OK;
848}
849
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800850status_t Camera3Stream::disconnect() {
851 ATRACE_CALL();
852 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700853 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
854 status_t res = disconnectLocked();
855
Shuzhen Wang686f6442017-06-20 16:16:04 -0700856 mBufferLimitLatency.log("Stream %d latency histogram for wait on max_buffers", mId);
857 mBufferLimitLatency.reset();
858
Igor Murashkine2172be2013-05-28 15:31:39 -0700859 if (res == -ENOTCONN) {
860 // "Already disconnected" -- not an error
861 return OK;
862 } else {
863 return res;
864 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800865}
866
Shuzhen Wang686f6442017-06-20 16:16:04 -0700867void Camera3Stream::dump(int fd, const Vector<String16> &args) const
868{
869 (void)args;
870 mBufferLimitLatency.dump(fd,
871 " Latency histogram for wait on max_buffers");
872}
873
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800874status_t Camera3Stream::getBufferLocked(camera3_stream_buffer *,
875 const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700876 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
877 return INVALID_OPERATION;
878}
879status_t Camera3Stream::returnBufferLocked(const camera3_stream_buffer &,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700880 nsecs_t, const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700881 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
882 return INVALID_OPERATION;
883}
884status_t Camera3Stream::getInputBufferLocked(camera3_stream_buffer *) {
885 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
886 return INVALID_OPERATION;
887}
888status_t Camera3Stream::returnInputBufferLocked(
889 const camera3_stream_buffer &) {
890 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
891 return INVALID_OPERATION;
892}
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800893status_t Camera3Stream::getInputBufferProducerLocked(sp<IGraphicBufferProducer>*) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700894 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
895 return INVALID_OPERATION;
896}
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700897
Igor Murashkin2fba5842013-04-22 14:03:54 -0700898void Camera3Stream::addBufferListener(
899 wp<Camera3StreamBufferListener> listener) {
900 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700901
902 List<wp<Camera3StreamBufferListener> >::iterator it, end;
903 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
904 it != end;
905 ) {
906 if (*it == listener) {
907 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
908 return;
909 }
910 it++;
911 }
912
Igor Murashkin2fba5842013-04-22 14:03:54 -0700913 mBufferListenerList.push_back(listener);
914}
915
916void Camera3Stream::removeBufferListener(
917 const sp<Camera3StreamBufferListener>& listener) {
918 Mutex::Autolock l(mLock);
919
920 bool erased = true;
921 List<wp<Camera3StreamBufferListener> >::iterator it, end;
922 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
923 it != end;
924 ) {
925
926 if (*it == listener) {
927 it = mBufferListenerList.erase(it);
928 erased = true;
929 } else {
930 ++it;
931 }
932 }
933
934 if (!erased) {
935 ALOGW("%s: Could not find listener to remove, already removed",
936 __FUNCTION__);
937 }
938}
939
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700940void Camera3Stream::setBufferFreedListener(
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700941 wp<Camera3StreamBufferFreedListener> listener) {
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700942 Mutex::Autolock l(mLock);
943 // Only allow set listener during stream configuration because stream is guaranteed to be IDLE
944 // at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks
945 if (mState != STATE_IN_CONFIG && mState != STATE_IN_RECONFIG) {
946 ALOGE("%s: listener must be set during stream configuration!",__FUNCTION__);
947 return;
948 }
949 mBufferFreedListener = listener;
950}
951
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800952}; // namespace camera3
953
954}; // namespace android