blob: d73a2f985d2e91c640cf1adfd92c29d9d4e1d35d [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),
Zhijun He125684a2015-12-26 15:07:30 -080063 mPrepared(false),
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -070064 mPrepareBlockRequest(true),
Zhijun He125684a2015-12-26 15:07:30 -080065 mPreparedBufferIdx(0),
Shuzhen Wang686f6442017-06-20 16:16:04 -070066 mLastMaxCount(Camera3StreamInterface::ALLOCATE_PIPELINE_MAX),
Emilian Peev710c1422017-08-30 11:19:38 +010067 mBufferLimitLatency(kBufferLimitLatencyBinSize),
68 mFormatOverridden(false),
Shuzhen Wangc28189a2017-11-27 23:05:10 -080069 mOriginalFormat(-1),
Shuzhen Wang26abaf42018-08-28 15:41:20 -070070 mPhysicalCameraId(physicalCameraId),
71 mLastTimestamp(0) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080072
73 camera3_stream::stream_type = type;
74 camera3_stream::width = width;
75 camera3_stream::height = height;
76 camera3_stream::format = format;
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080077 camera3_stream::data_space = dataSpace;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070078 camera3_stream::rotation = rotation;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080079 camera3_stream::max_buffers = 0;
80 camera3_stream::priv = NULL;
Shuzhen Wangc28189a2017-11-27 23:05:10 -080081 camera3_stream::physical_camera_id = mPhysicalCameraId.string();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080082
Yin-Chia Yehe9154ce2015-12-07 14:38:04 -080083 if ((format == HAL_PIXEL_FORMAT_BLOB || format == HAL_PIXEL_FORMAT_RAW_OPAQUE) &&
84 maxSize == 0) {
85 ALOGE("%s: BLOB or RAW_OPAQUE format with size == 0", __FUNCTION__);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080086 mState = STATE_ERROR;
87 }
88}
89
90int Camera3Stream::getId() const {
91 return mId;
92}
93
Zhijun He125684a2015-12-26 15:07:30 -080094int Camera3Stream::getStreamSetId() const {
95 return mSetId;
96}
97
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080098uint32_t Camera3Stream::getWidth() const {
99 return camera3_stream::width;
100}
101
102uint32_t Camera3Stream::getHeight() const {
103 return camera3_stream::height;
104}
105
106int Camera3Stream::getFormat() const {
107 return camera3_stream::format;
108}
109
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800110android_dataspace Camera3Stream::getDataSpace() const {
111 return camera3_stream::data_space;
112}
113
Emilian Peev050f5dc2017-05-18 14:43:56 +0100114uint64_t Camera3Stream::getUsage() const {
115 return mUsage;
116}
117
118void Camera3Stream::setUsage(uint64_t usage) {
119 mUsage = usage;
120}
121
Emilian Peev710c1422017-08-30 11:19:38 +0100122void Camera3Stream::setFormatOverride(bool formatOverridden) {
123 mFormatOverridden = formatOverridden;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700124 if (formatOverridden) mOriginalFormat = camera3_stream::format;
Emilian Peev710c1422017-08-30 11:19:38 +0100125}
126
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700127bool Camera3Stream::isFormatOverridden() const {
Emilian Peev710c1422017-08-30 11:19:38 +0100128 return mFormatOverridden;
129}
130
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700131int Camera3Stream::getOriginalFormat() const {
132 return mOriginalFormat;
Emilian Peev710c1422017-08-30 11:19:38 +0100133}
134
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700135void Camera3Stream::setDataSpaceOverride(bool dataSpaceOverridden) {
136 mDataSpaceOverridden = dataSpaceOverridden;
137 if (dataSpaceOverridden) mOriginalDataSpace = camera3_stream::data_space;
138}
139
140bool Camera3Stream::isDataSpaceOverridden() const {
141 return mDataSpaceOverridden;
142}
143
144android_dataspace Camera3Stream::getOriginalDataSpace() const {
145 return mOriginalDataSpace;
Emilian Peev710c1422017-08-30 11:19:38 +0100146}
147
Shuzhen Wang5c22c152017-12-31 17:12:25 -0800148const String8& Camera3Stream::physicalCameraId() const {
149 return mPhysicalCameraId;
150}
151
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000152status_t Camera3Stream::forceToIdle() {
153 ATRACE_CALL();
154 Mutex::Autolock l(mLock);
155 status_t res;
156
157 switch (mState) {
158 case STATE_ERROR:
159 case STATE_CONSTRUCTED:
160 case STATE_IN_CONFIG:
161 case STATE_PREPARING:
162 case STATE_IN_RECONFIG:
163 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
164 res = NO_INIT;
165 break;
166 case STATE_CONFIGURED:
167 if (hasOutstandingBuffersLocked()) {
168 sp<StatusTracker> statusTracker = mStatusTracker.promote();
169 if (statusTracker != 0) {
170 statusTracker->markComponentIdle(mStatusId, Fence::NO_FENCE);
171 }
172 }
173
174 mState = STATE_IN_IDLE;
175 res = OK;
176
177 break;
178 default:
179 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
180 res = NO_INIT;
181 }
182
183 return res;
184}
185
186status_t Camera3Stream::restoreConfiguredState() {
187 ATRACE_CALL();
188 Mutex::Autolock l(mLock);
189 status_t res;
190
191 switch (mState) {
192 case STATE_ERROR:
193 case STATE_CONSTRUCTED:
194 case STATE_IN_CONFIG:
195 case STATE_PREPARING:
196 case STATE_IN_RECONFIG:
197 case STATE_CONFIGURED:
198 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
199 res = NO_INIT;
200 break;
201 case STATE_IN_IDLE:
202 if (hasOutstandingBuffersLocked()) {
203 sp<StatusTracker> statusTracker = mStatusTracker.promote();
204 if (statusTracker != 0) {
205 statusTracker->markComponentActive(mStatusId);
206 }
207 }
208
209 mState = STATE_CONFIGURED;
210 res = OK;
211
212 break;
213 default:
214 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
215 res = NO_INIT;
216 }
217
218 return res;
219}
220
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800221camera3_stream* Camera3Stream::startConfiguration() {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700222 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800223 Mutex::Autolock l(mLock);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700224 status_t res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800225
226 switch (mState) {
227 case STATE_ERROR:
228 ALOGE("%s: In error state", __FUNCTION__);
229 return NULL;
230 case STATE_CONSTRUCTED:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000231 case STATE_IN_IDLE:
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800232 // OK
233 break;
234 case STATE_IN_CONFIG:
235 case STATE_IN_RECONFIG:
236 // Can start config again with no trouble; but don't redo
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800237 // mOldUsage/mOldMaxBuffers
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800238 return this;
239 case STATE_CONFIGURED:
Chien-Yu Chen90746f42015-04-15 13:50:13 -0700240 if (hasOutstandingBuffersLocked()) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800241 ALOGE("%s: Cannot configure stream; has outstanding buffers",
242 __FUNCTION__);
243 return NULL;
244 }
245 break;
246 default:
247 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
248 return NULL;
249 }
250
Emilian Peev050f5dc2017-05-18 14:43:56 +0100251 mOldUsage = mUsage;
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800252 mOldMaxBuffers = camera3_stream::max_buffers;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700253
Emilian Peev050f5dc2017-05-18 14:43:56 +0100254 res = getEndpointUsage(&mUsage);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700255 if (res != OK) {
256 ALOGE("%s: Cannot query consumer endpoint usage!",
257 __FUNCTION__);
258 return NULL;
259 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800260
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000261 if (mState == STATE_IN_IDLE) {
262 // Skip configuration.
263 return this;
264 }
265
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700266 // Stop tracking if currently doing so
267 if (mStatusId != StatusTracker::NO_STATUS_ID) {
268 sp<StatusTracker> statusTracker = mStatusTracker.promote();
269 if (statusTracker != 0) {
270 statusTracker->removeComponent(mStatusId);
271 }
272 mStatusId = StatusTracker::NO_STATUS_ID;
273 }
274
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800275 if (mState == STATE_CONSTRUCTED) {
276 mState = STATE_IN_CONFIG;
277 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700278 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800279 mState = STATE_IN_RECONFIG;
280 }
281
282 return this;
283}
284
285bool Camera3Stream::isConfiguring() const {
286 Mutex::Autolock l(mLock);
287 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
288}
289
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700290status_t Camera3Stream::finishConfiguration(/*out*/bool* streamReconfigured) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700291 ATRACE_CALL();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700292 if (streamReconfigured != nullptr) {
293 *streamReconfigured = false;
294 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800295 Mutex::Autolock l(mLock);
296 switch (mState) {
297 case STATE_ERROR:
298 ALOGE("%s: In error state", __FUNCTION__);
299 return INVALID_OPERATION;
300 case STATE_IN_CONFIG:
301 case STATE_IN_RECONFIG:
302 // OK
303 break;
304 case STATE_CONSTRUCTED:
305 case STATE_CONFIGURED:
306 ALOGE("%s: Cannot finish configuration that hasn't been started",
307 __FUNCTION__);
308 return INVALID_OPERATION;
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000309 case STATE_IN_IDLE:
310 //Skip configuration in this state
311 return OK;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800312 default:
313 ALOGE("%s: Unknown state", __FUNCTION__);
314 return INVALID_OPERATION;
315 }
316
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700317 // Register for idle tracking
318 sp<StatusTracker> statusTracker = mStatusTracker.promote();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700319 if (statusTracker != 0 && mStatusId == StatusTracker::NO_STATUS_ID) {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700320 mStatusId = statusTracker->addComponent();
321 }
322
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800323 // Check if the stream configuration is unchanged, and skip reallocation if
324 // so. As documented in hardware/camera3.h:configure_streams().
325 if (mState == STATE_IN_RECONFIG &&
Emilian Peev050f5dc2017-05-18 14:43:56 +0100326 mOldUsage == mUsage &&
Jayant Chowdhary7d355db2019-03-18 13:41:29 -0700327 mOldMaxBuffers == camera3_stream::max_buffers && !mDataSpaceOverridden) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800328 mState = STATE_CONFIGURED;
329 return OK;
330 }
331
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700332 // Reset prepared state, since buffer config has changed, and existing
333 // allocations are no longer valid
334 mPrepared = false;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700335 mPrepareBlockRequest = true;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700336 mStreamUnpreparable = false;
337
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700338 bool reconfiguring = (mState == STATE_IN_RECONFIG);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800339 status_t res;
340 res = configureQueueLocked();
Shuzhen Wang210ba5c2018-07-25 16:47:40 -0700341 // configureQueueLocked could return error in case of abandoned surface.
342 // Treat as non-fatal error.
343 if (res == NO_INIT || res == DEAD_OBJECT) {
344 ALOGE("%s: Unable to configure stream %d queue (non-fatal): %s (%d)",
345 __FUNCTION__, mId, strerror(-res), res);
346 mState = STATE_ABANDONED;
347 return res;
348 } else if (res != OK) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800349 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
350 __FUNCTION__, mId, strerror(-res), res);
351 mState = STATE_ERROR;
352 return res;
353 }
354
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700355 if (reconfiguring && streamReconfigured != nullptr) {
356 *streamReconfigured = true;
357 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800358 mState = STATE_CONFIGURED;
359
360 return res;
361}
362
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700363status_t Camera3Stream::cancelConfiguration() {
364 ATRACE_CALL();
365 Mutex::Autolock l(mLock);
366 switch (mState) {
367 case STATE_ERROR:
368 ALOGE("%s: In error state", __FUNCTION__);
369 return INVALID_OPERATION;
370 case STATE_IN_CONFIG:
371 case STATE_IN_RECONFIG:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000372 case STATE_IN_IDLE:
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700373 // OK
374 break;
375 case STATE_CONSTRUCTED:
376 case STATE_CONFIGURED:
377 ALOGE("%s: Cannot cancel configuration that hasn't been started",
378 __FUNCTION__);
379 return INVALID_OPERATION;
380 default:
381 ALOGE("%s: Unknown state", __FUNCTION__);
382 return INVALID_OPERATION;
383 }
384
Emilian Peev050f5dc2017-05-18 14:43:56 +0100385 mUsage = mOldUsage;
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800386 camera3_stream::max_buffers = mOldMaxBuffers;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700387
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000388 mState = ((mState == STATE_IN_RECONFIG) || (mState == STATE_IN_IDLE)) ? STATE_CONFIGURED :
389 STATE_CONSTRUCTED;
390
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700391 return OK;
392}
393
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700394bool Camera3Stream::isUnpreparable() {
395 ATRACE_CALL();
396
397 Mutex::Autolock l(mLock);
398 return mStreamUnpreparable;
399}
400
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700401status_t Camera3Stream::startPrepare(int maxCount, bool blockRequest) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700402 ATRACE_CALL();
403
404 Mutex::Autolock l(mLock);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700405
Ruben Brunkc78ac262015-08-13 17:58:46 -0700406 if (maxCount < 0) {
407 ALOGE("%s: Stream %d: Can't prepare stream if max buffer count (%d) is < 0",
408 __FUNCTION__, mId, maxCount);
409 return BAD_VALUE;
410 }
411
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700412 // This function should be only called when the stream is configured already.
413 if (mState != STATE_CONFIGURED) {
414 ALOGE("%s: Stream %d: Can't prepare stream if stream is not in CONFIGURED "
415 "state %d", __FUNCTION__, mId, mState);
416 return INVALID_OPERATION;
417 }
418
419 // This function can't be called if the stream has already received filled
420 // buffers
421 if (mStreamUnpreparable) {
422 ALOGE("%s: Stream %d: Can't prepare stream that's already in use",
423 __FUNCTION__, mId);
424 return INVALID_OPERATION;
425 }
426
427 if (getHandoutOutputBufferCountLocked() > 0) {
428 ALOGE("%s: Stream %d: Can't prepare stream that has outstanding buffers",
429 __FUNCTION__, mId);
430 return INVALID_OPERATION;
431 }
432
Ruben Brunkc78ac262015-08-13 17:58:46 -0700433 size_t pipelineMax = getBufferCountLocked();
434 size_t clampedCount = (pipelineMax < static_cast<size_t>(maxCount)) ?
435 pipelineMax : static_cast<size_t>(maxCount);
436 size_t bufferCount = (maxCount == Camera3StreamInterface::ALLOCATE_PIPELINE_MAX) ?
437 pipelineMax : clampedCount;
438
439 mPrepared = bufferCount <= mLastMaxCount;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700440 mPrepareBlockRequest = blockRequest;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700441
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700442 if (mPrepared) return OK;
443
Ruben Brunkc78ac262015-08-13 17:58:46 -0700444 mLastMaxCount = bufferCount;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700445
446 mPreparedBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount);
447 mPreparedBufferIdx = 0;
448
449 mState = STATE_PREPARING;
450
451 return NOT_ENOUGH_DATA;
452}
453
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700454bool Camera3Stream::isBlockedByPrepare() const {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700455 Mutex::Autolock l(mLock);
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700456 return mState == STATE_PREPARING && mPrepareBlockRequest;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700457}
458
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700459bool Camera3Stream::isAbandoned() const {
460 Mutex::Autolock l(mLock);
461 return mState == STATE_ABANDONED;
462}
463
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700464status_t Camera3Stream::prepareNextBuffer() {
465 ATRACE_CALL();
466
467 Mutex::Autolock l(mLock);
468 status_t res = OK;
469
470 // This function should be only called when the stream is preparing
471 if (mState != STATE_PREPARING) {
472 ALOGE("%s: Stream %d: Can't prepare buffer if stream is not in PREPARING "
473 "state %d", __FUNCTION__, mId, mState);
474 return INVALID_OPERATION;
475 }
476
477 // Get next buffer - this may allocate, and take a while for large buffers
478 res = getBufferLocked( &mPreparedBuffers.editItemAt(mPreparedBufferIdx) );
479 if (res != OK) {
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800480 ALOGE("%s: Stream %d: Unable to allocate buffer %zu during preparation",
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700481 __FUNCTION__, mId, mPreparedBufferIdx);
482 return NO_INIT;
483 }
484
485 mPreparedBufferIdx++;
486
487 // Check if we still have buffers left to allocate
488 if (mPreparedBufferIdx < mPreparedBuffers.size()) {
489 return NOT_ENOUGH_DATA;
490 }
491
492 // Done with prepare - mark stream as such, and return all buffers
493 // via cancelPrepare
494 mPrepared = true;
495
496 return cancelPrepareLocked();
497}
498
499status_t Camera3Stream::cancelPrepare() {
500 ATRACE_CALL();
501
502 Mutex::Autolock l(mLock);
503
504 return cancelPrepareLocked();
505}
506
507status_t Camera3Stream::cancelPrepareLocked() {
508 status_t res = OK;
509
510 // This function should be only called when the stream is mid-preparing.
511 if (mState != STATE_PREPARING) {
512 ALOGE("%s: Stream %d: Can't cancel prepare stream if stream is not in "
513 "PREPARING state %d", __FUNCTION__, mId, mState);
514 return INVALID_OPERATION;
515 }
516
517 // Return all valid buffers to stream, in ERROR state to indicate
518 // they weren't filled.
519 for (size_t i = 0; i < mPreparedBufferIdx; i++) {
520 mPreparedBuffers.editItemAt(i).release_fence = -1;
521 mPreparedBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
522 returnBufferLocked(mPreparedBuffers[i], 0);
523 }
524 mPreparedBuffers.clear();
525 mPreparedBufferIdx = 0;
526
527 mState = STATE_CONFIGURED;
528
529 return res;
530}
531
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700532status_t Camera3Stream::tearDown() {
533 ATRACE_CALL();
534 Mutex::Autolock l(mLock);
535
536 status_t res = OK;
537
538 // This function should be only called when the stream is configured.
539 if (mState != STATE_CONFIGURED) {
540 ALOGE("%s: Stream %d: Can't tear down stream if stream is not in "
541 "CONFIGURED state %d", __FUNCTION__, mId, mState);
542 return INVALID_OPERATION;
543 }
544
545 // If any buffers have been handed to the HAL, the stream cannot be torn down.
546 if (getHandoutOutputBufferCountLocked() > 0) {
547 ALOGE("%s: Stream %d: Can't tear down a stream that has outstanding buffers",
548 __FUNCTION__, mId);
549 return INVALID_OPERATION;
550 }
551
552 // Free buffers by disconnecting and then reconnecting to the buffer queue
553 // Only unused buffers will be dropped immediately; buffers that have been filled
554 // and are waiting to be acquired by the consumer and buffers that are currently
555 // acquired will be freed once they are released by the consumer.
556
557 res = disconnectLocked();
558 if (res != OK) {
559 if (res == -ENOTCONN) {
560 // queue has been disconnected, nothing left to do, so exit with success
561 return OK;
562 }
563 ALOGE("%s: Stream %d: Unable to disconnect to tear down buffers: %s (%d)",
564 __FUNCTION__, mId, strerror(-res), res);
565 return res;
566 }
567
568 mState = STATE_IN_CONFIG;
569
570 res = configureQueueLocked();
571 if (res != OK) {
572 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
573 __FUNCTION__, mId, strerror(-res), res);
574 mState = STATE_ERROR;
575 return res;
576 }
577
578 // Reset prepared state, since we've reconnected to the queue and can prepare again.
579 mPrepared = false;
580 mStreamUnpreparable = false;
581
582 mState = STATE_CONFIGURED;
583
584 return OK;
585}
586
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800587status_t Camera3Stream::getBuffer(camera3_stream_buffer *buffer,
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700588 nsecs_t waitBufferTimeout,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800589 const std::vector<size_t>& surface_ids) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800590 ATRACE_CALL();
591 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700592 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700593
Zhijun He6adc9cc2014-04-15 14:09:55 -0700594 // This function should be only called when the stream is configured already.
595 if (mState != STATE_CONFIGURED) {
596 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
597 __FUNCTION__, mId, mState);
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -0800598 if (mState == STATE_ABANDONED) {
599 return DEAD_OBJECT;
600 } else {
601 return INVALID_OPERATION;
602 }
Zhijun He6adc9cc2014-04-15 14:09:55 -0700603 }
604
605 // Wait for new buffer returned back if we are running into the limit.
606 if (getHandoutOutputBufferCountLocked() == camera3_stream::max_buffers) {
607 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
Shuzhen Wang686f6442017-06-20 16:16:04 -0700608 __FUNCTION__, camera3_stream::max_buffers);
609 nsecs_t waitStart = systemTime(SYSTEM_TIME_MONOTONIC);
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700610 if (waitBufferTimeout < kWaitForBufferDuration) {
611 waitBufferTimeout = kWaitForBufferDuration;
612 }
613 res = mOutputBufferReturnedSignal.waitRelative(mLock, waitBufferTimeout);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700614 nsecs_t waitEnd = systemTime(SYSTEM_TIME_MONOTONIC);
615 mBufferLimitLatency.add(waitStart, waitEnd);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700616 if (res != OK) {
617 if (res == TIMED_OUT) {
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700618 ALOGE("%s: wait for output buffer return timed out after %lldms (max_buffers %d)",
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700619 __FUNCTION__, waitBufferTimeout / 1000000LL,
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700620 camera3_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700621 }
622 return res;
623 }
624 }
625
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800626 res = getBufferLocked(buffer, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700627 if (res == OK) {
628 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700629 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700630 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700631 mOutstandingBuffers.push_back(*buffer->buffer);
632 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700633 }
634
635 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800636}
637
Emilian Peev889234d2017-07-18 18:21:26 -0700638bool Camera3Stream::isOutstandingBuffer(const camera3_stream_buffer &buffer) const{
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700639 if (buffer.buffer == nullptr) {
640 return false;
641 }
642
Emilian Peev889234d2017-07-18 18:21:26 -0700643 Mutex::Autolock l(mOutstandingBuffersLock);
644
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700645 for (auto b : mOutstandingBuffers) {
646 if (b == *buffer.buffer) {
647 return true;
648 }
649 }
650 return false;
651}
652
653void Camera3Stream::removeOutstandingBuffer(const camera3_stream_buffer &buffer) {
654 if (buffer.buffer == nullptr) {
655 return;
656 }
657
Emilian Peev889234d2017-07-18 18:21:26 -0700658 Mutex::Autolock l(mOutstandingBuffersLock);
659
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700660 for (auto b = mOutstandingBuffers.begin(); b != mOutstandingBuffers.end(); b++) {
661 if (*b == *buffer.buffer) {
662 mOutstandingBuffers.erase(b);
663 return;
664 }
665 }
666}
667
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800668status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700669 nsecs_t timestamp, bool timestampIncreasing,
Emilian Peev538c90e2018-12-17 18:03:19 +0000670 const std::vector<size_t>& surface_ids, uint64_t frameNumber) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800671 ATRACE_CALL();
672 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700673
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700674 // Check if this buffer is outstanding.
675 if (!isOutstandingBuffer(buffer)) {
676 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
677 return BAD_VALUE;
678 }
679
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700680 removeOutstandingBuffer(buffer);
681
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700682 // Buffer status may be changed, so make a copy of the stream_buffer struct.
683 camera3_stream_buffer b = buffer;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700684 if (timestampIncreasing && timestamp != 0 && timestamp <= mLastTimestamp) {
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700685 ALOGE("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64,
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700686 __FUNCTION__, mId, timestamp, mLastTimestamp);
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700687 b.status = CAMERA3_BUFFER_STATUS_ERROR;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700688 }
689 mLastTimestamp = timestamp;
690
Igor Murashkin13d315e2014-04-03 18:09:04 -0700691 /**
692 * TODO: Check that the state is valid first.
693 *
694 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
695 * >= HAL3.2 CONFIGURED only
696 *
697 * Do this for getBuffer as well.
698 */
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700699 status_t res = returnBufferLocked(b, timestamp, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700700 if (res == OK) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000701 fireBufferListenersLocked(b, /*acquired*/false, /*output*/true, timestamp, frameNumber);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700702 }
703
Chien-Yu Chenb83c1fe2015-09-10 16:15:21 -0700704 // Even if returning the buffer failed, we still want to signal whoever is waiting for the
705 // buffer to be returned.
706 mOutputBufferReturnedSignal.signal();
707
Igor Murashkin2fba5842013-04-22 14:03:54 -0700708 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800709}
710
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700711status_t Camera3Stream::getInputBuffer(camera3_stream_buffer *buffer, bool respectHalLimit) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700712 ATRACE_CALL();
713 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700714 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700715
Zhijun He6adc9cc2014-04-15 14:09:55 -0700716 // This function should be only called when the stream is configured already.
717 if (mState != STATE_CONFIGURED) {
718 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
719 __FUNCTION__, mId, mState);
720 return INVALID_OPERATION;
721 }
722
723 // Wait for new buffer returned back if we are running into the limit.
Eino-Ville Talvalaba435252017-06-21 16:07:25 -0700724 if (getHandoutInputBufferCountLocked() == camera3_stream::max_buffers && respectHalLimit) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700725 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
726 __FUNCTION__, camera3_stream::max_buffers);
727 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
728 if (res != OK) {
729 if (res == TIMED_OUT) {
730 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
731 kWaitForBufferDuration / 1000000LL);
732 }
733 return res;
734 }
735 }
736
737 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700738 if (res == OK) {
739 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700740 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700741 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700742 mOutstandingBuffers.push_back(*buffer->buffer);
743 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700744 }
745
746 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700747}
748
749status_t Camera3Stream::returnInputBuffer(const camera3_stream_buffer &buffer) {
750 ATRACE_CALL();
751 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700752
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700753 // Check if this buffer is outstanding.
754 if (!isOutstandingBuffer(buffer)) {
755 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
756 return BAD_VALUE;
757 }
758
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700759 removeOutstandingBuffer(buffer);
760
Igor Murashkin2fba5842013-04-22 14:03:54 -0700761 status_t res = returnInputBufferLocked(buffer);
762 if (res == OK) {
763 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700764 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700765 }
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700766
Igor Murashkin2fba5842013-04-22 14:03:54 -0700767 return res;
768}
769
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700770status_t Camera3Stream::getInputBufferProducer(sp<IGraphicBufferProducer> *producer) {
771 ATRACE_CALL();
772 Mutex::Autolock l(mLock);
773
774 return getInputBufferProducerLocked(producer);
775}
776
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800777void Camera3Stream::fireBufferRequestForFrameNumber(uint64_t frameNumber,
778 const CameraMetadata& settings) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000779 ATRACE_CALL();
780 Mutex::Autolock l(mLock);
781
782 for (auto &it : mBufferListenerList) {
783 sp<Camera3StreamBufferListener> listener = it.promote();
784 if (listener.get() != nullptr) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800785 listener->onBufferRequestForFrameNumber(frameNumber, getId(), settings);
Emilian Peev538c90e2018-12-17 18:03:19 +0000786 }
787 }
788}
789
Igor Murashkin2fba5842013-04-22 14:03:54 -0700790void Camera3Stream::fireBufferListenersLocked(
Emilian Peev538c90e2018-12-17 18:03:19 +0000791 const camera3_stream_buffer& buffer, bool acquired, bool output, nsecs_t timestamp,
792 uint64_t frameNumber) {
Igor Murashkin2fba5842013-04-22 14:03:54 -0700793 List<wp<Camera3StreamBufferListener> >::iterator it, end;
794
795 // TODO: finish implementing
796
797 Camera3StreamBufferListener::BufferInfo info =
798 Camera3StreamBufferListener::BufferInfo();
799 info.mOutput = output;
Shuzhen Wangb0fdc1e2016-03-20 23:21:39 -0700800 info.mError = (buffer.status == CAMERA3_BUFFER_STATUS_ERROR);
Emilian Peev538c90e2018-12-17 18:03:19 +0000801 info.mFrameNumber = frameNumber;
802 info.mTimestamp = timestamp;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700803 // TODO: rest of fields
804
805 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
806 it != end;
807 ++it) {
808
809 sp<Camera3StreamBufferListener> listener = it->promote();
810 if (listener != 0) {
811 if (acquired) {
812 listener->onBufferAcquired(info);
813 } else {
814 listener->onBufferReleased(info);
815 }
816 }
817 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700818}
819
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800820bool Camera3Stream::hasOutstandingBuffers() const {
821 ATRACE_CALL();
822 Mutex::Autolock l(mLock);
823 return hasOutstandingBuffersLocked();
824}
825
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700826size_t Camera3Stream::getOutstandingBuffersCount() const {
827 ATRACE_CALL();
828 Mutex::Autolock l(mLock);
829 return getHandoutOutputBufferCountLocked();
830}
831
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700832status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
833 Mutex::Autolock l(mLock);
834 sp<StatusTracker> oldTracker = mStatusTracker.promote();
835 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
836 oldTracker->removeComponent(mStatusId);
837 }
838 mStatusId = StatusTracker::NO_STATUS_ID;
839 mStatusTracker = statusTracker;
840
841 return OK;
842}
843
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800844status_t Camera3Stream::disconnect() {
845 ATRACE_CALL();
846 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700847 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
848 status_t res = disconnectLocked();
849
Shuzhen Wang686f6442017-06-20 16:16:04 -0700850 mBufferLimitLatency.log("Stream %d latency histogram for wait on max_buffers", mId);
851 mBufferLimitLatency.reset();
852
Igor Murashkine2172be2013-05-28 15:31:39 -0700853 if (res == -ENOTCONN) {
854 // "Already disconnected" -- not an error
855 return OK;
856 } else {
857 return res;
858 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800859}
860
Shuzhen Wang686f6442017-06-20 16:16:04 -0700861void Camera3Stream::dump(int fd, const Vector<String16> &args) const
862{
863 (void)args;
864 mBufferLimitLatency.dump(fd,
865 " Latency histogram for wait on max_buffers");
866}
867
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800868status_t Camera3Stream::getBufferLocked(camera3_stream_buffer *,
869 const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700870 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
871 return INVALID_OPERATION;
872}
873status_t Camera3Stream::returnBufferLocked(const camera3_stream_buffer &,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700874 nsecs_t, const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700875 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
876 return INVALID_OPERATION;
877}
878status_t Camera3Stream::getInputBufferLocked(camera3_stream_buffer *) {
879 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
880 return INVALID_OPERATION;
881}
882status_t Camera3Stream::returnInputBufferLocked(
883 const camera3_stream_buffer &) {
884 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
885 return INVALID_OPERATION;
886}
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800887status_t Camera3Stream::getInputBufferProducerLocked(sp<IGraphicBufferProducer>*) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700888 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
889 return INVALID_OPERATION;
890}
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700891
Igor Murashkin2fba5842013-04-22 14:03:54 -0700892void Camera3Stream::addBufferListener(
893 wp<Camera3StreamBufferListener> listener) {
894 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700895
896 List<wp<Camera3StreamBufferListener> >::iterator it, end;
897 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
898 it != end;
899 ) {
900 if (*it == listener) {
901 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
902 return;
903 }
904 it++;
905 }
906
Igor Murashkin2fba5842013-04-22 14:03:54 -0700907 mBufferListenerList.push_back(listener);
908}
909
910void Camera3Stream::removeBufferListener(
911 const sp<Camera3StreamBufferListener>& listener) {
912 Mutex::Autolock l(mLock);
913
914 bool erased = true;
915 List<wp<Camera3StreamBufferListener> >::iterator it, end;
916 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
917 it != end;
918 ) {
919
920 if (*it == listener) {
921 it = mBufferListenerList.erase(it);
922 erased = true;
923 } else {
924 ++it;
925 }
926 }
927
928 if (!erased) {
929 ALOGW("%s: Could not find listener to remove, already removed",
930 __FUNCTION__);
931 }
932}
933
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700934void Camera3Stream::setBufferFreedListener(
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700935 wp<Camera3StreamBufferFreedListener> listener) {
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700936 Mutex::Autolock l(mLock);
937 // Only allow set listener during stream configuration because stream is guaranteed to be IDLE
938 // at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks
939 if (mState != STATE_IN_CONFIG && mState != STATE_IN_RECONFIG) {
940 ALOGE("%s: listener must be set during stream configuration!",__FUNCTION__);
941 return;
942 }
943 mBufferFreedListener = listener;
944}
945
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800946}; // namespace camera3
947
948}; // namespace android