blob: b02cd6a980757adae0814b0e8f7e0f00ab0664d2 [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-OutputStream"
18#define ATRACE_TAG ATRACE_TAG_CAMERA
19//#define LOG_NDEBUG 0
20
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080021#include <utils/Log.h>
22#include <utils/Trace.h>
23#include "Camera3OutputStream.h"
24
25#ifndef container_of
26#define container_of(ptr, type, member) \
27 (type *)((char*)(ptr) - offsetof(type, member))
28#endif
29
30namespace android {
31
32namespace camera3 {
33
34Camera3OutputStream::Camera3OutputStream(int id,
Eino-Ville Talvala727d1722015-06-09 13:44:19 -070035 sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080036 uint32_t width, uint32_t height, int format,
Shuzhen Wangc28dccc2016-02-11 23:48:46 -080037 android_dataspace dataSpace, camera3_stream_rotation_t rotation,
38 nsecs_t timestampOffset, int setId) :
Igor Murashkine3a9f962013-05-08 18:03:15 -070039 Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height,
Zhijun He125684a2015-12-26 15:07:30 -080040 /*maxSize*/0, format, dataSpace, rotation, setId),
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080041 mConsumer(consumer),
Ruchit Sharmae0711f22014-08-18 13:48:24 -040042 mTransform(0),
Zhijun He125684a2015-12-26 15:07:30 -080043 mTraceFirstBuffer(true),
Shuzhen Wangc28dccc2016-02-11 23:48:46 -080044 mUseBufferManager(false),
Zhijun He5d677d12016-05-29 16:52:39 -070045 mTimestampOffset(timestampOffset),
Shuzhen Wang686f6442017-06-20 16:16:04 -070046 mConsumerUsage(0),
47 mDequeueBufferLatency(kDequeueLatencyBinSize) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080048
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080049 if (mConsumer == NULL) {
50 ALOGE("%s: Consumer is NULL!", __FUNCTION__);
51 mState = STATE_ERROR;
52 }
Zhijun He125684a2015-12-26 15:07:30 -080053
54 if (setId > CAMERA3_STREAM_SET_ID_INVALID) {
55 mBufferReleasedListener = new BufferReleasedListener(this);
56 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080057}
58
59Camera3OutputStream::Camera3OutputStream(int id,
Eino-Ville Talvala727d1722015-06-09 13:44:19 -070060 sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -080061 uint32_t width, uint32_t height, size_t maxSize, int format,
Shuzhen Wangc28dccc2016-02-11 23:48:46 -080062 android_dataspace dataSpace, camera3_stream_rotation_t rotation,
63 nsecs_t timestampOffset, int setId) :
Igor Murashkine3a9f962013-05-08 18:03:15 -070064 Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, maxSize,
Zhijun He125684a2015-12-26 15:07:30 -080065 format, dataSpace, rotation, setId),
Igor Murashkina55b5452013-04-02 16:36:33 -070066 mConsumer(consumer),
Ruchit Sharmae0711f22014-08-18 13:48:24 -040067 mTransform(0),
Zhijun He125684a2015-12-26 15:07:30 -080068 mTraceFirstBuffer(true),
Shuzhen Wangc28dccc2016-02-11 23:48:46 -080069 mUseMonoTimestamp(false),
70 mUseBufferManager(false),
Zhijun He5d677d12016-05-29 16:52:39 -070071 mTimestampOffset(timestampOffset),
Shuzhen Wang686f6442017-06-20 16:16:04 -070072 mConsumerUsage(0),
73 mDequeueBufferLatency(kDequeueLatencyBinSize) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080074
Yin-Chia Yehe9154ce2015-12-07 14:38:04 -080075 if (format != HAL_PIXEL_FORMAT_BLOB && format != HAL_PIXEL_FORMAT_RAW_OPAQUE) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080076 ALOGE("%s: Bad format for size-only stream: %d", __FUNCTION__,
77 format);
78 mState = STATE_ERROR;
79 }
80
81 if (mConsumer == NULL) {
82 ALOGE("%s: Consumer is NULL!", __FUNCTION__);
83 mState = STATE_ERROR;
84 }
Zhijun He125684a2015-12-26 15:07:30 -080085
86 if (setId > CAMERA3_STREAM_SET_ID_INVALID) {
87 mBufferReleasedListener = new BufferReleasedListener(this);
88 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -080089}
90
Zhijun He5d677d12016-05-29 16:52:39 -070091Camera3OutputStream::Camera3OutputStream(int id,
92 uint32_t width, uint32_t height, int format,
93 uint32_t consumerUsage, android_dataspace dataSpace,
94 camera3_stream_rotation_t rotation, nsecs_t timestampOffset, int setId) :
95 Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height,
96 /*maxSize*/0, format, dataSpace, rotation, setId),
97 mConsumer(nullptr),
98 mTransform(0),
99 mTraceFirstBuffer(true),
100 mUseBufferManager(false),
101 mTimestampOffset(timestampOffset),
Shuzhen Wang686f6442017-06-20 16:16:04 -0700102 mConsumerUsage(consumerUsage),
103 mDequeueBufferLatency(kDequeueLatencyBinSize) {
Zhijun He5d677d12016-05-29 16:52:39 -0700104 // Deferred consumer only support preview surface format now.
105 if (format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
106 ALOGE("%s: Deferred consumer only supports IMPLEMENTATION_DEFINED format now!",
107 __FUNCTION__);
108 mState = STATE_ERROR;
109 }
110
111 // Sanity check for the consumer usage flag.
112 if ((consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) == 0 &&
113 (consumerUsage & GraphicBuffer::USAGE_HW_COMPOSER) == 0) {
114 ALOGE("%s: Deferred consumer usage flag is illegal (0x%x)!", __FUNCTION__, consumerUsage);
115 mState = STATE_ERROR;
116 }
117
118 mConsumerName = String8("Deferred");
119 if (setId > CAMERA3_STREAM_SET_ID_INVALID) {
120 mBufferReleasedListener = new BufferReleasedListener(this);
121 }
122
123}
124
Igor Murashkine3a9f962013-05-08 18:03:15 -0700125Camera3OutputStream::Camera3OutputStream(int id, camera3_stream_type_t type,
126 uint32_t width, uint32_t height,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800127 int format,
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700128 android_dataspace dataSpace,
Zhijun He125684a2015-12-26 15:07:30 -0800129 camera3_stream_rotation_t rotation,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700130 uint32_t consumerUsage, nsecs_t timestampOffset,
Zhijun He125684a2015-12-26 15:07:30 -0800131 int setId) :
Igor Murashkine3a9f962013-05-08 18:03:15 -0700132 Camera3IOStreamBase(id, type, width, height,
133 /*maxSize*/0,
Zhijun He125684a2015-12-26 15:07:30 -0800134 format, dataSpace, rotation, setId),
135 mTransform(0),
136 mTraceFirstBuffer(true),
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800137 mUseMonoTimestamp(false),
Zhijun He5d677d12016-05-29 16:52:39 -0700138 mUseBufferManager(false),
Shuzhen Wang0129d522016-10-30 22:43:41 -0700139 mTimestampOffset(timestampOffset),
Shuzhen Wang686f6442017-06-20 16:16:04 -0700140 mConsumerUsage(consumerUsage),
141 mDequeueBufferLatency(kDequeueLatencyBinSize) {
Zhijun He125684a2015-12-26 15:07:30 -0800142
143 if (setId > CAMERA3_STREAM_SET_ID_INVALID) {
144 mBufferReleasedListener = new BufferReleasedListener(this);
145 }
Igor Murashkine3a9f962013-05-08 18:03:15 -0700146
147 // Subclasses expected to initialize mConsumer themselves
148}
149
150
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800151Camera3OutputStream::~Camera3OutputStream() {
152 disconnectLocked();
153}
154
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800155status_t Camera3OutputStream::getBufferLocked(camera3_stream_buffer *buffer,
156 const std::vector<size_t>&) {
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800157 ATRACE_CALL();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800158
159 ANativeWindowBuffer* anb;
Zhijun He125684a2015-12-26 15:07:30 -0800160 int fenceFd = -1;
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700161
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800162 status_t res;
163 res = getBufferLockedCommon(&anb, &fenceFd);
164 if (res != OK) {
165 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800166 }
167
Igor Murashkine3a9f962013-05-08 18:03:15 -0700168 /**
169 * FenceFD now owned by HAL except in case of error,
170 * in which case we reassign it to acquire_fence
171 */
172 handoutBufferLocked(*buffer, &(anb->handle), /*acquireFence*/fenceFd,
Zhijun He6adc9cc2014-04-15 14:09:55 -0700173 /*releaseFence*/-1, CAMERA3_BUFFER_STATUS_OK, /*output*/true);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800174
175 return OK;
176}
177
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800178status_t Camera3OutputStream::queueBufferToConsumer(sp<ANativeWindow>& consumer,
179 ANativeWindowBuffer* buffer, int anwReleaseFence) {
180 return consumer->queueBuffer(consumer.get(), buffer, anwReleaseFence);
181}
182
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800183status_t Camera3OutputStream::returnBufferLocked(
184 const camera3_stream_buffer &buffer,
185 nsecs_t timestamp) {
186 ATRACE_CALL();
Igor Murashkine3a9f962013-05-08 18:03:15 -0700187
188 status_t res = returnAnyBufferLocked(buffer, timestamp, /*output*/true);
189
190 if (res != OK) {
191 return res;
192 }
193
194 mLastTimestamp = timestamp;
Eino-Ville Talvalac31dc7e2017-01-31 17:35:41 -0800195 mFrameCount++;
Igor Murashkine3a9f962013-05-08 18:03:15 -0700196
197 return OK;
198}
199
200status_t Camera3OutputStream::returnBufferCheckedLocked(
201 const camera3_stream_buffer &buffer,
202 nsecs_t timestamp,
203 bool output,
204 /*out*/
205 sp<Fence> *releaseFenceOut) {
206
207 (void)output;
208 ALOG_ASSERT(output, "Expected output to be true");
209
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800210 status_t res;
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700211
Yin-Chia Yeh4c9736f2015-03-05 15:01:36 -0800212 // Fence management - always honor release fence from HAL
213 sp<Fence> releaseFence = new Fence(buffer.release_fence);
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700214 int anwReleaseFence = releaseFence->dup();
215
216 /**
Zhijun He124ccf42013-05-22 14:01:30 -0700217 * Release the lock briefly to avoid deadlock with
218 * StreamingProcessor::startStream -> Camera3Stream::isConfiguring (this
219 * thread will go into StreamingProcessor::onFrameAvailable) during
220 * queueBuffer
221 */
222 sp<ANativeWindow> currentConsumer = mConsumer;
223 mLock.unlock();
224
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800225 ANativeWindowBuffer *anwBuffer = container_of(buffer.buffer, ANativeWindowBuffer, handle);
Zhijun He124ccf42013-05-22 14:01:30 -0700226 /**
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700227 * Return buffer back to ANativeWindow
228 */
229 if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR) {
230 // Cancel buffer
Zhijun He7b171a92016-06-24 16:05:52 -0700231 ALOGW("A frame is dropped for stream %d", mId);
Zhijun He124ccf42013-05-22 14:01:30 -0700232 res = currentConsumer->cancelBuffer(currentConsumer.get(),
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800233 anwBuffer,
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700234 anwReleaseFence);
235 if (res != OK) {
236 ALOGE("%s: Stream %d: Error cancelling buffer to native window:"
Igor Murashkine3a9f962013-05-08 18:03:15 -0700237 " %s (%d)", __FUNCTION__, mId, strerror(-res), res);
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700238 }
Zhijun He1ff811b2016-01-26 14:39:51 -0800239
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800240 notifyBufferReleased(anwBuffer);
Zhijun He1ff811b2016-01-26 14:39:51 -0800241 if (mUseBufferManager) {
242 // Return this buffer back to buffer manager.
243 mBufferReleasedListener->onBufferReleased();
244 }
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700245 } else {
Ruchit Sharmae0711f22014-08-18 13:48:24 -0400246 if (mTraceFirstBuffer && (stream_type == CAMERA3_STREAM_OUTPUT)) {
247 {
248 char traceLog[48];
249 snprintf(traceLog, sizeof(traceLog), "Stream %d: first full buffer\n", mId);
250 ATRACE_NAME(traceLog);
251 }
252 mTraceFirstBuffer = false;
253 }
254
Shuzhen Wang13a69632016-01-26 09:51:07 -0800255 /* Certain consumers (such as AudioSource or HardwareComposer) use
256 * MONOTONIC time, causing time misalignment if camera timestamp is
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800257 * in BOOTTIME. Do the conversion if necessary. */
258 res = native_window_set_buffers_timestamp(mConsumer.get(),
259 mUseMonoTimestamp ? timestamp - mTimestampOffset : timestamp);
260 if (res != OK) {
261 ALOGE("%s: Stream %d: Error setting timestamp: %s (%d)",
262 __FUNCTION__, mId, strerror(-res), res);
263 return res;
Yin-Chia Yeh4c9736f2015-03-05 15:01:36 -0800264 }
265
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800266 res = queueBufferToConsumer(currentConsumer, anwBuffer, anwReleaseFence);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800267 if (res != OK) {
Igor Murashkine3a9f962013-05-08 18:03:15 -0700268 ALOGE("%s: Stream %d: Error queueing buffer to native window: "
269 "%s (%d)", __FUNCTION__, mId, strerror(-res), res);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800270 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800271 }
Zhijun He124ccf42013-05-22 14:01:30 -0700272 mLock.lock();
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700273
274 // Once a valid buffer has been returned to the queue, can no longer
275 // dequeue all buffers for preallocation.
276 if (buffer.status != CAMERA3_BUFFER_STATUS_ERROR) {
277 mStreamUnpreparable = true;
278 }
279
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700280 if (res != OK) {
281 close(anwReleaseFence);
Igor Murashkin5a1798a2013-05-07 10:58:13 -0700282 }
283
Igor Murashkine3a9f962013-05-08 18:03:15 -0700284 *releaseFenceOut = releaseFence;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800285
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700286 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800287}
288
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800289void Camera3OutputStream::dump(int fd, const Vector<String16> &args) const {
290 (void) args;
291 String8 lines;
292 lines.appendFormat(" Stream[%d]: Output\n", mId);
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700293 lines.appendFormat(" Consumer name: %s\n", mConsumerName.string());
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800294 write(fd, lines.string(), lines.size());
Igor Murashkine3a9f962013-05-08 18:03:15 -0700295
296 Camera3IOStreamBase::dump(fd, args);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700297
298 mDequeueBufferLatency.dump(fd,
299 " DequeueBuffer latency histogram:");
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800300}
301
302status_t Camera3OutputStream::setTransform(int transform) {
303 ATRACE_CALL();
304 Mutex::Autolock l(mLock);
305 return setTransformLocked(transform);
306}
307
308status_t Camera3OutputStream::setTransformLocked(int transform) {
309 status_t res = OK;
310 if (mState == STATE_ERROR) {
311 ALOGE("%s: Stream in error state", __FUNCTION__);
312 return INVALID_OPERATION;
313 }
314
315 mTransform = transform;
316 if (mState == STATE_CONFIGURED) {
317 res = native_window_set_buffers_transform(mConsumer.get(),
318 transform);
319 if (res != OK) {
320 ALOGE("%s: Unable to configure stream transform to %x: %s (%d)",
321 __FUNCTION__, transform, strerror(-res), res);
322 }
323 }
324 return res;
325}
326
327status_t Camera3OutputStream::configureQueueLocked() {
328 status_t res;
329
Ruchit Sharmae0711f22014-08-18 13:48:24 -0400330 mTraceFirstBuffer = true;
Igor Murashkine3a9f962013-05-08 18:03:15 -0700331 if ((res = Camera3IOStreamBase::configureQueueLocked()) != OK) {
332 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800333 }
334
Shuzhen Wang0129d522016-10-30 22:43:41 -0700335 if ((res = configureConsumerQueueLocked()) != OK) {
336 return res;
337 }
338
339 // Set dequeueBuffer/attachBuffer timeout if the consumer is not hw composer or hw texture.
340 // We need skip these cases as timeout will disable the non-blocking (async) mode.
341 if (!(isConsumedByHWComposer() || isConsumedByHWTexture())) {
342 mConsumer->setDequeueTimeout(kDequeueBufferTimeout);
343 }
344
345 return OK;
346}
347
348status_t Camera3OutputStream::configureConsumerQueueLocked() {
349 status_t res;
350
351 mTraceFirstBuffer = true;
352
Igor Murashkine3a9f962013-05-08 18:03:15 -0700353 ALOG_ASSERT(mConsumer != 0, "mConsumer should never be NULL");
354
Zhijun He125684a2015-12-26 15:07:30 -0800355 // Configure consumer-side ANativeWindow interface. The listener may be used
356 // to notify buffer manager (if it is used) of the returned buffers.
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700357 res = mConsumer->connect(NATIVE_WINDOW_API_CAMERA,
358 /*listener*/mBufferReleasedListener,
359 /*reportBufferRemoval*/true);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800360 if (res != OK) {
361 ALOGE("%s: Unable to connect to native window for stream %d",
362 __FUNCTION__, mId);
363 return res;
364 }
365
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700366 mConsumerName = mConsumer->getConsumerName();
367
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800368 res = native_window_set_usage(mConsumer.get(), camera3_stream::usage);
369 if (res != OK) {
370 ALOGE("%s: Unable to configure usage %08x for stream %d",
371 __FUNCTION__, camera3_stream::usage, mId);
372 return res;
373 }
374
375 res = native_window_set_scaling_mode(mConsumer.get(),
376 NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW);
377 if (res != OK) {
378 ALOGE("%s: Unable to configure stream scaling: %s (%d)",
379 __FUNCTION__, strerror(-res), res);
380 return res;
381 }
382
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800383 if (mMaxSize == 0) {
384 // For buffers of known size
Eino-Ville Talvala7d70c5e2014-07-24 18:10:23 -0700385 res = native_window_set_buffers_dimensions(mConsumer.get(),
386 camera3_stream::width, camera3_stream::height);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800387 } else {
388 // For buffers with bounded size
Eino-Ville Talvala7d70c5e2014-07-24 18:10:23 -0700389 res = native_window_set_buffers_dimensions(mConsumer.get(),
390 mMaxSize, 1);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800391 }
392 if (res != OK) {
Eino-Ville Talvala7d70c5e2014-07-24 18:10:23 -0700393 ALOGE("%s: Unable to configure stream buffer dimensions"
394 " %d x %d (maxSize %zu) for stream %d",
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800395 __FUNCTION__, camera3_stream::width, camera3_stream::height,
Eino-Ville Talvala7d70c5e2014-07-24 18:10:23 -0700396 mMaxSize, mId);
397 return res;
398 }
399 res = native_window_set_buffers_format(mConsumer.get(),
400 camera3_stream::format);
401 if (res != OK) {
402 ALOGE("%s: Unable to configure stream buffer format %#x for stream %d",
403 __FUNCTION__, camera3_stream::format, mId);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800404 return res;
405 }
406
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800407 res = native_window_set_buffers_data_space(mConsumer.get(),
408 camera3_stream::data_space);
409 if (res != OK) {
410 ALOGE("%s: Unable to configure stream dataspace %#x for stream %d",
411 __FUNCTION__, camera3_stream::data_space, mId);
412 return res;
413 }
414
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800415 int maxConsumerBuffers;
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700416 res = static_cast<ANativeWindow*>(mConsumer.get())->query(
417 mConsumer.get(),
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800418 NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers);
419 if (res != OK) {
420 ALOGE("%s: Unable to query consumer undequeued"
421 " buffer count for stream %d", __FUNCTION__, mId);
422 return res;
423 }
424
Alex Ray20cb3002013-05-28 20:18:22 -0700425 ALOGV("%s: Consumer wants %d buffers, HAL wants %d", __FUNCTION__,
426 maxConsumerBuffers, camera3_stream::max_buffers);
427 if (camera3_stream::max_buffers == 0) {
Zhijun He2ab500c2013-07-23 08:02:53 -0700428 ALOGE("%s: Camera HAL requested max_buffer count: %d, requires at least 1",
Alex Ray20cb3002013-05-28 20:18:22 -0700429 __FUNCTION__, camera3_stream::max_buffers);
430 return INVALID_OPERATION;
431 }
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800432
433 mTotalBufferCount = maxConsumerBuffers + camera3_stream::max_buffers;
Zhijun He6adc9cc2014-04-15 14:09:55 -0700434 mHandoutTotalBufferCount = 0;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800435 mFrameCount = 0;
436 mLastTimestamp = 0;
Shuzhen Wangc28dccc2016-02-11 23:48:46 -0800437 mUseMonoTimestamp = (isConsumedByHWComposer() | isVideoStream());
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800438
439 res = native_window_set_buffer_count(mConsumer.get(),
440 mTotalBufferCount);
441 if (res != OK) {
442 ALOGE("%s: Unable to set buffer count for stream %d",
443 __FUNCTION__, mId);
444 return res;
445 }
446
447 res = native_window_set_buffers_transform(mConsumer.get(),
448 mTransform);
449 if (res != OK) {
450 ALOGE("%s: Unable to configure stream transform to %x: %s (%d)",
451 __FUNCTION__, mTransform, strerror(-res), res);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700452 return res;
Zhijun Hef0645c12016-08-02 00:58:11 -0700453 }
454
Zhijun He125684a2015-12-26 15:07:30 -0800455 /**
Zhijun Heedd41ae2016-02-03 14:45:53 -0800456 * Camera3 Buffer manager is only supported by HAL3.3 onwards, as the older HALs requires
Zhijun He125684a2015-12-26 15:07:30 -0800457 * buffers to be statically allocated for internal static buffer registration, while the
458 * buffers provided by buffer manager are really dynamically allocated. Camera3Device only
Zhijun Heedd41ae2016-02-03 14:45:53 -0800459 * sets the mBufferManager if device version is > HAL3.2, which guarantees that the buffer
460 * manager setup is skipped in below code. Note that HAL3.2 is also excluded here, as some
461 * HAL3.2 devices may not support the dynamic buffer registeration.
Zhijun He125684a2015-12-26 15:07:30 -0800462 */
463 if (mBufferManager != 0 && mSetId > CAMERA3_STREAM_SET_ID_INVALID) {
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700464 uint32_t consumerUsage = 0;
465 getEndpointUsage(&consumerUsage);
Zhijun He125684a2015-12-26 15:07:30 -0800466 StreamInfo streamInfo(
467 getId(), getStreamSetId(), getWidth(), getHeight(), getFormat(), getDataSpace(),
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700468 camera3_stream::usage | consumerUsage, mTotalBufferCount,
469 /*isConfigured*/true);
470 wp<Camera3OutputStream> weakThis(this);
471 res = mBufferManager->registerStream(weakThis,
472 streamInfo);
Zhijun He125684a2015-12-26 15:07:30 -0800473 if (res == OK) {
474 // Disable buffer allocation for this BufferQueue, buffer manager will take over
475 // the buffer allocation responsibility.
476 mConsumer->getIGraphicBufferProducer()->allowAllocation(false);
477 mUseBufferManager = true;
478 } else {
479 ALOGE("%s: Unable to register stream %d to camera3 buffer manager, "
480 "(error %d %s), fall back to BufferQueue for buffer management!",
481 __FUNCTION__, mId, res, strerror(-res));
482 }
483 }
484
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800485 return OK;
486}
487
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800488status_t Camera3OutputStream::getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd) {
489 ATRACE_CALL();
490 status_t res;
491
492 if ((res = getBufferPreconditionCheckLocked()) != OK) {
493 return res;
494 }
495
496 bool gotBufferFromManager = false;
497
498 if (mUseBufferManager) {
499 sp<GraphicBuffer> gb;
500 res = mBufferManager->getBufferForStream(getId(), getStreamSetId(), &gb, fenceFd);
501 if (res == OK) {
502 // Attach this buffer to the bufferQueue: the buffer will be in dequeue state after a
503 // successful return.
504 *anb = gb.get();
505 res = mConsumer->attachBuffer(*anb);
506 if (res != OK) {
507 ALOGE("%s: Stream %d: Can't attach the output buffer to this surface: %s (%d)",
508 __FUNCTION__, mId, strerror(-res), res);
509 return res;
510 }
511 gotBufferFromManager = true;
512 ALOGV("Stream %d: Attached new buffer", getId());
513 } else if (res == ALREADY_EXISTS) {
514 // Have sufficient free buffers already attached, can just
515 // dequeue from buffer queue
516 ALOGV("Stream %d: Reusing attached buffer", getId());
517 gotBufferFromManager = false;
518 } else if (res != OK) {
519 ALOGE("%s: Stream %d: Can't get next output buffer from buffer manager: %s (%d)",
520 __FUNCTION__, mId, strerror(-res), res);
521 return res;
522 }
523 }
524 if (!gotBufferFromManager) {
525 /**
526 * Release the lock briefly to avoid deadlock for below scenario:
527 * Thread 1: StreamingProcessor::startStream -> Camera3Stream::isConfiguring().
528 * This thread acquired StreamingProcessor lock and try to lock Camera3Stream lock.
529 * Thread 2: Camera3Stream::returnBuffer->StreamingProcessor::onFrameAvailable().
530 * This thread acquired Camera3Stream lock and bufferQueue lock, and try to lock
531 * StreamingProcessor lock.
532 * Thread 3: Camera3Stream::getBuffer(). This thread acquired Camera3Stream lock
533 * and try to lock bufferQueue lock.
534 * Then there is circular locking dependency.
535 */
536 sp<ANativeWindow> currentConsumer = mConsumer;
537 mLock.unlock();
538
Shuzhen Wang686f6442017-06-20 16:16:04 -0700539 nsecs_t dequeueStart = systemTime(SYSTEM_TIME_MONOTONIC);
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800540 res = currentConsumer->dequeueBuffer(currentConsumer.get(), anb, fenceFd);
Shuzhen Wang686f6442017-06-20 16:16:04 -0700541 nsecs_t dequeueEnd = systemTime(SYSTEM_TIME_MONOTONIC);
542 mDequeueBufferLatency.add(dequeueStart, dequeueEnd);
543
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800544 mLock.lock();
545 if (res != OK) {
546 ALOGE("%s: Stream %d: Can't dequeue next output buffer: %s (%d)",
547 __FUNCTION__, mId, strerror(-res), res);
548
549 // Only transition to STATE_ABANDONED from STATE_CONFIGURED. (If it is STATE_PREPARING,
550 // let prepareNextBuffer handle the error.)
551 if (res == NO_INIT && mState == STATE_CONFIGURED) {
552 mState = STATE_ABANDONED;
553 }
554
555 return res;
556 }
557 }
558
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700559 if (res == OK) {
560 std::vector<sp<GraphicBuffer>> removedBuffers;
561 res = mConsumer->getAndFlushRemovedBuffers(&removedBuffers);
562 if (res == OK) {
563 onBuffersRemovedLocked(removedBuffers);
Shuzhen Wangfd76cf52017-05-15 10:01:04 -0700564
565 if (mUseBufferManager && removedBuffers.size() > 0) {
566 mBufferManager->onBuffersRemoved(getId(), getStreamSetId(), removedBuffers.size());
567 }
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700568 }
569 }
570
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800571 return res;
572}
573
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800574status_t Camera3OutputStream::disconnectLocked() {
575 status_t res;
576
Igor Murashkine3a9f962013-05-08 18:03:15 -0700577 if ((res = Camera3IOStreamBase::disconnectLocked()) != OK) {
578 return res;
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800579 }
580
Zhijun He5d677d12016-05-29 16:52:39 -0700581 // Stream configuration was not finished (can only be in STATE_IN_CONFIG or STATE_CONSTRUCTED
582 // state), don't need change the stream state, return OK.
583 if (mConsumer == nullptr) {
584 return OK;
585 }
586
Zhijun He125684a2015-12-26 15:07:30 -0800587 ALOGV("%s: disconnecting stream %d from native window", __FUNCTION__, getId());
588
Igor Murashkine3a9f962013-05-08 18:03:15 -0700589 res = native_window_api_disconnect(mConsumer.get(),
590 NATIVE_WINDOW_API_CAMERA);
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800591 /**
592 * This is not an error. if client calling process dies, the window will
593 * also die and all calls to it will return DEAD_OBJECT, thus it's already
594 * "disconnected"
595 */
596 if (res == DEAD_OBJECT) {
597 ALOGW("%s: While disconnecting stream %d from native window, the"
598 " native window died from under us", __FUNCTION__, mId);
599 }
600 else if (res != OK) {
Igor Murashkine3a9f962013-05-08 18:03:15 -0700601 ALOGE("%s: Unable to disconnect stream %d from native window "
602 "(error %d %s)",
603 __FUNCTION__, mId, res, strerror(-res));
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800604 mState = STATE_ERROR;
605 return res;
606 }
607
Zhijun He125684a2015-12-26 15:07:30 -0800608 // Since device is already idle, there is no getBuffer call to buffer manager, unregister the
609 // stream at this point should be safe.
610 if (mUseBufferManager) {
611 res = mBufferManager->unregisterStream(getId(), getStreamSetId());
612 if (res != OK) {
613 ALOGE("%s: Unable to unregister stream %d from buffer manager "
614 "(error %d %s)", __FUNCTION__, mId, res, strerror(-res));
615 mState = STATE_ERROR;
616 return res;
617 }
618 // Note that, to make prepare/teardown case work, we must not mBufferManager.clear(), as
619 // the stream is still in usable state after this call.
620 mUseBufferManager = false;
621 }
622
Igor Murashkine3a9f962013-05-08 18:03:15 -0700623 mState = (mState == STATE_IN_RECONFIG) ? STATE_IN_CONFIG
624 : STATE_CONSTRUCTED;
Shuzhen Wang686f6442017-06-20 16:16:04 -0700625
626 mDequeueBufferLatency.log("Stream %d dequeueBuffer latency histogram", mId);
627 mDequeueBufferLatency.reset();
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800628 return OK;
629}
630
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700631status_t Camera3OutputStream::getEndpointUsage(uint32_t *usage) const {
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700632
633 status_t res;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700634
Zhijun He5d677d12016-05-29 16:52:39 -0700635 if (mConsumer == nullptr) {
636 // mConsumerUsage was sanitized before the Camera3OutputStream was constructed.
637 *usage = mConsumerUsage;
638 return OK;
639 }
640
Shuzhen Wang0129d522016-10-30 22:43:41 -0700641 res = getEndpointUsageForSurface(usage, mConsumer);
642
643 return res;
644}
645
646status_t Camera3OutputStream::getEndpointUsageForSurface(uint32_t *usage,
647 const sp<Surface>& surface) const {
648 status_t res;
649 int32_t u = 0;
650
651 res = static_cast<ANativeWindow*>(surface.get())->query(surface.get(),
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700652 NATIVE_WINDOW_CONSUMER_USAGE_BITS, &u);
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700653
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700654 // If an opaque output stream's endpoint is ImageReader, add
Yin-Chia Yeh47cf8e62017-04-04 13:00:03 -0700655 // GRALLOC_USAGE_HW_CAMERA_ZSL to the usage so HAL knows it will be used
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700656 // for the ZSL use case.
657 // Assume it's for ImageReader if the consumer usage doesn't have any of these bits set:
658 // 1. GRALLOC_USAGE_HW_TEXTURE
659 // 2. GRALLOC_USAGE_HW_RENDER
660 // 3. GRALLOC_USAGE_HW_COMPOSER
661 // 4. GRALLOC_USAGE_HW_VIDEO_ENCODER
662 if (camera3_stream::format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED &&
Shuzhen Wang0129d522016-10-30 22:43:41 -0700663 (u & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
664 GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_VIDEO_ENCODER)) == 0) {
Yin-Chia Yeh47cf8e62017-04-04 13:00:03 -0700665 u |= GRALLOC_USAGE_HW_CAMERA_ZSL;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700666 }
667
668 *usage = u;
Eino-Ville Talvalab2f5b192013-07-30 14:36:03 -0700669 return res;
670}
671
Chien-Yu Chen85a64552015-08-28 15:46:12 -0700672bool Camera3OutputStream::isVideoStream() const {
673 uint32_t usage = 0;
674 status_t res = getEndpointUsage(&usage);
675 if (res != OK) {
676 ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res);
677 return false;
678 }
679
680 return (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) != 0;
681}
682
Zhijun He125684a2015-12-26 15:07:30 -0800683status_t Camera3OutputStream::setBufferManager(sp<Camera3BufferManager> bufferManager) {
684 Mutex::Autolock l(mLock);
685 if (mState != STATE_CONSTRUCTED) {
Zhijun He5d677d12016-05-29 16:52:39 -0700686 ALOGE("%s: this method can only be called when stream in CONSTRUCTED state.",
Zhijun He125684a2015-12-26 15:07:30 -0800687 __FUNCTION__);
688 return INVALID_OPERATION;
689 }
690 mBufferManager = bufferManager;
691
692 return OK;
693}
694
695void Camera3OutputStream::BufferReleasedListener::onBufferReleased() {
696 sp<Camera3OutputStream> stream = mParent.promote();
697 if (stream == nullptr) {
698 ALOGV("%s: Parent camera3 output stream was destroyed", __FUNCTION__);
699 return;
700 }
701
702 Mutex::Autolock l(stream->mLock);
703 if (!(stream->mUseBufferManager)) {
704 return;
705 }
706
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700707 ALOGV("Stream %d: Buffer released", stream->getId());
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700708 bool shouldFreeBuffer = false;
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700709 status_t res = stream->mBufferManager->onBufferReleased(
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700710 stream->getId(), stream->getStreamSetId(), &shouldFreeBuffer);
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700711 if (res != OK) {
712 ALOGE("%s: signaling buffer release to buffer manager failed: %s (%d).", __FUNCTION__,
713 strerror(-res), res);
714 stream->mState = STATE_ERROR;
715 }
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700716
717 if (shouldFreeBuffer) {
718 sp<GraphicBuffer> buffer;
719 // Detach and free a buffer (when buffer goes out of scope)
720 stream->detachBufferLocked(&buffer, /*fenceFd*/ nullptr);
721 if (buffer.get() != nullptr) {
722 stream->mBufferManager->notifyBufferRemoved(
723 stream->getId(), stream->getStreamSetId());
724 }
725 }
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700726}
727
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700728void Camera3OutputStream::onBuffersRemovedLocked(
729 const std::vector<sp<GraphicBuffer>>& removedBuffers) {
Yin-Chia Yehdb1e8642017-07-14 15:19:30 -0700730 sp<Camera3StreamBufferFreedListener> callback = mBufferFreedListener.promote();
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700731 if (callback != nullptr) {
732 for (auto gb : removedBuffers) {
733 callback->onBufferFreed(mId, gb->handle);
734 }
735 }
736}
737
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700738status_t Camera3OutputStream::detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd) {
739 Mutex::Autolock l(mLock);
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700740 return detachBufferLocked(buffer, fenceFd);
741}
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700742
Yin-Chia Yeh89954d92017-05-21 17:28:53 -0700743status_t Camera3OutputStream::detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd) {
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700744 ALOGV("Stream %d: detachBuffer", getId());
745 if (buffer == nullptr) {
746 return BAD_VALUE;
747 }
748
Zhijun He125684a2015-12-26 15:07:30 -0800749 sp<Fence> fence;
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700750 status_t res = mConsumer->detachNextBuffer(buffer, &fence);
Zhijun He125684a2015-12-26 15:07:30 -0800751 if (res == NO_MEMORY) {
752 // This may rarely happen, which indicates that the released buffer was freed by other
753 // call (e.g., attachBuffer, dequeueBuffer etc.) before reaching here. We should notify the
754 // buffer manager that this buffer has been freed. It's not fatal, but should be avoided,
755 // therefore log a warning.
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700756 *buffer = 0;
Zhijun He125684a2015-12-26 15:07:30 -0800757 ALOGW("%s: the released buffer has already been freed by the buffer queue!", __FUNCTION__);
758 } else if (res != OK) {
Eino-Ville Talvalaff51b472016-06-28 15:26:19 -0700759 // Treat other errors as abandonment
Zhijun He125684a2015-12-26 15:07:30 -0800760 ALOGE("%s: detach next buffer failed: %s (%d).", __FUNCTION__, strerror(-res), res);
Eino-Ville Talvalaff51b472016-06-28 15:26:19 -0700761 mState = STATE_ABANDONED;
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700762 return res;
Zhijun He125684a2015-12-26 15:07:30 -0800763 }
764
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700765 if (fenceFd != nullptr) {
766 if (fence!= 0 && fence->isValid()) {
767 *fenceFd = fence->dup();
768 } else {
769 *fenceFd = -1;
770 }
Zhijun He125684a2015-12-26 15:07:30 -0800771 }
Eino-Ville Talvala77c1a352016-06-13 12:32:43 -0700772
Yin-Chia Yeh017d49c2017-03-31 19:11:00 -0700773 std::vector<sp<GraphicBuffer>> removedBuffers;
774 res = mConsumer->getAndFlushRemovedBuffers(&removedBuffers);
775 if (res == OK) {
776 onBuffersRemovedLocked(removedBuffers);
777 }
778 return res;
Zhijun He125684a2015-12-26 15:07:30 -0800779}
Shuzhen Wang13a69632016-01-26 09:51:07 -0800780
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800781status_t Camera3OutputStream::notifyBufferReleased(ANativeWindowBuffer* /*anwBuffer*/) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700782 return OK;
783}
784
785bool Camera3OutputStream::isConsumerConfigurationDeferred(size_t surface_id) const {
Zhijun He5d677d12016-05-29 16:52:39 -0700786 Mutex::Autolock l(mLock);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700787
788 if (surface_id != 0) {
Shuzhen Wang758c2152017-01-10 18:26:18 -0800789 ALOGE("%s: surface_id %zu for Camera3OutputStream should be 0!", __FUNCTION__, surface_id);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700790 }
Zhijun He5d677d12016-05-29 16:52:39 -0700791 return mConsumer == nullptr;
792}
793
Shuzhen Wang758c2152017-01-10 18:26:18 -0800794status_t Camera3OutputStream::setConsumers(const std::vector<sp<Surface>>& consumers) {
Shuzhen Wangbee0f0a2017-01-24 14:51:37 -0800795 Mutex::Autolock l(mLock);
Shuzhen Wang758c2152017-01-10 18:26:18 -0800796 if (consumers.size() != 1) {
797 ALOGE("%s: it's illegal to set %zu consumer surfaces!",
798 __FUNCTION__, consumers.size());
799 return INVALID_OPERATION;
800 }
801 if (consumers[0] == nullptr) {
802 ALOGE("%s: it's illegal to set null consumer surface!", __FUNCTION__);
Zhijun He5d677d12016-05-29 16:52:39 -0700803 return INVALID_OPERATION;
804 }
805
806 if (mConsumer != nullptr) {
807 ALOGE("%s: consumer surface was already set!", __FUNCTION__);
808 return INVALID_OPERATION;
809 }
810
Shuzhen Wang758c2152017-01-10 18:26:18 -0800811 mConsumer = consumers[0];
Zhijun He5d677d12016-05-29 16:52:39 -0700812 return OK;
813}
814
Shuzhen Wang13a69632016-01-26 09:51:07 -0800815bool Camera3OutputStream::isConsumedByHWComposer() const {
816 uint32_t usage = 0;
817 status_t res = getEndpointUsage(&usage);
818 if (res != OK) {
819 ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res);
820 return false;
821 }
822
823 return (usage & GRALLOC_USAGE_HW_COMPOSER) != 0;
824}
825
Zhijun Hef0645c12016-08-02 00:58:11 -0700826bool Camera3OutputStream::isConsumedByHWTexture() const {
827 uint32_t usage = 0;
828 status_t res = getEndpointUsage(&usage);
829 if (res != OK) {
830 ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res);
831 return false;
832 }
833
834 return (usage & GRALLOC_USAGE_HW_TEXTURE) != 0;
835}
836
Eino-Ville Talvalafd58f1a2013-03-06 16:20:06 -0800837}; // namespace camera3
838
839}; // namespace android