Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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_NDEBUG 0 |
| 18 | #define LOG_TAG "NdkCameraDevice" |
| 19 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 20 | |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/Trace.h> |
| 23 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 24 | #include <camera/NdkCameraDevice.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 25 | #include "impl/ACameraCaptureSession.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 26 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 27 | using namespace android::acam; |
| 28 | |
| 29 | bool areWindowTypesEqual(ACameraWindowType *a, ACameraWindowType *b) { |
| 30 | #ifdef __ANDROID_VNDK__ |
| 31 | return utils::isWindowNativeHandleEqual(a, b); |
| 32 | #else |
| 33 | return a == b; |
| 34 | #endif |
| 35 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 36 | |
| 37 | EXPORT |
| 38 | camera_status_t ACameraDevice_close(ACameraDevice* device) { |
| 39 | ATRACE_CALL(); |
| 40 | if (device == nullptr) { |
| 41 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 42 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 43 | } |
| 44 | delete device; |
| 45 | return ACAMERA_OK; |
| 46 | } |
| 47 | |
| 48 | EXPORT |
| 49 | const char* ACameraDevice_getId(const ACameraDevice* device) { |
| 50 | ATRACE_CALL(); |
| 51 | if (device == nullptr) { |
| 52 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 53 | return nullptr; |
| 54 | } |
| 55 | return device->getId(); |
| 56 | } |
| 57 | |
| 58 | EXPORT |
| 59 | camera_status_t ACameraDevice_createCaptureRequest( |
| 60 | const ACameraDevice* device, |
| 61 | ACameraDevice_request_template templateId, |
| 62 | ACaptureRequest** request) { |
| 63 | ATRACE_CALL(); |
| 64 | if (device == nullptr || request == nullptr) { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 65 | ALOGE("%s: invalid argument! device %p request %p", |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 66 | __FUNCTION__, device, request); |
| 67 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 68 | } |
| 69 | switch (templateId) { |
| 70 | case TEMPLATE_PREVIEW: |
| 71 | case TEMPLATE_STILL_CAPTURE: |
| 72 | case TEMPLATE_RECORD: |
| 73 | case TEMPLATE_VIDEO_SNAPSHOT: |
| 74 | case TEMPLATE_ZERO_SHUTTER_LAG: |
| 75 | case TEMPLATE_MANUAL: |
| 76 | break; |
| 77 | default: |
| 78 | ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId); |
| 79 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 80 | } |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 81 | return device->createCaptureRequest(templateId, nullptr /*physicalIdList*/, request); |
| 82 | } |
| 83 | |
| 84 | EXPORT |
| 85 | camera_status_t ACameraDevice_createCaptureRequest_withPhysicalIds( |
| 86 | const ACameraDevice* device, |
| 87 | ACameraDevice_request_template templateId, |
| 88 | const ACameraIdList* physicalCameraIdList, |
| 89 | ACaptureRequest** request) { |
| 90 | ATRACE_CALL(); |
| 91 | if (device == nullptr || request == nullptr || physicalCameraIdList == nullptr) { |
| 92 | ALOGE("%s: invalid argument! device %p request %p, physicalCameraIdList %p", |
| 93 | __FUNCTION__, device, request, physicalCameraIdList); |
| 94 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 95 | } |
| 96 | switch (templateId) { |
| 97 | case TEMPLATE_PREVIEW: |
| 98 | case TEMPLATE_STILL_CAPTURE: |
| 99 | case TEMPLATE_RECORD: |
| 100 | case TEMPLATE_VIDEO_SNAPSHOT: |
| 101 | case TEMPLATE_ZERO_SHUTTER_LAG: |
| 102 | case TEMPLATE_MANUAL: |
| 103 | break; |
| 104 | default: |
| 105 | ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId); |
| 106 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 107 | } |
| 108 | return device->createCaptureRequest(templateId, physicalCameraIdList, request); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 111 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 112 | camera_status_t ACaptureSessionOutputContainer_create( |
| 113 | /*out*/ACaptureSessionOutputContainer** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 114 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 115 | if (out == nullptr) { |
| 116 | ALOGE("%s: Error: out null", __FUNCTION__); |
| 117 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 118 | } |
| 119 | *out = new ACaptureSessionOutputContainer(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 120 | return ACAMERA_OK; |
| 121 | } |
| 122 | |
| 123 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 124 | void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 125 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 126 | if (container != nullptr) { |
| 127 | delete container; |
| 128 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 129 | return; |
| 130 | } |
| 131 | |
| 132 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 133 | camera_status_t ACaptureSessionOutput_create( |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 134 | ACameraWindowType* window, /*out*/ACaptureSessionOutput** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 135 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 136 | if (window == nullptr || out == nullptr) { |
| 137 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 138 | __FUNCTION__, window, out); |
| 139 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 140 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 141 | *out = new ACaptureSessionOutput(window, false); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 142 | return ACAMERA_OK; |
| 143 | } |
| 144 | |
| 145 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 146 | camera_status_t ACaptureSessionSharedOutput_create( |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 147 | ACameraWindowType* window, /*out*/ACaptureSessionOutput** out) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 148 | ATRACE_CALL(); |
| 149 | if (window == nullptr || out == nullptr) { |
| 150 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 151 | __FUNCTION__, window, out); |
| 152 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 153 | } |
| 154 | *out = new ACaptureSessionOutput(window, true); |
| 155 | return ACAMERA_OK; |
| 156 | } |
| 157 | |
| 158 | EXPORT |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 159 | camera_status_t ACaptureSessionPhysicalOutput_create( |
| 160 | ACameraWindowType* window, const char* physicalId, |
| 161 | /*out*/ACaptureSessionOutput** out) { |
| 162 | ATRACE_CALL(); |
| 163 | if (window == nullptr || physicalId == nullptr || out == nullptr) { |
| 164 | ALOGE("%s: Error: bad argument. window %p, physicalId %p, out %p", |
| 165 | __FUNCTION__, window, physicalId, out); |
| 166 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 167 | } |
| 168 | *out = new ACaptureSessionOutput(window, false, physicalId); |
| 169 | return ACAMERA_OK; |
| 170 | } |
| 171 | |
| 172 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 173 | camera_status_t ACaptureSessionSharedOutput_add(ACaptureSessionOutput *out, |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 174 | ACameraWindowType* window) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 175 | ATRACE_CALL(); |
| 176 | if ((window == nullptr) || (out == nullptr)) { |
| 177 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 178 | __FUNCTION__, window, out); |
| 179 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 180 | } |
| 181 | if (!out->mIsShared) { |
| 182 | ALOGE("%s: Error trying to insert a new window in non-shared output configuration", |
| 183 | __FUNCTION__); |
| 184 | return ACAMERA_ERROR_INVALID_OPERATION; |
| 185 | } |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 186 | if (areWindowTypesEqual(out->mWindow, window)) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 187 | ALOGE("%s: Error trying to add the same window associated with the output configuration", |
| 188 | __FUNCTION__); |
| 189 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 190 | } |
| 191 | |
| 192 | auto insert = out->mSharedWindows.insert(window); |
| 193 | camera_status_t ret = (insert.second) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER; |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | EXPORT |
| 198 | camera_status_t ACaptureSessionSharedOutput_remove(ACaptureSessionOutput *out, |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 199 | ACameraWindowType* window) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 200 | ATRACE_CALL(); |
| 201 | if ((window == nullptr) || (out == nullptr)) { |
| 202 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 203 | __FUNCTION__, window, out); |
| 204 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 205 | } |
| 206 | if (!out->mIsShared) { |
| 207 | ALOGE("%s: Error trying to remove a window in non-shared output configuration", |
| 208 | __FUNCTION__); |
| 209 | return ACAMERA_ERROR_INVALID_OPERATION; |
| 210 | } |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 211 | if (areWindowTypesEqual(out->mWindow, window)) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 212 | ALOGE("%s: Error trying to remove the same window associated with the output configuration", |
| 213 | __FUNCTION__); |
| 214 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 215 | } |
| 216 | |
| 217 | auto remove = out->mSharedWindows.erase(window); |
| 218 | camera_status_t ret = (remove) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER; |
| 219 | return ret; |
| 220 | } |
| 221 | |
| 222 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 223 | void ACaptureSessionOutput_free(ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 224 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 225 | if (output != nullptr) { |
| 226 | delete output; |
| 227 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 228 | return; |
| 229 | } |
| 230 | |
| 231 | EXPORT |
| 232 | camera_status_t ACaptureSessionOutputContainer_add( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 233 | ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 234 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 235 | if (container == nullptr || output == nullptr) { |
| 236 | ALOGE("%s: Error: invalid input: container %p, output %p", |
| 237 | __FUNCTION__, container, output); |
| 238 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 239 | } |
| 240 | auto pair = container->mOutputs.insert(*output); |
| 241 | if (!pair.second) { |
| 242 | ALOGW("%s: output %p already exists!", __FUNCTION__, output); |
| 243 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 244 | return ACAMERA_OK; |
| 245 | } |
| 246 | |
| 247 | EXPORT |
| 248 | camera_status_t ACaptureSessionOutputContainer_remove( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 249 | ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 250 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 251 | if (container == nullptr || output == nullptr) { |
| 252 | ALOGE("%s: Error: invalid input: container %p, output %p", |
| 253 | __FUNCTION__, container, output); |
| 254 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 255 | } |
| 256 | container->mOutputs.erase(*output); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 257 | return ACAMERA_OK; |
| 258 | } |
| 259 | |
| 260 | EXPORT |
| 261 | camera_status_t ACameraDevice_createCaptureSession( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 262 | ACameraDevice* device, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 263 | const ACaptureSessionOutputContainer* outputs, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 264 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 265 | /*out*/ACameraCaptureSession** session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 266 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 267 | if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) { |
| 268 | ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p", |
| 269 | __FUNCTION__, device, outputs, callbacks, session); |
| 270 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 271 | } |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 272 | return device->createCaptureSession(outputs, nullptr, callbacks, session); |
| 273 | } |
| 274 | |
| 275 | EXPORT |
| 276 | camera_status_t ACameraDevice_createCaptureSessionWithSessionParameters( |
| 277 | ACameraDevice* device, |
| 278 | const ACaptureSessionOutputContainer* outputs, |
| 279 | const ACaptureRequest* sessionParameters, |
| 280 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 281 | /*out*/ACameraCaptureSession** session) { |
| 282 | ATRACE_CALL(); |
| 283 | if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) { |
| 284 | ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p", |
| 285 | __FUNCTION__, device, outputs, callbacks, session); |
| 286 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 287 | } |
| 288 | return device->createCaptureSession(outputs, sessionParameters, callbacks, session); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 289 | } |
Shuzhen Wang | 24810e7 | 2019-03-18 10:55:01 -0700 | [diff] [blame] | 290 | |
| 291 | EXPORT |
| 292 | camera_status_t ACameraDevice_isSessionConfigurationSupported( |
| 293 | const ACameraDevice* device, |
| 294 | const ACaptureSessionOutputContainer* sessionOutputContainer) { |
| 295 | ATRACE_CALL(); |
| 296 | if (device == nullptr || sessionOutputContainer == nullptr) { |
| 297 | ALOGE("%s: Error: invalid input: device %p, sessionOutputContainer %p", |
| 298 | __FUNCTION__, device, sessionOutputContainer); |
| 299 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 300 | } |
| 301 | return device->isSessionConfigurationSupported(sessionOutputContainer); |
| 302 | } |