Eino-Ville Talvala | 8be20f5 | 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 | 8be20f5 | 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-InputStream" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Dan Stoza | 549e735 | 2015-03-12 15:21:16 -0700 | [diff] [blame] | 21 | #include <gui/BufferItem.h> |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 22 | #include <utils/Log.h> |
| 23 | #include <utils/Trace.h> |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame^] | 24 | #include <camera/StringUtils.h> |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 25 | #include "Camera3InputStream.h" |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | namespace camera3 { |
| 30 | |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame^] | 31 | const std::string Camera3InputStream::FAKE_ID; |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 32 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 33 | Camera3InputStream::Camera3InputStream(int id, |
| 34 | uint32_t width, uint32_t height, int format) : |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 35 | Camera3IOStreamBase(id, CAMERA_STREAM_INPUT, width, height, /*maxSize*/0, |
| 36 | format, HAL_DATASPACE_UNKNOWN, CAMERA_STREAM_ROTATION_0, |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 37 | FAKE_ID, |
| 38 | std::unordered_set<int32_t>{ANDROID_SENSOR_PIXEL_MODE_DEFAULT}) { |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 39 | |
| 40 | if (format == HAL_PIXEL_FORMAT_BLOB) { |
| 41 | ALOGE("%s: Bad format, BLOB not supported", __FUNCTION__); |
| 42 | mState = STATE_ERROR; |
| 43 | } |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 46 | Camera3InputStream::~Camera3InputStream() { |
| 47 | disconnectLocked(); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 50 | status_t Camera3InputStream::getInputBufferLocked( |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 51 | camera_stream_buffer *buffer, Size *size) { |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 52 | ATRACE_CALL(); |
| 53 | status_t res; |
| 54 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 55 | if (size == nullptr) { |
| 56 | ALOGE("%s: size must not be null", __FUNCTION__); |
| 57 | return BAD_VALUE; |
| 58 | } |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 59 | // FIXME: will not work in (re-)registration |
| 60 | if (mState == STATE_IN_CONFIG || mState == STATE_IN_RECONFIG) { |
| 61 | ALOGE("%s: Stream %d: Buffer registration for input streams" |
| 62 | " not implemented (state %d)", |
| 63 | __FUNCTION__, mId, mState); |
| 64 | return INVALID_OPERATION; |
| 65 | } |
| 66 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 67 | if ((res = getBufferPreconditionCheckLocked()) != OK) { |
| 68 | return res; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | ANativeWindowBuffer* anb; |
| 72 | int fenceFd; |
| 73 | |
| 74 | assert(mConsumer != 0); |
| 75 | |
| 76 | BufferItem bufferItem; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 77 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 78 | res = mConsumer->acquireBuffer(&bufferItem, /*waitForFence*/false); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 79 | if (res != OK) { |
Shuzhen Wang | 0cf01cb | 2019-09-05 13:33:06 -0700 | [diff] [blame] | 80 | // This may or may not be an error condition depending on caller. |
| 81 | ALOGV("%s: Stream %d: Can't acquire next output buffer: %s (%d)", |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 82 | __FUNCTION__, mId, strerror(-res), res); |
| 83 | return res; |
| 84 | } |
| 85 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 86 | size->width = bufferItem.mGraphicBuffer->getWidth(); |
| 87 | size->height = bufferItem.mGraphicBuffer->getHeight(); |
| 88 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 89 | anb = bufferItem.mGraphicBuffer->getNativeBuffer(); |
| 90 | assert(anb != NULL); |
| 91 | fenceFd = bufferItem.mFence->dup(); |
| 92 | /** |
| 93 | * FenceFD now owned by HAL except in case of error, |
| 94 | * in which case we reassign it to acquire_fence |
| 95 | */ |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 96 | handoutBufferLocked(*buffer, &(anb->handle), /*acquireFence*/fenceFd, |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 97 | /*releaseFence*/-1, CAMERA_BUFFER_STATUS_OK, /*output*/false); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 98 | mBuffersInFlight.push_back(bufferItem); |
| 99 | |
Eino-Ville Talvala | c31dc7e | 2017-01-31 17:35:41 -0800 | [diff] [blame] | 100 | mFrameCount++; |
| 101 | mLastTimestamp = bufferItem.mTimestamp; |
| 102 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 103 | return OK; |
| 104 | } |
| 105 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 106 | status_t Camera3InputStream::returnBufferCheckedLocked( |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 107 | const camera_stream_buffer &buffer, |
Jing Mike | c7f9b13 | 2023-03-12 11:12:04 +0800 | [diff] [blame] | 108 | [[maybe_unused]] nsecs_t timestamp, |
| 109 | [[maybe_unused]] nsecs_t readoutTimestamp, |
| 110 | [[maybe_unused]] bool output, |
Emilian Peev | 5104fe9 | 2021-10-21 14:27:09 -0700 | [diff] [blame] | 111 | int32_t /*transform*/, |
Yin-Chia Yeh | 58b1b4e | 2018-10-15 12:18:36 -0700 | [diff] [blame] | 112 | const std::vector<size_t>&, |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 113 | /*out*/ |
| 114 | sp<Fence> *releaseFenceOut) { |
| 115 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 116 | ALOG_ASSERT(!output, "Expected output to be false"); |
| 117 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 118 | status_t res; |
| 119 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 120 | bool bufferFound = false; |
| 121 | BufferItem bufferItem; |
| 122 | { |
| 123 | // Find the buffer we are returning |
| 124 | Vector<BufferItem>::iterator it, end; |
| 125 | for (it = mBuffersInFlight.begin(), end = mBuffersInFlight.end(); |
| 126 | it != end; |
| 127 | ++it) { |
| 128 | |
| 129 | const BufferItem& tmp = *it; |
| 130 | ANativeWindowBuffer *anb = tmp.mGraphicBuffer->getNativeBuffer(); |
| 131 | if (anb != NULL && &(anb->handle) == buffer.buffer) { |
| 132 | bufferFound = true; |
| 133 | bufferItem = tmp; |
| 134 | mBuffersInFlight.erase(it); |
Eino-Ville Talvala | 05a8cf5 | 2016-03-28 14:08:56 -0700 | [diff] [blame] | 135 | break; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | } |
| 139 | if (!bufferFound) { |
| 140 | ALOGE("%s: Stream %d: Can't return buffer that wasn't sent to HAL", |
| 141 | __FUNCTION__, mId); |
| 142 | return INVALID_OPERATION; |
| 143 | } |
| 144 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 145 | if (buffer.status == CAMERA_BUFFER_STATUS_ERROR) { |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 146 | if (buffer.release_fence != -1) { |
| 147 | ALOGE("%s: Stream %d: HAL should not set release_fence(%d) when " |
| 148 | "there is an error", __FUNCTION__, mId, buffer.release_fence); |
| 149 | close(buffer.release_fence); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Reassign release fence as the acquire fence incase of error |
| 154 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 155 | const_cast<camera_stream_buffer*>(&buffer)->release_fence = |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 156 | buffer.acquire_fence; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Unconditionally return buffer to the buffer queue. |
| 161 | * - Fwk takes over the release_fence ownership |
| 162 | */ |
| 163 | sp<Fence> releaseFence = new Fence(buffer.release_fence); |
| 164 | res = mConsumer->releaseBuffer(bufferItem, releaseFence); |
| 165 | if (res != OK) { |
| 166 | ALOGE("%s: Stream %d: Error releasing buffer back to buffer queue:" |
| 167 | " %s (%d)", __FUNCTION__, mId, strerror(-res), res); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 170 | *releaseFenceOut = releaseFence; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 171 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 172 | return res; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 175 | status_t Camera3InputStream::returnInputBufferLocked( |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 176 | const camera_stream_buffer &buffer) { |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 177 | ATRACE_CALL(); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 178 | |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 179 | return returnAnyBufferLocked(buffer, /*timestamp*/0, /*readoutTimestamp*/0, |
| 180 | /*output*/false, /*transform*/ -1); |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 183 | status_t Camera3InputStream::getInputBufferProducerLocked( |
| 184 | sp<IGraphicBufferProducer> *producer) { |
| 185 | ATRACE_CALL(); |
| 186 | |
| 187 | if (producer == NULL) { |
| 188 | return BAD_VALUE; |
| 189 | } else if (mProducer == NULL) { |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 190 | ALOGE("%s: No input stream is configured", __FUNCTION__); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 191 | return INVALID_OPERATION; |
| 192 | } |
| 193 | |
| 194 | *producer = mProducer; |
| 195 | return OK; |
| 196 | } |
| 197 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 198 | status_t Camera3InputStream::disconnectLocked() { |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 199 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 200 | status_t res; |
| 201 | |
| 202 | if ((res = Camera3IOStreamBase::disconnectLocked()) != OK) { |
| 203 | return res; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | assert(mBuffersInFlight.size() == 0); |
| 207 | |
Chien-Yu Chen | ed0412e | 2015-04-27 15:04:22 -0700 | [diff] [blame] | 208 | mConsumer->abandon(); |
| 209 | |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 210 | /** |
| 211 | * no-op since we can't disconnect the producer from the consumer-side |
| 212 | */ |
| 213 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 214 | mState = (mState == STATE_IN_RECONFIG) ? STATE_IN_CONFIG |
| 215 | : STATE_CONSTRUCTED; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 216 | return OK; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Jing Mike | c7f9b13 | 2023-03-12 11:12:04 +0800 | [diff] [blame] | 219 | void Camera3InputStream::dump(int fd, [[maybe_unused]] const Vector<String16> &args) const { |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame^] | 220 | std::string lines; |
| 221 | lines += fmt::sprintf(" Stream[%d]: Input\n", mId); |
| 222 | write(fd, lines.c_str(), lines.size()); |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 223 | |
| 224 | Camera3IOStreamBase::dump(fd, args); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | status_t Camera3InputStream::configureQueueLocked() { |
| 228 | status_t res; |
| 229 | |
Igor Murashkin | ae3d0ba | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 230 | if ((res = Camera3IOStreamBase::configureQueueLocked()) != OK) { |
| 231 | return res; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | assert(mMaxSize == 0); |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 235 | assert(camera_stream::format != HAL_PIXEL_FORMAT_BLOB); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 236 | |
Zhijun He | 6adc9cc | 2014-04-15 14:09:55 -0700 | [diff] [blame] | 237 | mHandoutTotalBufferCount = 0; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 238 | mFrameCount = 0; |
Eino-Ville Talvala | c31dc7e | 2017-01-31 17:35:41 -0800 | [diff] [blame] | 239 | mLastTimestamp = 0; |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 240 | |
| 241 | if (mConsumer.get() == 0) { |
Dan Stoza | 8aa0f06 | 2014-03-12 14:31:05 -0700 | [diff] [blame] | 242 | sp<IGraphicBufferProducer> producer; |
| 243 | sp<IGraphicBufferConsumer> consumer; |
| 244 | BufferQueue::createBufferQueue(&producer, &consumer); |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 245 | |
| 246 | int minUndequeuedBuffers = 0; |
Dan Stoza | 8aa0f06 | 2014-03-12 14:31:05 -0700 | [diff] [blame] | 247 | res = producer->query(NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffers); |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 248 | if (res != OK || minUndequeuedBuffers < 0) { |
| 249 | ALOGE("%s: Stream %d: Could not query min undequeued buffers (error %d, bufCount %d)", |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 250 | __FUNCTION__, mId, res, minUndequeuedBuffers); |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 251 | return res; |
| 252 | } |
| 253 | size_t minBufs = static_cast<size_t>(minUndequeuedBuffers); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 254 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 255 | if (camera_stream::max_buffers == 0) { |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 256 | ALOGE("%s: %d: HAL sets max_buffer to 0. Must be at least 1.", |
| 257 | __FUNCTION__, __LINE__); |
| 258 | return INVALID_OPERATION; |
| 259 | } |
| 260 | |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 261 | /* |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 262 | * We promise never to 'acquire' more than camera_stream::max_buffers |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 263 | * at any one time. |
| 264 | * |
| 265 | * Boost the number up to meet the minimum required buffer count. |
| 266 | * |
| 267 | * (Note that this sets consumer-side buffer count only, |
| 268 | * and not the sum of producer+consumer side as in other camera streams). |
| 269 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 270 | mTotalBufferCount = camera_stream::max_buffers > minBufs ? |
| 271 | camera_stream::max_buffers : minBufs; |
Igor Murashkin | 054aab3 | 2013-11-18 11:39:27 -0800 | [diff] [blame] | 272 | // TODO: somehow set the total buffer count when producer connects? |
| 273 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 274 | mConsumer = new BufferItemConsumer(consumer, mUsage, |
Mathias Agopian | 5e1f08b | 2013-07-16 22:54:39 -0700 | [diff] [blame] | 275 | mTotalBufferCount); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 276 | mConsumer->setName(String8::format("Camera3-InputStream-%d", mId)); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 277 | |
| 278 | mProducer = producer; |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 279 | |
| 280 | mConsumer->setBufferFreedListener(this); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 283 | res = mConsumer->setDefaultBufferSize(camera_stream::width, |
| 284 | camera_stream::height); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 285 | if (res != OK) { |
| 286 | ALOGE("%s: Stream %d: Could not set buffer dimensions %dx%d", |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 287 | __FUNCTION__, mId, camera_stream::width, camera_stream::height); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 288 | return res; |
| 289 | } |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 290 | res = mConsumer->setDefaultBufferFormat(camera_stream::format); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 291 | if (res != OK) { |
| 292 | ALOGE("%s: Stream %d: Could not set buffer format %d", |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 293 | __FUNCTION__, mId, camera_stream::format); |
Igor Murashkin | 0776a14 | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 294 | return res; |
| 295 | } |
| 296 | |
| 297 | return OK; |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 300 | status_t Camera3InputStream::getEndpointUsage(uint64_t *usage) const { |
Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 301 | // Per HAL3 spec, input streams have 0 for their initial usage field. |
| 302 | *usage = 0; |
| 303 | return OK; |
| 304 | } |
| 305 | |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 306 | void Camera3InputStream::onBufferFreed(const wp<GraphicBuffer>& gb) { |
| 307 | const sp<GraphicBuffer> buffer = gb.promote(); |
| 308 | if (buffer != nullptr) { |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 309 | camera_stream_buffer streamBuffer = |
| 310 | {nullptr, &buffer->handle, CAMERA_BUFFER_STATUS_OK, -1, -1}; |
Emilian Peev | 889234d | 2017-07-18 18:21:26 -0700 | [diff] [blame] | 311 | // Check if this buffer is outstanding. |
| 312 | if (isOutstandingBuffer(streamBuffer)) { |
| 313 | ALOGV("%s: Stream %d: Trying to free a buffer that is still being " |
| 314 | "processed.", __FUNCTION__, mId); |
| 315 | return; |
| 316 | } |
| 317 | |
Yin-Chia Yeh | db1e864 | 2017-07-14 15:19:30 -0700 | [diff] [blame] | 318 | sp<Camera3StreamBufferFreedListener> callback = mBufferFreedListener.promote(); |
| 319 | if (callback != nullptr) { |
| 320 | callback->onBufferFreed(mId, buffer->handle); |
Yin-Chia Yeh | be83fa7 | 2017-03-30 13:35:36 -0700 | [diff] [blame] | 321 | } |
| 322 | } else { |
| 323 | ALOGE("%s: GraphicBuffer is freed before onBufferFreed callback finishes!", __FUNCTION__); |
| 324 | } |
| 325 | } |
| 326 | |
Eino-Ville Talvala | 8be20f5 | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 327 | }; // namespace camera3 |
| 328 | |
| 329 | }; // namespace android |