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