blob: 4acbce39d9d0a231d3e09d48a18e98774632f34c [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:
112 if (stream_type == CAMERA3_STREAM_INPUT) {
113 ALOGE("%s: Cannot configure an input stream twice",
114 __FUNCTION__);
115 return NULL;
116 } else if (hasOutstandingBuffersLocked()) {
117 ALOGE("%s: Cannot configure stream; has outstanding buffers",
118 __FUNCTION__);
119 return NULL;
120 }
121 break;
122 default:
123 ALOGE("%s: Unknown state %d", __FUNCTION__, mState);
124 return NULL;
125 }
126
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700127 oldUsage = camera3_stream::usage;
128 oldMaxBuffers = camera3_stream::max_buffers;
129
130 res = getEndpointUsage(&(camera3_stream::usage));
131 if (res != OK) {
132 ALOGE("%s: Cannot query consumer endpoint usage!",
133 __FUNCTION__);
134 return NULL;
135 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800136
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700137 // Stop tracking if currently doing so
138 if (mStatusId != StatusTracker::NO_STATUS_ID) {
139 sp<StatusTracker> statusTracker = mStatusTracker.promote();
140 if (statusTracker != 0) {
141 statusTracker->removeComponent(mStatusId);
142 }
143 mStatusId = StatusTracker::NO_STATUS_ID;
144 }
145
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800146 if (mState == STATE_CONSTRUCTED) {
147 mState = STATE_IN_CONFIG;
148 } else { // mState == STATE_CONFIGURED
Igor Murashkin13d315e2014-04-03 18:09:04 -0700149 LOG_ALWAYS_FATAL_IF(mState != STATE_CONFIGURED, "Invalid state: 0x%x", mState);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800150 mState = STATE_IN_RECONFIG;
151 }
152
153 return this;
154}
155
156bool Camera3Stream::isConfiguring() const {
157 Mutex::Autolock l(mLock);
158 return (mState == STATE_IN_CONFIG) || (mState == STATE_IN_RECONFIG);
159}
160
161status_t Camera3Stream::finishConfiguration(camera3_device *hal3Device) {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700162 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800163 Mutex::Autolock l(mLock);
164 switch (mState) {
165 case STATE_ERROR:
166 ALOGE("%s: In error state", __FUNCTION__);
167 return INVALID_OPERATION;
168 case STATE_IN_CONFIG:
169 case STATE_IN_RECONFIG:
170 // OK
171 break;
172 case STATE_CONSTRUCTED:
173 case STATE_CONFIGURED:
174 ALOGE("%s: Cannot finish configuration that hasn't been started",
175 __FUNCTION__);
176 return INVALID_OPERATION;
177 default:
178 ALOGE("%s: Unknown state", __FUNCTION__);
179 return INVALID_OPERATION;
180 }
181
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700182 // Register for idle tracking
183 sp<StatusTracker> statusTracker = mStatusTracker.promote();
184 if (statusTracker != 0) {
185 mStatusId = statusTracker->addComponent();
186 }
187
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800188 // Check if the stream configuration is unchanged, and skip reallocation if
189 // so. As documented in hardware/camera3.h:configure_streams().
190 if (mState == STATE_IN_RECONFIG &&
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700191 oldUsage == camera3_stream::usage &&
192 oldMaxBuffers == camera3_stream::max_buffers) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800193 mState = STATE_CONFIGURED;
194 return OK;
195 }
196
197 status_t res;
198 res = configureQueueLocked();
199 if (res != OK) {
200 ALOGE("%s: Unable to configure stream %d queue: %s (%d)",
201 __FUNCTION__, mId, strerror(-res), res);
202 mState = STATE_ERROR;
203 return res;
204 }
205
206 res = registerBuffersLocked(hal3Device);
207 if (res != OK) {
208 ALOGE("%s: Unable to register stream buffers with HAL: %s (%d)",
209 __FUNCTION__, strerror(-res), res);
210 mState = STATE_ERROR;
211 return res;
212 }
213
214 mState = STATE_CONFIGURED;
215
216 return res;
217}
218
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700219status_t Camera3Stream::cancelConfiguration() {
220 ATRACE_CALL();
221 Mutex::Autolock l(mLock);
222 switch (mState) {
223 case STATE_ERROR:
224 ALOGE("%s: In error state", __FUNCTION__);
225 return INVALID_OPERATION;
226 case STATE_IN_CONFIG:
227 case STATE_IN_RECONFIG:
228 // OK
229 break;
230 case STATE_CONSTRUCTED:
231 case STATE_CONFIGURED:
232 ALOGE("%s: Cannot cancel configuration that hasn't been started",
233 __FUNCTION__);
234 return INVALID_OPERATION;
235 default:
236 ALOGE("%s: Unknown state", __FUNCTION__);
237 return INVALID_OPERATION;
238 }
239
240 camera3_stream::usage = oldUsage;
241 camera3_stream::max_buffers = oldMaxBuffers;
242
Yin-Chia Yeh3ea3fcd2014-09-05 14:14:44 -0700243 mState = (mState == STATE_IN_RECONFIG) ? STATE_CONFIGURED : STATE_CONSTRUCTED;
Eino-Ville Talvala17543512014-08-06 14:32:02 -0700244 return OK;
245}
246
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800247status_t Camera3Stream::getBuffer(camera3_stream_buffer *buffer) {
248 ATRACE_CALL();
249 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700250 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700251
Zhijun He6adc9cc2014-04-15 14:09:55 -0700252 // This function should be only called when the stream is configured already.
253 if (mState != STATE_CONFIGURED) {
254 ALOGE("%s: Stream %d: Can't get buffers if stream is not in CONFIGURED state %d",
255 __FUNCTION__, mId, mState);
256 return INVALID_OPERATION;
257 }
258
259 // Wait for new buffer returned back if we are running into the limit.
260 if (getHandoutOutputBufferCountLocked() == camera3_stream::max_buffers) {
261 ALOGV("%s: Already dequeued max output buffers (%d), wait for next returned one.",
262 __FUNCTION__, camera3_stream::max_buffers);
263 res = mOutputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
264 if (res != OK) {
265 if (res == TIMED_OUT) {
266 ALOGE("%s: wait for output buffer return timed out after %lldms", __FUNCTION__,
267 kWaitForBufferDuration / 1000000LL);
268 }
269 return res;
270 }
271 }
272
273 res = getBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700274 if (res == OK) {
275 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/true);
276 }
277
278 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800279}
280
281status_t Camera3Stream::returnBuffer(const camera3_stream_buffer &buffer,
282 nsecs_t timestamp) {
283 ATRACE_CALL();
284 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700285
Igor Murashkin13d315e2014-04-03 18:09:04 -0700286 /**
287 * TODO: Check that the state is valid first.
288 *
289 * <HAL3.2 IN_CONFIG and IN_RECONFIG in addition to CONFIGURED.
290 * >= HAL3.2 CONFIGURED only
291 *
292 * Do this for getBuffer as well.
293 */
Igor Murashkin2fba5842013-04-22 14:03:54 -0700294 status_t res = returnBufferLocked(buffer, timestamp);
295 if (res == OK) {
296 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/true);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700297 mOutputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700298 }
299
300 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800301}
302
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700303status_t Camera3Stream::getInputBuffer(camera3_stream_buffer *buffer) {
304 ATRACE_CALL();
305 Mutex::Autolock l(mLock);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700306 status_t res = OK;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700307
Zhijun He6adc9cc2014-04-15 14:09:55 -0700308 // This function should be only called when the stream is configured already.
309 if (mState != STATE_CONFIGURED) {
310 ALOGE("%s: Stream %d: Can't get input buffers if stream is not in CONFIGURED state %d",
311 __FUNCTION__, mId, mState);
312 return INVALID_OPERATION;
313 }
314
315 // Wait for new buffer returned back if we are running into the limit.
316 if (getHandoutInputBufferCountLocked() == camera3_stream::max_buffers) {
317 ALOGV("%s: Already dequeued max input buffers (%d), wait for next returned one.",
318 __FUNCTION__, camera3_stream::max_buffers);
319 res = mInputBufferReturnedSignal.waitRelative(mLock, kWaitForBufferDuration);
320 if (res != OK) {
321 if (res == TIMED_OUT) {
322 ALOGE("%s: wait for input buffer return timed out after %lldms", __FUNCTION__,
323 kWaitForBufferDuration / 1000000LL);
324 }
325 return res;
326 }
327 }
328
329 res = getInputBufferLocked(buffer);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700330 if (res == OK) {
331 fireBufferListenersLocked(*buffer, /*acquired*/true, /*output*/false);
332 }
333
334 return res;
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700335}
336
337status_t Camera3Stream::returnInputBuffer(const camera3_stream_buffer &buffer) {
338 ATRACE_CALL();
339 Mutex::Autolock l(mLock);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700340
341 status_t res = returnInputBufferLocked(buffer);
342 if (res == OK) {
343 fireBufferListenersLocked(buffer, /*acquired*/false, /*output*/false);
Zhijun He6adc9cc2014-04-15 14:09:55 -0700344 mInputBufferReturnedSignal.signal();
Igor Murashkin2fba5842013-04-22 14:03:54 -0700345 }
346 return res;
347}
348
349void Camera3Stream::fireBufferListenersLocked(
350 const camera3_stream_buffer& /*buffer*/, bool acquired, bool output) {
351 List<wp<Camera3StreamBufferListener> >::iterator it, end;
352
353 // TODO: finish implementing
354
355 Camera3StreamBufferListener::BufferInfo info =
356 Camera3StreamBufferListener::BufferInfo();
357 info.mOutput = output;
358 // TODO: rest of fields
359
360 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
361 it != end;
362 ++it) {
363
364 sp<Camera3StreamBufferListener> listener = it->promote();
365 if (listener != 0) {
366 if (acquired) {
367 listener->onBufferAcquired(info);
368 } else {
369 listener->onBufferReleased(info);
370 }
371 }
372 }
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700373}
374
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800375bool Camera3Stream::hasOutstandingBuffers() const {
376 ATRACE_CALL();
377 Mutex::Autolock l(mLock);
378 return hasOutstandingBuffersLocked();
379}
380
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700381status_t Camera3Stream::setStatusTracker(sp<StatusTracker> statusTracker) {
382 Mutex::Autolock l(mLock);
383 sp<StatusTracker> oldTracker = mStatusTracker.promote();
384 if (oldTracker != 0 && mStatusId != StatusTracker::NO_STATUS_ID) {
385 oldTracker->removeComponent(mStatusId);
386 }
387 mStatusId = StatusTracker::NO_STATUS_ID;
388 mStatusTracker = statusTracker;
389
390 return OK;
391}
392
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800393status_t Camera3Stream::disconnect() {
394 ATRACE_CALL();
395 Mutex::Autolock l(mLock);
Igor Murashkine2172be2013-05-28 15:31:39 -0700396 ALOGV("%s: Stream %d: Disconnecting...", __FUNCTION__, mId);
397 status_t res = disconnectLocked();
398
399 if (res == -ENOTCONN) {
400 // "Already disconnected" -- not an error
401 return OK;
402 } else {
403 return res;
404 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800405}
406
407status_t Camera3Stream::registerBuffersLocked(camera3_device *hal3Device) {
408 ATRACE_CALL();
Igor Murashkin13d315e2014-04-03 18:09:04 -0700409
410 /**
411 * >= CAMERA_DEVICE_API_VERSION_3_2:
412 *
413 * camera3_device_t->ops->register_stream_buffers() is not called and must
414 * be NULL.
415 */
416 if (hal3Device->common.version >= CAMERA_DEVICE_API_VERSION_3_2) {
417 ALOGV("%s: register_stream_buffers unused as of HAL3.2", __FUNCTION__);
418
Igor Murashkinc758f222014-08-19 15:14:29 -0700419 if (hal3Device->ops->register_stream_buffers != NULL) {
Igor Murashkin13d315e2014-04-03 18:09:04 -0700420 ALOGE("%s: register_stream_buffers is deprecated in HAL3.2; "
421 "must be set to NULL in camera3_device::ops", __FUNCTION__);
422 return INVALID_OPERATION;
423 } else {
Zhijun He13c878f2014-05-06 11:33:52 -0700424 ALOGD("%s: Skipping NULL check for deprecated register_stream_buffers", __FUNCTION__);
Igor Murashkin13d315e2014-04-03 18:09:04 -0700425 }
426
427 return OK;
428 } else {
429 ALOGV("%s: register_stream_buffers using deprecated code path", __FUNCTION__);
430 }
431
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800432 status_t res;
433
434 size_t bufferCount = getBufferCountLocked();
435
436 Vector<buffer_handle_t*> buffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700437 buffers.insertAt(/*prototype_item*/NULL, /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800438
439 camera3_stream_buffer_set bufferSet = camera3_stream_buffer_set();
440 bufferSet.stream = this;
441 bufferSet.num_buffers = bufferCount;
442 bufferSet.buffers = buffers.editArray();
443
444 Vector<camera3_stream_buffer_t> streamBuffers;
Igor Murashkin13d315e2014-04-03 18:09:04 -0700445 streamBuffers.insertAt(camera3_stream_buffer_t(), /*index*/0, bufferCount);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800446
447 // Register all buffers with the HAL. This means getting all the buffers
448 // from the stream, providing them to the HAL with the
449 // register_stream_buffers() method, and then returning them back to the
450 // stream in the error state, since they won't have valid data.
451 //
452 // Only registered buffers can be sent to the HAL.
453
454 uint32_t bufferIdx = 0;
455 for (; bufferIdx < bufferCount; bufferIdx++) {
456 res = getBufferLocked( &streamBuffers.editItemAt(bufferIdx) );
457 if (res != OK) {
458 ALOGE("%s: Unable to get buffer %d for registration with HAL",
459 __FUNCTION__, bufferIdx);
460 // Skip registering, go straight to cleanup
461 break;
462 }
463
464 sp<Fence> fence = new Fence(streamBuffers[bufferIdx].acquire_fence);
Mathias Agopiand7644242013-05-16 18:07:35 -0700465 fence->waitForever("Camera3Stream::registerBuffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800466
467 buffers.editItemAt(bufferIdx) = streamBuffers[bufferIdx].buffer;
468 }
469 if (bufferIdx == bufferCount) {
470 // Got all buffers, register with HAL
Colin Crosse5729fa2014-03-21 15:04:25 -0700471 ALOGV("%s: Registering %zu buffers with camera HAL",
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800472 __FUNCTION__, bufferCount);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700473 ATRACE_BEGIN("camera3->register_stream_buffers");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800474 res = hal3Device->ops->register_stream_buffers(hal3Device,
475 &bufferSet);
Eino-Ville Talvala17a61ad2013-06-03 16:53:32 -0700476 ATRACE_END();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800477 }
478
479 // Return all valid buffers to stream, in ERROR state to indicate
480 // they weren't filled.
481 for (size_t i = 0; i < bufferIdx; i++) {
482 streamBuffers.editItemAt(i).release_fence = -1;
483 streamBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR;
484 returnBufferLocked(streamBuffers[i], 0);
485 }
486
487 return res;
488}
489
Igor Murashkin5a269fa2013-04-15 14:59:22 -0700490status_t Camera3Stream::getBufferLocked(camera3_stream_buffer *) {
491 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
492 return INVALID_OPERATION;
493}
494status_t Camera3Stream::returnBufferLocked(const camera3_stream_buffer &,
495 nsecs_t) {
496 ALOGE("%s: This type of stream does not support output", __FUNCTION__);
497 return INVALID_OPERATION;
498}
499status_t Camera3Stream::getInputBufferLocked(camera3_stream_buffer *) {
500 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
501 return INVALID_OPERATION;
502}
503status_t Camera3Stream::returnInputBufferLocked(
504 const camera3_stream_buffer &) {
505 ALOGE("%s: This type of stream does not support input", __FUNCTION__);
506 return INVALID_OPERATION;
507}
508
Igor Murashkin2fba5842013-04-22 14:03:54 -0700509void Camera3Stream::addBufferListener(
510 wp<Camera3StreamBufferListener> listener) {
511 Mutex::Autolock l(mLock);
Zhijun Hef0d962a2014-06-30 10:24:11 -0700512
513 List<wp<Camera3StreamBufferListener> >::iterator it, end;
514 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
515 it != end;
516 ) {
517 if (*it == listener) {
518 ALOGE("%s: Try to add the same listener twice, ignoring...", __FUNCTION__);
519 return;
520 }
521 it++;
522 }
523
Igor Murashkin2fba5842013-04-22 14:03:54 -0700524 mBufferListenerList.push_back(listener);
525}
526
527void Camera3Stream::removeBufferListener(
528 const sp<Camera3StreamBufferListener>& listener) {
529 Mutex::Autolock l(mLock);
530
531 bool erased = true;
532 List<wp<Camera3StreamBufferListener> >::iterator it, end;
533 for (it = mBufferListenerList.begin(), end = mBufferListenerList.end();
534 it != end;
535 ) {
536
537 if (*it == listener) {
538 it = mBufferListenerList.erase(it);
539 erased = true;
540 } else {
541 ++it;
542 }
543 }
544
545 if (!erased) {
546 ALOGW("%s: Could not find listener to remove, already removed",
547 __FUNCTION__);
548 }
549}
550
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800551}; // namespace camera3
552
553}; // namespace android