blob: f829741d7b5ff15f761ad4b96998b10228898eed [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,
50 android_dataspace dataSpace) :
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;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080063 camera3_stream::usage = 0;
64 camera3_stream::max_buffers = 0;
65 camera3_stream::priv = NULL;
66
67 if (format == HAL_PIXEL_FORMAT_BLOB && maxSize == 0) {
68 ALOGE("%s: BLOB format with size == 0", __FUNCTION__);
69 mState = STATE_ERROR;
70 }
71}
72
73int Camera3Stream::getId() const {
74 return mId;
75}
76
77uint32_t Camera3Stream::getWidth() const {
78 return camera3_stream::width;
79}
80
81uint32_t Camera3Stream::getHeight() const {
82 return camera3_stream::height;
83}
84
85int Camera3Stream::getFormat() const {
86 return camera3_stream::format;
87}
88
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080089android_dataspace Camera3Stream::getDataSpace() const {
90 return camera3_stream::data_space;
91}
92
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080093camera3_stream* Camera3Stream::startConfiguration() {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070094 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080095 Mutex::Autolock l(mLock);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -070096 status_t res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080097
98 switch (mState) {
99 case STATE_ERROR:
100 ALOGE("%s: In error state", __FUNCTION__);
101 return NULL;
102 case STATE_CONSTRUCTED:
103 // OK
104 break;
105 case STATE_IN_CONFIG:
106 case STATE_IN_RECONFIG:
107 // Can start config again with no trouble; but don't redo
108 // oldUsage/oldMaxBuffers
109 return this;
110 case STATE_CONFIGURED:
111 if (stream_type == CAMERA3_STREAM_INPUT) {
112 ALOGE("%s: Cannot configure an input stream twice",
113 __FUNCTION__);
114 return NULL;
115 } else if (hasOutstandingBuffersLocked()) {
116 ALOGE("%s: Cannot configure stream; has outstanding buffers",
117 __FUNCTION__);
118 return NULL;
119 }
120 break;
121 default:
122 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
123 return NULL;
124 }
125
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700126 oldUsage = camera3_stream::usage;
127 oldMaxBuffers = camera3_stream::max_buffers;
128
129 res = getEndpointUsage(&(camera3_stream::usage));
130 if (res != OK) {
131 ALOGE("%s: Cannot query consumer endpoint usage!",
132 __FUNCTION__);
133 return NULL;
134 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800135
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700136 // Stop tracking if currently doing so
137 if (mStatusId != StatusTracker::NO_STATUS_ID) {
138 sp<StatusTracker> statusTracker = mStatusTracker.promote();
139 if (statusTracker != 0) {
140 statusTracker->removeComponent(mStatusId);
141 }
142 mStatusId = StatusTracker::NO_STATUS_ID;
143 }
144
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800145 if (mState == STATE_CONSTRUCTED) {
146 mState = STATE_IN_CONFIG;
147 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700148 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800149 mState = STATE_IN_RECONFIG;
150 }
151
152 return this;
153}
154
155bool Camera3Stream::isConfiguring() const {
156 Mutex::Autolock l(mLock);
157 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
158}
159
160status_t Camera3Stream::finishConfiguration(camera3_device *hal3Device) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700161 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800162 Mutex::Autolock l(mLock);
163 switch (mState) {
164 case STATE_ERROR:
165 ALOGE("%s: In error state", __FUNCTION__);
166 return INVALID_OPERATION;
167 case STATE_IN_CONFIG:
168 case STATE_IN_RECONFIG:
169 // OK
170 break;
171 case STATE_CONSTRUCTED:
172 case STATE_CONFIGURED:
173 ALOGE("%s: Cannot finish configuration that hasn't been started",
174 __FUNCTION__);
175 return INVALID_OPERATION;
176 default:
177 ALOGE("%s: Unknown state", __FUNCTION__);
178 return INVALID_OPERATION;
179 }
180
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700181 // Register for idle tracking
182 sp<StatusTracker> statusTracker = mStatusTracker.promote();
183 if (statusTracker != 0) {
184 mStatusId = statusTracker->addComponent();
185 }
186
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800187 // Check if the stream configuration is unchanged, and skip reallocation if
188 // so. As documented in hardware/camera3.h:configure_streams().
189 if (mState == STATE_IN_RECONFIG &&
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700190 oldUsage == camera3_stream::usage &&
191 oldMaxBuffers == camera3_stream::max_buffers) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800192 mState = STATE_CONFIGURED;
193 return OK;
194 }
195
196 status_t res;
197 res = configureQueueLocked();
198 if (res != OK) {
199 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
200 __FUNCTION__, mId, strerror(-res), res);
201 mState = STATE_ERROR;
202 return res;
203 }
204
205 res = registerBuffersLocked(hal3Device);
206 if (res != OK) {
207 ALOGE("%s: Unable to register stream buffers with HAL: %s (%d)",
208 __FUNCTION__, strerror(-res), res);
209 mState = STATE_ERROR;
210 return res;
211 }
212
213 mState = STATE_CONFIGURED;
214
215 return res;
216}
217
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700218status_t Camera3Stream::cancelConfiguration() {
219 ATRACE_CALL();
220 Mutex::Autolock l(mLock);
221 switch (mState) {
222 case STATE_ERROR:
223 ALOGE("%s: In error state", __FUNCTION__);
224 return INVALID_OPERATION;
225 case STATE_IN_CONFIG:
226 case STATE_IN_RECONFIG:
227 // OK
228 break;
229 case STATE_CONSTRUCTED:
230 case STATE_CONFIGURED:
231 ALOGE("%s: Cannot cancel configuration that hasn't been started",
232 __FUNCTION__);
233 return INVALID_OPERATION;
234 default:
235 ALOGE("%s: Unknown state", __FUNCTION__);
236 return INVALID_OPERATION;
237 }
238
239 camera3_stream::usage = oldUsage;
240 camera3_stream::max_buffers = oldMaxBuffers;
241
Yin-Chia Yeh3ea3fcd2014-09-05 14:14:44 -0700242 mState = (mState == STATE_IN_RECONFIG) ? STATE_CONFIGURED : STATE_CONSTRUCTED;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700243 return OK;
244}
245
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800246status_t Camera3Stream::getBuffer(camera3_stream_buffer *buffer) {
247 ATRACE_CALL();
248 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700249 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700250
Zhijun He6adc9cc2014-04-15 14:09:55 -0700251 // This function should be only called when the stream is configured already.
252 if (mState != STATE_CONFIGURED) {
253 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
254 __FUNCTION__, mId, mState);
255 return INVALID_OPERATION;
256 }
257
258 // Wait for new buffer returned back if we are running into the limit.
259 if (getHandoutOutputBufferCountLocked() == camera3_stream::max_buffers) {
260 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
261 __FUNCTION__, camera3_stream::max_buffers);
262 res = mOutputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
263 if (res != OK) {
264 if (res == TIMED_OUT) {
265 ALOGE("%s: wait for output buffer return timed out after %lldms", __FUNCTION__,
266 kWaitForBufferDuration / 1000000LL);
267 }
268 return res;
269 }
270 }
271
272 res = getBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700273 if (res == OK) {
274 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
275 }
276
277 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800278}
279
280status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer,
281 nsecs_t timestamp) {
282 ATRACE_CALL();
283 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700284
Igor Murashkin13d315e2014-04-03 18:09:04 -0700285 /**
286 * TODO: Check that the state is valid first.
287 *
288 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
289 * >= HAL3.2 CONFIGURED only
290 *
291 * Do this for getBuffer as well.
292 */
Igor Murashkin2fba5842013-04-22 14:03:54 -0700293 status_t res = returnBufferLocked(buffer, timestamp);
294 if (res == OK) {
295 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/true);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700296 mOutputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700297 }
298
299 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800300}
301
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700302status_t Camera3Stream::getInputBuffer(camera3_stream_buffer *buffer) {
303 ATRACE_CALL();
304 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700305 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700306
Zhijun He6adc9cc2014-04-15 14:09:55 -0700307 // This function should be only called when the stream is configured already.
308 if (mState != STATE_CONFIGURED) {
309 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
310 __FUNCTION__, mId, mState);
311 return INVALID_OPERATION;
312 }
313
314 // Wait for new buffer returned back if we are running into the limit.
315 if (getHandoutInputBufferCountLocked() == camera3_stream::max_buffers) {
316 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
317 __FUNCTION__, camera3_stream::max_buffers);
318 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
319 if (res != OK) {
320 if (res == TIMED_OUT) {
321 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
322 kWaitForBufferDuration / 1000000LL);
323 }
324 return res;
325 }
326 }
327
328 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700329 if (res == OK) {
330 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
331 }
332
333 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700334}
335
336status_t Camera3Stream::returnInputBuffer(const camera3_stream_buffer &buffer) {
337 ATRACE_CALL();
338 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700339
340 status_t res = returnInputBufferLocked(buffer);
341 if (res == OK) {
342 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700343 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700344 }
345 return res;
346}
347
348void Camera3Stream::fireBufferListenersLocked(
349 const camera3_stream_buffer& /*buffer*/, bool acquired, bool output) {
350 List<wp<Camera3StreamBufferListener> >::iterator it, end;
351
352 // TODO: finish implementing
353
354 Camera3StreamBufferListener::BufferInfo info =
355 Camera3StreamBufferListener::BufferInfo();
356 info.mOutput = output;
357 // TODO: rest of fields
358
359 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
360 it != end;
361 ++it) {
362
363 sp<Camera3StreamBufferListener> listener = it->promote();
364 if (listener != 0) {
365 if (acquired) {
366 listener->onBufferAcquired(info);
367 } else {
368 listener->onBufferReleased(info);
369 }
370 }
371 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700372}
373
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800374bool Camera3Stream::hasOutstandingBuffers() const {
375 ATRACE_CALL();
376 Mutex::Autolock l(mLock);
377 return hasOutstandingBuffersLocked();
378}
379
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700380status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
381 Mutex::Autolock l(mLock);
382 sp<StatusTracker> oldTracker = mStatusTracker.promote();
383 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
384 oldTracker->removeComponent(mStatusId);
385 }
386 mStatusId = StatusTracker::NO_STATUS_ID;
387 mStatusTracker = statusTracker;
388
389 return OK;
390}
391
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800392status_t Camera3Stream::disconnect() {
393 ATRACE_CALL();
394 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700395 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
396 status_t res = disconnectLocked();
397
398 if (res == -ENOTCONN) {
399 // "Already disconnected" -- not an error
400 return OK;
401 } else {
402 return res;
403 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800404}
405
406status_t Camera3Stream::registerBuffersLocked(camera3_device *hal3Device) {
407 ATRACE_CALL();
Igor Murashkin13d315e2014-04-03 18:09:04 -0700408
409 /**
410 * >= CAMERA_DEVICE_API_VERSION_3_2:
411 *
412 * camera3_device_t->ops->register_stream_buffers() is not called and must
413 * be NULL.
414 */
415 if (hal3Device->common.version >= CAMERA_DEVICE_API_VERSION_3_2) {
416 ALOGV("%s: register_stream_buffers unused as of HAL3.2", __FUNCTION__);
417
Igor Murashkinc758f222014-08-19 15:14:29 -0700418 if (hal3Device->ops->register_stream_buffers != NULL) {
Igor Murashkin13d315e2014-04-03 18:09:04 -0700419 ALOGE("%s: register_stream_buffers is deprecated in HAL3.2; "
420 "must be set to NULL in camera3_device::ops", __FUNCTION__);
421 return INVALID_OPERATION;
422 } else {
Zhijun He13c878f2014-05-06 11:33:52 -0700423 ALOGD("%s: Skipping NULL check for deprecated register_stream_buffers", __FUNCTION__);
Igor Murashkin13d315e2014-04-03 18:09:04 -0700424 }
425
426 return OK;
427 } else {
428 ALOGV("%s: register_stream_buffers using deprecated code path", __FUNCTION__);
429 }
430
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800431 status_t res;
432
433 size_t bufferCount = getBufferCountLocked();
434
435 Vector<buffer_handle_t*> buffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700436 buffers.insertAt(/*prototype_item*/NULL, /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800437
438 camera3_stream_buffer_set bufferSet = camera3_stream_buffer_set();
439 bufferSet.stream = this;
440 bufferSet.num_buffers = bufferCount;
441 bufferSet.buffers = buffers.editArray();
442
443 Vector<camera3_stream_buffer_t> streamBuffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700444 streamBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800445
446 // Register all buffers with the HAL. This means getting all the buffers
447 // from the stream, providing them to the HAL with the
448 // register_stream_buffers() method, and then returning them back to the
449 // stream in the error state, since they won't have valid data.
450 //
451 // Only registered buffers can be sent to the HAL.
452
453 uint32_t bufferIdx = 0;
454 for (; bufferIdx < bufferCount; bufferIdx++) {
455 res = getBufferLocked( &streamBuffers.editItemAt(bufferIdx) );
456 if (res != OK) {
457 ALOGE("%s: Unable to get buffer %d for registration with HAL",
458 __FUNCTION__, bufferIdx);
459 // Skip registering, go straight to cleanup
460 break;
461 }
462
463 sp<Fence> fence = new Fence(streamBuffers[bufferIdx].acquire_fence);
Mathias Agopiand7644242013-05-16 18:07:35 -0700464 fence->waitForever("Camera3Stream::registerBuffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800465
466 buffers.editItemAt(bufferIdx) = streamBuffers[bufferIdx].buffer;
467 }
468 if (bufferIdx == bufferCount) {
469 // Got all buffers, register with HAL
Colin Crosse5729fa2014-03-21 15:04:25 -0700470 ALOGV("%s: Registering %zu buffers with camera HAL",
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800471 __FUNCTION__, bufferCount);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700472 ATRACE_BEGIN("camera3->register_stream_buffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800473 res = hal3Device->ops->register_stream_buffers(hal3Device,
474 &bufferSet);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700475 ATRACE_END();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800476 }
477
478 // Return all valid buffers to stream, in ERROR state to indicate
479 // they weren't filled.
480 for (size_t i = 0; i < bufferIdx; i++) {
481 streamBuffers.editItemAt(i).release_fence = -1;
482 streamBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
483 returnBufferLocked(streamBuffers[i], 0);
484 }
485
486 return res;
487}
488
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700489status_t Camera3Stream::getBufferLocked(camera3_stream_buffer *) {
490 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
491 return INVALID_OPERATION;
492}
493status_t Camera3Stream::returnBufferLocked(const camera3_stream_buffer &,
494 nsecs_t) {
495 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
496 return INVALID_OPERATION;
497}
498status_t Camera3Stream::getInputBufferLocked(camera3_stream_buffer *) {
499 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
500 return INVALID_OPERATION;
501}
502status_t Camera3Stream::returnInputBufferLocked(
503 const camera3_stream_buffer &) {
504 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
505 return INVALID_OPERATION;
506}
507
Igor Murashkin2fba5842013-04-22 14:03:54 -0700508void Camera3Stream::addBufferListener(
509 wp<Camera3StreamBufferListener> listener) {
510 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700511
512 List<wp<Camera3StreamBufferListener> >::iterator it, end;
513 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
514 it != end;
515 ) {
516 if (*it == listener) {
517 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
518 return;
519 }
520 it++;
521 }
522
Igor Murashkin2fba5842013-04-22 14:03:54 -0700523 mBufferListenerList.push_back(listener);
524}
525
526void Camera3Stream::removeBufferListener(
527 const sp<Camera3StreamBufferListener>& listener) {
528 Mutex::Autolock l(mLock);
529
530 bool erased = true;
531 List<wp<Camera3StreamBufferListener> >::iterator it, end;
532 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
533 it != end;
534 ) {
535
536 if (*it == listener) {
537 it = mBufferListenerList.erase(it);
538 erased = true;
539 } else {
540 ++it;
541 }
542 }
543
544 if (!erased) {
545 ALOGW("%s: Could not find listener to remove, already removed",
546 __FUNCTION__);
547 }
548}
549
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800550}; // namespace camera3
551
552}; // namespace android