blob: ffdb90b69b08ee6f5c8380abc1d23f14c86f5842 [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
Emilian Peevf0348ae2021-01-13 13:39:45 -0800420void Camera3Stream::markUnpreparable() {
421 ATRACE_CALL();
422
423 Mutex::Autolock l(mLock);
424 mStreamUnpreparable = true;
425}
426
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700427status_t Camera3Stream::startPrepare(int maxCount, bool blockRequest) {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700428 ATRACE_CALL();
429
430 Mutex::Autolock l(mLock);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700431
Ruben Brunkc78ac262015-08-13 17:58:46 -0700432 if (maxCount < 0) {
433 ALOGE("%s: Stream %d: Can't prepare stream if max buffer count (%d) is < 0",
434 __FUNCTION__, mId, maxCount);
435 return BAD_VALUE;
436 }
437
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700438 // This function should be only called when the stream is configured already.
439 if (mState != STATE_CONFIGURED) {
440 ALOGE("%s: Stream %d: Can't prepare stream if stream is not in CONFIGURED "
441 "state %d", __FUNCTION__, mId, mState);
442 return INVALID_OPERATION;
443 }
444
445 // This function can't be called if the stream has already received filled
446 // buffers
447 if (mStreamUnpreparable) {
448 ALOGE("%s: Stream %d: Can't prepare stream that's already in use",
449 __FUNCTION__, mId);
450 return INVALID_OPERATION;
451 }
452
453 if (getHandoutOutputBufferCountLocked() > 0) {
454 ALOGE("%s: Stream %d: Can't prepare stream that has outstanding buffers",
455 __FUNCTION__, mId);
456 return INVALID_OPERATION;
457 }
458
Ruben Brunkc78ac262015-08-13 17:58:46 -0700459 size_t pipelineMax = getBufferCountLocked();
460 size_t clampedCount = (pipelineMax < static_cast<size_t>(maxCount)) ?
461 pipelineMax : static_cast<size_t>(maxCount);
462 size_t bufferCount = (maxCount == Camera3StreamInterface::ALLOCATE_PIPELINE_MAX) ?
463 pipelineMax : clampedCount;
464
465 mPrepared = bufferCount <= mLastMaxCount;
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700466 mPrepareBlockRequest = blockRequest;
Ruben Brunkc78ac262015-08-13 17:58:46 -0700467
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700468 if (mPrepared) return OK;
469
Ruben Brunkc78ac262015-08-13 17:58:46 -0700470 mLastMaxCount = bufferCount;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700471
Emilian Peevf4816702020-04-03 15:44:51 -0700472 mPreparedBuffers.insertAt(camera_stream_buffer_t(), /*index*/0, bufferCount);
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700473 mPreparedBufferIdx = 0;
474
475 mState = STATE_PREPARING;
476
477 return NOT_ENOUGH_DATA;
478}
479
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700480bool Camera3Stream::isBlockedByPrepare() const {
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700481 Mutex::Autolock l(mLock);
Shuzhen Wangb3a0fb52018-09-13 17:24:08 -0700482 return mState == STATE_PREPARING && mPrepareBlockRequest;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700483}
484
Chien-Yu Chene8c535e2016-04-14 12:18:26 -0700485bool Camera3Stream::isAbandoned() const {
486 Mutex::Autolock l(mLock);
487 return mState == STATE_ABANDONED;
488}
489
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700490status_t Camera3Stream::prepareNextBuffer() {
491 ATRACE_CALL();
492
493 Mutex::Autolock l(mLock);
494 status_t res = OK;
495
496 // This function should be only called when the stream is preparing
497 if (mState != STATE_PREPARING) {
498 ALOGE("%s: Stream %d: Can't prepare buffer if stream is not in PREPARING "
499 "state %d", __FUNCTION__, mId, mState);
500 return INVALID_OPERATION;
501 }
502
503 // Get next buffer - this may allocate, and take a while for large buffers
504 res = getBufferLocked( &mPreparedBuffers.editItemAt(mPreparedBufferIdx) );
505 if (res != OK) {
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800506 ALOGE("%s: Stream %d: Unable to allocate buffer %zu during preparation",
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700507 __FUNCTION__, mId, mPreparedBufferIdx);
508 return NO_INIT;
509 }
510
511 mPreparedBufferIdx++;
512
513 // Check if we still have buffers left to allocate
514 if (mPreparedBufferIdx < mPreparedBuffers.size()) {
515 return NOT_ENOUGH_DATA;
516 }
517
518 // Done with prepare - mark stream as such, and return all buffers
519 // via cancelPrepare
520 mPrepared = true;
521
522 return cancelPrepareLocked();
523}
524
525status_t Camera3Stream::cancelPrepare() {
526 ATRACE_CALL();
527
528 Mutex::Autolock l(mLock);
529
530 return cancelPrepareLocked();
531}
532
533status_t Camera3Stream::cancelPrepareLocked() {
534 status_t res = OK;
535
536 // This function should be only called when the stream is mid-preparing.
537 if (mState != STATE_PREPARING) {
538 ALOGE("%s: Stream %d: Can't cancel prepare stream if stream is not in "
539 "PREPARING state %d", __FUNCTION__, mId, mState);
540 return INVALID_OPERATION;
541 }
542
543 // Return all valid buffers to stream, in ERROR state to indicate
544 // they weren't filled.
545 for (size_t i = 0; i < mPreparedBufferIdx; i++) {
546 mPreparedBuffers.editItemAt(i).release_fence = -1;
Emilian Peevf4816702020-04-03 15:44:51 -0700547 mPreparedBuffers.editItemAt(i).status = CAMERA_BUFFER_STATUS_ERROR;
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700548 returnBufferLocked(mPreparedBuffers[i], 0);
549 }
550 mPreparedBuffers.clear();
551 mPreparedBufferIdx = 0;
552
553 mState = STATE_CONFIGURED;
554
555 return res;
556}
557
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700558status_t Camera3Stream::tearDown() {
559 ATRACE_CALL();
560 Mutex::Autolock l(mLock);
561
562 status_t res = OK;
563
564 // This function should be only called when the stream is configured.
565 if (mState != STATE_CONFIGURED) {
566 ALOGE("%s: Stream %d: Can't tear down stream if stream is not in "
567 "CONFIGURED state %d", __FUNCTION__, mId, mState);
568 return INVALID_OPERATION;
569 }
570
571 // If any buffers have been handed to the HAL, the stream cannot be torn down.
572 if (getHandoutOutputBufferCountLocked() > 0) {
573 ALOGE("%s: Stream %d: Can't tear down a stream that has outstanding buffers",
574 __FUNCTION__, mId);
575 return INVALID_OPERATION;
576 }
577
578 // Free buffers by disconnecting and then reconnecting to the buffer queue
579 // Only unused buffers will be dropped immediately; buffers that have been filled
580 // and are waiting to be acquired by the consumer and buffers that are currently
581 // acquired will be freed once they are released by the consumer.
582
583 res = disconnectLocked();
584 if (res != OK) {
585 if (res == -ENOTCONN) {
586 // queue has been disconnected, nothing left to do, so exit with success
587 return OK;
588 }
589 ALOGE("%s: Stream %d: Unable to disconnect to tear down buffers: %s (%d)",
590 __FUNCTION__, mId, strerror(-res), res);
591 return res;
592 }
593
594 mState = STATE_IN_CONFIG;
595
596 res = configureQueueLocked();
597 if (res != OK) {
598 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
599 __FUNCTION__, mId, strerror(-res), res);
600 mState = STATE_ERROR;
601 return res;
602 }
603
604 // Reset prepared state, since we've reconnected to the queue and can prepare again.
605 mPrepared = false;
606 mStreamUnpreparable = false;
607
608 mState = STATE_CONFIGURED;
609
610 return OK;
611}
612
Emilian Peevf4816702020-04-03 15:44:51 -0700613status_t Camera3Stream::getBuffer(camera_stream_buffer *buffer,
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700614 nsecs_t waitBufferTimeout,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800615 const std::vector<size_t>& surface_ids) {
Jayant Chowdharyd4776262020-06-23 23:45:57 -0700616 ATRACE_HFR_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800617 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700618 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700619
Zhijun He6adc9cc2014-04-15 14:09:55 -0700620 // This function should be only called when the stream is configured already.
621 if (mState != STATE_CONFIGURED) {
622 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
623 __FUNCTION__, mId, mState);
Yin-Chia Yehcd333fe2019-02-08 13:45:41 -0800624 if (mState == STATE_ABANDONED) {
625 return DEAD_OBJECT;
626 } else {
627 return INVALID_OPERATION;
628 }
Zhijun He6adc9cc2014-04-15 14:09:55 -0700629 }
630
631 // Wait for new buffer returned back if we are running into the limit.
Emilian Peevf4816702020-04-03 15:44:51 -0700632 if (getHandoutOutputBufferCountLocked() == camera_stream::max_buffers) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700633 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
Emilian Peevf4816702020-04-03 15:44:51 -0700634 __FUNCTION__, camera_stream::max_buffers);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700635 nsecs_t waitStart = systemTime(SYSTEM_TIME_MONOTONIC);
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700636 if (waitBufferTimeout < kWaitForBufferDuration) {
637 waitBufferTimeout = kWaitForBufferDuration;
638 }
639 res = mOutputBufferReturnedSignal.waitRelative(mLock, waitBufferTimeout);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700640 nsecs_t waitEnd = systemTime(SYSTEM_TIME_MONOTONIC);
641 mBufferLimitLatency.add(waitStart, waitEnd);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700642 if (res != OK) {
643 if (res == TIMED_OUT) {
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700644 ALOGE("%s: wait for output buffer return timed out after %lldms (max_buffers %d)",
Yin-Chia Yehb3a80b12018-09-04 12:13:05 -0700645 __FUNCTION__, waitBufferTimeout / 1000000LL,
Emilian Peevf4816702020-04-03 15:44:51 -0700646 camera_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700647 }
648 return res;
649 }
650 }
651
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800652 res = getBufferLocked(buffer, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700653 if (res == OK) {
654 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700655 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700656 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700657 mOutstandingBuffers.push_back(*buffer->buffer);
658 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700659 }
660
661 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800662}
663
Emilian Peevf4816702020-04-03 15:44:51 -0700664bool Camera3Stream::isOutstandingBuffer(const camera_stream_buffer &buffer) const{
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700665 if (buffer.buffer == nullptr) {
666 return false;
667 }
668
Emilian Peev889234d2017-07-18 18:21:26 -0700669 Mutex::Autolock l(mOutstandingBuffersLock);
670
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700671 for (auto b : mOutstandingBuffers) {
672 if (b == *buffer.buffer) {
673 return true;
674 }
675 }
676 return false;
677}
678
Emilian Peevf4816702020-04-03 15:44:51 -0700679void Camera3Stream::removeOutstandingBuffer(const camera_stream_buffer &buffer) {
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700680 if (buffer.buffer == nullptr) {
681 return;
682 }
683
Emilian Peev889234d2017-07-18 18:21:26 -0700684 Mutex::Autolock l(mOutstandingBuffersLock);
685
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700686 for (auto b = mOutstandingBuffers.begin(); b != mOutstandingBuffers.end(); b++) {
687 if (*b == *buffer.buffer) {
688 mOutstandingBuffers.erase(b);
689 return;
690 }
691 }
692}
693
Emilian Peevf4816702020-04-03 15:44:51 -0700694status_t Camera3Stream::returnBuffer(const camera_stream_buffer &buffer,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700695 nsecs_t timestamp, bool timestampIncreasing,
Emilian Peev538c90e2018-12-17 18:03:19 +0000696 const std::vector<size_t>& surface_ids, uint64_t frameNumber) {
Jayant Chowdharyd4776262020-06-23 23:45:57 -0700697 ATRACE_HFR_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800698 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700699
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700700 // Check if this buffer is outstanding.
701 if (!isOutstandingBuffer(buffer)) {
702 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
703 return BAD_VALUE;
704 }
705
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700706 removeOutstandingBuffer(buffer);
707
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700708 // Buffer status may be changed, so make a copy of the stream_buffer struct.
Emilian Peevf4816702020-04-03 15:44:51 -0700709 camera_stream_buffer b = buffer;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700710 if (timestampIncreasing && timestamp != 0 && timestamp <= mLastTimestamp) {
Shuzhen Wangf0c4a6b2018-09-05 09:36:14 -0700711 ALOGE("%s: Stream %d: timestamp %" PRId64 " is not increasing. Prev timestamp %" PRId64,
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700712 __FUNCTION__, mId, timestamp, mLastTimestamp);
Emilian Peevf4816702020-04-03 15:44:51 -0700713 b.status = CAMERA_BUFFER_STATUS_ERROR;
Shuzhen Wang26abaf42018-08-28 15:41:20 -0700714 }
715 mLastTimestamp = timestamp;
716
Igor Murashkin13d315e2014-04-03 18:09:04 -0700717 /**
718 * TODO: Check that the state is valid first.
719 *
720 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
721 * >= HAL3.2 CONFIGURED only
722 *
723 * Do this for getBuffer as well.
724 */
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700725 status_t res = returnBufferLocked(b, timestamp, surface_ids);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700726 if (res == OK) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000727 fireBufferListenersLocked(b, /*acquired*/false, /*output*/true, timestamp, frameNumber);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700728 }
729
Chien-Yu Chenb83c1fe2015-09-10 16:15:21 -0700730 // Even if returning the buffer failed, we still want to signal whoever is waiting for the
731 // buffer to be returned.
732 mOutputBufferReturnedSignal.signal();
733
Igor Murashkin2fba5842013-04-22 14:03:54 -0700734 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800735}
736
Emilian Peevf4816702020-04-03 15:44:51 -0700737status_t Camera3Stream::getInputBuffer(camera_stream_buffer *buffer, bool respectHalLimit) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700738 ATRACE_CALL();
739 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700740 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700741
Zhijun He6adc9cc2014-04-15 14:09:55 -0700742 // This function should be only called when the stream is configured already.
743 if (mState != STATE_CONFIGURED) {
744 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
745 __FUNCTION__, mId, mState);
746 return INVALID_OPERATION;
747 }
748
749 // Wait for new buffer returned back if we are running into the limit.
Emilian Peevf4816702020-04-03 15:44:51 -0700750 if (getHandoutInputBufferCountLocked() == camera_stream::max_buffers && respectHalLimit) {
Zhijun He6adc9cc2014-04-15 14:09:55 -0700751 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
Emilian Peevf4816702020-04-03 15:44:51 -0700752 __FUNCTION__, camera_stream::max_buffers);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700753 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
754 if (res != OK) {
755 if (res == TIMED_OUT) {
756 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
757 kWaitForBufferDuration / 1000000LL);
758 }
759 return res;
760 }
761 }
762
763 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700764 if (res == OK) {
765 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700766 if (buffer->buffer) {
Emilian Peev889234d2017-07-18 18:21:26 -0700767 Mutex::Autolock l(mOutstandingBuffersLock);
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700768 mOutstandingBuffers.push_back(*buffer->buffer);
769 }
Igor Murashkin2fba5842013-04-22 14:03:54 -0700770 }
771
772 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700773}
774
Emilian Peevf4816702020-04-03 15:44:51 -0700775status_t Camera3Stream::returnInputBuffer(const camera_stream_buffer &buffer) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700776 ATRACE_CALL();
777 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700778
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700779 // Check if this buffer is outstanding.
780 if (!isOutstandingBuffer(buffer)) {
781 ALOGE("%s: Stream %d: Returning an unknown buffer.", __FUNCTION__, mId);
782 return BAD_VALUE;
783 }
784
Shuzhen Wang1c484a62017-07-14 15:14:19 -0700785 removeOutstandingBuffer(buffer);
786
Igor Murashkin2fba5842013-04-22 14:03:54 -0700787 status_t res = returnInputBufferLocked(buffer);
788 if (res == OK) {
789 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700790 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700791 }
Chien-Yu Chene02e9322016-04-11 16:59:33 -0700792
Igor Murashkin2fba5842013-04-22 14:03:54 -0700793 return res;
794}
795
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700796status_t Camera3Stream::getInputBufferProducer(sp<IGraphicBufferProducer> *producer) {
797 ATRACE_CALL();
798 Mutex::Autolock l(mLock);
799
800 return getInputBufferProducerLocked(producer);
801}
802
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800803void Camera3Stream::fireBufferRequestForFrameNumber(uint64_t frameNumber,
804 const CameraMetadata& settings) {
Emilian Peev538c90e2018-12-17 18:03:19 +0000805 ATRACE_CALL();
806 Mutex::Autolock l(mLock);
807
808 for (auto &it : mBufferListenerList) {
809 sp<Camera3StreamBufferListener> listener = it.promote();
810 if (listener.get() != nullptr) {
Shuzhen Wang68ac7ad2019-01-30 14:03:28 -0800811 listener->onBufferRequestForFrameNumber(frameNumber, getId(), settings);
Emilian Peev538c90e2018-12-17 18:03:19 +0000812 }
813 }
814}
815
Igor Murashkin2fba5842013-04-22 14:03:54 -0700816void Camera3Stream::fireBufferListenersLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700817 const camera_stream_buffer& buffer, bool acquired, bool output, nsecs_t timestamp,
Emilian Peev538c90e2018-12-17 18:03:19 +0000818 uint64_t frameNumber) {
Igor Murashkin2fba5842013-04-22 14:03:54 -0700819 List<wp<Camera3StreamBufferListener> >::iterator it, end;
820
821 // TODO: finish implementing
822
823 Camera3StreamBufferListener::BufferInfo info =
824 Camera3StreamBufferListener::BufferInfo();
825 info.mOutput = output;
Emilian Peevf4816702020-04-03 15:44:51 -0700826 info.mError = (buffer.status == CAMERA_BUFFER_STATUS_ERROR);
Emilian Peev538c90e2018-12-17 18:03:19 +0000827 info.mFrameNumber = frameNumber;
828 info.mTimestamp = timestamp;
Shuzhen Wange8675782019-12-05 09:12:14 -0800829 info.mStreamId = getId();
830
Igor Murashkin2fba5842013-04-22 14:03:54 -0700831 // TODO: rest of fields
832
833 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
834 it != end;
835 ++it) {
836
837 sp<Camera3StreamBufferListener> listener = it->promote();
838 if (listener != 0) {
839 if (acquired) {
840 listener->onBufferAcquired(info);
841 } else {
842 listener->onBufferReleased(info);
843 }
844 }
845 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700846}
847
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800848bool Camera3Stream::hasOutstandingBuffers() const {
849 ATRACE_CALL();
850 Mutex::Autolock l(mLock);
851 return hasOutstandingBuffersLocked();
852}
853
Yin-Chia Yehd5cd5ff2018-10-01 14:43:04 -0700854size_t Camera3Stream::getOutstandingBuffersCount() const {
855 ATRACE_CALL();
856 Mutex::Autolock l(mLock);
857 return getHandoutOutputBufferCountLocked();
858}
859
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700860status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
861 Mutex::Autolock l(mLock);
862 sp<StatusTracker> oldTracker = mStatusTracker.promote();
863 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
864 oldTracker->removeComponent(mStatusId);
865 }
866 mStatusId = StatusTracker::NO_STATUS_ID;
867 mStatusTracker = statusTracker;
868
869 return OK;
870}
871
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800872status_t Camera3Stream::disconnect() {
873 ATRACE_CALL();
874 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700875 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
876 status_t res = disconnectLocked();
877
Shuzhen Wang686f6442017-06-20 16:16:04 -0700878 mBufferLimitLatency.log("Stream %d latency histogram for wait on max_buffers", mId);
879 mBufferLimitLatency.reset();
880
Igor Murashkine2172be2013-05-28 15:31:39 -0700881 if (res == -ENOTCONN) {
882 // "Already disconnected" -- not an error
883 return OK;
884 } else {
885 return res;
886 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800887}
888
Shuzhen Wang686f6442017-06-20 16:16:04 -0700889void Camera3Stream::dump(int fd, const Vector<String16> &args) const
890{
891 (void)args;
892 mBufferLimitLatency.dump(fd,
893 " Latency histogram for wait on max_buffers");
894}
895
Emilian Peevf4816702020-04-03 15:44:51 -0700896status_t Camera3Stream::getBufferLocked(camera_stream_buffer *,
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800897 const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700898 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
899 return INVALID_OPERATION;
900}
Emilian Peevf4816702020-04-03 15:44:51 -0700901status_t Camera3Stream::returnBufferLocked(const camera_stream_buffer &,
Yin-Chia Yeh58b1b4e2018-10-15 12:18:36 -0700902 nsecs_t, const std::vector<size_t>&) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700903 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
904 return INVALID_OPERATION;
905}
Emilian Peevf4816702020-04-03 15:44:51 -0700906status_t Camera3Stream::getInputBufferLocked(camera_stream_buffer *) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700907 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
908 return INVALID_OPERATION;
909}
910status_t Camera3Stream::returnInputBufferLocked(
Emilian Peevf4816702020-04-03 15:44:51 -0700911 const camera_stream_buffer &) {
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700912 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
913 return INVALID_OPERATION;
914}
Eino-Ville Talvala02bf0322016-02-18 12:41:10 -0800915status_t Camera3Stream::getInputBufferProducerLocked(sp<IGraphicBufferProducer>*) {
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700916 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
917 return INVALID_OPERATION;
918}
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700919
Igor Murashkin2fba5842013-04-22 14:03:54 -0700920void Camera3Stream::addBufferListener(
921 wp<Camera3StreamBufferListener> listener) {
922 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700923
924 List<wp<Camera3StreamBufferListener> >::iterator it, end;
925 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
926 it != end;
927 ) {
928 if (*it == listener) {
929 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
930 return;
931 }
932 it++;
933 }
934
Igor Murashkin2fba5842013-04-22 14:03:54 -0700935 mBufferListenerList.push_back(listener);
936}
937
938void Camera3Stream::removeBufferListener(
939 const sp<Camera3StreamBufferListener>& listener) {
940 Mutex::Autolock l(mLock);
941
942 bool erased = true;
943 List<wp<Camera3StreamBufferListener> >::iterator it, end;
944 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
945 it != end;
946 ) {
947
948 if (*it == listener) {
949 it = mBufferListenerList.erase(it);
950 erased = true;
951 } else {
952 ++it;
953 }
954 }
955
956 if (!erased) {
957 ALOGW("%s: Could not find listener to remove, already removed",
958 __FUNCTION__);
959 }
960}
961
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700962void Camera3Stream::setBufferFreedListener(
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700963 wp<Camera3StreamBufferFreedListener> listener) {
Yin-Chia Yehbe83fa72017-03-30 13:35:36 -0700964 Mutex::Autolock l(mLock);
965 // Only allow set listener during stream configuration because stream is guaranteed to be IDLE
966 // at this state, so setBufferFreedListener won't collide with onBufferFreed callbacks
967 if (mState != STATE_IN_CONFIG && mState != STATE_IN_RECONFIG) {
968 ALOGE("%s: listener must be set during stream configuration!",__FUNCTION__);
969 return;
970 }
971 mBufferFreedListener = listener;
972}
973
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800974}; // namespace camera3
975
976}; // namespace android