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> |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 25 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 26 | #include "impl/ACameraCaptureSession.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 27 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 28 | using namespace android::acam; |
| 29 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 30 | EXPORT |
| 31 | camera_status_t ACameraDevice_close(ACameraDevice* device) { |
| 32 | ATRACE_CALL(); |
| 33 | if (device == nullptr) { |
| 34 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 35 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 36 | } |
| 37 | delete device; |
| 38 | return ACAMERA_OK; |
| 39 | } |
| 40 | |
| 41 | EXPORT |
| 42 | const char* ACameraDevice_getId(const ACameraDevice* device) { |
| 43 | ATRACE_CALL(); |
| 44 | if (device == nullptr) { |
| 45 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 46 | return nullptr; |
| 47 | } |
| 48 | return device->getId(); |
| 49 | } |
| 50 | |
| 51 | EXPORT |
| 52 | camera_status_t ACameraDevice_createCaptureRequest( |
| 53 | const ACameraDevice* device, |
| 54 | ACameraDevice_request_template templateId, |
| 55 | ACaptureRequest** request) { |
| 56 | ATRACE_CALL(); |
| 57 | if (device == nullptr || request == nullptr) { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 58 | ALOGE("%s: invalid argument! device %p request %p", |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 59 | __FUNCTION__, device, request); |
| 60 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 61 | } |
Jyoti Bhayana | 3c6b7f3 | 2024-12-01 23:25:01 -0800 | [diff] [blame^] | 62 | if (device->isSharedMode() && !device->isPrimaryClient()) { |
| 63 | return ACAMERA_ERROR_UNSUPPORTED_OPERATION; |
| 64 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 65 | switch (templateId) { |
| 66 | case TEMPLATE_PREVIEW: |
| 67 | case TEMPLATE_STILL_CAPTURE: |
| 68 | case TEMPLATE_RECORD: |
| 69 | case TEMPLATE_VIDEO_SNAPSHOT: |
| 70 | case TEMPLATE_ZERO_SHUTTER_LAG: |
| 71 | case TEMPLATE_MANUAL: |
| 72 | break; |
| 73 | default: |
| 74 | ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId); |
| 75 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 76 | } |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 77 | return device->createCaptureRequest(templateId, nullptr /*physicalIdList*/, request); |
| 78 | } |
| 79 | |
| 80 | EXPORT |
| 81 | camera_status_t ACameraDevice_createCaptureRequest_withPhysicalIds( |
| 82 | const ACameraDevice* device, |
| 83 | ACameraDevice_request_template templateId, |
| 84 | const ACameraIdList* physicalCameraIdList, |
| 85 | ACaptureRequest** request) { |
| 86 | ATRACE_CALL(); |
| 87 | if (device == nullptr || request == nullptr || physicalCameraIdList == nullptr) { |
| 88 | ALOGE("%s: invalid argument! device %p request %p, physicalCameraIdList %p", |
| 89 | __FUNCTION__, device, request, physicalCameraIdList); |
| 90 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 91 | } |
Jyoti Bhayana | 3c6b7f3 | 2024-12-01 23:25:01 -0800 | [diff] [blame^] | 92 | if (device->isSharedMode() && !device->isPrimaryClient()) { |
| 93 | return ACAMERA_ERROR_UNSUPPORTED_OPERATION; |
| 94 | } |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 95 | switch (templateId) { |
| 96 | case TEMPLATE_PREVIEW: |
| 97 | case TEMPLATE_STILL_CAPTURE: |
| 98 | case TEMPLATE_RECORD: |
| 99 | case TEMPLATE_VIDEO_SNAPSHOT: |
| 100 | case TEMPLATE_ZERO_SHUTTER_LAG: |
| 101 | case TEMPLATE_MANUAL: |
| 102 | break; |
| 103 | default: |
| 104 | ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId); |
| 105 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 106 | } |
| 107 | return device->createCaptureRequest(templateId, physicalCameraIdList, request); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 110 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 111 | camera_status_t ACaptureSessionOutputContainer_create( |
| 112 | /*out*/ACaptureSessionOutputContainer** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 113 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 114 | if (out == nullptr) { |
| 115 | ALOGE("%s: Error: out null", __FUNCTION__); |
| 116 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 117 | } |
| 118 | *out = new ACaptureSessionOutputContainer(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 119 | return ACAMERA_OK; |
| 120 | } |
| 121 | |
| 122 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 123 | void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 124 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 125 | if (container != nullptr) { |
| 126 | delete container; |
| 127 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 128 | return; |
| 129 | } |
| 130 | |
| 131 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 132 | camera_status_t ACaptureSessionOutput_create( |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 133 | ANativeWindow* window, /*out*/ACaptureSessionOutput** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 134 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 135 | if (window == nullptr || out == nullptr) { |
| 136 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 137 | __FUNCTION__, window, out); |
| 138 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 139 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 140 | *out = new ACaptureSessionOutput(window, false); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 141 | return ACAMERA_OK; |
| 142 | } |
| 143 | |
| 144 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 145 | camera_status_t ACaptureSessionSharedOutput_create( |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 146 | ANativeWindow* window, /*out*/ACaptureSessionOutput** out) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 147 | ATRACE_CALL(); |
| 148 | if (window == nullptr || out == nullptr) { |
| 149 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 150 | __FUNCTION__, window, out); |
| 151 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 152 | } |
| 153 | *out = new ACaptureSessionOutput(window, true); |
| 154 | return ACAMERA_OK; |
| 155 | } |
| 156 | |
| 157 | EXPORT |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 158 | camera_status_t ACaptureSessionPhysicalOutput_create( |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 159 | ANativeWindow* window, const char* physicalId, |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 160 | /*out*/ACaptureSessionOutput** out) { |
| 161 | ATRACE_CALL(); |
| 162 | if (window == nullptr || physicalId == nullptr || out == nullptr) { |
| 163 | ALOGE("%s: Error: bad argument. window %p, physicalId %p, out %p", |
| 164 | __FUNCTION__, window, physicalId, out); |
| 165 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 166 | } |
| 167 | *out = new ACaptureSessionOutput(window, false, physicalId); |
| 168 | return ACAMERA_OK; |
| 169 | } |
| 170 | |
| 171 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 172 | camera_status_t ACaptureSessionSharedOutput_add(ACaptureSessionOutput *out, |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 173 | ANativeWindow* window) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 174 | ATRACE_CALL(); |
| 175 | if ((window == nullptr) || (out == nullptr)) { |
| 176 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 177 | __FUNCTION__, window, out); |
| 178 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 179 | } |
| 180 | if (!out->mIsShared) { |
| 181 | ALOGE("%s: Error trying to insert a new window in non-shared output configuration", |
| 182 | __FUNCTION__); |
| 183 | return ACAMERA_ERROR_INVALID_OPERATION; |
| 184 | } |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 185 | if (out->isWindowEqual(window)) { |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 186 | ALOGE("%s: Error trying to add the same window associated with the output configuration", |
| 187 | __FUNCTION__); |
| 188 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 189 | } |
| 190 | |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 191 | |
| 192 | bool insert = out->addSharedWindow(window); |
| 193 | camera_status_t ret = (insert) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | EXPORT |
| 198 | camera_status_t ACaptureSessionSharedOutput_remove(ACaptureSessionOutput *out, |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 199 | ANativeWindow* 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 | } |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 211 | if (out->isWindowEqual(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 | |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 217 | auto remove = out->removeSharedWindow(window); |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 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 | } |