Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 1 | /* |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2018 The Android Open Source Project |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 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 Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 21 | #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 | |
| 30 | namespace android { |
| 31 | |
| 32 | namespace camera3 { |
| 33 | |
| 34 | Camera3OutputStream::Camera3OutputStream(int id, |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 35 | sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 36 | uint32_t width, uint32_t height, int format, |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 37 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 38 | nsecs_t timestampOffset, const String8& physicalCameraId, |
| 39 | int setId) : |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 40 | Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 41 | /*maxSize*/0, format, dataSpace, rotation, |
| 42 | physicalCameraId, setId), |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 43 | mConsumer(consumer), |
Ruchit Sharma | e0711f2 | 2014-08-18 13:48:24 -0400 | [diff] [blame] | 44 | mTransform(0), |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 45 | mTraceFirstBuffer(true), |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 46 | mUseBufferManager(false), |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 47 | mTimestampOffset(timestampOffset), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 48 | mConsumerUsage(0), |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 49 | mDropBuffers(false), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 50 | mDequeueBufferLatency(kDequeueLatencyBinSize) { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 51 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 52 | if (mConsumer == NULL) { |
| 53 | ALOGE("%s: Consumer is NULL!", __FUNCTION__); |
| 54 | mState = STATE_ERROR; |
| 55 | } |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 56 | |
| 57 | if (setId > CAMERA3_STREAM_SET_ID_INVALID) { |
| 58 | mBufferReleasedListener = new BufferReleasedListener(this); |
| 59 | } |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | Camera3OutputStream::Camera3OutputStream(int id, |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 63 | sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 64 | uint32_t width, uint32_t height, size_t maxSize, int format, |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 65 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 66 | nsecs_t timestampOffset, const String8& physicalCameraId, int setId) : |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 67 | Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, maxSize, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 68 | format, dataSpace, rotation, physicalCameraId, setId), |
Igor Murashkin | a55b545 | 2013-04-02 16:36:33 -0700 | [diff] [blame] | 69 | mConsumer(consumer), |
Ruchit Sharma | e0711f2 | 2014-08-18 13:48:24 -0400 | [diff] [blame] | 70 | mTransform(0), |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 71 | mTraceFirstBuffer(true), |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 72 | mUseMonoTimestamp(false), |
| 73 | mUseBufferManager(false), |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 74 | mTimestampOffset(timestampOffset), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 75 | mConsumerUsage(0), |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 76 | mDropBuffers(false), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 77 | mDequeueBufferLatency(kDequeueLatencyBinSize) { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 78 | |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 79 | if (format != HAL_PIXEL_FORMAT_BLOB && format != HAL_PIXEL_FORMAT_RAW_OPAQUE) { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 80 | ALOGE("%s: Bad format for size-only stream: %d", __FUNCTION__, |
| 81 | format); |
| 82 | mState = STATE_ERROR; |
| 83 | } |
| 84 | |
| 85 | if (mConsumer == NULL) { |
| 86 | ALOGE("%s: Consumer is NULL!", __FUNCTION__); |
| 87 | mState = STATE_ERROR; |
| 88 | } |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 89 | |
| 90 | if (setId > CAMERA3_STREAM_SET_ID_INVALID) { |
| 91 | mBufferReleasedListener = new BufferReleasedListener(this); |
| 92 | } |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 93 | } |
| 94 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 95 | Camera3OutputStream::Camera3OutputStream(int id, |
| 96 | uint32_t width, uint32_t height, int format, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 97 | uint64_t consumerUsage, android_dataspace dataSpace, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 98 | camera3_stream_rotation_t rotation, nsecs_t timestampOffset, |
| 99 | const String8& physicalCameraId, int setId) : |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 100 | Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 101 | /*maxSize*/0, format, dataSpace, rotation, |
| 102 | physicalCameraId, setId), |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 103 | mConsumer(nullptr), |
| 104 | mTransform(0), |
| 105 | mTraceFirstBuffer(true), |
| 106 | mUseBufferManager(false), |
| 107 | mTimestampOffset(timestampOffset), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 108 | mConsumerUsage(consumerUsage), |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 109 | mDropBuffers(false), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 110 | mDequeueBufferLatency(kDequeueLatencyBinSize) { |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 111 | // Deferred consumer only support preview surface format now. |
| 112 | if (format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) { |
| 113 | ALOGE("%s: Deferred consumer only supports IMPLEMENTATION_DEFINED format now!", |
| 114 | __FUNCTION__); |
| 115 | mState = STATE_ERROR; |
| 116 | } |
| 117 | |
| 118 | // Sanity check for the consumer usage flag. |
| 119 | if ((consumerUsage & GraphicBuffer::USAGE_HW_TEXTURE) == 0 && |
| 120 | (consumerUsage & GraphicBuffer::USAGE_HW_COMPOSER) == 0) { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 121 | ALOGE("%s: Deferred consumer usage flag is illegal %" PRIu64 "!", |
| 122 | __FUNCTION__, consumerUsage); |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 123 | mState = STATE_ERROR; |
| 124 | } |
| 125 | |
| 126 | mConsumerName = String8("Deferred"); |
| 127 | if (setId > CAMERA3_STREAM_SET_ID_INVALID) { |
| 128 | mBufferReleasedListener = new BufferReleasedListener(this); |
| 129 | } |
| 130 | |
| 131 | } |
| 132 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 133 | Camera3OutputStream::Camera3OutputStream(int id, camera3_stream_type_t type, |
| 134 | uint32_t width, uint32_t height, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 135 | int format, |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 136 | android_dataspace dataSpace, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 137 | camera3_stream_rotation_t rotation, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 138 | const String8& physicalCameraId, |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 139 | uint64_t consumerUsage, nsecs_t timestampOffset, |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 140 | int setId) : |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 141 | Camera3IOStreamBase(id, type, width, height, |
| 142 | /*maxSize*/0, |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 143 | format, dataSpace, rotation, |
| 144 | physicalCameraId, setId), |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 145 | mTransform(0), |
| 146 | mTraceFirstBuffer(true), |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 147 | mUseMonoTimestamp(false), |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 148 | mUseBufferManager(false), |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 149 | mTimestampOffset(timestampOffset), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 150 | mConsumerUsage(consumerUsage), |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 151 | mDropBuffers(false), |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 152 | mDequeueBufferLatency(kDequeueLatencyBinSize) { |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 153 | |
| 154 | if (setId > CAMERA3_STREAM_SET_ID_INVALID) { |
| 155 | mBufferReleasedListener = new BufferReleasedListener(this); |
| 156 | } |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 157 | |
| 158 | // Subclasses expected to initialize mConsumer themselves |
| 159 | } |
| 160 | |
| 161 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 162 | Camera3OutputStream::~Camera3OutputStream() { |
| 163 | disconnectLocked(); |
| 164 | } |
| 165 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 166 | status_t Camera3OutputStream::getBufferLocked(camera3_stream_buffer *buffer, |
| 167 | const std::vector<size_t>&) { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 168 | ATRACE_CALL(); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 169 | |
| 170 | ANativeWindowBuffer* anb; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 171 | int fenceFd = -1; |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 172 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 173 | status_t res; |
| 174 | res = getBufferLockedCommon(&anb, &fenceFd); |
| 175 | if (res != OK) { |
| 176 | return res; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 179 | /** |
| 180 | * FenceFD now owned by HAL except in case of error, |
| 181 | * in which case we reassign it to acquire_fence |
| 182 | */ |
| 183 | handoutBufferLocked(*buffer, &(anb->handle), /*acquireFence*/fenceFd, |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 184 | /*releaseFence*/-1, CAMERA3_BUFFER_STATUS_OK, /*output*/true); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 185 | |
| 186 | return OK; |
| 187 | } |
| 188 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 189 | status_t Camera3OutputStream::queueBufferToConsumer(sp<ANativeWindow>& consumer, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 190 | ANativeWindowBuffer* buffer, int anwReleaseFence, |
| 191 | const std::vector<size_t>&) { |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 192 | return consumer->queueBuffer(consumer.get(), buffer, anwReleaseFence); |
| 193 | } |
| 194 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 195 | status_t Camera3OutputStream::returnBufferLocked( |
| 196 | const camera3_stream_buffer &buffer, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 197 | nsecs_t timestamp, const std::vector<size_t>& surface_ids) { |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 198 | ATRACE_CALL(); |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 199 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 200 | status_t res = returnAnyBufferLocked(buffer, timestamp, /*output*/true, surface_ids); |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 201 | |
| 202 | if (res != OK) { |
| 203 | return res; |
| 204 | } |
| 205 | |
| 206 | mLastTimestamp = timestamp; |
Eino-Ville Talvala | c31dc7e | 2017-01-31 17:35:41 -0800 | [diff] [blame] | 207 | mFrameCount++; |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 208 | |
| 209 | return OK; |
| 210 | } |
| 211 | |
| 212 | status_t Camera3OutputStream::returnBufferCheckedLocked( |
| 213 | const camera3_stream_buffer &buffer, |
| 214 | nsecs_t timestamp, |
| 215 | bool output, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 216 | const std::vector<size_t>& surface_ids, |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 217 | /*out*/ |
| 218 | sp<Fence> *releaseFenceOut) { |
| 219 | |
| 220 | (void)output; |
| 221 | ALOG_ASSERT(output, "Expected output to be true"); |
| 222 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 223 | status_t res; |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 224 | |
Yin-Chia Yeh | 4c9736f | 2015-03-05 15:01:36 -0800 | [diff] [blame] | 225 | // Fence management - always honor release fence from HAL |
| 226 | sp<Fence> releaseFence = new Fence(buffer.release_fence); |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 227 | int anwReleaseFence = releaseFence->dup(); |
| 228 | |
| 229 | /** |
Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 230 | * Release the lock briefly to avoid deadlock with |
| 231 | * StreamingProcessor::startStream -> Camera3Stream::isConfiguring (this |
| 232 | * thread will go into StreamingProcessor::onFrameAvailable) during |
| 233 | * queueBuffer |
| 234 | */ |
| 235 | sp<ANativeWindow> currentConsumer = mConsumer; |
| 236 | mLock.unlock(); |
| 237 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 238 | ANativeWindowBuffer *anwBuffer = container_of(buffer.buffer, ANativeWindowBuffer, handle); |
Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 239 | /** |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 240 | * Return buffer back to ANativeWindow |
| 241 | */ |
Shuzhen Wang | f0c4a6b | 2018-09-05 09:36:14 -0700 | [diff] [blame] | 242 | if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR || mDropBuffers || timestamp == 0) { |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 243 | // Cancel buffer |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 244 | if (mDropBuffers) { |
| 245 | ALOGV("%s: Dropping a frame for stream %d.", __FUNCTION__, mId); |
Shuzhen Wang | f0c4a6b | 2018-09-05 09:36:14 -0700 | [diff] [blame] | 246 | } else if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR) { |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 247 | ALOGW("%s: A frame is dropped for stream %d due to buffer error.", __FUNCTION__, mId); |
Shuzhen Wang | f0c4a6b | 2018-09-05 09:36:14 -0700 | [diff] [blame] | 248 | } else { |
| 249 | ALOGE("%s: Stream %d: timestamp shouldn't be 0", __FUNCTION__, mId); |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 252 | res = currentConsumer->cancelBuffer(currentConsumer.get(), |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 253 | anwBuffer, |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 254 | anwReleaseFence); |
| 255 | if (res != OK) { |
| 256 | ALOGE("%s: Stream %d: Error cancelling buffer to native window:" |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 257 | " %s (%d)", __FUNCTION__, mId, strerror(-res), res); |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 258 | } |
Zhijun He | 1ff811b | 2016-01-26 14:39:51 -0800 | [diff] [blame] | 259 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 260 | notifyBufferReleased(anwBuffer); |
Zhijun He | 1ff811b | 2016-01-26 14:39:51 -0800 | [diff] [blame] | 261 | if (mUseBufferManager) { |
| 262 | // Return this buffer back to buffer manager. |
| 263 | mBufferReleasedListener->onBufferReleased(); |
| 264 | } |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 265 | } else { |
Ruchit Sharma | e0711f2 | 2014-08-18 13:48:24 -0400 | [diff] [blame] | 266 | if (mTraceFirstBuffer && (stream_type == CAMERA3_STREAM_OUTPUT)) { |
| 267 | { |
| 268 | char traceLog[48]; |
| 269 | snprintf(traceLog, sizeof(traceLog), "Stream %d: first full buffer\n", mId); |
| 270 | ATRACE_NAME(traceLog); |
| 271 | } |
| 272 | mTraceFirstBuffer = false; |
| 273 | } |
| 274 | |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 275 | /* Certain consumers (such as AudioSource or HardwareComposer) use |
| 276 | * MONOTONIC time, causing time misalignment if camera timestamp is |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 277 | * in BOOTTIME. Do the conversion if necessary. */ |
| 278 | res = native_window_set_buffers_timestamp(mConsumer.get(), |
| 279 | mUseMonoTimestamp ? timestamp - mTimestampOffset : timestamp); |
| 280 | if (res != OK) { |
| 281 | ALOGE("%s: Stream %d: Error setting timestamp: %s (%d)", |
| 282 | __FUNCTION__, mId, strerror(-res), res); |
| 283 | return res; |
Yin-Chia Yeh | 4c9736f | 2015-03-05 15:01:36 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 286 | res = queueBufferToConsumer(currentConsumer, anwBuffer, anwReleaseFence, surface_ids); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 287 | if (res != OK) { |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 288 | ALOGE("%s: Stream %d: Error queueing buffer to native window: " |
| 289 | "%s (%d)", __FUNCTION__, mId, strerror(-res), res); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 290 | } |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 291 | } |
Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 292 | mLock.lock(); |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 293 | |
| 294 | // Once a valid buffer has been returned to the queue, can no longer |
| 295 | // dequeue all buffers for preallocation. |
| 296 | if (buffer.status != CAMERA3_BUFFER_STATUS_ERROR) { |
| 297 | mStreamUnpreparable = true; |
| 298 | } |
| 299 | |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 300 | if (res != OK) { |
| 301 | close(anwReleaseFence); |
Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 304 | *releaseFenceOut = releaseFence; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 305 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 306 | return res; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 309 | void Camera3OutputStream::dump(int fd, const Vector<String16> &args) const { |
| 310 | (void) args; |
| 311 | String8 lines; |
| 312 | lines.appendFormat(" Stream[%d]: Output\n", mId); |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 313 | lines.appendFormat(" Consumer name: %s\n", mConsumerName.string()); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 314 | write(fd, lines.string(), lines.size()); |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 315 | |
| 316 | Camera3IOStreamBase::dump(fd, args); |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 317 | |
| 318 | mDequeueBufferLatency.dump(fd, |
| 319 | " DequeueBuffer latency histogram:"); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | status_t Camera3OutputStream::setTransform(int transform) { |
| 323 | ATRACE_CALL(); |
| 324 | Mutex::Autolock l(mLock); |
| 325 | return setTransformLocked(transform); |
| 326 | } |
| 327 | |
| 328 | status_t Camera3OutputStream::setTransformLocked(int transform) { |
| 329 | status_t res = OK; |
| 330 | if (mState == STATE_ERROR) { |
| 331 | ALOGE("%s: Stream in error state", __FUNCTION__); |
| 332 | return INVALID_OPERATION; |
| 333 | } |
| 334 | |
| 335 | mTransform = transform; |
| 336 | if (mState == STATE_CONFIGURED) { |
| 337 | res = native_window_set_buffers_transform(mConsumer.get(), |
| 338 | transform); |
| 339 | if (res != OK) { |
| 340 | ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", |
| 341 | __FUNCTION__, transform, strerror(-res), res); |
| 342 | } |
| 343 | } |
| 344 | return res; |
| 345 | } |
| 346 | |
| 347 | status_t Camera3OutputStream::configureQueueLocked() { |
| 348 | status_t res; |
| 349 | |
Ruchit Sharma | e0711f2 | 2014-08-18 13:48:24 -0400 | [diff] [blame] | 350 | mTraceFirstBuffer = true; |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 351 | if ((res = Camera3IOStreamBase::configureQueueLocked()) != OK) { |
| 352 | return res; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 355 | if ((res = configureConsumerQueueLocked()) != OK) { |
| 356 | return res; |
| 357 | } |
| 358 | |
| 359 | // Set dequeueBuffer/attachBuffer timeout if the consumer is not hw composer or hw texture. |
| 360 | // We need skip these cases as timeout will disable the non-blocking (async) mode. |
| 361 | if (!(isConsumedByHWComposer() || isConsumedByHWTexture())) { |
| 362 | mConsumer->setDequeueTimeout(kDequeueBufferTimeout); |
| 363 | } |
| 364 | |
| 365 | return OK; |
| 366 | } |
| 367 | |
| 368 | status_t Camera3OutputStream::configureConsumerQueueLocked() { |
| 369 | status_t res; |
| 370 | |
| 371 | mTraceFirstBuffer = true; |
| 372 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 373 | ALOG_ASSERT(mConsumer != 0, "mConsumer should never be NULL"); |
| 374 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 375 | // Configure consumer-side ANativeWindow interface. The listener may be used |
| 376 | // to notify buffer manager (if it is used) of the returned buffers. |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 377 | res = mConsumer->connect(NATIVE_WINDOW_API_CAMERA, |
| 378 | /*listener*/mBufferReleasedListener, |
| 379 | /*reportBufferRemoval*/true); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 380 | if (res != OK) { |
| 381 | ALOGE("%s: Unable to connect to native window for stream %d", |
| 382 | __FUNCTION__, mId); |
| 383 | return res; |
| 384 | } |
| 385 | |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 386 | mConsumerName = mConsumer->getConsumerName(); |
| 387 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 388 | res = native_window_set_usage(mConsumer.get(), mUsage); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 389 | if (res != OK) { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 390 | ALOGE("%s: Unable to configure usage %" PRIu64 " for stream %d", |
| 391 | __FUNCTION__, mUsage, mId); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 392 | return res; |
| 393 | } |
| 394 | |
| 395 | res = native_window_set_scaling_mode(mConsumer.get(), |
| 396 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 397 | if (res != OK) { |
| 398 | ALOGE("%s: Unable to configure stream scaling: %s (%d)", |
| 399 | __FUNCTION__, strerror(-res), res); |
| 400 | return res; |
| 401 | } |
| 402 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 403 | if (mMaxSize == 0) { |
| 404 | // For buffers of known size |
Eino-Ville Talvala | 7d70c5e | 2014-07-24 18:10:23 -0700 | [diff] [blame] | 405 | res = native_window_set_buffers_dimensions(mConsumer.get(), |
| 406 | camera3_stream::width, camera3_stream::height); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 407 | } else { |
| 408 | // For buffers with bounded size |
Eino-Ville Talvala | 7d70c5e | 2014-07-24 18:10:23 -0700 | [diff] [blame] | 409 | res = native_window_set_buffers_dimensions(mConsumer.get(), |
| 410 | mMaxSize, 1); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 411 | } |
| 412 | if (res != OK) { |
Eino-Ville Talvala | 7d70c5e | 2014-07-24 18:10:23 -0700 | [diff] [blame] | 413 | ALOGE("%s: Unable to configure stream buffer dimensions" |
| 414 | " %d x %d (maxSize %zu) for stream %d", |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 415 | __FUNCTION__, camera3_stream::width, camera3_stream::height, |
Eino-Ville Talvala | 7d70c5e | 2014-07-24 18:10:23 -0700 | [diff] [blame] | 416 | mMaxSize, mId); |
| 417 | return res; |
| 418 | } |
| 419 | res = native_window_set_buffers_format(mConsumer.get(), |
| 420 | camera3_stream::format); |
| 421 | if (res != OK) { |
| 422 | ALOGE("%s: Unable to configure stream buffer format %#x for stream %d", |
| 423 | __FUNCTION__, camera3_stream::format, mId); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 424 | return res; |
| 425 | } |
| 426 | |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 427 | res = native_window_set_buffers_data_space(mConsumer.get(), |
| 428 | camera3_stream::data_space); |
| 429 | if (res != OK) { |
| 430 | ALOGE("%s: Unable to configure stream dataspace %#x for stream %d", |
| 431 | __FUNCTION__, camera3_stream::data_space, mId); |
| 432 | return res; |
| 433 | } |
| 434 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 435 | int maxConsumerBuffers; |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 436 | res = static_cast<ANativeWindow*>(mConsumer.get())->query( |
| 437 | mConsumer.get(), |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 438 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers); |
| 439 | if (res != OK) { |
| 440 | ALOGE("%s: Unable to query consumer undequeued" |
| 441 | " buffer count for stream %d", __FUNCTION__, mId); |
| 442 | return res; |
| 443 | } |
| 444 | |
Alex Ray | 20cb300 | 2013-05-28 20:18:22 -0700 | [diff] [blame] | 445 | ALOGV("%s: Consumer wants %d buffers, HAL wants %d", __FUNCTION__, |
| 446 | maxConsumerBuffers, camera3_stream::max_buffers); |
| 447 | if (camera3_stream::max_buffers == 0) { |
Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 448 | ALOGE("%s: Camera HAL requested max_buffer count: %d, requires at least 1", |
Alex Ray | 20cb300 | 2013-05-28 20:18:22 -0700 | [diff] [blame] | 449 | __FUNCTION__, camera3_stream::max_buffers); |
| 450 | return INVALID_OPERATION; |
| 451 | } |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 452 | |
| 453 | mTotalBufferCount = maxConsumerBuffers + camera3_stream::max_buffers; |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 454 | mHandoutTotalBufferCount = 0; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 455 | mFrameCount = 0; |
| 456 | mLastTimestamp = 0; |
Shuzhen Wang | c28dccc | 2016-02-11 23:48:46 -0800 | [diff] [blame] | 457 | mUseMonoTimestamp = (isConsumedByHWComposer() | isVideoStream()); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 458 | |
| 459 | res = native_window_set_buffer_count(mConsumer.get(), |
| 460 | mTotalBufferCount); |
| 461 | if (res != OK) { |
| 462 | ALOGE("%s: Unable to set buffer count for stream %d", |
| 463 | __FUNCTION__, mId); |
| 464 | return res; |
| 465 | } |
| 466 | |
| 467 | res = native_window_set_buffers_transform(mConsumer.get(), |
| 468 | mTransform); |
| 469 | if (res != OK) { |
| 470 | ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", |
| 471 | __FUNCTION__, mTransform, strerror(-res), res); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 472 | return res; |
Zhijun He | f0645c1 | 2016-08-02 00:58:11 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 475 | /** |
Zhijun He | edd41ae | 2016-02-03 14:45:53 -0800 | [diff] [blame] | 476 | * Camera3 Buffer manager is only supported by HAL3.3 onwards, as the older HALs requires |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 477 | * buffers to be statically allocated for internal static buffer registration, while the |
| 478 | * buffers provided by buffer manager are really dynamically allocated. Camera3Device only |
Zhijun He | edd41ae | 2016-02-03 14:45:53 -0800 | [diff] [blame] | 479 | * sets the mBufferManager if device version is > HAL3.2, which guarantees that the buffer |
| 480 | * manager setup is skipped in below code. Note that HAL3.2 is also excluded here, as some |
| 481 | * HAL3.2 devices may not support the dynamic buffer registeration. |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 482 | */ |
| 483 | if (mBufferManager != 0 && mSetId > CAMERA3_STREAM_SET_ID_INVALID) { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 484 | uint64_t consumerUsage = 0; |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 485 | getEndpointUsage(&consumerUsage); |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 486 | StreamInfo streamInfo( |
| 487 | getId(), getStreamSetId(), getWidth(), getHeight(), getFormat(), getDataSpace(), |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 488 | mUsage | consumerUsage, mTotalBufferCount, |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 489 | /*isConfigured*/true); |
| 490 | wp<Camera3OutputStream> weakThis(this); |
| 491 | res = mBufferManager->registerStream(weakThis, |
| 492 | streamInfo); |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 493 | if (res == OK) { |
| 494 | // Disable buffer allocation for this BufferQueue, buffer manager will take over |
| 495 | // the buffer allocation responsibility. |
| 496 | mConsumer->getIGraphicBufferProducer()->allowAllocation(false); |
| 497 | mUseBufferManager = true; |
| 498 | } else { |
| 499 | ALOGE("%s: Unable to register stream %d to camera3 buffer manager, " |
| 500 | "(error %d %s), fall back to BufferQueue for buffer management!", |
| 501 | __FUNCTION__, mId, res, strerror(-res)); |
| 502 | } |
| 503 | } |
| 504 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 505 | return OK; |
| 506 | } |
| 507 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 508 | status_t Camera3OutputStream::getBufferLockedCommon(ANativeWindowBuffer** anb, int* fenceFd) { |
| 509 | ATRACE_CALL(); |
| 510 | status_t res; |
| 511 | |
| 512 | if ((res = getBufferPreconditionCheckLocked()) != OK) { |
| 513 | return res; |
| 514 | } |
| 515 | |
| 516 | bool gotBufferFromManager = false; |
| 517 | |
| 518 | if (mUseBufferManager) { |
| 519 | sp<GraphicBuffer> gb; |
| 520 | res = mBufferManager->getBufferForStream(getId(), getStreamSetId(), &gb, fenceFd); |
| 521 | if (res == OK) { |
| 522 | // Attach this buffer to the bufferQueue: the buffer will be in dequeue state after a |
| 523 | // successful return. |
| 524 | *anb = gb.get(); |
| 525 | res = mConsumer->attachBuffer(*anb); |
| 526 | if (res != OK) { |
| 527 | ALOGE("%s: Stream %d: Can't attach the output buffer to this surface: %s (%d)", |
| 528 | __FUNCTION__, mId, strerror(-res), res); |
| 529 | return res; |
| 530 | } |
| 531 | gotBufferFromManager = true; |
| 532 | ALOGV("Stream %d: Attached new buffer", getId()); |
| 533 | } else if (res == ALREADY_EXISTS) { |
| 534 | // Have sufficient free buffers already attached, can just |
| 535 | // dequeue from buffer queue |
| 536 | ALOGV("Stream %d: Reusing attached buffer", getId()); |
| 537 | gotBufferFromManager = false; |
| 538 | } else if (res != OK) { |
| 539 | ALOGE("%s: Stream %d: Can't get next output buffer from buffer manager: %s (%d)", |
| 540 | __FUNCTION__, mId, strerror(-res), res); |
| 541 | return res; |
| 542 | } |
| 543 | } |
| 544 | if (!gotBufferFromManager) { |
| 545 | /** |
| 546 | * Release the lock briefly to avoid deadlock for below scenario: |
| 547 | * Thread 1: StreamingProcessor::startStream -> Camera3Stream::isConfiguring(). |
| 548 | * This thread acquired StreamingProcessor lock and try to lock Camera3Stream lock. |
| 549 | * Thread 2: Camera3Stream::returnBuffer->StreamingProcessor::onFrameAvailable(). |
| 550 | * This thread acquired Camera3Stream lock and bufferQueue lock, and try to lock |
| 551 | * StreamingProcessor lock. |
| 552 | * Thread 3: Camera3Stream::getBuffer(). This thread acquired Camera3Stream lock |
| 553 | * and try to lock bufferQueue lock. |
| 554 | * Then there is circular locking dependency. |
| 555 | */ |
| 556 | sp<ANativeWindow> currentConsumer = mConsumer; |
| 557 | mLock.unlock(); |
| 558 | |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 559 | nsecs_t dequeueStart = systemTime(SYSTEM_TIME_MONOTONIC); |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 560 | res = currentConsumer->dequeueBuffer(currentConsumer.get(), anb, fenceFd); |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 561 | nsecs_t dequeueEnd = systemTime(SYSTEM_TIME_MONOTONIC); |
| 562 | mDequeueBufferLatency.add(dequeueStart, dequeueEnd); |
| 563 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 564 | mLock.lock(); |
| 565 | if (res != OK) { |
| 566 | ALOGE("%s: Stream %d: Can't dequeue next output buffer: %s (%d)", |
| 567 | __FUNCTION__, mId, strerror(-res), res); |
| 568 | |
| 569 | // Only transition to STATE_ABANDONED from STATE_CONFIGURED. (If it is STATE_PREPARING, |
| 570 | // let prepareNextBuffer handle the error.) |
Shuzhen Wang | b14fef4 | 2018-07-16 10:22:21 -0700 | [diff] [blame] | 571 | if ((res == NO_INIT || res == DEAD_OBJECT) && mState == STATE_CONFIGURED) { |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 572 | mState = STATE_ABANDONED; |
| 573 | } |
| 574 | |
| 575 | return res; |
| 576 | } |
| 577 | } |
| 578 | |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 579 | if (res == OK) { |
| 580 | std::vector<sp<GraphicBuffer>> removedBuffers; |
| 581 | res = mConsumer->getAndFlushRemovedBuffers(&removedBuffers); |
| 582 | if (res == OK) { |
| 583 | onBuffersRemovedLocked(removedBuffers); |
Shuzhen Wang | fd76cf5 | 2017-05-15 10:01:04 -0700 | [diff] [blame] | 584 | |
| 585 | if (mUseBufferManager && removedBuffers.size() > 0) { |
| 586 | mBufferManager->onBuffersRemoved(getId(), getStreamSetId(), removedBuffers.size()); |
| 587 | } |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 591 | return res; |
| 592 | } |
| 593 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 594 | status_t Camera3OutputStream::disconnectLocked() { |
| 595 | status_t res; |
| 596 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 597 | if ((res = Camera3IOStreamBase::disconnectLocked()) != OK) { |
| 598 | return res; |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 601 | // Stream configuration was not finished (can only be in STATE_IN_CONFIG or STATE_CONSTRUCTED |
| 602 | // state), don't need change the stream state, return OK. |
| 603 | if (mConsumer == nullptr) { |
| 604 | return OK; |
| 605 | } |
| 606 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 607 | ALOGV("%s: disconnecting stream %d from native window", __FUNCTION__, getId()); |
| 608 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 609 | res = native_window_api_disconnect(mConsumer.get(), |
| 610 | NATIVE_WINDOW_API_CAMERA); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 611 | /** |
| 612 | * This is not an error. if client calling process dies, the window will |
| 613 | * also die and all calls to it will return DEAD_OBJECT, thus it's already |
| 614 | * "disconnected" |
| 615 | */ |
| 616 | if (res == DEAD_OBJECT) { |
| 617 | ALOGW("%s: While disconnecting stream %d from native window, the" |
| 618 | " native window died from under us", __FUNCTION__, mId); |
| 619 | } |
| 620 | else if (res != OK) { |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 621 | ALOGE("%s: Unable to disconnect stream %d from native window " |
| 622 | "(error %d %s)", |
| 623 | __FUNCTION__, mId, res, strerror(-res)); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 624 | mState = STATE_ERROR; |
| 625 | return res; |
| 626 | } |
| 627 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 628 | // Since device is already idle, there is no getBuffer call to buffer manager, unregister the |
| 629 | // stream at this point should be safe. |
| 630 | if (mUseBufferManager) { |
| 631 | res = mBufferManager->unregisterStream(getId(), getStreamSetId()); |
| 632 | if (res != OK) { |
| 633 | ALOGE("%s: Unable to unregister stream %d from buffer manager " |
| 634 | "(error %d %s)", __FUNCTION__, mId, res, strerror(-res)); |
| 635 | mState = STATE_ERROR; |
| 636 | return res; |
| 637 | } |
| 638 | // Note that, to make prepare/teardown case work, we must not mBufferManager.clear(), as |
| 639 | // the stream is still in usable state after this call. |
| 640 | mUseBufferManager = false; |
| 641 | } |
| 642 | |
Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 643 | mState = (mState == STATE_IN_RECONFIG) ? STATE_IN_CONFIG |
| 644 | : STATE_CONSTRUCTED; |
Shuzhen Wang | 686f644 | 2017-06-20 16:16:04 -0700 | [diff] [blame] | 645 | |
| 646 | mDequeueBufferLatency.log("Stream %d dequeueBuffer latency histogram", mId); |
| 647 | mDequeueBufferLatency.reset(); |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 648 | return OK; |
| 649 | } |
| 650 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 651 | status_t Camera3OutputStream::getEndpointUsage(uint64_t *usage) const { |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 652 | |
| 653 | status_t res; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 654 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 655 | if (mConsumer == nullptr) { |
| 656 | // mConsumerUsage was sanitized before the Camera3OutputStream was constructed. |
| 657 | *usage = mConsumerUsage; |
| 658 | return OK; |
| 659 | } |
| 660 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 661 | res = getEndpointUsageForSurface(usage, mConsumer); |
| 662 | |
| 663 | return res; |
| 664 | } |
| 665 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 666 | status_t Camera3OutputStream::getEndpointUsageForSurface(uint64_t *usage, |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 667 | const sp<Surface>& surface) const { |
| 668 | status_t res; |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 669 | uint64_t u = 0; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 670 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 671 | res = native_window_get_consumer_usage(static_cast<ANativeWindow*>(surface.get()), &u); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 672 | // If an opaque output stream's endpoint is ImageReader, add |
Yin-Chia Yeh | 47cf8e6 | 2017-04-04 13:00:03 -0700 | [diff] [blame] | 673 | // GRALLOC_USAGE_HW_CAMERA_ZSL to the usage so HAL knows it will be used |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 674 | // for the ZSL use case. |
| 675 | // Assume it's for ImageReader if the consumer usage doesn't have any of these bits set: |
| 676 | // 1. GRALLOC_USAGE_HW_TEXTURE |
| 677 | // 2. GRALLOC_USAGE_HW_RENDER |
| 678 | // 3. GRALLOC_USAGE_HW_COMPOSER |
| 679 | // 4. GRALLOC_USAGE_HW_VIDEO_ENCODER |
| 680 | if (camera3_stream::format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED && |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 681 | (u & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER | |
| 682 | GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_VIDEO_ENCODER)) == 0) { |
Yin-Chia Yeh | 47cf8e6 | 2017-04-04 13:00:03 -0700 | [diff] [blame] | 683 | u |= GRALLOC_USAGE_HW_CAMERA_ZSL; |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | *usage = u; |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 687 | return res; |
| 688 | } |
| 689 | |
Chien-Yu Chen | 85a6455 | 2015-08-28 15:46:12 -0700 | [diff] [blame] | 690 | bool Camera3OutputStream::isVideoStream() const { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 691 | uint64_t usage = 0; |
Chien-Yu Chen | 85a6455 | 2015-08-28 15:46:12 -0700 | [diff] [blame] | 692 | status_t res = getEndpointUsage(&usage); |
| 693 | if (res != OK) { |
| 694 | ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res); |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | return (usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) != 0; |
| 699 | } |
| 700 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 701 | status_t Camera3OutputStream::setBufferManager(sp<Camera3BufferManager> bufferManager) { |
| 702 | Mutex::Autolock l(mLock); |
| 703 | if (mState != STATE_CONSTRUCTED) { |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 704 | ALOGE("%s: this method can only be called when stream in CONSTRUCTED state.", |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 705 | __FUNCTION__); |
| 706 | return INVALID_OPERATION; |
| 707 | } |
| 708 | mBufferManager = bufferManager; |
| 709 | |
| 710 | return OK; |
| 711 | } |
| 712 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 713 | status_t Camera3OutputStream::updateStream(const std::vector<sp<Surface>> &/*outputSurfaces*/, |
| 714 | const std::vector<OutputStreamInfo> &/*outputInfo*/, |
| 715 | const std::vector<size_t> &/*removedSurfaceIds*/, |
| 716 | KeyedVector<sp<Surface>, size_t> * /*outputMapo*/) { |
| 717 | ALOGE("%s: this method is not supported!", __FUNCTION__); |
| 718 | return INVALID_OPERATION; |
| 719 | } |
| 720 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 721 | void Camera3OutputStream::BufferReleasedListener::onBufferReleased() { |
| 722 | sp<Camera3OutputStream> stream = mParent.promote(); |
| 723 | if (stream == nullptr) { |
| 724 | ALOGV("%s: Parent camera3 output stream was destroyed", __FUNCTION__); |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | Mutex::Autolock l(stream->mLock); |
| 729 | if (!(stream->mUseBufferManager)) { |
| 730 | return; |
| 731 | } |
| 732 | |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 733 | ALOGV("Stream %d: Buffer released", stream->getId()); |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 734 | bool shouldFreeBuffer = false; |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 735 | status_t res = stream->mBufferManager->onBufferReleased( |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 736 | stream->getId(), stream->getStreamSetId(), &shouldFreeBuffer); |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 737 | if (res != OK) { |
| 738 | ALOGE("%s: signaling buffer release to buffer manager failed: %s (%d).", __FUNCTION__, |
| 739 | strerror(-res), res); |
| 740 | stream->mState = STATE_ERROR; |
| 741 | } |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 742 | |
| 743 | if (shouldFreeBuffer) { |
| 744 | sp<GraphicBuffer> buffer; |
| 745 | // Detach and free a buffer (when buffer goes out of scope) |
| 746 | stream->detachBufferLocked(&buffer, /*fenceFd*/ nullptr); |
| 747 | if (buffer.get() != nullptr) { |
| 748 | stream->mBufferManager->notifyBufferRemoved( |
| 749 | stream->getId(), stream->getStreamSetId()); |
| 750 | } |
| 751 | } |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 752 | } |
| 753 | |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 754 | void Camera3OutputStream::onBuffersRemovedLocked( |
| 755 | const std::vector<sp<GraphicBuffer>>& removedBuffers) { |
Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 756 | sp<Camera3StreamBufferFreedListener> callback = mBufferFreedListener.promote(); |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 757 | if (callback != nullptr) { |
Chih-Hung Hsieh | 48fc619 | 2017-08-04 14:37:31 -0700 | [diff] [blame] | 758 | for (const auto& gb : removedBuffers) { |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 759 | callback->onBufferFreed(mId, gb->handle); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 764 | status_t Camera3OutputStream::detachBuffer(sp<GraphicBuffer>* buffer, int* fenceFd) { |
| 765 | Mutex::Autolock l(mLock); |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 766 | return detachBufferLocked(buffer, fenceFd); |
| 767 | } |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 768 | |
Yin-Chia Yeh | 89954d9 | 2017-05-21 17:28:53 -0700 | [diff] [blame] | 769 | status_t Camera3OutputStream::detachBufferLocked(sp<GraphicBuffer>* buffer, int* fenceFd) { |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 770 | ALOGV("Stream %d: detachBuffer", getId()); |
| 771 | if (buffer == nullptr) { |
| 772 | return BAD_VALUE; |
| 773 | } |
| 774 | |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 775 | sp<Fence> fence; |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 776 | status_t res = mConsumer->detachNextBuffer(buffer, &fence); |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 777 | if (res == NO_MEMORY) { |
| 778 | // This may rarely happen, which indicates that the released buffer was freed by other |
| 779 | // call (e.g., attachBuffer, dequeueBuffer etc.) before reaching here. We should notify the |
| 780 | // buffer manager that this buffer has been freed. It's not fatal, but should be avoided, |
| 781 | // therefore log a warning. |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 782 | *buffer = 0; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 783 | ALOGW("%s: the released buffer has already been freed by the buffer queue!", __FUNCTION__); |
| 784 | } else if (res != OK) { |
Eino-Ville Talvala | ff51b47 | 2016-06-28 15:26:19 -0700 | [diff] [blame] | 785 | // Treat other errors as abandonment |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 786 | ALOGE("%s: detach next buffer failed: %s (%d).", __FUNCTION__, strerror(-res), res); |
Eino-Ville Talvala | ff51b47 | 2016-06-28 15:26:19 -0700 | [diff] [blame] | 787 | mState = STATE_ABANDONED; |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 788 | return res; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 789 | } |
| 790 | |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 791 | if (fenceFd != nullptr) { |
| 792 | if (fence!= 0 && fence->isValid()) { |
| 793 | *fenceFd = fence->dup(); |
| 794 | } else { |
| 795 | *fenceFd = -1; |
| 796 | } |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 797 | } |
Eino-Ville Talvala | 77c1a35 | 2016-06-13 12:32:43 -0700 | [diff] [blame] | 798 | |
Yin-Chia Yeh | 017d49c | 2017-03-31 19:11:00 -0700 | [diff] [blame] | 799 | std::vector<sp<GraphicBuffer>> removedBuffers; |
| 800 | res = mConsumer->getAndFlushRemovedBuffers(&removedBuffers); |
| 801 | if (res == OK) { |
| 802 | onBuffersRemovedLocked(removedBuffers); |
| 803 | } |
| 804 | return res; |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 805 | } |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 806 | |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 807 | status_t Camera3OutputStream::dropBuffers(bool dropping) { |
| 808 | Mutex::Autolock l(mLock); |
| 809 | mDropBuffers = dropping; |
| 810 | return OK; |
| 811 | } |
| 812 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 813 | const String8& Camera3OutputStream::getPhysicalCameraId() const { |
| 814 | Mutex::Autolock l(mLock); |
| 815 | return physicalCameraId(); |
| 816 | } |
| 817 | |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 818 | status_t Camera3OutputStream::notifyBufferReleased(ANativeWindowBuffer* /*anwBuffer*/) { |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 819 | return OK; |
| 820 | } |
| 821 | |
| 822 | bool Camera3OutputStream::isConsumerConfigurationDeferred(size_t surface_id) const { |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 823 | Mutex::Autolock l(mLock); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 824 | |
| 825 | if (surface_id != 0) { |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 826 | ALOGE("%s: surface_id %zu for Camera3OutputStream should be 0!", __FUNCTION__, surface_id); |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 827 | } |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 828 | return mConsumer == nullptr; |
| 829 | } |
| 830 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 831 | status_t Camera3OutputStream::setConsumers(const std::vector<sp<Surface>>& consumers) { |
Shuzhen Wang | bee0f0a | 2017-01-24 14:51:37 -0800 | [diff] [blame] | 832 | Mutex::Autolock l(mLock); |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 833 | if (consumers.size() != 1) { |
| 834 | ALOGE("%s: it's illegal to set %zu consumer surfaces!", |
| 835 | __FUNCTION__, consumers.size()); |
| 836 | return INVALID_OPERATION; |
| 837 | } |
| 838 | if (consumers[0] == nullptr) { |
| 839 | ALOGE("%s: it's illegal to set null consumer surface!", __FUNCTION__); |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 840 | return INVALID_OPERATION; |
| 841 | } |
| 842 | |
| 843 | if (mConsumer != nullptr) { |
| 844 | ALOGE("%s: consumer surface was already set!", __FUNCTION__); |
| 845 | return INVALID_OPERATION; |
| 846 | } |
| 847 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 848 | mConsumer = consumers[0]; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 849 | return OK; |
| 850 | } |
| 851 | |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 852 | bool Camera3OutputStream::isConsumedByHWComposer() const { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 853 | uint64_t usage = 0; |
Shuzhen Wang | 13a6963 | 2016-01-26 09:51:07 -0800 | [diff] [blame] | 854 | status_t res = getEndpointUsage(&usage); |
| 855 | if (res != OK) { |
| 856 | ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res); |
| 857 | return false; |
| 858 | } |
| 859 | |
| 860 | return (usage & GRALLOC_USAGE_HW_COMPOSER) != 0; |
| 861 | } |
| 862 | |
Zhijun He | f0645c1 | 2016-08-02 00:58:11 -0700 | [diff] [blame] | 863 | bool Camera3OutputStream::isConsumedByHWTexture() const { |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 864 | uint64_t usage = 0; |
Zhijun He | f0645c1 | 2016-08-02 00:58:11 -0700 | [diff] [blame] | 865 | status_t res = getEndpointUsage(&usage); |
| 866 | if (res != OK) { |
| 867 | ALOGE("%s: getting end point usage failed: %s (%d).", __FUNCTION__, strerror(-res), res); |
| 868 | return false; |
| 869 | } |
| 870 | |
| 871 | return (usage & GRALLOC_USAGE_HW_TEXTURE) != 0; |
| 872 | } |
| 873 | |
Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 874 | }; // namespace camera3 |
| 875 | |
| 876 | }; // namespace android |