blob: 8d72b4c8d37e630f683975ac2df1cdace089b1ce [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"
Jayant Chowdharyd4776262020-06-23 23:45:57 -070025#include "utils/TraceHFR.h"
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080026
Igor Murashkin13d315e2014-04-03 18:09:04 -070027#include <cutils/properties.h>
28
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080029namespace android {
30
31namespace camera3 {
32
33Camera3Stream::~Camera3Stream() {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070034 sp<StatusTracker> statusTracker = mStatusTracker.promote();
35 if (statusTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
36 statusTracker->removeComponent(mStatusId);
37 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080038}
39
Emilian Peevf4816702020-04-03 15:44:51 -070040Camera3Stream* Camera3Stream::cast(camera_stream *stream) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080041 return static_cast<Camera3Stream*>(stream);
42}
43
Emilian Peevf4816702020-04-03 15:44:51 -070044const Camera3Stream* Camera3Stream::cast(const camera_stream *stream) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080045 return static_cast<const Camera3Stream*>(stream);
46}
47
48Camera3Stream::Camera3Stream(int id,
Emilian Peevf4816702020-04-03 15:44:51 -070049 camera_stream_type type,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080050 uint32_t width, uint32_t height, size_t maxSize, int format,
Emilian Peevf4816702020-04-03 15:44:51 -070051 android_dataspace dataSpace, camera_stream_rotation_t rotation,
Shuzhen Wangc28189a2017-11-27 23:05:10 -080052 const String8& physicalCameraId, int setId) :
Emilian Peevf4816702020-04-03 15:44:51 -070053 camera_stream(),
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080054 mId(id),
Zhijun He125684a2015-12-26 15:07:30 -080055 mSetId(setId),
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080056 mName(String8::format("Camera3Stream[%d]", id)),
57 mMaxSize(maxSize),
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070058 mState(STATE_CONSTRUCTED),
Ruben Brunkc78ac262015-08-13 17:58:46 -070059 mStatusId(StatusTracker::NO_STATUS_ID),
Zhijun He5d677d12016-05-29 16:52:39 -070060 mStreamUnpreparable(true),
Emilian Peev050f5dc2017-05-18 14:43:56 +010061 mUsage(0),
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -080062 mOldUsage(0),
63 mOldMaxBuffers(0),
Shuzhen Wangf9b4eb92019-06-10 11:06:01 -070064 mOldFormat(-1),
65 mOldDataSpace(HAL_DATASPACE_UNKNOWN),
Zhijun He125684a2015-12-26 15:07:30 -080066 mPrepared(false),
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -070067 mPrepareBlockRequest(true),
Zhijun He125684a2015-12-26 15:07:30 -080068 mPreparedBufferIdx(0),
Shuzhen Wang686f6442017-06-20 16:16:04 -070069 mLastMaxCount(Camera3StreamInterface::ALLOCATE_PIPELINE_MAX),
Emilian Peev710c1422017-08-30 11:19:38 +010070 mBufferLimitLatency(kBufferLimitLatencyBinSize),
71 mFormatOverridden(false),
Yin-Chia Yeh90667662019-07-01 15:45:00 -070072 mOriginalFormat(format),
Shuzhen Wang92653952019-05-07 15:11:43 -070073 mDataSpaceOverridden(false),
Shuzhen Wang2f5010d2019-08-22 12:41:12 -070074 mOriginalDataSpace(dataSpace),
Shuzhen Wang26abaf42018-08-28 15:41:20 -070075 mPhysicalCameraId(physicalCameraId),
76 mLastTimestamp(0) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080077
Emilian Peevf4816702020-04-03 15:44:51 -070078 camera_stream::stream_type = type;
79 camera_stream::width = width;
80 camera_stream::height = height;
81 camera_stream::format = format;
82 camera_stream::data_space = dataSpace;
83 camera_stream::rotation = rotation;
84 camera_stream::max_buffers = 0;
85 camera_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 {
Emilian Peevf4816702020-04-03 15:44:51 -0700103 return camera_stream::width;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800104}
105
106uint32_t Camera3Stream::getHeight() const {
Emilian Peevf4816702020-04-03 15:44:51 -0700107 return camera_stream::height;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800108}
109
110int Camera3Stream::getFormat() const {
Emilian Peevf4816702020-04-03 15:44:51 -0700111 return camera_stream::format;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800112}
113
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800114android_dataspace Camera3Stream::getDataSpace() const {
Emilian Peevf4816702020-04-03 15:44:51 -0700115 return camera_stream::data_space;
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800116}
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
Shuzhen Wang316781a2020-08-18 18:11:01 -0700154int Camera3Stream::getMaxHalBuffers() const {
Emilian Peevf4816702020-04-03 15:44:51 -0700155 return camera_stream::max_buffers;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700156}
157
Yin-Chia Yeh5fd603e2019-11-20 11:22:27 -0800158void Camera3Stream::setOfflineProcessingSupport(bool support) {
159 mSupportOfflineProcessing = support;
160}
161
162bool Camera3Stream::getOfflineProcessingSupport() const {
163 return mSupportOfflineProcessing;
164}
165
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000166status_t Camera3Stream::forceToIdle() {
167 ATRACE_CALL();
168 Mutex::Autolock l(mLock);
169 status_t res;
170
171 switch (mState) {
172 case STATE_ERROR:
173 case STATE_CONSTRUCTED:
174 case STATE_IN_CONFIG:
175 case STATE_PREPARING:
176 case STATE_IN_RECONFIG:
177 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
178 res = NO_INIT;
179 break;
180 case STATE_CONFIGURED:
181 if (hasOutstandingBuffersLocked()) {
182 sp<StatusTracker> statusTracker = mStatusTracker.promote();
183 if (statusTracker != 0) {
184 statusTracker->markComponentIdle(mStatusId, Fence::NO_FENCE);
185 }
186 }
187
188 mState = STATE_IN_IDLE;
189 res = OK;
190
191 break;
192 default:
193 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
194 res = NO_INIT;
195 }
196
197 return res;
198}
199
200status_t Camera3Stream::restoreConfiguredState() {
201 ATRACE_CALL();
202 Mutex::Autolock l(mLock);
203 status_t res;
204
205 switch (mState) {
206 case STATE_ERROR:
207 case STATE_CONSTRUCTED:
208 case STATE_IN_CONFIG:
209 case STATE_PREPARING:
210 case STATE_IN_RECONFIG:
211 case STATE_CONFIGURED:
212 ALOGE("%s: Invalid state: %d", __FUNCTION__, mState);
213 res = NO_INIT;
214 break;
215 case STATE_IN_IDLE:
216 if (hasOutstandingBuffersLocked()) {
217 sp<StatusTracker> statusTracker = mStatusTracker.promote();
218 if (statusTracker != 0) {
219 statusTracker->markComponentActive(mStatusId);
220 }
221 }
222
223 mState = STATE_CONFIGURED;
224 res = OK;
225
226 break;
227 default:
228 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
229 res = NO_INIT;
230 }
231
232 return res;
233}
234
Emilian Peevf4816702020-04-03 15:44:51 -0700235camera_stream* Camera3Stream::startConfiguration() {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700236 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800237 Mutex::Autolock l(mLock);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700238 status_t res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800239
240 switch (mState) {
241 case STATE_ERROR:
242 ALOGE("%s: In error state", __FUNCTION__);
243 return NULL;
244 case STATE_CONSTRUCTED:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000245 case STATE_IN_IDLE:
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800246 // OK
247 break;
248 case STATE_IN_CONFIG:
249 case STATE_IN_RECONFIG:
250 // Can start config again with no trouble; but don't redo
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800251 // mOldUsage/mOldMaxBuffers
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800252 return this;
253 case STATE_CONFIGURED:
Chien-Yu Chen90746f42015-04-15 13:50:13 -0700254 if (hasOutstandingBuffersLocked()) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800255 ALOGE("%s: Cannot configure stream; has outstanding buffers",
256 __FUNCTION__);
257 return NULL;
258 }
259 break;
260 default:
261 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
262 return NULL;
263 }
264
Emilian Peev050f5dc2017-05-18 14:43:56 +0100265 mOldUsage = mUsage;
Emilian Peevf4816702020-04-03 15:44:51 -0700266 mOldMaxBuffers = camera_stream::max_buffers;
267 mOldFormat = camera_stream::format;
268 mOldDataSpace = camera_stream::data_space;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700269
Emilian Peev050f5dc2017-05-18 14:43:56 +0100270 res = getEndpointUsage(&mUsage);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700271 if (res != OK) {
272 ALOGE("%s: Cannot query consumer endpoint usage!",
273 __FUNCTION__);
274 return NULL;
275 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800276
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000277 if (mState == STATE_IN_IDLE) {
278 // Skip configuration.
279 return this;
280 }
281
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700282 // Stop tracking if currently doing so
283 if (mStatusId != StatusTracker::NO_STATUS_ID) {
284 sp<StatusTracker> statusTracker = mStatusTracker.promote();
285 if (statusTracker != 0) {
286 statusTracker->removeComponent(mStatusId);
287 }
288 mStatusId = StatusTracker::NO_STATUS_ID;
289 }
290
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800291 if (mState == STATE_CONSTRUCTED) {
292 mState = STATE_IN_CONFIG;
293 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700294 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800295 mState = STATE_IN_RECONFIG;
296 }
297
298 return this;
299}
300
301bool Camera3Stream::isConfiguring() const {
302 Mutex::Autolock l(mLock);
303 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
304}
305
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700306status_t Camera3Stream::finishConfiguration(/*out*/bool* streamReconfigured) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700307 ATRACE_CALL();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700308 if (streamReconfigured != nullptr) {
309 *streamReconfigured = false;
310 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800311 Mutex::Autolock l(mLock);
312 switch (mState) {
313 case STATE_ERROR:
314 ALOGE("%s: In error state", __FUNCTION__);
315 return INVALID_OPERATION;
316 case STATE_IN_CONFIG:
317 case STATE_IN_RECONFIG:
318 // OK
319 break;
320 case STATE_CONSTRUCTED:
321 case STATE_CONFIGURED:
322 ALOGE("%s: Cannot finish configuration that hasn't been started",
323 __FUNCTION__);
324 return INVALID_OPERATION;
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000325 case STATE_IN_IDLE:
326 //Skip configuration in this state
327 return OK;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800328 default:
329 ALOGE("%s: Unknown state", __FUNCTION__);
330 return INVALID_OPERATION;
331 }
332
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700333 // Register for idle tracking
334 sp<StatusTracker> statusTracker = mStatusTracker.promote();
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700335 if (statusTracker != 0 && mStatusId == StatusTracker::NO_STATUS_ID) {
Yin-Chia Yeh87b3ec02019-06-03 10:44:39 -0700336 std::string name = std::string("Stream ") + std::to_string(mId);
337 mStatusId = statusTracker->addComponent(name.c_str());
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700338 }
339
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800340 // Check if the stream configuration is unchanged, and skip reallocation if
Emilian Peevf4816702020-04-03 15:44:51 -0700341 // so.
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800342 if (mState == STATE_IN_RECONFIG &&
Emilian Peev050f5dc2017-05-18 14:43:56 +0100343 mOldUsage == mUsage &&
Emilian Peevf4816702020-04-03 15:44:51 -0700344 mOldMaxBuffers == camera_stream::max_buffers &&
345 mOldDataSpace == camera_stream::data_space &&
346 mOldFormat == camera_stream::format) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800347 mState = STATE_CONFIGURED;
348 return OK;
349 }
350
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700351 // Reset prepared state, since buffer config has changed, and existing
352 // allocations are no longer valid
353 mPrepared = false;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700354 mPrepareBlockRequest = true;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700355 mStreamUnpreparable = false;
356
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700357 bool reconfiguring = (mState == STATE_IN_RECONFIG);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800358 status_t res;
359 res = configureQueueLocked();
Shuzhen Wang210ba5c2018-07-25 16:47:40 -0700360 // configureQueueLocked could return error in case of abandoned surface.
361 // Treat as non-fatal error.
362 if (res == NO_INIT || res == DEAD_OBJECT) {
363 ALOGE("%s: Unable to configure stream %d queue (non-fatal): %s (%d)",
364 __FUNCTION__, mId, strerror(-res), res);
365 mState = STATE_ABANDONED;
366 return res;
367 } else if (res != OK) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800368 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
369 __FUNCTION__, mId, strerror(-res), res);
370 mState = STATE_ERROR;
371 return res;
372 }
373
Yin-Chia Yeh573a2702019-04-17 10:08:55 -0700374 if (reconfiguring && streamReconfigured != nullptr) {
375 *streamReconfigured = true;
376 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800377 mState = STATE_CONFIGURED;
378
379 return res;
380}
381
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700382status_t Camera3Stream::cancelConfiguration() {
383 ATRACE_CALL();
384 Mutex::Autolock l(mLock);
385 switch (mState) {
386 case STATE_ERROR:
387 ALOGE("%s: In error state", __FUNCTION__);
388 return INVALID_OPERATION;
389 case STATE_IN_CONFIG:
390 case STATE_IN_RECONFIG:
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000391 case STATE_IN_IDLE:
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700392 // OK
393 break;
394 case STATE_CONSTRUCTED:
395 case STATE_CONFIGURED:
396 ALOGE("%s: Cannot cancel configuration that hasn't been started",
397 __FUNCTION__);
398 return INVALID_OPERATION;
399 default:
400 ALOGE("%s: Unknown state", __FUNCTION__);
401 return INVALID_OPERATION;
402 }
403
Emilian Peev050f5dc2017-05-18 14:43:56 +0100404 mUsage = mOldUsage;
Emilian Peevf4816702020-04-03 15:44:51 -0700405 camera_stream::max_buffers = mOldMaxBuffers;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700406
Emilian Peevac3ce6c2017-12-12 15:27:02 +0000407 mState = ((mState == STATE_IN_RECONFIG) || (mState == STATE_IN_IDLE)) ? STATE_CONFIGURED :
408 STATE_CONSTRUCTED;
409
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700410 return OK;
411}
412
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700413bool Camera3Stream::isUnpreparable() {
414 ATRACE_CALL();
415
416 Mutex::Autolock l(mLock);
417 return mStreamUnpreparable;
418}
419
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700420status_t Camera3Stream::startPrepare(int maxCount, bool blockRequest) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700421 ATRACE_CALL();
422
423 Mutex::Autolock l(mLock);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700424
Ruben Brunkc78ac262015-08-13 17:58:46 -0700425 if (maxCount < 0) {
426 ALOGE("%s: Stream %d: Can't prepare stream if max buffer count (%d) is < 0",
427 __FUNCTION__, mId, maxCount);
428 return BAD_VALUE;
429 }
430
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700431 // This function should be only called when the stream is configured already.
432 if (mState != STATE_CONFIGURED) {
433 ALOGE("%s: Stream %d: Can't prepare stream if stream is not in CONFIGURED "
434 "state %d", __FUNCTION__, mId, mState);
435 return INVALID_OPERATION;
436 }
437
438 // This function can't be called if the stream has already received filled
439 // buffers
440 if (mStreamUnpreparable) {
441 ALOGE("%s: Stream %d: Can't prepare stream that's already in use",
442 __FUNCTION__, mId);
443 return INVALID_OPERATION;
444 }
445
446 if (getHandoutOutputBufferCountLocked() > 0) {
447 ALOGE("%s: Stream %d: Can't prepare stream that has outstanding buffers",
448 __FUNCTION__, mId);
449 return INVALID_OPERATION;
450 }
451
Ruben Brunkc78ac262015-08-13 17:58:46 -0700452 size_t pipelineMax = getBufferCountLocked();
453 size_t clampedCount = (pipelineMax < static_cast<size_t>(maxCount)) ?
454 pipelineMax : static_cast<size_t>(maxCount);
455 size_t bufferCount = (maxCount == Camera3StreamInterface::ALLOCATE_PIPELINE_MAX) ?
456 pipelineMax : clampedCount;
457
458 mPrepared = bufferCount <= mLastMaxCount;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700459 mPrepareBlockRequest = blockRequest;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700460
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700461 if (mPrepared) return OK;
462
Ruben Brunkc78ac262015-08-13 17:58:46 -0700463 mLastMaxCount = bufferCount;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700464
Emilian Peevf4816702020-04-03 15:44:51 -0700465 mPreparedBuffers.insertAt(camera_stream_buffer_t(), /*index*/0, bufferCount);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700466 mPreparedBufferIdx = 0;
467
468 mState = STATE_PREPARING;
469
470 return NOT_ENOUGH_DATA;
471}
472
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700473bool Camera3Stream::isBlockedByPrepare() const {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700474 Mutex::Autolock l(mLock);
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700475 return mState == STATE_PREPARING && mPrepareBlockRequest;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700476}
477
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700478bool Camera3Stream::isAbandoned() const {
479 Mutex::Autolock l(mLock);
480 return mState == STATE_ABANDONED;
481}
482
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700483status_t Camera3Stream::prepareNextBuffer() {
484 ATRACE_CALL();
485
486 Mutex::Autolock l(mLock);
487 status_t res = OK;
488
489 // This function should be only called when the stream is preparing
490 if (mState != STATE_PREPARING) {
491 ALOGE("%s: Stream %d: Can't prepare buffer if stream is not in PREPARING "
492 "state %d", __FUNCTION__, mId, mState);
493 return INVALID_OPERATION;
494 }
495
496 // Get next buffer - this may allocate, and take a while for large buffers
497 res = getBufferLocked( &mPreparedBuffers.editItemAt(mPreparedBufferIdx) );
498 if (res != OK) {
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800499 ALOGE("%s: Stream %d: Unable to allocate buffer %zu during preparation",
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700500 __FUNCTION__, mId, mPreparedBufferIdx);
501 return NO_INIT;
502 }
503
504 mPreparedBufferIdx++;
505
506 // Check if we still have buffers left to allocate
507 if (mPreparedBufferIdx < mPreparedBuffers.size()) {
508 return NOT_ENOUGH_DATA;
509 }
510
511 // Done with prepare - mark stream as such, and return all buffers
512 // via cancelPrepare
513 mPrepared = true;
514
515 return cancelPrepareLocked();
516}
517
518status_t Camera3Stream::cancelPrepare() {
519 ATRACE_CALL();
520
521 Mutex::Autolock l(mLock);
522
523 return cancelPrepareLocked();
524}
525
526status_t Camera3Stream::cancelPrepareLocked() {
527 status_t res = OK;
528
529 // This function should be only called when the stream is mid-preparing.
530 if (mState != STATE_PREPARING) {
531 ALOGE("%s: Stream %d: Can't cancel prepare stream if stream is not in "
532 "PREPARING state %d", __FUNCTION__, mId, mState);
533 return INVALID_OPERATION;
534 }
535
536 // Return all valid buffers to stream, in ERROR state to indicate
537 // they weren't filled.
538 for (size_t i = 0; i < mPreparedBufferIdx; i++) {
539 mPreparedBuffers.editItemAt(i).release_fence = -1;
Emilian Peevf4816702020-04-03 15:44:51 -0700540 mPreparedBuffers.editItemAt(i).status = CAMERA_BUFFER_STATUS_ERROR;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700541 returnBufferLocked(mPreparedBuffers[i], 0);
542 }
543 mPreparedBuffers.clear();
544 mPreparedBufferIdx = 0;
545
546 mState = STATE_CONFIGURED;
547
548 return res;
549}
550
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700551status_t Camera3Stream::tearDown() {
552 ATRACE_CALL();
553 Mutex::Autolock l(mLock);
554
555 status_t res = OK;
556
557 // This function should be only called when the stream is configured.
558 if (mState != STATE_CONFIGURED) {
559 ALOGE("%s: Stream %d: Can't tear down stream if stream is not in "
560 "CONFIGURED state %d", __FUNCTION__, mId, mState);
561 return INVALID_OPERATION;
562 }
563
564 // If any buffers have been handed to the HAL, the stream cannot be torn down.
565 if (getHandoutOutputBufferCountLocked() > 0) {
566 ALOGE("%s: Stream %d: Can't tear down a stream that has outstanding buffers",
567 __FUNCTION__, mId);
568 return INVALID_OPERATION;
569 }
570
571 // Free buffers by disconnecting and then reconnecting to the buffer queue
572 // Only unused buffers will be dropped immediately; buffers that have been filled
573 // and are waiting to be acquired by the consumer and buffers that are currently
574 // acquired will be freed once they are released by the consumer.
575
576 res = disconnectLocked();
577 if (res != OK) {
578 if (res == -ENOTCONN) {
579 // queue has been disconnected, nothing left to do, so exit with success
580 return OK;
581 }
582 ALOGE("%s: Stream %d: Unable to disconnect to tear down buffers: %s (%d)",
583 __FUNCTION__, mId, strerror(-res), res);
584 return res;
585 }
586
587 mState = STATE_IN_CONFIG;
588
589 res = configureQueueLocked();
590 if (res != OK) {
591 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
592 __FUNCTION__, mId, strerror(-res), res);
593 mState = STATE_ERROR;
594 return res;
595 }
596
597 // Reset prepared state, since we've reconnected to the queue and can prepare again.
598 mPrepared = false;
599 mStreamUnpreparable = false;
600
601 mState = STATE_CONFIGURED;
602
603 return OK;
604}
605
Emilian Peevf4816702020-04-03 15:44:51 -0700606status_t Camera3Stream::getBuffer(camera_stream_buffer *buffer,
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700607 nsecs_t waitBufferTimeout,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800608 const std::vector<size_t>& surface_ids) {
Jayant Chowdharyd4776262020-06-23 23:45:57 -0700609 ATRACE_HFR_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800610 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700611 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700612
Zhijun He6adc9cc2014-04-15 14:09:55 -0700613 // This function should be only called when the stream is configured already.
614 if (mState != STATE_CONFIGURED) {
615 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
616 __FUNCTION__, mId, mState);
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -0800617 if (mState == STATE_ABANDONED) {
618 return DEAD_OBJECT;
619 } else {
620 return INVALID_OPERATION;
621 }
Zhijun He6adc9cc2014-04-15 14:09:55 -0700622 }
623
624 // Wait for new buffer returned back if we are running into the limit.
Emilian Peevf4816702020-04-03 15:44:51 -0700625 if (getHandoutOutputBufferCountLocked() == camera_stream::max_buffers) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700626 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
Emilian Peevf4816702020-04-03 15:44:51 -0700627 __FUNCTION__, camera_stream::max_buffers);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700628 nsecs_t waitStart = systemTime(SYSTEM_TIME_MONOTONIC);
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700629 if (waitBufferTimeout < kWaitForBufferDuration) {
630 waitBufferTimeout = kWaitForBufferDuration;
631 }
632 res = mOutputBufferReturnedSignal.waitRelative(mLock, waitBufferTimeout);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700633 nsecs_t waitEnd = systemTime(SYSTEM_TIME_MONOTONIC);
634 mBufferLimitLatency.add(waitStart, waitEnd);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700635 if (res != OK) {
636 if (res == TIMED_OUT) {
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700637 ALOGE("%s: wait for output buffer return timed out after %lldms (max_buffers %d)",
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700638 __FUNCTION__, waitBufferTimeout / 1000000LL,
Emilian Peevf4816702020-04-03 15:44:51 -0700639 camera_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700640 }
641 return res;
642 }
643 }
644
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800645 res = getBufferLocked(buffer, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700646 if (res == OK) {
647 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700648 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700649 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700650 mOutstandingBuffers.push_back(*buffer->buffer);
651 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700652 }
653
654 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800655}
656
Emilian Peevf4816702020-04-03 15:44:51 -0700657bool Camera3Stream::isOutstandingBuffer(const camera_stream_buffer &buffer) const{
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700658 if (buffer.buffer == nullptr) {
659 return false;
660 }
661
Emilian Peev889234d2017-07-18 18:21:26 -0700662 Mutex::Autolock l(mOutstandingBuffersLock);
663
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700664 for (auto b : mOutstandingBuffers) {
665 if (b == *buffer.buffer) {
666 return true;
667 }
668 }
669 return false;
670}
671
Emilian Peevf4816702020-04-03 15:44:51 -0700672void Camera3Stream::removeOutstandingBuffer(const camera_stream_buffer &buffer) {
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700673 if (buffer.buffer == nullptr) {
674 return;
675 }
676
Emilian Peev889234d2017-07-18 18:21:26 -0700677 Mutex::Autolock l(mOutstandingBuffersLock);
678
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700679 for (auto b = mOutstandingBuffers.begin(); b != mOutstandingBuffers.end(); b++) {
680 if (*b == *buffer.buffer) {
681 mOutstandingBuffers.erase(b);
682 return;
683 }
684 }
685}
686
Emilian Peevf4816702020-04-03 15:44:51 -0700687status_t Camera3Stream::returnBuffer(const camera_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700688 nsecs_t timestamp, bool timestampIncreasing,
Emilian Peev538c90e2018-12-17 18:03:19 +0000689 const std::vector<size_t>& surface_ids, uint64_t frameNumber) {
Jayant Chowdharyd4776262020-06-23 23:45:57 -0700690 ATRACE_HFR_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800691 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700692
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700693 // Check if this buffer is outstanding.
694 if (!isOutstandingBuffer(buffer)) {
695 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
696 return BAD_VALUE;
697 }
698
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700699 removeOutstandingBuffer(buffer);
700
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700701 // Buffer status may be changed, so make a copy of the stream_buffer struct.
Emilian Peevf4816702020-04-03 15:44:51 -0700702 camera_stream_buffer b = buffer;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700703 if (timestampIncreasing && timestamp != 0 && timestamp <= mLastTimestamp) {
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700704 ALOGE("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64,
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700705 __FUNCTION__, mId, timestamp, mLastTimestamp);
Emilian Peevf4816702020-04-03 15:44:51 -0700706 b.status = CAMERA_BUFFER_STATUS_ERROR;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700707 }
708 mLastTimestamp = timestamp;
709
Igor Murashkin13d315e2014-04-03 18:09:04 -0700710 /**
711 * TODO: Check that the state is valid first.
712 *
713 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
714 * >= HAL3.2 CONFIGURED only
715 *
716 * Do this for getBuffer as well.
717 */
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700718 status_t res = returnBufferLocked(b, timestamp, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700719 if (res == OK) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000720 fireBufferListenersLocked(b, /*acquired*/false, /*output*/true, timestamp, frameNumber);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700721 }
722
Chien-Yu Chenb83c1fe2015-09-10 16:15:21 -0700723 // Even if returning the buffer failed, we still want to signal whoever is waiting for the
724 // buffer to be returned.
725 mOutputBufferReturnedSignal.signal();
726
Igor Murashkin2fba5842013-04-22 14:03:54 -0700727 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800728}
729
Emilian Peevf4816702020-04-03 15:44:51 -0700730status_t Camera3Stream::getInputBuffer(camera_stream_buffer *buffer, bool respectHalLimit) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700731 ATRACE_CALL();
732 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700733 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700734
Zhijun He6adc9cc2014-04-15 14:09:55 -0700735 // This function should be only called when the stream is configured already.
736 if (mState != STATE_CONFIGURED) {
737 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
738 __FUNCTION__, mId, mState);
739 return INVALID_OPERATION;
740 }
741
742 // Wait for new buffer returned back if we are running into the limit.
Emilian Peevf4816702020-04-03 15:44:51 -0700743 if (getHandoutInputBufferCountLocked() == camera_stream::max_buffers && respectHalLimit) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700744 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
Emilian Peevf4816702020-04-03 15:44:51 -0700745 __FUNCTION__, camera_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700746 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
747 if (res != OK) {
748 if (res == TIMED_OUT) {
749 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
750 kWaitForBufferDuration / 1000000LL);
751 }
752 return res;
753 }
754 }
755
756 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700757 if (res == OK) {
758 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700759 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700760 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700761 mOutstandingBuffers.push_back(*buffer->buffer);
762 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700763 }
764
765 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700766}
767
Emilian Peevf4816702020-04-03 15:44:51 -0700768status_t Camera3Stream::returnInputBuffer(const camera_stream_buffer &buffer) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700769 ATRACE_CALL();
770 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700771
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700772 // Check if this buffer is outstanding.
773 if (!isOutstandingBuffer(buffer)) {
774 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
775 return BAD_VALUE;
776 }
777
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700778 removeOutstandingBuffer(buffer);
779
Igor Murashkin2fba5842013-04-22 14:03:54 -0700780 status_t res = returnInputBufferLocked(buffer);
781 if (res == OK) {
782 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700783 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700784 }
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700785
Igor Murashkin2fba5842013-04-22 14:03:54 -0700786 return res;
787}
788
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700789status_t Camera3Stream::getInputBufferProducer(sp<IGraphicBufferProducer> *producer) {
790 ATRACE_CALL();
791 Mutex::Autolock l(mLock);
792
793 return getInputBufferProducerLocked(producer);
794}
795
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800796void Camera3Stream::fireBufferRequestForFrameNumber(uint64_t frameNumber,
797 const CameraMetadata& settings) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000798 ATRACE_CALL();
799 Mutex::Autolock l(mLock);
800
801 for (auto &it : mBufferListenerList) {
802 sp<Camera3StreamBufferListener> listener = it.promote();
803 if (listener.get() != nullptr) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800804 listener->onBufferRequestForFrameNumber(frameNumber, getId(), settings);
Emilian Peev538c90e2018-12-17 18:03:19 +0000805 }
806 }
807}
808
Igor Murashkin2fba5842013-04-22 14:03:54 -0700809void Camera3Stream::fireBufferListenersLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700810 const camera_stream_buffer& buffer, bool acquired, bool output, nsecs_t timestamp,
Emilian Peev538c90e2018-12-17 18:03:19 +0000811 uint64_t frameNumber) {
Igor Murashkin2fba5842013-04-22 14:03:54 -0700812 List<wp<Camera3StreamBufferListener> >::iterator it, end;
813
814 // TODO: finish implementing
815
816 Camera3StreamBufferListener::BufferInfo info =
817 Camera3StreamBufferListener::BufferInfo();
818 info.mOutput = output;
Emilian Peevf4816702020-04-03 15:44:51 -0700819 info.mError = (buffer.status == CAMERA_BUFFER_STATUS_ERROR);
Emilian Peev538c90e2018-12-17 18:03:19 +0000820 info.mFrameNumber = frameNumber;
821 info.mTimestamp = timestamp;
Shuzhen Wange8675782019-12-05 09:12:14 -0800822 info.mStreamId = getId();
823
Igor Murashkin2fba5842013-04-22 14:03:54 -0700824 // TODO: rest of fields
825
826 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
827 it != end;
828 ++it) {
829
830 sp<Camera3StreamBufferListener> listener = it->promote();
831 if (listener != 0) {
832 if (acquired) {
833 listener->onBufferAcquired(info);
834 } else {
835 listener->onBufferReleased(info);
836 }
837 }
838 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700839}
840
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800841bool Camera3Stream::hasOutstandingBuffers() const {
842 ATRACE_CALL();
843 Mutex::Autolock l(mLock);
844 return hasOutstandingBuffersLocked();
845}
846
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700847size_t Camera3Stream::getOutstandingBuffersCount() const {
848 ATRACE_CALL();
849 Mutex::Autolock l(mLock);
850 return getHandoutOutputBufferCountLocked();
851}
852
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700853status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
854 Mutex::Autolock l(mLock);
855 sp<StatusTracker> oldTracker = mStatusTracker.promote();
856 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
857 oldTracker->removeComponent(mStatusId);
858 }
859 mStatusId = StatusTracker::NO_STATUS_ID;
860 mStatusTracker = statusTracker;
861
862 return OK;
863}
864
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800865status_t Camera3Stream::disconnect() {
866 ATRACE_CALL();
867 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700868 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
869 status_t res = disconnectLocked();
870
Shuzhen Wang686f6442017-06-20 16:16:04 -0700871 mBufferLimitLatency.log("Stream %d latency histogram for wait on max_buffers", mId);
872 mBufferLimitLatency.reset();
873
Igor Murashkine2172be2013-05-28 15:31:39 -0700874 if (res == -ENOTCONN) {
875 // "Already disconnected" -- not an error
876 return OK;
877 } else {
878 return res;
879 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800880}
881
Shuzhen Wang686f6442017-06-20 16:16:04 -0700882void Camera3Stream::dump(int fd, const Vector<String16> &args) const
883{
884 (void)args;
885 mBufferLimitLatency.dump(fd,
886 " Latency histogram for wait on max_buffers");
887}
888
Emilian Peevf4816702020-04-03 15:44:51 -0700889status_t Camera3Stream::getBufferLocked(camera_stream_buffer *,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800890 const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700891 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
892 return INVALID_OPERATION;
893}
Emilian Peevf4816702020-04-03 15:44:51 -0700894status_t Camera3Stream::returnBufferLocked(const camera_stream_buffer &,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700895 nsecs_t, const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700896 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
897 return INVALID_OPERATION;
898}
Emilian Peevf4816702020-04-03 15:44:51 -0700899status_t Camera3Stream::getInputBufferLocked(camera_stream_buffer *) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700900 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
901 return INVALID_OPERATION;
902}
903status_t Camera3Stream::returnInputBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700904 const camera_stream_buffer &) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700905 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
906 return INVALID_OPERATION;
907}
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800908status_t Camera3Stream::getInputBufferProducerLocked(sp<IGraphicBufferProducer>*) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700909 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
910 return INVALID_OPERATION;
911}
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700912
Igor Murashkin2fba5842013-04-22 14:03:54 -0700913void Camera3Stream::addBufferListener(
914 wp<Camera3StreamBufferListener> listener) {
915 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700916
917 List<wp<Camera3StreamBufferListener> >::iterator it, end;
918 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
919 it != end;
920 ) {
921 if (*it == listener) {
922 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
923 return;
924 }
925 it++;
926 }
927
Igor Murashkin2fba5842013-04-22 14:03:54 -0700928 mBufferListenerList.push_back(listener);
929}
930
931void Camera3Stream::removeBufferListener(
932 const sp<Camera3StreamBufferListener>& listener) {
933 Mutex::Autolock l(mLock);
934
935 bool erased = true;
936 List<wp<Camera3StreamBufferListener> >::iterator it, end;
937 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
938 it != end;
939 ) {
940
941 if (*it == listener) {
942 it = mBufferListenerList.erase(it);
943 erased = true;
944 } else {
945 ++it;
946 }
947 }
948
949 if (!erased) {
950 ALOGW("%s: Could not find listener to remove, already removed",
951 __FUNCTION__);
952 }
953}
954
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700955void Camera3Stream::setBufferFreedListener(
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700956 wp<Camera3StreamBufferFreedListener> listener) {
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700957 Mutex::Autolock l(mLock);
958 // Only allow set listener during stream configuration because stream is guaranteed to be IDLE
959 // at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks
960 if (mState != STATE_IN_CONFIG && mState != STATE_IN_RECONFIG) {
961 ALOGE("%s: listener must be set during stream configuration!",__FUNCTION__);
962 return;
963 }
964 mBufferFreedListener = listener;
965}
966
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800967}; // namespace camera3
968
969}; // namespace android