blob: 02727a3701977866a995a9959d189a0c9d9e8cb4 [file] [log] [blame]
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#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,
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070050 android_dataspace dataSpace, camera3_stream_rotation_t rotation) :
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080051 camera3_stream(),
52 mId(id),
53 mName(String8::format("Camera3Stream[%d]", id)),
54 mMaxSize(maxSize),
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070055 mState(STATE_CONSTRUCTED),
56 mStatusId(StatusTracker::NO_STATUS_ID) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080057
58 camera3_stream::stream_type = type;
59 camera3_stream::width = width;
60 camera3_stream::height = height;
61 camera3_stream::format = format;
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080062 camera3_stream::data_space = dataSpace;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070063 camera3_stream::rotation = rotation;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080064 camera3_stream::usage = 0;
65 camera3_stream::max_buffers = 0;
66 camera3_stream::priv = NULL;
67
68 if (format == HAL_PIXEL_FORMAT_BLOB && maxSize == 0) {
69 ALOGE("%s: BLOB format with size == 0", __FUNCTION__);
70 mState = STATE_ERROR;
71 }
72}
73
74int Camera3Stream::getId() const {
75 return mId;
76}
77
78uint32_t Camera3Stream::getWidth() const {
79 return camera3_stream::width;
80}
81
82uint32_t Camera3Stream::getHeight() const {
83 return camera3_stream::height;
84}
85
86int Camera3Stream::getFormat() const {
87 return camera3_stream::format;
88}
89
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080090android_dataspace Camera3Stream::getDataSpace() const {
91 return camera3_stream::data_space;
92}
93
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080094camera3_stream* Camera3Stream::startConfiguration() {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070095 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080096 Mutex::Autolock l(mLock);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070097 status_t res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080098
99 switch (mState) {
100 case STATE_ERROR:
101 ALOGE("%s: In error state", __FUNCTION__);
102 return NULL;
103 case STATE_CONSTRUCTED:
104 // OK
105 break;
106 case STATE_IN_CONFIG:
107 case STATE_IN_RECONFIG:
108 // Can start config again with no trouble; but don't redo
109 // oldUsage/oldMaxBuffers
110 return this;
111 case STATE_CONFIGURED:
Chien-Yu Chen90746f42015-04-15 13:50:13 -0700112 if (hasOutstandingBuffersLocked()) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800113 ALOGE("%s: Cannot configure stream; has outstanding buffers",
114 __FUNCTION__);
115 return NULL;
116 }
117 break;
118 default:
119 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
120 return NULL;
121 }
122
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700123 oldUsage = camera3_stream::usage;
124 oldMaxBuffers = camera3_stream::max_buffers;
125
126 res = getEndpointUsage(&(camera3_stream::usage));
127 if (res != OK) {
128 ALOGE("%s: Cannot query consumer endpoint usage!",
129 __FUNCTION__);
130 return NULL;
131 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800132
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700133 // Stop tracking if currently doing so
134 if (mStatusId != StatusTracker::NO_STATUS_ID) {
135 sp<StatusTracker> statusTracker = mStatusTracker.promote();
136 if (statusTracker != 0) {
137 statusTracker->removeComponent(mStatusId);
138 }
139 mStatusId = StatusTracker::NO_STATUS_ID;
140 }
141
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800142 if (mState == STATE_CONSTRUCTED) {
143 mState = STATE_IN_CONFIG;
144 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700145 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800146 mState = STATE_IN_RECONFIG;
147 }
148
149 return this;
150}
151
152bool Camera3Stream::isConfiguring() const {
153 Mutex::Autolock l(mLock);
154 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
155}
156
157status_t Camera3Stream::finishConfiguration(camera3_device *hal3Device) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700158 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800159 Mutex::Autolock l(mLock);
160 switch (mState) {
161 case STATE_ERROR:
162 ALOGE("%s: In error state", __FUNCTION__);
163 return INVALID_OPERATION;
164 case STATE_IN_CONFIG:
165 case STATE_IN_RECONFIG:
166 // OK
167 break;
168 case STATE_CONSTRUCTED:
169 case STATE_CONFIGURED:
170 ALOGE("%s: Cannot finish configuration that hasn't been started",
171 __FUNCTION__);
172 return INVALID_OPERATION;
173 default:
174 ALOGE("%s: Unknown state", __FUNCTION__);
175 return INVALID_OPERATION;
176 }
177
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700178 // Register for idle tracking
179 sp<StatusTracker> statusTracker = mStatusTracker.promote();
180 if (statusTracker != 0) {
181 mStatusId = statusTracker->addComponent();
182 }
183
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800184 // Check if the stream configuration is unchanged, and skip reallocation if
185 // so. As documented in hardware/camera3.h:configure_streams().
186 if (mState == STATE_IN_RECONFIG &&
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700187 oldUsage == camera3_stream::usage &&
188 oldMaxBuffers == camera3_stream::max_buffers) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800189 mState = STATE_CONFIGURED;
190 return OK;
191 }
192
193 status_t res;
194 res = configureQueueLocked();
195 if (res != OK) {
196 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
197 __FUNCTION__, mId, strerror(-res), res);
198 mState = STATE_ERROR;
199 return res;
200 }
201
202 res = registerBuffersLocked(hal3Device);
203 if (res != OK) {
204 ALOGE("%s: Unable to register stream buffers with HAL: %s (%d)",
205 __FUNCTION__, strerror(-res), res);
206 mState = STATE_ERROR;
207 return res;
208 }
209
210 mState = STATE_CONFIGURED;
211
212 return res;
213}
214
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700215status_t Camera3Stream::cancelConfiguration() {
216 ATRACE_CALL();
217 Mutex::Autolock l(mLock);
218 switch (mState) {
219 case STATE_ERROR:
220 ALOGE("%s: In error state", __FUNCTION__);
221 return INVALID_OPERATION;
222 case STATE_IN_CONFIG:
223 case STATE_IN_RECONFIG:
224 // OK
225 break;
226 case STATE_CONSTRUCTED:
227 case STATE_CONFIGURED:
228 ALOGE("%s: Cannot cancel configuration that hasn't been started",
229 __FUNCTION__);
230 return INVALID_OPERATION;
231 default:
232 ALOGE("%s: Unknown state", __FUNCTION__);
233 return INVALID_OPERATION;
234 }
235
236 camera3_stream::usage = oldUsage;
237 camera3_stream::max_buffers = oldMaxBuffers;
238
Yin-Chia Yeh3ea3fcd2014-09-05 14:14:44 -0700239 mState = (mState == STATE_IN_RECONFIG) ? STATE_CONFIGURED : STATE_CONSTRUCTED;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700240 return OK;
241}
242
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800243status_t Camera3Stream::getBuffer(camera3_stream_buffer *buffer) {
244 ATRACE_CALL();
245 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700246 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700247
Zhijun He6adc9cc2014-04-15 14:09:55 -0700248 // This function should be only called when the stream is configured already.
249 if (mState != STATE_CONFIGURED) {
250 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
251 __FUNCTION__, mId, mState);
252 return INVALID_OPERATION;
253 }
254
255 // Wait for new buffer returned back if we are running into the limit.
256 if (getHandoutOutputBufferCountLocked() == camera3_stream::max_buffers) {
257 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
258 __FUNCTION__, camera3_stream::max_buffers);
259 res = mOutputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
260 if (res != OK) {
261 if (res == TIMED_OUT) {
262 ALOGE("%s: wait for output buffer return timed out after %lldms", __FUNCTION__,
263 kWaitForBufferDuration / 1000000LL);
264 }
265 return res;
266 }
267 }
268
269 res = getBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700270 if (res == OK) {
271 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
272 }
273
274 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800275}
276
277status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer,
278 nsecs_t timestamp) {
279 ATRACE_CALL();
280 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700281
Igor Murashkin13d315e2014-04-03 18:09:04 -0700282 /**
283 * TODO: Check that the state is valid first.
284 *
285 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
286 * >= HAL3.2 CONFIGURED only
287 *
288 * Do this for getBuffer as well.
289 */
Igor Murashkin2fba5842013-04-22 14:03:54 -0700290 status_t res = returnBufferLocked(buffer, timestamp);
291 if (res == OK) {
292 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/true);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700293 mOutputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700294 }
295
296 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800297}
298
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700299status_t Camera3Stream::getInputBuffer(camera3_stream_buffer *buffer) {
300 ATRACE_CALL();
301 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700302 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700303
Zhijun He6adc9cc2014-04-15 14:09:55 -0700304 // This function should be only called when the stream is configured already.
305 if (mState != STATE_CONFIGURED) {
306 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
307 __FUNCTION__, mId, mState);
308 return INVALID_OPERATION;
309 }
310
311 // Wait for new buffer returned back if we are running into the limit.
312 if (getHandoutInputBufferCountLocked() == camera3_stream::max_buffers) {
313 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
314 __FUNCTION__, camera3_stream::max_buffers);
315 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
316 if (res != OK) {
317 if (res == TIMED_OUT) {
318 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
319 kWaitForBufferDuration / 1000000LL);
320 }
321 return res;
322 }
323 }
324
325 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700326 if (res == OK) {
327 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
328 }
329
330 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700331}
332
333status_t Camera3Stream::returnInputBuffer(const camera3_stream_buffer &buffer) {
334 ATRACE_CALL();
335 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700336
337 status_t res = returnInputBufferLocked(buffer);
338 if (res == OK) {
339 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700340 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700341 }
342 return res;
343}
344
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700345status_t Camera3Stream::getInputBufferProducer(sp<IGraphicBufferProducer> *producer) {
346 ATRACE_CALL();
347 Mutex::Autolock l(mLock);
348
349 return getInputBufferProducerLocked(producer);
350}
351
Igor Murashkin2fba5842013-04-22 14:03:54 -0700352void Camera3Stream::fireBufferListenersLocked(
353 const camera3_stream_buffer& /*buffer*/, bool acquired, bool output) {
354 List<wp<Camera3StreamBufferListener> >::iterator it, end;
355
356 // TODO: finish implementing
357
358 Camera3StreamBufferListener::BufferInfo info =
359 Camera3StreamBufferListener::BufferInfo();
360 info.mOutput = output;
361 // TODO: rest of fields
362
363 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
364 it != end;
365 ++it) {
366
367 sp<Camera3StreamBufferListener> listener = it->promote();
368 if (listener != 0) {
369 if (acquired) {
370 listener->onBufferAcquired(info);
371 } else {
372 listener->onBufferReleased(info);
373 }
374 }
375 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700376}
377
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800378bool Camera3Stream::hasOutstandingBuffers() const {
379 ATRACE_CALL();
380 Mutex::Autolock l(mLock);
381 return hasOutstandingBuffersLocked();
382}
383
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700384status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
385 Mutex::Autolock l(mLock);
386 sp<StatusTracker> oldTracker = mStatusTracker.promote();
387 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
388 oldTracker->removeComponent(mStatusId);
389 }
390 mStatusId = StatusTracker::NO_STATUS_ID;
391 mStatusTracker = statusTracker;
392
393 return OK;
394}
395
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800396status_t Camera3Stream::disconnect() {
397 ATRACE_CALL();
398 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700399 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
400 status_t res = disconnectLocked();
401
402 if (res == -ENOTCONN) {
403 // "Already disconnected" -- not an error
404 return OK;
405 } else {
406 return res;
407 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800408}
409
410status_t Camera3Stream::registerBuffersLocked(camera3_device *hal3Device) {
411 ATRACE_CALL();
Igor Murashkin13d315e2014-04-03 18:09:04 -0700412
413 /**
414 * >= CAMERA_DEVICE_API_VERSION_3_2:
415 *
416 * camera3_device_t->ops->register_stream_buffers() is not called and must
417 * be NULL.
418 */
419 if (hal3Device->common.version >= CAMERA_DEVICE_API_VERSION_3_2) {
420 ALOGV("%s: register_stream_buffers unused as of HAL3.2", __FUNCTION__);
421
Igor Murashkinc758f222014-08-19 15:14:29 -0700422 if (hal3Device->ops->register_stream_buffers != NULL) {
Igor Murashkin13d315e2014-04-03 18:09:04 -0700423 ALOGE("%s: register_stream_buffers is deprecated in HAL3.2; "
424 "must be set to NULL in camera3_device::ops", __FUNCTION__);
425 return INVALID_OPERATION;
426 } else {
Zhijun He13c878f2014-05-06 11:33:52 -0700427 ALOGD("%s: Skipping NULL check for deprecated register_stream_buffers", __FUNCTION__);
Igor Murashkin13d315e2014-04-03 18:09:04 -0700428 }
429
430 return OK;
431 } else {
432 ALOGV("%s: register_stream_buffers using deprecated code path", __FUNCTION__);
433 }
434
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800435 status_t res;
436
437 size_t bufferCount = getBufferCountLocked();
438
439 Vector<buffer_handle_t*> buffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700440 buffers.insertAt(/*prototype_item*/NULL, /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800441
442 camera3_stream_buffer_set bufferSet = camera3_stream_buffer_set();
443 bufferSet.stream = this;
444 bufferSet.num_buffers = bufferCount;
445 bufferSet.buffers = buffers.editArray();
446
447 Vector<camera3_stream_buffer_t> streamBuffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700448 streamBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800449
450 // Register all buffers with the HAL. This means getting all the buffers
451 // from the stream, providing them to the HAL with the
452 // register_stream_buffers() method, and then returning them back to the
453 // stream in the error state, since they won't have valid data.
454 //
455 // Only registered buffers can be sent to the HAL.
456
457 uint32_t bufferIdx = 0;
458 for (; bufferIdx < bufferCount; bufferIdx++) {
459 res = getBufferLocked( &streamBuffers.editItemAt(bufferIdx) );
460 if (res != OK) {
461 ALOGE("%s: Unable to get buffer %d for registration with HAL",
462 __FUNCTION__, bufferIdx);
463 // Skip registering, go straight to cleanup
464 break;
465 }
466
467 sp<Fence> fence = new Fence(streamBuffers[bufferIdx].acquire_fence);
Mathias Agopiand7644242013-05-16 18:07:35 -0700468 fence->waitForever("Camera3Stream::registerBuffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800469
470 buffers.editItemAt(bufferIdx) = streamBuffers[bufferIdx].buffer;
471 }
472 if (bufferIdx == bufferCount) {
473 // Got all buffers, register with HAL
Colin Crosse5729fa2014-03-21 15:04:25 -0700474 ALOGV("%s: Registering %zu buffers with camera HAL",
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800475 __FUNCTION__, bufferCount);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700476 ATRACE_BEGIN("camera3->register_stream_buffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800477 res = hal3Device->ops->register_stream_buffers(hal3Device,
478 &bufferSet);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700479 ATRACE_END();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800480 }
481
482 // Return all valid buffers to stream, in ERROR state to indicate
483 // they weren't filled.
484 for (size_t i = 0; i < bufferIdx; i++) {
485 streamBuffers.editItemAt(i).release_fence = -1;
486 streamBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
487 returnBufferLocked(streamBuffers[i], 0);
488 }
489
490 return res;
491}
492
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700493status_t Camera3Stream::getBufferLocked(camera3_stream_buffer *) {
494 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
495 return INVALID_OPERATION;
496}
497status_t Camera3Stream::returnBufferLocked(const camera3_stream_buffer &,
498 nsecs_t) {
499 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
500 return INVALID_OPERATION;
501}
502status_t Camera3Stream::getInputBufferLocked(camera3_stream_buffer *) {
503 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
504 return INVALID_OPERATION;
505}
506status_t Camera3Stream::returnInputBufferLocked(
507 const camera3_stream_buffer &) {
508 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
509 return INVALID_OPERATION;
510}
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700511status_t Camera3Stream::getInputBufferProducerLocked(sp<IGraphicBufferProducer> *producer) {
512 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
513 return INVALID_OPERATION;
514}
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700515
Igor Murashkin2fba5842013-04-22 14:03:54 -0700516void Camera3Stream::addBufferListener(
517 wp<Camera3StreamBufferListener> listener) {
518 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700519
520 List<wp<Camera3StreamBufferListener> >::iterator it, end;
521 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
522 it != end;
523 ) {
524 if (*it == listener) {
525 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
526 return;
527 }
528 it++;
529 }
530
Igor Murashkin2fba5842013-04-22 14:03:54 -0700531 mBufferListenerList.push_back(listener);
532}
533
534void Camera3Stream::removeBufferListener(
535 const sp<Camera3StreamBufferListener>& listener) {
536 Mutex::Autolock l(mLock);
537
538 bool erased = true;
539 List<wp<Camera3StreamBufferListener> >::iterator it, end;
540 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
541 it != end;
542 ) {
543
544 if (*it == listener) {
545 it = mBufferListenerList.erase(it);
546 erased = true;
547 } else {
548 ++it;
549 }
550 }
551
552 if (!erased) {
553 ALOGW("%s: Could not find listener to remove, already removed",
554 __FUNCTION__);
555 }
556}
557
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800558}; // namespace camera3
559
560}; // namespace android