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