| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2013 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #define LOG_TAG "Camera3-OutputStream" | 
|  | 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA | 
|  | 19 | //#define LOG_NDEBUG 0 | 
|  | 20 |  | 
| Eino-Ville 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, | 
|  | 35 | sp<ANativeWindow> consumer, | 
|  | 36 | uint32_t width, uint32_t height, int format) : | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 37 | Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, | 
|  | 38 | /*maxSize*/0, format), | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 39 | mConsumer(consumer), | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 40 | mTransform(0) { | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 41 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 42 | if (mConsumer == NULL) { | 
|  | 43 | ALOGE("%s: Consumer is NULL!", __FUNCTION__); | 
|  | 44 | mState = STATE_ERROR; | 
|  | 45 | } | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 | Camera3OutputStream::Camera3OutputStream(int id, | 
|  | 49 | sp<ANativeWindow> consumer, | 
|  | 50 | uint32_t width, uint32_t height, size_t maxSize, int format) : | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 51 | Camera3IOStreamBase(id, CAMERA3_STREAM_OUTPUT, width, height, maxSize, | 
|  | 52 | format), | 
| Igor Murashkin | a55b545 | 2013-04-02 16:36:33 -0700 | [diff] [blame] | 53 | mConsumer(consumer), | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 54 | mTransform(0) { | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 55 |  | 
|  | 56 | if (format != HAL_PIXEL_FORMAT_BLOB) { | 
|  | 57 | ALOGE("%s: Bad format for size-only stream: %d", __FUNCTION__, | 
|  | 58 | format); | 
|  | 59 | mState = STATE_ERROR; | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | if (mConsumer == NULL) { | 
|  | 63 | ALOGE("%s: Consumer is NULL!", __FUNCTION__); | 
|  | 64 | mState = STATE_ERROR; | 
|  | 65 | } | 
|  | 66 | } | 
|  | 67 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 68 | Camera3OutputStream::Camera3OutputStream(int id, camera3_stream_type_t type, | 
|  | 69 | uint32_t width, uint32_t height, | 
|  | 70 | int format) : | 
|  | 71 | Camera3IOStreamBase(id, type, width, height, | 
|  | 72 | /*maxSize*/0, | 
|  | 73 | format), | 
|  | 74 | mTransform(0) { | 
|  | 75 |  | 
|  | 76 | // Subclasses expected to initialize mConsumer themselves | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 80 | Camera3OutputStream::~Camera3OutputStream() { | 
|  | 81 | disconnectLocked(); | 
|  | 82 | } | 
|  | 83 |  | 
|  | 84 | status_t Camera3OutputStream::getBufferLocked(camera3_stream_buffer *buffer) { | 
|  | 85 | ATRACE_CALL(); | 
|  | 86 | status_t res; | 
|  | 87 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 88 | if ((res = getBufferPreconditionCheckLocked()) != OK) { | 
|  | 89 | return res; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
|  | 92 | ANativeWindowBuffer* anb; | 
|  | 93 | int fenceFd; | 
|  | 94 |  | 
| Zhijun He | 15ad247 | 2013-10-11 16:21:11 -0700 | [diff] [blame^] | 95 | /** | 
|  | 96 | * Release the lock briefly to avoid deadlock for below scenario: | 
|  | 97 | * Thread 1: StreamingProcessor::startStream -> Camera3Stream::isConfiguring(). | 
|  | 98 | * This thread acquired StreamingProcessor lock and try to lock Camera3Stream lock. | 
|  | 99 | * Thread 2: Camera3Stream::returnBuffer->StreamingProcessor::onFrameAvailable(). | 
|  | 100 | * This thread acquired Camera3Stream lock and bufferQueue lock, and try to lock | 
|  | 101 | * StreamingProcessor lock. | 
|  | 102 | * Thread 3: Camera3Stream::getBuffer(). This thread acquired Camera3Stream lock | 
|  | 103 | * and try to lock bufferQueue lock. | 
|  | 104 | * Then there is circular locking dependency. | 
|  | 105 | */ | 
|  | 106 | sp<ANativeWindow> currentConsumer = mConsumer; | 
|  | 107 | mLock.unlock(); | 
|  | 108 |  | 
|  | 109 | res = currentConsumer->dequeueBuffer(currentConsumer.get(), &anb, &fenceFd); | 
|  | 110 | mLock.lock(); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 111 | if (res != OK) { | 
|  | 112 | ALOGE("%s: Stream %d: Can't dequeue next output buffer: %s (%d)", | 
|  | 113 | __FUNCTION__, mId, strerror(-res), res); | 
|  | 114 | return res; | 
|  | 115 | } | 
|  | 116 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 117 | /** | 
|  | 118 | * FenceFD now owned by HAL except in case of error, | 
|  | 119 | * in which case we reassign it to acquire_fence | 
|  | 120 | */ | 
|  | 121 | handoutBufferLocked(*buffer, &(anb->handle), /*acquireFence*/fenceFd, | 
|  | 122 | /*releaseFence*/-1, CAMERA3_BUFFER_STATUS_OK); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 123 |  | 
|  | 124 | return OK; | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | status_t Camera3OutputStream::returnBufferLocked( | 
|  | 128 | const camera3_stream_buffer &buffer, | 
|  | 129 | nsecs_t timestamp) { | 
|  | 130 | ATRACE_CALL(); | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 131 |  | 
|  | 132 | status_t res = returnAnyBufferLocked(buffer, timestamp, /*output*/true); | 
|  | 133 |  | 
|  | 134 | if (res != OK) { | 
|  | 135 | return res; | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | mLastTimestamp = timestamp; | 
|  | 139 |  | 
|  | 140 | return OK; | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | status_t Camera3OutputStream::returnBufferCheckedLocked( | 
|  | 144 | const camera3_stream_buffer &buffer, | 
|  | 145 | nsecs_t timestamp, | 
|  | 146 | bool output, | 
|  | 147 | /*out*/ | 
|  | 148 | sp<Fence> *releaseFenceOut) { | 
|  | 149 |  | 
|  | 150 | (void)output; | 
|  | 151 | ALOG_ASSERT(output, "Expected output to be true"); | 
|  | 152 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 153 | status_t res; | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 154 | sp<Fence> releaseFence; | 
|  | 155 |  | 
|  | 156 | /** | 
|  | 157 | * Fence management - calculate Release Fence | 
|  | 158 | */ | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 159 | if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR) { | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 160 | if (buffer.release_fence != -1) { | 
|  | 161 | ALOGE("%s: Stream %d: HAL should not set release_fence(%d) when " | 
|  | 162 | "there is an error", __FUNCTION__, mId, buffer.release_fence); | 
|  | 163 | close(buffer.release_fence); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 164 | } | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 165 |  | 
|  | 166 | /** | 
|  | 167 | * Reassign release fence as the acquire fence in case of error | 
|  | 168 | */ | 
|  | 169 | releaseFence = new Fence(buffer.acquire_fence); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 170 | } else { | 
|  | 171 | res = native_window_set_buffers_timestamp(mConsumer.get(), timestamp); | 
|  | 172 | if (res != OK) { | 
|  | 173 | ALOGE("%s: Stream %d: Error setting timestamp: %s (%d)", | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 174 | __FUNCTION__, mId, strerror(-res), res); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 175 | return res; | 
|  | 176 | } | 
|  | 177 |  | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 178 | releaseFence = new Fence(buffer.release_fence); | 
|  | 179 | } | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 180 |  | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 181 | int anwReleaseFence = releaseFence->dup(); | 
|  | 182 |  | 
|  | 183 | /** | 
| Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 184 | * Release the lock briefly to avoid deadlock with | 
|  | 185 | * StreamingProcessor::startStream -> Camera3Stream::isConfiguring (this | 
|  | 186 | * thread will go into StreamingProcessor::onFrameAvailable) during | 
|  | 187 | * queueBuffer | 
|  | 188 | */ | 
|  | 189 | sp<ANativeWindow> currentConsumer = mConsumer; | 
|  | 190 | mLock.unlock(); | 
|  | 191 |  | 
|  | 192 | /** | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 193 | * Return buffer back to ANativeWindow | 
|  | 194 | */ | 
|  | 195 | if (buffer.status == CAMERA3_BUFFER_STATUS_ERROR) { | 
|  | 196 | // Cancel buffer | 
| Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 197 | res = currentConsumer->cancelBuffer(currentConsumer.get(), | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 198 | container_of(buffer.buffer, ANativeWindowBuffer, handle), | 
|  | 199 | anwReleaseFence); | 
|  | 200 | if (res != OK) { | 
|  | 201 | ALOGE("%s: Stream %d: Error cancelling buffer to native window:" | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 202 | " %s (%d)", __FUNCTION__, mId, strerror(-res), res); | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 203 | } | 
|  | 204 | } else { | 
| Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 205 | res = currentConsumer->queueBuffer(currentConsumer.get(), | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 206 | container_of(buffer.buffer, ANativeWindowBuffer, handle), | 
|  | 207 | anwReleaseFence); | 
|  | 208 | if (res != OK) { | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 209 | ALOGE("%s: Stream %d: Error queueing buffer to native window: " | 
|  | 210 | "%s (%d)", __FUNCTION__, mId, strerror(-res), res); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 211 | } | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 212 | } | 
| Zhijun He | 124ccf4 | 2013-05-22 14:01:30 -0700 | [diff] [blame] | 213 | mLock.lock(); | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 214 | if (res != OK) { | 
|  | 215 | close(anwReleaseFence); | 
| Igor Murashkin | 5a1798a | 2013-05-07 10:58:13 -0700 | [diff] [blame] | 216 | } | 
|  | 217 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 218 | *releaseFenceOut = releaseFence; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 219 |  | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 220 | return res; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 221 | } | 
|  | 222 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 223 | void Camera3OutputStream::dump(int fd, const Vector<String16> &args) const { | 
|  | 224 | (void) args; | 
|  | 225 | String8 lines; | 
|  | 226 | lines.appendFormat("    Stream[%d]: Output\n", mId); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 227 | write(fd, lines.string(), lines.size()); | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 228 |  | 
|  | 229 | Camera3IOStreamBase::dump(fd, args); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 230 | } | 
|  | 231 |  | 
|  | 232 | status_t Camera3OutputStream::setTransform(int transform) { | 
|  | 233 | ATRACE_CALL(); | 
|  | 234 | Mutex::Autolock l(mLock); | 
|  | 235 | return setTransformLocked(transform); | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | status_t Camera3OutputStream::setTransformLocked(int transform) { | 
|  | 239 | status_t res = OK; | 
|  | 240 | if (mState == STATE_ERROR) { | 
|  | 241 | ALOGE("%s: Stream in error state", __FUNCTION__); | 
|  | 242 | return INVALID_OPERATION; | 
|  | 243 | } | 
|  | 244 |  | 
|  | 245 | mTransform = transform; | 
|  | 246 | if (mState == STATE_CONFIGURED) { | 
|  | 247 | res = native_window_set_buffers_transform(mConsumer.get(), | 
|  | 248 | transform); | 
|  | 249 | if (res != OK) { | 
|  | 250 | ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", | 
|  | 251 | __FUNCTION__, transform, strerror(-res), res); | 
|  | 252 | } | 
|  | 253 | } | 
|  | 254 | return res; | 
|  | 255 | } | 
|  | 256 |  | 
|  | 257 | status_t Camera3OutputStream::configureQueueLocked() { | 
|  | 258 | status_t res; | 
|  | 259 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 260 | if ((res = Camera3IOStreamBase::configureQueueLocked()) != OK) { | 
|  | 261 | return res; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 262 | } | 
|  | 263 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 264 | ALOG_ASSERT(mConsumer != 0, "mConsumer should never be NULL"); | 
|  | 265 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 266 | // Configure consumer-side ANativeWindow interface | 
|  | 267 | res = native_window_api_connect(mConsumer.get(), | 
|  | 268 | NATIVE_WINDOW_API_CAMERA); | 
|  | 269 | if (res != OK) { | 
|  | 270 | ALOGE("%s: Unable to connect to native window for stream %d", | 
|  | 271 | __FUNCTION__, mId); | 
|  | 272 | return res; | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | res = native_window_set_usage(mConsumer.get(), camera3_stream::usage); | 
|  | 276 | if (res != OK) { | 
|  | 277 | ALOGE("%s: Unable to configure usage %08x for stream %d", | 
|  | 278 | __FUNCTION__, camera3_stream::usage, mId); | 
|  | 279 | return res; | 
|  | 280 | } | 
|  | 281 |  | 
|  | 282 | res = native_window_set_scaling_mode(mConsumer.get(), | 
|  | 283 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); | 
|  | 284 | if (res != OK) { | 
|  | 285 | ALOGE("%s: Unable to configure stream scaling: %s (%d)", | 
|  | 286 | __FUNCTION__, strerror(-res), res); | 
|  | 287 | return res; | 
|  | 288 | } | 
|  | 289 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 290 | if (mMaxSize == 0) { | 
|  | 291 | // For buffers of known size | 
|  | 292 | res = native_window_set_buffers_geometry(mConsumer.get(), | 
|  | 293 | camera3_stream::width, camera3_stream::height, | 
|  | 294 | camera3_stream::format); | 
|  | 295 | } else { | 
|  | 296 | // For buffers with bounded size | 
|  | 297 | res = native_window_set_buffers_geometry(mConsumer.get(), | 
|  | 298 | mMaxSize, 1, | 
|  | 299 | camera3_stream::format); | 
|  | 300 | } | 
|  | 301 | if (res != OK) { | 
|  | 302 | ALOGE("%s: Unable to configure stream buffer geometry" | 
|  | 303 | " %d x %d, format %x for stream %d", | 
|  | 304 | __FUNCTION__, camera3_stream::width, camera3_stream::height, | 
|  | 305 | camera3_stream::format, mId); | 
|  | 306 | return res; | 
|  | 307 | } | 
|  | 308 |  | 
|  | 309 | int maxConsumerBuffers; | 
|  | 310 | res = mConsumer->query(mConsumer.get(), | 
|  | 311 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers); | 
|  | 312 | if (res != OK) { | 
|  | 313 | ALOGE("%s: Unable to query consumer undequeued" | 
|  | 314 | " buffer count for stream %d", __FUNCTION__, mId); | 
|  | 315 | return res; | 
|  | 316 | } | 
|  | 317 |  | 
| Alex Ray | 20cb300 | 2013-05-28 20:18:22 -0700 | [diff] [blame] | 318 | ALOGV("%s: Consumer wants %d buffers, HAL wants %d", __FUNCTION__, | 
|  | 319 | maxConsumerBuffers, camera3_stream::max_buffers); | 
|  | 320 | if (camera3_stream::max_buffers == 0) { | 
| Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 321 | 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] | 322 | __FUNCTION__, camera3_stream::max_buffers); | 
|  | 323 | return INVALID_OPERATION; | 
|  | 324 | } | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 325 |  | 
|  | 326 | mTotalBufferCount = maxConsumerBuffers + camera3_stream::max_buffers; | 
|  | 327 | mDequeuedBufferCount = 0; | 
|  | 328 | mFrameCount = 0; | 
|  | 329 | mLastTimestamp = 0; | 
|  | 330 |  | 
|  | 331 | res = native_window_set_buffer_count(mConsumer.get(), | 
|  | 332 | mTotalBufferCount); | 
|  | 333 | if (res != OK) { | 
|  | 334 | ALOGE("%s: Unable to set buffer count for stream %d", | 
|  | 335 | __FUNCTION__, mId); | 
|  | 336 | return res; | 
|  | 337 | } | 
|  | 338 |  | 
|  | 339 | res = native_window_set_buffers_transform(mConsumer.get(), | 
|  | 340 | mTransform); | 
|  | 341 | if (res != OK) { | 
|  | 342 | ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", | 
|  | 343 | __FUNCTION__, mTransform, strerror(-res), res); | 
|  | 344 | } | 
|  | 345 |  | 
|  | 346 | return OK; | 
|  | 347 | } | 
|  | 348 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 349 | status_t Camera3OutputStream::disconnectLocked() { | 
|  | 350 | status_t res; | 
|  | 351 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 352 | if ((res = Camera3IOStreamBase::disconnectLocked()) != OK) { | 
|  | 353 | return res; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 354 | } | 
|  | 355 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 356 | res = native_window_api_disconnect(mConsumer.get(), | 
|  | 357 | NATIVE_WINDOW_API_CAMERA); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 358 |  | 
|  | 359 | /** | 
|  | 360 | * This is not an error. if client calling process dies, the window will | 
|  | 361 | * also die and all calls to it will return DEAD_OBJECT, thus it's already | 
|  | 362 | * "disconnected" | 
|  | 363 | */ | 
|  | 364 | if (res == DEAD_OBJECT) { | 
|  | 365 | ALOGW("%s: While disconnecting stream %d from native window, the" | 
|  | 366 | " native window died from under us", __FUNCTION__, mId); | 
|  | 367 | } | 
|  | 368 | else if (res != OK) { | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 369 | ALOGE("%s: Unable to disconnect stream %d from native window " | 
|  | 370 | "(error %d %s)", | 
|  | 371 | __FUNCTION__, mId, res, strerror(-res)); | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 372 | mState = STATE_ERROR; | 
|  | 373 | return res; | 
|  | 374 | } | 
|  | 375 |  | 
| Igor Murashkin | e3a9f96 | 2013-05-08 18:03:15 -0700 | [diff] [blame] | 376 | mState = (mState == STATE_IN_RECONFIG) ? STATE_IN_CONFIG | 
|  | 377 | : STATE_CONSTRUCTED; | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 378 | return OK; | 
|  | 379 | } | 
|  | 380 |  | 
| Eino-Ville Talvala | b2f5b19 | 2013-07-30 14:36:03 -0700 | [diff] [blame] | 381 | status_t Camera3OutputStream::getEndpointUsage(uint32_t *usage) { | 
|  | 382 |  | 
|  | 383 | status_t res; | 
|  | 384 | int32_t u = 0; | 
|  | 385 | res = mConsumer->query(mConsumer.get(), | 
|  | 386 | NATIVE_WINDOW_CONSUMER_USAGE_BITS, &u); | 
|  | 387 | *usage = u; | 
|  | 388 |  | 
|  | 389 | return res; | 
|  | 390 | } | 
|  | 391 |  | 
| Eino-Ville Talvala | fd58f1a | 2013-03-06 16:20:06 -0800 | [diff] [blame] | 392 | }; // namespace camera3 | 
|  | 393 |  | 
|  | 394 | }; // namespace android |