Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 17 | #define LOG_TAG "Camera2-Device" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 20 | //#define LOG_NNDEBUG 0 // Per-frame verbose logging |
| 21 | |
| 22 | #ifdef LOG_NNDEBUG |
| 23 | #define ALOGVV(...) ALOGV(__VA_ARGS__) |
| 24 | #else |
| 25 | #define ALOGVV(...) ((void)0) |
| 26 | #endif |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 27 | |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 28 | #include <inttypes.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 29 | #include <utils/Log.h> |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 30 | #include <utils/Trace.h> |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 31 | #include <utils/Timers.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 32 | #include "Camera2Device.h" |
Eino-Ville Talvala | f67e23e | 2014-07-23 17:17:59 -0700 | [diff] [blame^] | 33 | #include "CameraService.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 37 | Camera2Device::Camera2Device(int id): |
| 38 | mId(id), |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 39 | mHal2Device(NULL) |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 40 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 41 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 42 | ALOGV("%s: Created device for camera %d", __FUNCTION__, id); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | Camera2Device::~Camera2Device() |
| 46 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 47 | ATRACE_CALL(); |
Igor Murashkin | 8dcdb95 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 48 | ALOGV("%s: Tearing down for camera id %d", __FUNCTION__, mId); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 49 | disconnect(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 52 | int Camera2Device::getId() const { |
| 53 | return mId; |
| 54 | } |
| 55 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 56 | status_t Camera2Device::initialize(camera_module_t *module) |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 57 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 58 | ATRACE_CALL(); |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 59 | ALOGV("%s: Initializing device for camera %d", __FUNCTION__, mId); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 60 | if (mHal2Device != NULL) { |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 61 | ALOGE("%s: Already initialized!", __FUNCTION__); |
| 62 | return INVALID_OPERATION; |
| 63 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 64 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 65 | status_t res; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 66 | char name[10]; |
| 67 | snprintf(name, sizeof(name), "%d", mId); |
| 68 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 69 | camera2_device_t *device; |
| 70 | |
Eino-Ville Talvala | f67e23e | 2014-07-23 17:17:59 -0700 | [diff] [blame^] | 71 | res = CameraService::filterOpenErrorCode(module->common.methods->open( |
| 72 | &module->common, name, reinterpret_cast<hw_device_t**>(&device))); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 73 | |
| 74 | if (res != OK) { |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 75 | ALOGE("%s: Could not open camera %d: %s (%d)", __FUNCTION__, |
| 76 | mId, strerror(-res), res); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 77 | return res; |
| 78 | } |
| 79 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 80 | if (device->common.version != CAMERA_DEVICE_API_VERSION_2_0) { |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 81 | ALOGE("%s: Could not open camera %d: " |
| 82 | "Camera device is not version %x, reports %x instead", |
| 83 | __FUNCTION__, mId, CAMERA_DEVICE_API_VERSION_2_0, |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 84 | device->common.version); |
| 85 | device->common.close(&device->common); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 86 | return BAD_VALUE; |
| 87 | } |
| 88 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 89 | camera_info info; |
| 90 | res = module->get_camera_info(mId, &info); |
| 91 | if (res != OK ) return res; |
| 92 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 93 | if (info.device_version != device->common.version) { |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 94 | ALOGE("%s: HAL reporting mismatched camera_info version (%x)" |
| 95 | " and device version (%x).", __FUNCTION__, |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 96 | device->common.version, info.device_version); |
| 97 | device->common.close(&device->common); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 98 | return BAD_VALUE; |
| 99 | } |
| 100 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 101 | res = mRequestQueue.setConsumerDevice(device); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 102 | if (res != OK) { |
| 103 | ALOGE("%s: Camera %d: Unable to connect request queue to device: %s (%d)", |
| 104 | __FUNCTION__, mId, strerror(-res), res); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 105 | device->common.close(&device->common); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 106 | return res; |
| 107 | } |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 108 | res = mFrameQueue.setProducerDevice(device); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 109 | if (res != OK) { |
| 110 | ALOGE("%s: Camera %d: Unable to connect frame queue to device: %s (%d)", |
| 111 | __FUNCTION__, mId, strerror(-res), res); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 112 | device->common.close(&device->common); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 113 | return res; |
| 114 | } |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 115 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 116 | res = device->ops->set_notify_callback(device, notificationCallback, |
| 117 | NULL); |
| 118 | if (res != OK) { |
| 119 | ALOGE("%s: Camera %d: Unable to initialize notification callback!", |
| 120 | __FUNCTION__, mId); |
| 121 | device->common.close(&device->common); |
| 122 | return res; |
| 123 | } |
| 124 | |
| 125 | mDeviceInfo = info.static_camera_characteristics; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 126 | mHal2Device = device; |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 127 | mDeviceVersion = device->common.version; |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 128 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 129 | return OK; |
| 130 | } |
| 131 | |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 132 | status_t Camera2Device::disconnect() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 133 | ATRACE_CALL(); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 134 | status_t res = OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 135 | if (mHal2Device) { |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 136 | ALOGV("%s: Closing device for camera %d", __FUNCTION__, mId); |
| 137 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 138 | int inProgressCount = mHal2Device->ops->get_in_progress_count(mHal2Device); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 139 | if (inProgressCount > 0) { |
| 140 | ALOGW("%s: Closing camera device %d with %d requests in flight!", |
| 141 | __FUNCTION__, mId, inProgressCount); |
| 142 | } |
Eino-Ville Talvala | c62bb78 | 2012-09-24 13:44:07 -0700 | [diff] [blame] | 143 | mReprocessStreams.clear(); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 144 | mStreams.clear(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 145 | res = mHal2Device->common.close(&mHal2Device->common); |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 146 | if (res != OK) { |
| 147 | ALOGE("%s: Could not close camera %d: %s (%d)", |
| 148 | __FUNCTION__, |
| 149 | mId, strerror(-res), res); |
| 150 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 151 | mHal2Device = NULL; |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 152 | ALOGV("%s: Shutdown complete", __FUNCTION__); |
| 153 | } |
| 154 | return res; |
| 155 | } |
| 156 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 157 | status_t Camera2Device::dump(int fd, const Vector<String16>& args) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 158 | ATRACE_CALL(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 159 | String8 result; |
Eino-Ville Talvala | 9719715 | 2012-08-06 14:25:19 -0700 | [diff] [blame] | 160 | int detailLevel = 0; |
| 161 | int n = args.size(); |
| 162 | String16 detailOption("-d"); |
| 163 | for (int i = 0; i + 1 < n; i++) { |
| 164 | if (args[i] == detailOption) { |
| 165 | String8 levelStr(args[i+1]); |
| 166 | detailLevel = atoi(levelStr.string()); |
| 167 | } |
| 168 | } |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 169 | |
Eino-Ville Talvala | 603b12e | 2012-08-08 09:25:58 -0700 | [diff] [blame] | 170 | result.appendFormat(" Camera2Device[%d] dump (detail level %d):\n", |
| 171 | mId, detailLevel); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 172 | |
Eino-Ville Talvala | 9719715 | 2012-08-06 14:25:19 -0700 | [diff] [blame] | 173 | if (detailLevel > 0) { |
| 174 | result = " Request queue contents:\n"; |
| 175 | write(fd, result.string(), result.size()); |
| 176 | mRequestQueue.dump(fd, args); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 177 | |
Eino-Ville Talvala | 9719715 | 2012-08-06 14:25:19 -0700 | [diff] [blame] | 178 | result = " Frame queue contents:\n"; |
| 179 | write(fd, result.string(), result.size()); |
| 180 | mFrameQueue.dump(fd, args); |
| 181 | } |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 182 | |
| 183 | result = " Active streams:\n"; |
| 184 | write(fd, result.string(), result.size()); |
| 185 | for (StreamList::iterator s = mStreams.begin(); s != mStreams.end(); s++) { |
| 186 | (*s)->dump(fd, args); |
| 187 | } |
| 188 | |
| 189 | result = " HAL device dump:\n"; |
| 190 | write(fd, result.string(), result.size()); |
| 191 | |
| 192 | status_t res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 193 | res = mHal2Device->ops->dump(mHal2Device, fd); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 194 | |
| 195 | return res; |
| 196 | } |
| 197 | |
Igor Murashkin | bd02dd1 | 2013-02-13 15:53:56 -0800 | [diff] [blame] | 198 | const CameraMetadata& Camera2Device::info() const { |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 199 | ALOGVV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 200 | |
| 201 | return mDeviceInfo; |
| 202 | } |
| 203 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 204 | status_t Camera2Device::capture(CameraMetadata &request, int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 205 | ATRACE_CALL(); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 206 | ALOGV("%s: E", __FUNCTION__); |
| 207 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 208 | mRequestQueue.enqueue(request.release()); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 209 | return OK; |
| 210 | } |
| 211 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 212 | status_t Camera2Device::captureList(const List<const CameraMetadata> &requests, |
| 213 | int64_t* /*lastFrameNumber*/) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 214 | ATRACE_CALL(); |
| 215 | ALOGE("%s: Camera2Device burst capture not implemented", __FUNCTION__); |
| 216 | return INVALID_OPERATION; |
| 217 | } |
| 218 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 219 | status_t Camera2Device::setStreamingRequest(const CameraMetadata &request, |
| 220 | int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 221 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 222 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 223 | CameraMetadata streamRequest(request); |
| 224 | return mRequestQueue.setStreamSlot(streamRequest.release()); |
| 225 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 226 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 227 | status_t Camera2Device::setStreamingRequestList(const List<const CameraMetadata> &requests, |
| 228 | int64_t* /*lastFrameNumber*/) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 229 | ATRACE_CALL(); |
| 230 | ALOGE("%s, Camera2Device streaming burst not implemented", __FUNCTION__); |
| 231 | return INVALID_OPERATION; |
| 232 | } |
| 233 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 234 | status_t Camera2Device::clearStreamingRequest(int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 235 | ATRACE_CALL(); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 236 | return mRequestQueue.setStreamSlot(NULL); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 239 | status_t Camera2Device::waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) { |
| 240 | ATRACE_CALL(); |
| 241 | return mRequestQueue.waitForDequeue(requestId, timeout); |
| 242 | } |
| 243 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 244 | status_t Camera2Device::createStream(sp<ANativeWindow> consumer, |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 245 | uint32_t width, uint32_t height, int format, size_t size, int *id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 246 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 247 | status_t res; |
| 248 | ALOGV("%s: E", __FUNCTION__); |
| 249 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 250 | sp<StreamAdapter> stream = new StreamAdapter(mHal2Device); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 251 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 252 | res = stream->connectToDevice(consumer, width, height, format, size); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 253 | if (res != OK) { |
| 254 | ALOGE("%s: Camera %d: Unable to create stream (%d x %d, format %x):" |
| 255 | "%s (%d)", |
| 256 | __FUNCTION__, mId, width, height, format, strerror(-res), res); |
| 257 | return res; |
| 258 | } |
| 259 | |
| 260 | *id = stream->getId(); |
| 261 | |
| 262 | mStreams.push_back(stream); |
| 263 | return OK; |
| 264 | } |
| 265 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 266 | status_t Camera2Device::createReprocessStreamFromStream(int outputId, int *id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 267 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 268 | status_t res; |
| 269 | ALOGV("%s: E", __FUNCTION__); |
| 270 | |
| 271 | bool found = false; |
| 272 | StreamList::iterator streamI; |
| 273 | for (streamI = mStreams.begin(); |
| 274 | streamI != mStreams.end(); streamI++) { |
| 275 | if ((*streamI)->getId() == outputId) { |
| 276 | found = true; |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | if (!found) { |
| 281 | ALOGE("%s: Camera %d: Output stream %d doesn't exist; can't create " |
| 282 | "reprocess stream from it!", __FUNCTION__, mId, outputId); |
| 283 | return BAD_VALUE; |
| 284 | } |
| 285 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 286 | sp<ReprocessStreamAdapter> stream = new ReprocessStreamAdapter(mHal2Device); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 287 | |
| 288 | res = stream->connectToDevice((*streamI)); |
| 289 | if (res != OK) { |
| 290 | ALOGE("%s: Camera %d: Unable to create reprocessing stream from "\ |
| 291 | "stream %d: %s (%d)", __FUNCTION__, mId, outputId, |
| 292 | strerror(-res), res); |
| 293 | return res; |
| 294 | } |
| 295 | |
| 296 | *id = stream->getId(); |
| 297 | |
| 298 | mReprocessStreams.push_back(stream); |
| 299 | return OK; |
| 300 | } |
| 301 | |
| 302 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 303 | status_t Camera2Device::getStreamInfo(int id, |
| 304 | uint32_t *width, uint32_t *height, uint32_t *format) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 305 | ATRACE_CALL(); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 306 | ALOGV("%s: E", __FUNCTION__); |
| 307 | bool found = false; |
| 308 | StreamList::iterator streamI; |
| 309 | for (streamI = mStreams.begin(); |
| 310 | streamI != mStreams.end(); streamI++) { |
| 311 | if ((*streamI)->getId() == id) { |
| 312 | found = true; |
| 313 | break; |
| 314 | } |
| 315 | } |
| 316 | if (!found) { |
| 317 | ALOGE("%s: Camera %d: Stream %d does not exist", |
| 318 | __FUNCTION__, mId, id); |
| 319 | return BAD_VALUE; |
| 320 | } |
| 321 | |
| 322 | if (width) *width = (*streamI)->getWidth(); |
| 323 | if (height) *height = (*streamI)->getHeight(); |
| 324 | if (format) *format = (*streamI)->getFormat(); |
| 325 | |
| 326 | return OK; |
| 327 | } |
| 328 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 329 | status_t Camera2Device::setStreamTransform(int id, |
| 330 | int transform) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 331 | ATRACE_CALL(); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 332 | ALOGV("%s: E", __FUNCTION__); |
| 333 | bool found = false; |
| 334 | StreamList::iterator streamI; |
| 335 | for (streamI = mStreams.begin(); |
| 336 | streamI != mStreams.end(); streamI++) { |
| 337 | if ((*streamI)->getId() == id) { |
| 338 | found = true; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | if (!found) { |
| 343 | ALOGE("%s: Camera %d: Stream %d does not exist", |
| 344 | __FUNCTION__, mId, id); |
| 345 | return BAD_VALUE; |
| 346 | } |
| 347 | |
| 348 | return (*streamI)->setTransform(transform); |
| 349 | } |
| 350 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 351 | status_t Camera2Device::deleteStream(int id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 352 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 353 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 354 | bool found = false; |
| 355 | for (StreamList::iterator streamI = mStreams.begin(); |
| 356 | streamI != mStreams.end(); streamI++) { |
| 357 | if ((*streamI)->getId() == id) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 358 | status_t res = (*streamI)->release(); |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 359 | if (res != OK) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 360 | ALOGE("%s: Unable to release stream %d from HAL device: " |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 361 | "%s (%d)", __FUNCTION__, id, strerror(-res), res); |
| 362 | return res; |
| 363 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 364 | mStreams.erase(streamI); |
| 365 | found = true; |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | if (!found) { |
| 370 | ALOGE("%s: Camera %d: Unable to find stream %d to delete", |
| 371 | __FUNCTION__, mId, id); |
| 372 | return BAD_VALUE; |
| 373 | } |
| 374 | return OK; |
| 375 | } |
| 376 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 377 | status_t Camera2Device::deleteReprocessStream(int id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 378 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 379 | ALOGV("%s: E", __FUNCTION__); |
| 380 | bool found = false; |
| 381 | for (ReprocessStreamList::iterator streamI = mReprocessStreams.begin(); |
| 382 | streamI != mReprocessStreams.end(); streamI++) { |
| 383 | if ((*streamI)->getId() == id) { |
| 384 | status_t res = (*streamI)->release(); |
| 385 | if (res != OK) { |
| 386 | ALOGE("%s: Unable to release reprocess stream %d from " |
| 387 | "HAL device: %s (%d)", __FUNCTION__, id, |
| 388 | strerror(-res), res); |
| 389 | return res; |
| 390 | } |
| 391 | mReprocessStreams.erase(streamI); |
| 392 | found = true; |
| 393 | break; |
| 394 | } |
| 395 | } |
| 396 | if (!found) { |
| 397 | ALOGE("%s: Camera %d: Unable to find stream %d to delete", |
| 398 | __FUNCTION__, mId, id); |
| 399 | return BAD_VALUE; |
| 400 | } |
| 401 | return OK; |
| 402 | } |
| 403 | |
| 404 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 405 | status_t Camera2Device::createDefaultRequest(int templateId, |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 406 | CameraMetadata *request) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 407 | ATRACE_CALL(); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 408 | status_t err; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 409 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 410 | camera_metadata_t *rawRequest; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 411 | err = mHal2Device->ops->construct_default_request( |
| 412 | mHal2Device, templateId, &rawRequest); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 413 | request->acquire(rawRequest); |
| 414 | return err; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | status_t Camera2Device::waitUntilDrained() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 418 | ATRACE_CALL(); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 419 | static const uint32_t kSleepTime = 50000; // 50 ms |
| 420 | static const uint32_t kMaxSleepTime = 10000000; // 10 s |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 421 | ALOGV("%s: Camera %d: Starting wait", __FUNCTION__, mId); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 422 | if (mRequestQueue.getBufferCount() == |
| 423 | CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS) return INVALID_OPERATION; |
| 424 | |
| 425 | // TODO: Set up notifications from HAL, instead of sleeping here |
| 426 | uint32_t totalTime = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 427 | while (mHal2Device->ops->get_in_progress_count(mHal2Device) > 0) { |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 428 | usleep(kSleepTime); |
| 429 | totalTime += kSleepTime; |
| 430 | if (totalTime > kMaxSleepTime) { |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 431 | ALOGE("%s: Waited %d us, %d requests still in flight", __FUNCTION__, |
Alex Ray | f0eeb53 | 2013-03-17 03:23:18 -0700 | [diff] [blame] | 432 | totalTime, mHal2Device->ops->get_in_progress_count(mHal2Device)); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 433 | return TIMED_OUT; |
| 434 | } |
| 435 | } |
Eino-Ville Talvala | 7adb52f | 2012-09-20 14:44:20 -0700 | [diff] [blame] | 436 | ALOGV("%s: Camera %d: HAL is idle", __FUNCTION__, mId); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 437 | return OK; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 440 | status_t Camera2Device::setNotifyCallback(NotificationListener *listener) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 441 | ATRACE_CALL(); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 442 | status_t res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 443 | res = mHal2Device->ops->set_notify_callback(mHal2Device, notificationCallback, |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 444 | reinterpret_cast<void*>(listener) ); |
| 445 | if (res != OK) { |
| 446 | ALOGE("%s: Unable to set notification callback!", __FUNCTION__); |
| 447 | } |
| 448 | return res; |
| 449 | } |
| 450 | |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 451 | bool Camera2Device::willNotify3A() { |
| 452 | return true; |
| 453 | } |
| 454 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 455 | void Camera2Device::notificationCallback(int32_t msg_type, |
| 456 | int32_t ext1, |
| 457 | int32_t ext2, |
| 458 | int32_t ext3, |
| 459 | void *user) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 460 | ATRACE_CALL(); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 461 | NotificationListener *listener = reinterpret_cast<NotificationListener*>(user); |
| 462 | ALOGV("%s: Notification %d, arguments %d, %d, %d", __FUNCTION__, msg_type, |
| 463 | ext1, ext2, ext3); |
| 464 | if (listener != NULL) { |
| 465 | switch (msg_type) { |
| 466 | case CAMERA2_MSG_ERROR: |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 467 | // TODO: This needs to be fixed. ext2 and ext3 need to be considered. |
| 468 | listener->notifyError( |
| 469 | ((ext1 == CAMERA2_MSG_ERROR_DEVICE) |
| 470 | || (ext1 == CAMERA2_MSG_ERROR_HARDWARE)) ? |
| 471 | ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE : |
| 472 | ICameraDeviceCallbacks::ERROR_CAMERA_SERVICE, |
| 473 | CaptureResultExtras()); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 474 | break; |
| 475 | case CAMERA2_MSG_SHUTTER: { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 476 | // TODO: Only needed for camera2 API, which is unsupported |
| 477 | // by HAL2 directly. |
| 478 | // nsecs_t timestamp = (nsecs_t)ext2 | ((nsecs_t)(ext3) << 32 ); |
| 479 | // listener->notifyShutter(requestId, timestamp); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | case CAMERA2_MSG_AUTOFOCUS: |
| 483 | listener->notifyAutoFocus(ext1, ext2); |
| 484 | break; |
| 485 | case CAMERA2_MSG_AUTOEXPOSURE: |
| 486 | listener->notifyAutoExposure(ext1, ext2); |
| 487 | break; |
| 488 | case CAMERA2_MSG_AUTOWB: |
| 489 | listener->notifyAutoWhitebalance(ext1, ext2); |
| 490 | break; |
| 491 | default: |
| 492 | ALOGE("%s: Unknown notification %d (arguments %d, %d, %d)!", |
| 493 | __FUNCTION__, msg_type, ext1, ext2, ext3); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 498 | status_t Camera2Device::waitForNextFrame(nsecs_t timeout) { |
| 499 | return mFrameQueue.waitForBuffer(timeout); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 502 | status_t Camera2Device::getNextResult(CaptureResult *result) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 503 | ATRACE_CALL(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 504 | ALOGV("%s: get CaptureResult", __FUNCTION__); |
| 505 | if (result == NULL) { |
| 506 | ALOGE("%s: result pointer is NULL", __FUNCTION__); |
| 507 | return BAD_VALUE; |
| 508 | } |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 509 | status_t res; |
| 510 | camera_metadata_t *rawFrame; |
| 511 | res = mFrameQueue.dequeue(&rawFrame); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 512 | if (rawFrame == NULL) { |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 513 | return NOT_ENOUGH_DATA; |
| 514 | } else if (res == OK) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 515 | result->mMetadata.acquire(rawFrame); |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 516 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 517 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 518 | return res; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 521 | status_t Camera2Device::triggerAutofocus(uint32_t id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 522 | ATRACE_CALL(); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 523 | status_t res; |
| 524 | ALOGV("%s: Triggering autofocus, id %d", __FUNCTION__, id); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 525 | res = mHal2Device->ops->trigger_action(mHal2Device, |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 526 | CAMERA2_TRIGGER_AUTOFOCUS, id, 0); |
| 527 | if (res != OK) { |
| 528 | ALOGE("%s: Error triggering autofocus (id %d)", |
| 529 | __FUNCTION__, id); |
| 530 | } |
| 531 | return res; |
| 532 | } |
| 533 | |
| 534 | status_t Camera2Device::triggerCancelAutofocus(uint32_t id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 535 | ATRACE_CALL(); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 536 | status_t res; |
| 537 | ALOGV("%s: Canceling autofocus, id %d", __FUNCTION__, id); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 538 | res = mHal2Device->ops->trigger_action(mHal2Device, |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 539 | CAMERA2_TRIGGER_CANCEL_AUTOFOCUS, id, 0); |
| 540 | if (res != OK) { |
| 541 | ALOGE("%s: Error canceling autofocus (id %d)", |
| 542 | __FUNCTION__, id); |
| 543 | } |
| 544 | return res; |
| 545 | } |
| 546 | |
| 547 | status_t Camera2Device::triggerPrecaptureMetering(uint32_t id) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 548 | ATRACE_CALL(); |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 549 | status_t res; |
| 550 | ALOGV("%s: Triggering precapture metering, id %d", __FUNCTION__, id); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 551 | res = mHal2Device->ops->trigger_action(mHal2Device, |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 552 | CAMERA2_TRIGGER_PRECAPTURE_METERING, id, 0); |
| 553 | if (res != OK) { |
| 554 | ALOGE("%s: Error triggering precapture metering (id %d)", |
| 555 | __FUNCTION__, id); |
| 556 | } |
| 557 | return res; |
| 558 | } |
| 559 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 560 | status_t Camera2Device::pushReprocessBuffer(int reprocessStreamId, |
| 561 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 562 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 563 | ALOGV("%s: E", __FUNCTION__); |
| 564 | bool found = false; |
| 565 | status_t res = OK; |
| 566 | for (ReprocessStreamList::iterator streamI = mReprocessStreams.begin(); |
| 567 | streamI != mReprocessStreams.end(); streamI++) { |
| 568 | if ((*streamI)->getId() == reprocessStreamId) { |
| 569 | res = (*streamI)->pushIntoStream(buffer, listener); |
| 570 | if (res != OK) { |
| 571 | ALOGE("%s: Unable to push buffer to reprocess stream %d: %s (%d)", |
| 572 | __FUNCTION__, reprocessStreamId, strerror(-res), res); |
| 573 | return res; |
| 574 | } |
| 575 | found = true; |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | if (!found) { |
| 580 | ALOGE("%s: Camera %d: Unable to find reprocess stream %d", |
| 581 | __FUNCTION__, mId, reprocessStreamId); |
| 582 | res = BAD_VALUE; |
| 583 | } |
| 584 | return res; |
| 585 | } |
| 586 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 587 | status_t Camera2Device::flush(int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 588 | ATRACE_CALL(); |
| 589 | |
| 590 | mRequestQueue.clear(); |
| 591 | return waitUntilDrained(); |
| 592 | } |
| 593 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 594 | uint32_t Camera2Device::getDeviceVersion() { |
| 595 | ATRACE_CALL(); |
| 596 | return mDeviceVersion; |
| 597 | } |
| 598 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 599 | /** |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 600 | * Camera2Device::MetadataQueue |
| 601 | */ |
| 602 | |
| 603 | Camera2Device::MetadataQueue::MetadataQueue(): |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 604 | mHal2Device(NULL), |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 605 | mFrameCount(0), |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 606 | mLatestRequestId(0), |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 607 | mCount(0), |
| 608 | mStreamSlotCount(0), |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame] | 609 | mSignalConsumer(true) |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 610 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 611 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 612 | camera2_request_queue_src_ops::dequeue_request = consumer_dequeue; |
| 613 | camera2_request_queue_src_ops::request_count = consumer_buffer_count; |
| 614 | camera2_request_queue_src_ops::free_request = consumer_free; |
| 615 | |
| 616 | camera2_frame_queue_dst_ops::dequeue_frame = producer_dequeue; |
| 617 | camera2_frame_queue_dst_ops::cancel_frame = producer_cancel; |
| 618 | camera2_frame_queue_dst_ops::enqueue_frame = producer_enqueue; |
| 619 | } |
| 620 | |
| 621 | Camera2Device::MetadataQueue::~MetadataQueue() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 622 | ATRACE_CALL(); |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 623 | clear(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 626 | // Connect to camera2 HAL as consumer (input requests/reprocessing) |
| 627 | status_t Camera2Device::MetadataQueue::setConsumerDevice(camera2_device_t *d) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 628 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 629 | status_t res; |
| 630 | res = d->ops->set_request_queue_src_ops(d, |
| 631 | this); |
| 632 | if (res != OK) return res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 633 | mHal2Device = d; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 634 | return OK; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 637 | status_t Camera2Device::MetadataQueue::setProducerDevice(camera2_device_t *d) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 638 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 639 | status_t res; |
| 640 | res = d->ops->set_frame_queue_dst_ops(d, |
| 641 | this); |
| 642 | return res; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | // Real interfaces |
| 646 | status_t Camera2Device::MetadataQueue::enqueue(camera_metadata_t *buf) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 647 | ATRACE_CALL(); |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 648 | ALOGVV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 649 | Mutex::Autolock l(mMutex); |
| 650 | |
| 651 | mCount++; |
| 652 | mEntries.push_back(buf); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 653 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 654 | return signalConsumerLocked(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | int Camera2Device::MetadataQueue::getBufferCount() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 658 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 659 | Mutex::Autolock l(mMutex); |
| 660 | if (mStreamSlotCount > 0) { |
| 661 | return CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS; |
| 662 | } |
| 663 | return mCount; |
| 664 | } |
| 665 | |
| 666 | status_t Camera2Device::MetadataQueue::dequeue(camera_metadata_t **buf, |
| 667 | bool incrementCount) |
| 668 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 669 | ATRACE_CALL(); |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 670 | ALOGVV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 671 | status_t res; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 672 | Mutex::Autolock l(mMutex); |
| 673 | |
| 674 | if (mCount == 0) { |
| 675 | if (mStreamSlotCount == 0) { |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 676 | ALOGVV("%s: Empty", __FUNCTION__); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 677 | *buf = NULL; |
| 678 | mSignalConsumer = true; |
| 679 | return OK; |
| 680 | } |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 681 | ALOGVV("%s: Streaming %d frames to queue", __FUNCTION__, |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 682 | mStreamSlotCount); |
| 683 | |
| 684 | for (List<camera_metadata_t*>::iterator slotEntry = mStreamSlot.begin(); |
| 685 | slotEntry != mStreamSlot.end(); |
| 686 | slotEntry++ ) { |
| 687 | size_t entries = get_camera_metadata_entry_count(*slotEntry); |
| 688 | size_t dataBytes = get_camera_metadata_data_count(*slotEntry); |
| 689 | |
| 690 | camera_metadata_t *copy = |
| 691 | allocate_camera_metadata(entries, dataBytes); |
| 692 | append_camera_metadata(copy, *slotEntry); |
| 693 | mEntries.push_back(copy); |
| 694 | } |
| 695 | mCount = mStreamSlotCount; |
| 696 | } |
Eino-Ville Talvala | 2c08dc6 | 2012-06-15 12:49:21 -0700 | [diff] [blame] | 697 | ALOGVV("MetadataQueue: deque (%d buffers)", mCount); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 698 | camera_metadata_t *b = *(mEntries.begin()); |
| 699 | mEntries.erase(mEntries.begin()); |
| 700 | |
| 701 | if (incrementCount) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 702 | ATRACE_INT("cam2_request", mFrameCount); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 703 | camera_metadata_entry_t frameCount; |
| 704 | res = find_camera_metadata_entry(b, |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 705 | ANDROID_REQUEST_FRAME_COUNT, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 706 | &frameCount); |
| 707 | if (res != OK) { |
| 708 | ALOGE("%s: Unable to add frame count: %s (%d)", |
| 709 | __FUNCTION__, strerror(-res), res); |
| 710 | } else { |
| 711 | *frameCount.data.i32 = mFrameCount; |
| 712 | } |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 713 | mFrameCount++; |
| 714 | } |
| 715 | |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 716 | // Check for request ID, and if present, signal waiters. |
| 717 | camera_metadata_entry_t requestId; |
| 718 | res = find_camera_metadata_entry(b, |
| 719 | ANDROID_REQUEST_ID, |
| 720 | &requestId); |
| 721 | if (res == OK) { |
| 722 | mLatestRequestId = requestId.data.i32[0]; |
| 723 | mNewRequestId.signal(); |
| 724 | } |
| 725 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 726 | *buf = b; |
| 727 | mCount--; |
| 728 | |
| 729 | return OK; |
| 730 | } |
| 731 | |
| 732 | status_t Camera2Device::MetadataQueue::waitForBuffer(nsecs_t timeout) |
| 733 | { |
| 734 | Mutex::Autolock l(mMutex); |
| 735 | status_t res; |
| 736 | while (mCount == 0) { |
| 737 | res = notEmpty.waitRelative(mMutex,timeout); |
| 738 | if (res != OK) return res; |
| 739 | } |
| 740 | return OK; |
| 741 | } |
| 742 | |
Eino-Ville Talvala | 4c9eb71 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 743 | status_t Camera2Device::MetadataQueue::waitForDequeue(int32_t id, |
| 744 | nsecs_t timeout) { |
| 745 | Mutex::Autolock l(mMutex); |
| 746 | status_t res; |
| 747 | while (mLatestRequestId != id) { |
| 748 | nsecs_t startTime = systemTime(); |
| 749 | |
| 750 | res = mNewRequestId.waitRelative(mMutex, timeout); |
| 751 | if (res != OK) return res; |
| 752 | |
| 753 | timeout -= (systemTime() - startTime); |
| 754 | } |
| 755 | |
| 756 | return OK; |
| 757 | } |
| 758 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 759 | status_t Camera2Device::MetadataQueue::setStreamSlot(camera_metadata_t *buf) |
| 760 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 761 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 762 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 763 | Mutex::Autolock l(mMutex); |
| 764 | if (buf == NULL) { |
| 765 | freeBuffers(mStreamSlot.begin(), mStreamSlot.end()); |
| 766 | mStreamSlotCount = 0; |
| 767 | return OK; |
| 768 | } |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 769 | camera_metadata_t *buf2 = clone_camera_metadata(buf); |
| 770 | if (!buf2) { |
| 771 | ALOGE("%s: Unable to clone metadata buffer!", __FUNCTION__); |
| 772 | return NO_MEMORY; |
| 773 | } |
| 774 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 775 | if (mStreamSlotCount > 1) { |
| 776 | List<camera_metadata_t*>::iterator deleter = ++mStreamSlot.begin(); |
| 777 | freeBuffers(++mStreamSlot.begin(), mStreamSlot.end()); |
| 778 | mStreamSlotCount = 1; |
| 779 | } |
| 780 | if (mStreamSlotCount == 1) { |
| 781 | free_camera_metadata( *(mStreamSlot.begin()) ); |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 782 | *(mStreamSlot.begin()) = buf2; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 783 | } else { |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 784 | mStreamSlot.push_front(buf2); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 785 | mStreamSlotCount = 1; |
| 786 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 787 | return signalConsumerLocked(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | status_t Camera2Device::MetadataQueue::setStreamSlot( |
| 791 | const List<camera_metadata_t*> &bufs) |
| 792 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 793 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 794 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 795 | Mutex::Autolock l(mMutex); |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 796 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 797 | if (mStreamSlotCount > 0) { |
| 798 | freeBuffers(mStreamSlot.begin(), mStreamSlot.end()); |
| 799 | } |
Eino-Ville Talvala | 6ed1ed1 | 2012-06-07 10:46:38 -0700 | [diff] [blame] | 800 | mStreamSlotCount = 0; |
| 801 | for (List<camera_metadata_t*>::const_iterator r = bufs.begin(); |
| 802 | r != bufs.end(); r++) { |
| 803 | camera_metadata_t *r2 = clone_camera_metadata(*r); |
| 804 | if (!r2) { |
| 805 | ALOGE("%s: Unable to clone metadata buffer!", __FUNCTION__); |
| 806 | return NO_MEMORY; |
| 807 | } |
| 808 | mStreamSlot.push_back(r2); |
| 809 | mStreamSlotCount++; |
| 810 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 811 | return signalConsumerLocked(); |
| 812 | } |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 813 | |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 814 | status_t Camera2Device::MetadataQueue::clear() |
| 815 | { |
| 816 | ATRACE_CALL(); |
| 817 | ALOGV("%s: E", __FUNCTION__); |
| 818 | |
| 819 | Mutex::Autolock l(mMutex); |
| 820 | |
| 821 | // Clear streaming slot |
| 822 | freeBuffers(mStreamSlot.begin(), mStreamSlot.end()); |
| 823 | mStreamSlotCount = 0; |
| 824 | |
| 825 | // Clear request queue |
| 826 | freeBuffers(mEntries.begin(), mEntries.end()); |
| 827 | mCount = 0; |
| 828 | return OK; |
| 829 | } |
| 830 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 831 | status_t Camera2Device::MetadataQueue::dump(int fd, |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 832 | const Vector<String16>& /*args*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 833 | ATRACE_CALL(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 834 | String8 result; |
| 835 | status_t notLocked; |
| 836 | notLocked = mMutex.tryLock(); |
| 837 | if (notLocked) { |
| 838 | result.append(" (Unable to lock queue mutex)\n"); |
| 839 | } |
| 840 | result.appendFormat(" Current frame number: %d\n", mFrameCount); |
| 841 | if (mStreamSlotCount == 0) { |
| 842 | result.append(" Stream slot: Empty\n"); |
| 843 | write(fd, result.string(), result.size()); |
| 844 | } else { |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 845 | result.appendFormat(" Stream slot: %zu entries\n", |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 846 | mStreamSlot.size()); |
| 847 | int i = 0; |
| 848 | for (List<camera_metadata_t*>::iterator r = mStreamSlot.begin(); |
| 849 | r != mStreamSlot.end(); r++) { |
| 850 | result = String8::format(" Stream slot buffer %d:\n", i); |
| 851 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 852 | dump_indented_camera_metadata(*r, fd, 2, 10); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 853 | i++; |
| 854 | } |
| 855 | } |
| 856 | if (mEntries.size() == 0) { |
| 857 | result = " Main queue is empty\n"; |
| 858 | write(fd, result.string(), result.size()); |
| 859 | } else { |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 860 | result = String8::format(" Main queue has %zu entries:\n", |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 861 | mEntries.size()); |
| 862 | int i = 0; |
| 863 | for (List<camera_metadata_t*>::iterator r = mEntries.begin(); |
| 864 | r != mEntries.end(); r++) { |
| 865 | result = String8::format(" Queue entry %d:\n", i); |
| 866 | write(fd, result.string(), result.size()); |
Eino-Ville Talvala | 428b77a | 2012-07-30 09:55:30 -0700 | [diff] [blame] | 867 | dump_indented_camera_metadata(*r, fd, 2, 10); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 868 | i++; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | if (notLocked == 0) { |
| 873 | mMutex.unlock(); |
| 874 | } |
| 875 | |
| 876 | return OK; |
| 877 | } |
| 878 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 879 | status_t Camera2Device::MetadataQueue::signalConsumerLocked() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 880 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 881 | status_t res = OK; |
| 882 | notEmpty.signal(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 883 | if (mSignalConsumer && mHal2Device != NULL) { |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 884 | mSignalConsumer = false; |
| 885 | |
| 886 | mMutex.unlock(); |
| 887 | ALOGV("%s: Signaling consumer", __FUNCTION__); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 888 | res = mHal2Device->ops->notify_request_queue_not_empty(mHal2Device); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 889 | mMutex.lock(); |
| 890 | } |
| 891 | return res; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | status_t Camera2Device::MetadataQueue::freeBuffers( |
| 895 | List<camera_metadata_t*>::iterator start, |
| 896 | List<camera_metadata_t*>::iterator end) |
| 897 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 898 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 899 | while (start != end) { |
| 900 | free_camera_metadata(*start); |
| 901 | start = mStreamSlot.erase(start); |
| 902 | } |
| 903 | return OK; |
| 904 | } |
| 905 | |
| 906 | Camera2Device::MetadataQueue* Camera2Device::MetadataQueue::getInstance( |
| 907 | const camera2_request_queue_src_ops_t *q) |
| 908 | { |
| 909 | const MetadataQueue* cmq = static_cast<const MetadataQueue*>(q); |
| 910 | return const_cast<MetadataQueue*>(cmq); |
| 911 | } |
| 912 | |
| 913 | Camera2Device::MetadataQueue* Camera2Device::MetadataQueue::getInstance( |
| 914 | const camera2_frame_queue_dst_ops_t *q) |
| 915 | { |
| 916 | const MetadataQueue* cmq = static_cast<const MetadataQueue*>(q); |
| 917 | return const_cast<MetadataQueue*>(cmq); |
| 918 | } |
| 919 | |
| 920 | int Camera2Device::MetadataQueue::consumer_buffer_count( |
| 921 | const camera2_request_queue_src_ops_t *q) |
| 922 | { |
| 923 | MetadataQueue *queue = getInstance(q); |
| 924 | return queue->getBufferCount(); |
| 925 | } |
| 926 | |
| 927 | int Camera2Device::MetadataQueue::consumer_dequeue( |
| 928 | const camera2_request_queue_src_ops_t *q, |
| 929 | camera_metadata_t **buffer) |
| 930 | { |
| 931 | MetadataQueue *queue = getInstance(q); |
| 932 | return queue->dequeue(buffer, true); |
| 933 | } |
| 934 | |
| 935 | int Camera2Device::MetadataQueue::consumer_free( |
| 936 | const camera2_request_queue_src_ops_t *q, |
| 937 | camera_metadata_t *old_buffer) |
| 938 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 939 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 940 | MetadataQueue *queue = getInstance(q); |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 941 | (void)queue; |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 942 | free_camera_metadata(old_buffer); |
| 943 | return OK; |
| 944 | } |
| 945 | |
| 946 | int Camera2Device::MetadataQueue::producer_dequeue( |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 947 | const camera2_frame_queue_dst_ops_t * /*q*/, |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 948 | size_t entries, size_t bytes, |
| 949 | camera_metadata_t **buffer) |
| 950 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 951 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 952 | camera_metadata_t *new_buffer = |
| 953 | allocate_camera_metadata(entries, bytes); |
| 954 | if (new_buffer == NULL) return NO_MEMORY; |
| 955 | *buffer = new_buffer; |
| 956 | return OK; |
| 957 | } |
| 958 | |
| 959 | int Camera2Device::MetadataQueue::producer_cancel( |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 960 | const camera2_frame_queue_dst_ops_t * /*q*/, |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 961 | camera_metadata_t *old_buffer) |
| 962 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 963 | ATRACE_CALL(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 964 | free_camera_metadata(old_buffer); |
| 965 | return OK; |
| 966 | } |
| 967 | |
| 968 | int Camera2Device::MetadataQueue::producer_enqueue( |
| 969 | const camera2_frame_queue_dst_ops_t *q, |
| 970 | camera_metadata_t *filled_buffer) |
| 971 | { |
| 972 | MetadataQueue *queue = getInstance(q); |
| 973 | return queue->enqueue(filled_buffer); |
| 974 | } |
| 975 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 976 | /** |
| 977 | * Camera2Device::StreamAdapter |
| 978 | */ |
| 979 | |
| 980 | #ifndef container_of |
| 981 | #define container_of(ptr, type, member) \ |
| 982 | (type *)((char*)(ptr) - offsetof(type, member)) |
| 983 | #endif |
| 984 | |
| 985 | Camera2Device::StreamAdapter::StreamAdapter(camera2_device_t *d): |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 986 | mState(RELEASED), |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 987 | mHal2Device(d), |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 988 | mId(-1), |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 989 | mWidth(0), mHeight(0), mFormat(0), mSize(0), mUsage(0), |
| 990 | mMaxProducerBuffers(0), mMaxConsumerBuffers(0), |
| 991 | mTotalBuffers(0), |
| 992 | mFormatRequested(0), |
| 993 | mActiveBuffers(0), |
| 994 | mFrameCount(0), |
| 995 | mLastTimestamp(0) |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 996 | { |
| 997 | camera2_stream_ops::dequeue_buffer = dequeue_buffer; |
| 998 | camera2_stream_ops::enqueue_buffer = enqueue_buffer; |
| 999 | camera2_stream_ops::cancel_buffer = cancel_buffer; |
| 1000 | camera2_stream_ops::set_crop = set_crop; |
| 1001 | } |
| 1002 | |
| 1003 | Camera2Device::StreamAdapter::~StreamAdapter() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1004 | ATRACE_CALL(); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1005 | if (mState != RELEASED) { |
| 1006 | release(); |
| 1007 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1010 | status_t Camera2Device::StreamAdapter::connectToDevice( |
| 1011 | sp<ANativeWindow> consumer, |
| 1012 | uint32_t width, uint32_t height, int format, size_t size) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1013 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1014 | status_t res; |
Eino-Ville Talvala | 9e4c3db | 2012-07-20 11:07:52 -0700 | [diff] [blame] | 1015 | ALOGV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1016 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1017 | if (mState != RELEASED) return INVALID_OPERATION; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1018 | if (consumer == NULL) { |
| 1019 | ALOGE("%s: Null consumer passed to stream adapter", __FUNCTION__); |
| 1020 | return BAD_VALUE; |
| 1021 | } |
| 1022 | |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1023 | ALOGV("%s: New stream parameters %d x %d, format 0x%x, size %zu", |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1024 | __FUNCTION__, width, height, format, size); |
| 1025 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1026 | mConsumerInterface = consumer; |
| 1027 | mWidth = width; |
| 1028 | mHeight = height; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1029 | mSize = (format == HAL_PIXEL_FORMAT_BLOB) ? size : 0; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1030 | mFormatRequested = format; |
| 1031 | |
| 1032 | // Allocate device-side stream interface |
| 1033 | |
| 1034 | uint32_t id; |
| 1035 | uint32_t formatActual; |
| 1036 | uint32_t usage; |
| 1037 | uint32_t maxBuffers = 2; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1038 | res = mHal2Device->ops->allocate_stream(mHal2Device, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1039 | mWidth, mHeight, mFormatRequested, getStreamOps(), |
| 1040 | &id, &formatActual, &usage, &maxBuffers); |
| 1041 | if (res != OK) { |
| 1042 | ALOGE("%s: Device stream allocation failed: %s (%d)", |
| 1043 | __FUNCTION__, strerror(-res), res); |
| 1044 | return res; |
| 1045 | } |
| 1046 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1047 | ALOGV("%s: Allocated stream id %d, actual format 0x%x, " |
| 1048 | "usage 0x%x, producer wants %d buffers", __FUNCTION__, |
| 1049 | id, formatActual, usage, maxBuffers); |
| 1050 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1051 | mId = id; |
| 1052 | mFormat = formatActual; |
| 1053 | mUsage = usage; |
| 1054 | mMaxProducerBuffers = maxBuffers; |
| 1055 | |
| 1056 | mState = ALLOCATED; |
| 1057 | |
| 1058 | // Configure consumer-side ANativeWindow interface |
| 1059 | res = native_window_api_connect(mConsumerInterface.get(), |
| 1060 | NATIVE_WINDOW_API_CAMERA); |
| 1061 | if (res != OK) { |
| 1062 | ALOGE("%s: Unable to connect to native window for stream %d", |
| 1063 | __FUNCTION__, mId); |
| 1064 | |
| 1065 | return res; |
| 1066 | } |
| 1067 | |
| 1068 | mState = CONNECTED; |
| 1069 | |
| 1070 | res = native_window_set_usage(mConsumerInterface.get(), mUsage); |
| 1071 | if (res != OK) { |
| 1072 | ALOGE("%s: Unable to configure usage %08x for stream %d", |
| 1073 | __FUNCTION__, mUsage, mId); |
| 1074 | return res; |
| 1075 | } |
| 1076 | |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1077 | res = native_window_set_scaling_mode(mConsumerInterface.get(), |
| 1078 | NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW); |
| 1079 | if (res != OK) { |
| 1080 | ALOGE("%s: Unable to configure stream scaling: %s (%d)", |
| 1081 | __FUNCTION__, strerror(-res), res); |
| 1082 | return res; |
| 1083 | } |
| 1084 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1085 | res = setTransform(0); |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1086 | if (res != OK) { |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1087 | return res; |
| 1088 | } |
| 1089 | |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1090 | if (mFormat == HAL_PIXEL_FORMAT_BLOB) { |
| 1091 | res = native_window_set_buffers_geometry(mConsumerInterface.get(), |
| 1092 | mSize, 1, mFormat); |
| 1093 | if (res != OK) { |
| 1094 | ALOGE("%s: Unable to configure compressed stream buffer geometry" |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1095 | " %d x %d, size %zu for stream %d", |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 1096 | __FUNCTION__, mWidth, mHeight, mSize, mId); |
| 1097 | return res; |
| 1098 | } |
| 1099 | } else { |
| 1100 | res = native_window_set_buffers_geometry(mConsumerInterface.get(), |
| 1101 | mWidth, mHeight, mFormat); |
| 1102 | if (res != OK) { |
| 1103 | ALOGE("%s: Unable to configure stream buffer geometry" |
| 1104 | " %d x %d, format 0x%x for stream %d", |
| 1105 | __FUNCTION__, mWidth, mHeight, mFormat, mId); |
| 1106 | return res; |
| 1107 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | int maxConsumerBuffers; |
| 1111 | res = mConsumerInterface->query(mConsumerInterface.get(), |
| 1112 | NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &maxConsumerBuffers); |
| 1113 | if (res != OK) { |
| 1114 | ALOGE("%s: Unable to query consumer undequeued" |
| 1115 | " buffer count for stream %d", __FUNCTION__, mId); |
| 1116 | return res; |
| 1117 | } |
| 1118 | mMaxConsumerBuffers = maxConsumerBuffers; |
| 1119 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1120 | ALOGV("%s: Consumer wants %d buffers", __FUNCTION__, |
| 1121 | mMaxConsumerBuffers); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1122 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1123 | mTotalBuffers = mMaxConsumerBuffers + mMaxProducerBuffers; |
| 1124 | mActiveBuffers = 0; |
| 1125 | mFrameCount = 0; |
| 1126 | mLastTimestamp = 0; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1127 | |
| 1128 | res = native_window_set_buffer_count(mConsumerInterface.get(), |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1129 | mTotalBuffers); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1130 | if (res != OK) { |
| 1131 | ALOGE("%s: Unable to set buffer count for stream %d", |
| 1132 | __FUNCTION__, mId); |
| 1133 | return res; |
| 1134 | } |
| 1135 | |
| 1136 | // Register allocated buffers with HAL device |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1137 | buffer_handle_t *buffers = new buffer_handle_t[mTotalBuffers]; |
| 1138 | ANativeWindowBuffer **anwBuffers = new ANativeWindowBuffer*[mTotalBuffers]; |
| 1139 | uint32_t bufferIdx = 0; |
| 1140 | for (; bufferIdx < mTotalBuffers; bufferIdx++) { |
Jamie Gennis | 1e5b2b3 | 2012-06-13 16:29:51 -0700 | [diff] [blame] | 1141 | res = native_window_dequeue_buffer_and_wait(mConsumerInterface.get(), |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1142 | &anwBuffers[bufferIdx]); |
| 1143 | if (res != OK) { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1144 | ALOGE("%s: Unable to dequeue buffer %d for initial registration for " |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1145 | "stream %d", __FUNCTION__, bufferIdx, mId); |
| 1146 | goto cleanUpBuffers; |
| 1147 | } |
| 1148 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1149 | buffers[bufferIdx] = anwBuffers[bufferIdx]->handle; |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1150 | ALOGV("%s: Buffer %p allocated", __FUNCTION__, (void*)buffers[bufferIdx]); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
Eino-Ville Talvala | 750d74b | 2012-08-01 09:05:04 -0700 | [diff] [blame] | 1153 | ALOGV("%s: Registering %d buffers with camera HAL", __FUNCTION__, mTotalBuffers); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1154 | res = mHal2Device->ops->register_stream_buffers(mHal2Device, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1155 | mId, |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1156 | mTotalBuffers, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1157 | buffers); |
| 1158 | if (res != OK) { |
| 1159 | ALOGE("%s: Unable to register buffers with HAL device for stream %d", |
| 1160 | __FUNCTION__, mId); |
| 1161 | } else { |
| 1162 | mState = ACTIVE; |
| 1163 | } |
| 1164 | |
| 1165 | cleanUpBuffers: |
Eino-Ville Talvala | 750d74b | 2012-08-01 09:05:04 -0700 | [diff] [blame] | 1166 | ALOGV("%s: Cleaning up %d buffers", __FUNCTION__, bufferIdx); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1167 | for (uint32_t i = 0; i < bufferIdx; i++) { |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1168 | res = mConsumerInterface->cancelBuffer(mConsumerInterface.get(), |
Jamie Gennis | 1e5b2b3 | 2012-06-13 16:29:51 -0700 | [diff] [blame] | 1169 | anwBuffers[i], -1); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1170 | if (res != OK) { |
| 1171 | ALOGE("%s: Unable to cancel buffer %d after registration", |
| 1172 | __FUNCTION__, i); |
| 1173 | } |
| 1174 | } |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1175 | delete[] anwBuffers; |
| 1176 | delete[] buffers; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1177 | |
| 1178 | return res; |
| 1179 | } |
| 1180 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1181 | status_t Camera2Device::StreamAdapter::release() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1182 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1183 | status_t res; |
Eino-Ville Talvala | 02f8457 | 2013-04-23 15:16:57 -0700 | [diff] [blame] | 1184 | ALOGV("%s: Releasing stream %d (%d x %d, format %d)", __FUNCTION__, mId, |
| 1185 | mWidth, mHeight, mFormat); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1186 | if (mState >= ALLOCATED) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1187 | res = mHal2Device->ops->release_stream(mHal2Device, mId); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1188 | if (res != OK) { |
| 1189 | ALOGE("%s: Unable to release stream %d", |
| 1190 | __FUNCTION__, mId); |
| 1191 | return res; |
| 1192 | } |
| 1193 | } |
| 1194 | if (mState >= CONNECTED) { |
| 1195 | res = native_window_api_disconnect(mConsumerInterface.get(), |
| 1196 | NATIVE_WINDOW_API_CAMERA); |
Igor Murashkin | a1e5dcc | 2012-10-02 15:21:31 -0700 | [diff] [blame] | 1197 | |
| 1198 | /* this is not an error. if client calling process dies, |
| 1199 | the window will also die and all calls to it will return |
| 1200 | DEAD_OBJECT, thus it's already "disconnected" */ |
| 1201 | if (res == DEAD_OBJECT) { |
| 1202 | ALOGW("%s: While disconnecting stream %d from native window, the" |
| 1203 | " native window died from under us", __FUNCTION__, mId); |
| 1204 | } |
| 1205 | else if (res != OK) { |
| 1206 | ALOGE("%s: Unable to disconnect stream %d from native window (error %d %s)", |
| 1207 | __FUNCTION__, mId, res, strerror(-res)); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1208 | return res; |
| 1209 | } |
| 1210 | } |
| 1211 | mId = -1; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 1212 | mState = RELEASED; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1213 | return OK; |
| 1214 | } |
| 1215 | |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1216 | status_t Camera2Device::StreamAdapter::setTransform(int transform) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1217 | ATRACE_CALL(); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 1218 | status_t res; |
| 1219 | if (mState < CONNECTED) { |
| 1220 | ALOGE("%s: Cannot set transform on unconnected stream", __FUNCTION__); |
| 1221 | return INVALID_OPERATION; |
| 1222 | } |
| 1223 | res = native_window_set_buffers_transform(mConsumerInterface.get(), |
| 1224 | transform); |
| 1225 | if (res != OK) { |
| 1226 | ALOGE("%s: Unable to configure stream transform to %x: %s (%d)", |
| 1227 | __FUNCTION__, transform, strerror(-res), res); |
| 1228 | } |
| 1229 | return res; |
| 1230 | } |
| 1231 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1232 | status_t Camera2Device::StreamAdapter::dump(int fd, |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1233 | const Vector<String16>& /*args*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1234 | ATRACE_CALL(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1235 | String8 result = String8::format(" Stream %d: %d x %d, format 0x%x\n", |
| 1236 | mId, mWidth, mHeight, mFormat); |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 1237 | result.appendFormat(" size %zu, usage 0x%x, requested format 0x%x\n", |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1238 | mSize, mUsage, mFormatRequested); |
| 1239 | result.appendFormat(" total buffers: %d, dequeued buffers: %d\n", |
| 1240 | mTotalBuffers, mActiveBuffers); |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 1241 | result.appendFormat(" frame count: %d, last timestamp %" PRId64 "\n", |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1242 | mFrameCount, mLastTimestamp); |
| 1243 | write(fd, result.string(), result.size()); |
| 1244 | return OK; |
| 1245 | } |
| 1246 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1247 | const camera2_stream_ops *Camera2Device::StreamAdapter::getStreamOps() { |
| 1248 | return static_cast<camera2_stream_ops *>(this); |
| 1249 | } |
| 1250 | |
| 1251 | ANativeWindow* Camera2Device::StreamAdapter::toANW( |
| 1252 | const camera2_stream_ops_t *w) { |
| 1253 | return static_cast<const StreamAdapter*>(w)->mConsumerInterface.get(); |
| 1254 | } |
| 1255 | |
| 1256 | int Camera2Device::StreamAdapter::dequeue_buffer(const camera2_stream_ops_t *w, |
| 1257 | buffer_handle_t** buffer) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1258 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1259 | int res; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1260 | StreamAdapter* stream = |
| 1261 | const_cast<StreamAdapter*>(static_cast<const StreamAdapter*>(w)); |
| 1262 | if (stream->mState != ACTIVE) { |
| 1263 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, stream->mState); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1264 | return INVALID_OPERATION; |
| 1265 | } |
| 1266 | |
| 1267 | ANativeWindow *a = toANW(w); |
| 1268 | ANativeWindowBuffer* anb; |
Jamie Gennis | 1e5b2b3 | 2012-06-13 16:29:51 -0700 | [diff] [blame] | 1269 | res = native_window_dequeue_buffer_and_wait(a, &anb); |
Eino-Ville Talvala | 750d74b | 2012-08-01 09:05:04 -0700 | [diff] [blame] | 1270 | if (res != OK) { |
| 1271 | ALOGE("Stream %d dequeue: Error from native_window: %s (%d)", stream->mId, |
| 1272 | strerror(-res), res); |
| 1273 | return res; |
| 1274 | } |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1275 | |
| 1276 | *buffer = &(anb->handle); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1277 | stream->mActiveBuffers++; |
| 1278 | |
Eino-Ville Talvala | 750d74b | 2012-08-01 09:05:04 -0700 | [diff] [blame] | 1279 | ALOGVV("Stream %d dequeue: Buffer %p dequeued", stream->mId, (void*)(**buffer)); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1280 | return res; |
| 1281 | } |
| 1282 | |
| 1283 | int Camera2Device::StreamAdapter::enqueue_buffer(const camera2_stream_ops_t* w, |
| 1284 | int64_t timestamp, |
| 1285 | buffer_handle_t* buffer) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1286 | ATRACE_CALL(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1287 | StreamAdapter *stream = |
| 1288 | const_cast<StreamAdapter*>(static_cast<const StreamAdapter*>(w)); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1289 | stream->mFrameCount++; |
| 1290 | ALOGVV("Stream %d enqueue: Frame %d (%p) captured at %lld ns", |
James Dong | a289bf6 | 2012-09-05 16:46:36 -0700 | [diff] [blame] | 1291 | stream->mId, stream->mFrameCount, (void*)(*buffer), timestamp); |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1292 | int state = stream->mState; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1293 | if (state != ACTIVE) { |
| 1294 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, state); |
| 1295 | return INVALID_OPERATION; |
| 1296 | } |
| 1297 | ANativeWindow *a = toANW(w); |
| 1298 | status_t err; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 1299 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1300 | err = native_window_set_buffers_timestamp(a, timestamp); |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1301 | if (err != OK) { |
| 1302 | ALOGE("%s: Error setting timestamp on native window: %s (%d)", |
| 1303 | __FUNCTION__, strerror(-err), err); |
| 1304 | return err; |
| 1305 | } |
| 1306 | err = a->queueBuffer(a, |
Jamie Gennis | 1e5b2b3 | 2012-06-13 16:29:51 -0700 | [diff] [blame] | 1307 | container_of(buffer, ANativeWindowBuffer, handle), -1); |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1308 | if (err != OK) { |
| 1309 | ALOGE("%s: Error queueing buffer to native window: %s (%d)", |
| 1310 | __FUNCTION__, strerror(-err), err); |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1311 | return err; |
Eino-Ville Talvala | bd4976a | 2012-06-07 10:40:25 -0700 | [diff] [blame] | 1312 | } |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1313 | |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1314 | stream->mActiveBuffers--; |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1315 | stream->mLastTimestamp = timestamp; |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1316 | return OK; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | int Camera2Device::StreamAdapter::cancel_buffer(const camera2_stream_ops_t* w, |
| 1320 | buffer_handle_t* buffer) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1321 | ATRACE_CALL(); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1322 | StreamAdapter *stream = |
| 1323 | const_cast<StreamAdapter*>(static_cast<const StreamAdapter*>(w)); |
Eino-Ville Talvala | 750d74b | 2012-08-01 09:05:04 -0700 | [diff] [blame] | 1324 | ALOGVV("Stream %d cancel: Buffer %p", |
| 1325 | stream->mId, (void*)(*buffer)); |
Eino-Ville Talvala | 3297daa | 2012-06-14 10:49:45 -0700 | [diff] [blame] | 1326 | if (stream->mState != ACTIVE) { |
| 1327 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, stream->mState); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1328 | return INVALID_OPERATION; |
| 1329 | } |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1330 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1331 | ANativeWindow *a = toANW(w); |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1332 | int err = a->cancelBuffer(a, |
Jamie Gennis | 1e5b2b3 | 2012-06-13 16:29:51 -0700 | [diff] [blame] | 1333 | container_of(buffer, ANativeWindowBuffer, handle), -1); |
James Dong | 31d377b | 2012-08-09 17:43:46 -0700 | [diff] [blame] | 1334 | if (err != OK) { |
| 1335 | ALOGE("%s: Error canceling buffer to native window: %s (%d)", |
| 1336 | __FUNCTION__, strerror(-err), err); |
| 1337 | return err; |
| 1338 | } |
| 1339 | |
| 1340 | stream->mActiveBuffers--; |
| 1341 | return OK; |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | int Camera2Device::StreamAdapter::set_crop(const camera2_stream_ops_t* w, |
| 1345 | int left, int top, int right, int bottom) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1346 | ATRACE_CALL(); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 1347 | int state = static_cast<const StreamAdapter*>(w)->mState; |
| 1348 | if (state != ACTIVE) { |
| 1349 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, state); |
| 1350 | return INVALID_OPERATION; |
| 1351 | } |
| 1352 | ANativeWindow *a = toANW(w); |
| 1353 | android_native_rect_t crop = { left, top, right, bottom }; |
| 1354 | return native_window_set_crop(a, &crop); |
| 1355 | } |
| 1356 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1357 | /** |
| 1358 | * Camera2Device::ReprocessStreamAdapter |
| 1359 | */ |
| 1360 | |
| 1361 | #ifndef container_of |
| 1362 | #define container_of(ptr, type, member) \ |
| 1363 | (type *)((char*)(ptr) - offsetof(type, member)) |
| 1364 | #endif |
| 1365 | |
| 1366 | Camera2Device::ReprocessStreamAdapter::ReprocessStreamAdapter(camera2_device_t *d): |
| 1367 | mState(RELEASED), |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1368 | mHal2Device(d), |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1369 | mId(-1), |
| 1370 | mWidth(0), mHeight(0), mFormat(0), |
| 1371 | mActiveBuffers(0), |
| 1372 | mFrameCount(0) |
| 1373 | { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1374 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1375 | camera2_stream_in_ops::acquire_buffer = acquire_buffer; |
| 1376 | camera2_stream_in_ops::release_buffer = release_buffer; |
| 1377 | } |
| 1378 | |
| 1379 | Camera2Device::ReprocessStreamAdapter::~ReprocessStreamAdapter() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1380 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1381 | if (mState != RELEASED) { |
| 1382 | release(); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | status_t Camera2Device::ReprocessStreamAdapter::connectToDevice( |
| 1387 | const sp<StreamAdapter> &outputStream) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1388 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1389 | status_t res; |
| 1390 | ALOGV("%s: E", __FUNCTION__); |
| 1391 | |
| 1392 | if (mState != RELEASED) return INVALID_OPERATION; |
| 1393 | if (outputStream == NULL) { |
| 1394 | ALOGE("%s: Null base stream passed to reprocess stream adapter", |
| 1395 | __FUNCTION__); |
| 1396 | return BAD_VALUE; |
| 1397 | } |
| 1398 | |
| 1399 | mBaseStream = outputStream; |
| 1400 | mWidth = outputStream->getWidth(); |
| 1401 | mHeight = outputStream->getHeight(); |
| 1402 | mFormat = outputStream->getFormat(); |
| 1403 | |
| 1404 | ALOGV("%s: New reprocess stream parameters %d x %d, format 0x%x", |
| 1405 | __FUNCTION__, mWidth, mHeight, mFormat); |
| 1406 | |
| 1407 | // Allocate device-side stream interface |
| 1408 | |
| 1409 | uint32_t id; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1410 | res = mHal2Device->ops->allocate_reprocess_stream_from_stream(mHal2Device, |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1411 | outputStream->getId(), getStreamOps(), |
| 1412 | &id); |
| 1413 | if (res != OK) { |
| 1414 | ALOGE("%s: Device reprocess stream allocation failed: %s (%d)", |
| 1415 | __FUNCTION__, strerror(-res), res); |
| 1416 | return res; |
| 1417 | } |
| 1418 | |
| 1419 | ALOGV("%s: Allocated reprocess stream id %d based on stream %d", |
| 1420 | __FUNCTION__, id, outputStream->getId()); |
| 1421 | |
| 1422 | mId = id; |
| 1423 | |
| 1424 | mState = ACTIVE; |
| 1425 | |
| 1426 | return OK; |
| 1427 | } |
| 1428 | |
| 1429 | status_t Camera2Device::ReprocessStreamAdapter::release() { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1430 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1431 | status_t res; |
| 1432 | ALOGV("%s: Releasing stream %d", __FUNCTION__, mId); |
| 1433 | if (mState >= ACTIVE) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1434 | res = mHal2Device->ops->release_reprocess_stream(mHal2Device, mId); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1435 | if (res != OK) { |
| 1436 | ALOGE("%s: Unable to release stream %d", |
| 1437 | __FUNCTION__, mId); |
| 1438 | return res; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | List<QueueEntry>::iterator s; |
| 1443 | for (s = mQueue.begin(); s != mQueue.end(); s++) { |
| 1444 | sp<BufferReleasedListener> listener = s->releaseListener.promote(); |
| 1445 | if (listener != 0) listener->onBufferReleased(s->handle); |
| 1446 | } |
| 1447 | for (s = mInFlightQueue.begin(); s != mInFlightQueue.end(); s++) { |
| 1448 | sp<BufferReleasedListener> listener = s->releaseListener.promote(); |
| 1449 | if (listener != 0) listener->onBufferReleased(s->handle); |
| 1450 | } |
| 1451 | mQueue.clear(); |
| 1452 | mInFlightQueue.clear(); |
| 1453 | |
| 1454 | mState = RELEASED; |
| 1455 | return OK; |
| 1456 | } |
| 1457 | |
| 1458 | status_t Camera2Device::ReprocessStreamAdapter::pushIntoStream( |
| 1459 | buffer_handle_t *handle, const wp<BufferReleasedListener> &releaseListener) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1460 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1461 | // TODO: Some error checking here would be nice |
| 1462 | ALOGV("%s: Pushing buffer %p to stream", __FUNCTION__, (void*)(*handle)); |
| 1463 | |
| 1464 | QueueEntry entry; |
| 1465 | entry.handle = handle; |
| 1466 | entry.releaseListener = releaseListener; |
| 1467 | mQueue.push_back(entry); |
| 1468 | return OK; |
| 1469 | } |
| 1470 | |
| 1471 | status_t Camera2Device::ReprocessStreamAdapter::dump(int fd, |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1472 | const Vector<String16>& /*args*/) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1473 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1474 | String8 result = |
| 1475 | String8::format(" Reprocess stream %d: %d x %d, fmt 0x%x\n", |
| 1476 | mId, mWidth, mHeight, mFormat); |
| 1477 | result.appendFormat(" acquired buffers: %d\n", |
| 1478 | mActiveBuffers); |
| 1479 | result.appendFormat(" frame count: %d\n", |
| 1480 | mFrameCount); |
| 1481 | write(fd, result.string(), result.size()); |
| 1482 | return OK; |
| 1483 | } |
| 1484 | |
| 1485 | const camera2_stream_in_ops *Camera2Device::ReprocessStreamAdapter::getStreamOps() { |
| 1486 | return static_cast<camera2_stream_in_ops *>(this); |
| 1487 | } |
| 1488 | |
| 1489 | int Camera2Device::ReprocessStreamAdapter::acquire_buffer( |
| 1490 | const camera2_stream_in_ops_t *w, |
| 1491 | buffer_handle_t** buffer) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1492 | ATRACE_CALL(); |
Igor Murashkin | ebe3f69 | 2012-10-12 16:56:11 -0700 | [diff] [blame] | 1493 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1494 | ReprocessStreamAdapter* stream = |
| 1495 | const_cast<ReprocessStreamAdapter*>( |
| 1496 | static_cast<const ReprocessStreamAdapter*>(w)); |
| 1497 | if (stream->mState != ACTIVE) { |
| 1498 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, stream->mState); |
| 1499 | return INVALID_OPERATION; |
| 1500 | } |
| 1501 | |
| 1502 | if (stream->mQueue.empty()) { |
| 1503 | *buffer = NULL; |
| 1504 | return OK; |
| 1505 | } |
| 1506 | |
| 1507 | QueueEntry &entry = *(stream->mQueue.begin()); |
| 1508 | |
| 1509 | *buffer = entry.handle; |
| 1510 | |
| 1511 | stream->mInFlightQueue.push_back(entry); |
| 1512 | stream->mQueue.erase(stream->mQueue.begin()); |
| 1513 | |
| 1514 | stream->mActiveBuffers++; |
| 1515 | |
| 1516 | ALOGV("Stream %d acquire: Buffer %p acquired", stream->mId, |
| 1517 | (void*)(**buffer)); |
| 1518 | return OK; |
| 1519 | } |
| 1520 | |
| 1521 | int Camera2Device::ReprocessStreamAdapter::release_buffer( |
| 1522 | const camera2_stream_in_ops_t* w, |
| 1523 | buffer_handle_t* buffer) { |
Eino-Ville Talvala | 852c381 | 2012-09-24 09:46:53 -0700 | [diff] [blame] | 1524 | ATRACE_CALL(); |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1525 | ReprocessStreamAdapter *stream = |
| 1526 | const_cast<ReprocessStreamAdapter*>( |
| 1527 | static_cast<const ReprocessStreamAdapter*>(w) ); |
| 1528 | stream->mFrameCount++; |
| 1529 | ALOGV("Reprocess stream %d release: Frame %d (%p)", |
| 1530 | stream->mId, stream->mFrameCount, (void*)*buffer); |
| 1531 | int state = stream->mState; |
| 1532 | if (state != ACTIVE) { |
| 1533 | ALOGE("%s: Called when in bad state: %d", __FUNCTION__, state); |
| 1534 | return INVALID_OPERATION; |
| 1535 | } |
| 1536 | stream->mActiveBuffers--; |
| 1537 | |
| 1538 | List<QueueEntry>::iterator s; |
| 1539 | for (s = stream->mInFlightQueue.begin(); s != stream->mInFlightQueue.end(); s++) { |
| 1540 | if ( s->handle == buffer ) break; |
| 1541 | } |
| 1542 | if (s == stream->mInFlightQueue.end()) { |
| 1543 | ALOGE("%s: Can't find buffer %p in in-flight list!", __FUNCTION__, |
| 1544 | buffer); |
| 1545 | return INVALID_OPERATION; |
| 1546 | } |
| 1547 | |
| 1548 | sp<BufferReleasedListener> listener = s->releaseListener.promote(); |
| 1549 | if (listener != 0) { |
| 1550 | listener->onBufferReleased(s->handle); |
| 1551 | } else { |
| 1552 | ALOGE("%s: Can't free buffer - missing listener", __FUNCTION__); |
| 1553 | } |
| 1554 | stream->mInFlightQueue.erase(s); |
| 1555 | |
| 1556 | return OK; |
| 1557 | } |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1558 | |
| 1559 | }; // namespace android |